Skip to content

Merge 2.9 release with master #2174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void shareScreen(Bitmap bitmap) {
* which then calls parseJson when results are fetched
*/
private void setAchievements() {
progressBar.setVisibility(View.VISIBLE);
if (checkAccount()) {
compositeDisposable.add(mediaWikiApi
.getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name)
Expand All @@ -195,17 +196,23 @@ private void setAchievements() {
if (response != null) {
setUploadCount(Achievements.from(response));
} else {
onError();
showSnackBarWithRetry();
}
},
t -> {
Timber.e(t, "Fetching achievements statistics failed");
onError();
showSnackBarWithRetry();
}
));
}
}

private void showSnackBarWithRetry() {
progressBar.setVisibility(View.GONE);
ViewUtil.showDismissibleSnackBar(findViewById(android.R.id.content),
R.string.achievements_fetch_failed, R.string.retry, view -> setAchievements());
}

/**
* Shows a generic error toast when error occurs while loading achievements or uploads
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void showBlockStatus()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.filter(result -> result)
.subscribe(result -> ViewUtil.showSnackbar(findViewById(android.R.id.content), R.string.block_notification)
.subscribe(result -> ViewUtil.showShortSnackbar(findViewById(android.R.id.content), R.string.block_notification)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ List<Media> loadBookmarkedPictures() {
for (Bookmark bookmark : bookmarks) {
List<Media> tmpMedias = mediaWikiApi.searchImages(bookmark.getMediaName(), 0);
for (Media m : tmpMedias) {
if (m.getCreator().equals(bookmark.getMediaCreator())) {
if (m.getCreator().trim().equals(bookmark.getMediaCreator().trim())) {
medias.add(m);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void handleNoInternet() {
statusTextView.setVisibility(VISIBLE);
statusTextView.setText(getString(R.string.no_internet));
} else {
ViewUtil.showSnackbar(parentLayout, R.string.no_internet);
ViewUtil.showShortSnackbar(parentLayout, R.string.no_internet);
}
}

Expand All @@ -140,7 +140,7 @@ private void handleNoInternet() {
private void handleError(Throwable throwable) {
Timber.e(throwable, "Error occurred while loading images inside a category");
try{
ViewUtil.showSnackbar(parentLayout, R.string.error_loading_images);
ViewUtil.showShortSnackbar(parentLayout, R.string.error_loading_images);
initErrorView();
}catch (Exception e){
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void handleNoInternet() {
statusTextView.setVisibility(VISIBLE);
statusTextView.setText(getString(R.string.no_internet));
} else {
ViewUtil.showSnackbar(parentLayout, R.string.no_internet);
ViewUtil.showShortSnackbar(parentLayout, R.string.no_internet);
}
}

Expand All @@ -135,7 +135,7 @@ private void handleNoInternet() {
private void handleError(Throwable throwable) {
Timber.e(throwable, "Error occurred while loading images inside a category");
try{
ViewUtil.showSnackbar(parentLayout, R.string.error_loading_images);
ViewUtil.showShortSnackbar(parentLayout, R.string.error_loading_images);
initErrorView();
}catch (Exception e){
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ private void handleSuccess(List<String> subCategoryList) {
private void handleError(Throwable throwable) {
if (!isParentCategory){
Timber.e(throwable, "Error occurred while loading queried subcategories");
ViewUtil.showSnackbar(categoriesRecyclerView,R.string.error_loading_categories);
ViewUtil.showShortSnackbar(categoriesRecyclerView,R.string.error_loading_categories);
}else {
Timber.e(throwable, "Error occurred while loading queried parentcategories");
ViewUtil.showSnackbar(categoriesRecyclerView,R.string.error_loading_categories);
ViewUtil.showShortSnackbar(categoriesRecyclerView,R.string.error_loading_categories);
}
}

Expand All @@ -161,6 +161,6 @@ private void initEmptyView() {
*/
private void handleNoInternet() {
progressBar.setVisibility(GONE);
ViewUtil.showSnackbar(categoriesRecyclerView, R.string.no_internet);
ViewUtil.showShortSnackbar(categoriesRecyclerView, R.string.no_internet);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.free.nrw.commons.contributions;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -119,22 +120,19 @@ private void addTabsAndFragments() {

// Set custom view to add nearby info icon next to text
View nearbyTabLinearLayout = LayoutInflater.from(this).inflate(R.layout.custom_nearby_tab_layout, null);
View nearbyInfoPopupWindowLayout = LayoutInflater.from(this).inflate(R.layout.nearby_info_popup_layout, null);
ImageView nearbyInfo = nearbyTabLinearLayout.findViewById(R.id.nearby_info_image);
tabLayout.getTabAt(1).setCustomView(nearbyTabLinearLayout);

nearbyInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*new AlertDialog.Builder(MainActivity.this)
new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.title_activity_nearby)
.setMessage(R.string.showcase_view_whole_nearby_activity)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();*/
String popupText = getResources().getString(R.string.showcase_view_whole_nearby_activity);
ViewUtil.displayPopupWindow(nearbyInfo, MainActivity.this, nearbyInfoPopupWindowLayout, popupText);
.show();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.File;

import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;

Expand All @@ -30,9 +31,11 @@ public class NetworkingModule {
@Singleton
public OkHttpClient provideOkHttpClient(Context context) {
File dir = new File(context.getCacheDir(), "okHttpCache");
return new OkHttpClient.Builder()
.cache(new Cache(dir, OK_HTTP_CACHE_SIZE))
.build();
return new OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.cache(new Cache(dir, OK_HTTP_CACHE_SIZE))
.build();
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void handleError(Throwable throwable) {
Timber.e(throwable, "Error occurred while loading queried categories");
try {
initErrorView();
ViewUtil.showSnackbar(categoriesRecyclerView, R.string.error_loading_categories);
ViewUtil.showShortSnackbar(categoriesRecyclerView, R.string.error_loading_categories);
}catch (Exception e){
e.printStackTrace();
}
Expand All @@ -217,6 +217,6 @@ private void initErrorView() {
*/
private void handleNoInternet() {
progressBar.setVisibility(GONE);
ViewUtil.showSnackbar(categoriesRecyclerView, R.string.no_internet);
ViewUtil.showShortSnackbar(categoriesRecyclerView, R.string.no_internet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void handleSuccess(List<Media> mediaList) {
private void handleError(Throwable throwable) {
Timber.e(throwable, "Error occurred while loading queried images");
try {
ViewUtil.showSnackbar(imagesRecyclerView, R.string.error_loading_images);
ViewUtil.showShortSnackbar(imagesRecyclerView, R.string.error_loading_images);
}catch (Exception e){
e.printStackTrace();
}
Expand All @@ -226,7 +226,7 @@ private void initErrorView() {
*/
private void handleNoInternet() {
progressBar.setVisibility(GONE);
ViewUtil.showSnackbar(imagesRecyclerView, R.string.no_internet);
ViewUtil.showShortSnackbar(imagesRecyclerView, R.string.no_internet);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear(); // see http://stackoverflow.com/a/8495697/17865
inflater.inflate(R.menu.fragment_image_detail, menu);
if (pager != null) {
MediaDetailProvider provider = (MediaDetailProvider) getParentFragment();
MediaDetailProvider provider = getMediaDetailProvider();
if(provider == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public MediaResult fetchMediaByFilename(String filename) throws IOException {
@Override
@NonNull
public Observable<String> searchCategories(String filterValue, int searchCatsLimit) {
List<String> categories = new ArrayList<>();
return Single.fromCallable(() -> {
List<CustomApiResult> categoryNodes = null;
try {
Expand All @@ -370,11 +371,12 @@ public Observable<String> searchCategories(String filterValue, int searchCatsLim
return new ArrayList<String>();
}

List<String> categories = new ArrayList<>();
for (CustomApiResult categoryNode : categoryNodes) {
String cat = categoryNode.getDocument().getTextContent();
String catString = cat.replace("Category:", "");
categories.add(catString);
if (!categories.contains(catString)) {
categories.add(catString);
}
}

return categories;
Expand Down
23 changes: 16 additions & 7 deletions app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
Expand All @@ -38,6 +37,7 @@
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener;
import fr.free.nrw.commons.utils.FragmentUtils;
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.utils.UriSerializer;
import fr.free.nrw.commons.utils.ViewUtil;
Expand Down Expand Up @@ -116,7 +116,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
resumeFragment();*/
bundle = new Bundle();
initBottomSheetBehaviour();
wikidataEditListener.setAuthenticationStateListener(this);
this.view = view;
return view;
}
Expand Down Expand Up @@ -387,7 +386,7 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
String gsonBoundaryCoordinates = gson.toJson(boundaryCoordinates);

if (placeList.size() == 0) {
ViewUtil.showSnackbar(view.findViewById(R.id.container), R.string.no_nearby);
ViewUtil.showShortSnackbar(view.findViewById(R.id.container), R.string.no_nearby);
}

bundle.putString("PlaceList", gsonPlaceList);
Expand Down Expand Up @@ -673,14 +672,17 @@ private void showErrorMessage(String message) {
}

private void addNetworkBroadcastReceiver() {
if (!FragmentUtils.isFragmentUIActive(this)) {
return;
}

IntentFilter intentFilter = new IntentFilter(NETWORK_INTENT_ACTION);
snackbar = Snackbar.make(transparentView , R.string.no_internet, Snackbar.LENGTH_INDEFINITE);

broadcastReceiver = new BroadcastReceiver() {
snackbar = Snackbar.make(transparentView, R.string.no_internet, Snackbar.LENGTH_INDEFINITE);

broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (snackbar != null) {
if (snackbar != null && getActivity() != null) {
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
snackbar.dismiss();
Expand All @@ -691,6 +693,10 @@ public void onReceive(Context context, Intent intent) {
}
};

if (getActivity() == null) {
return;
}

getActivity().registerReceiver(broadcastReceiver, intentFilter);

}
Expand Down Expand Up @@ -723,6 +729,7 @@ private void performNearbyOperations() {
@Override
public void onAttach(Context context) {
super.onAttach(context);
wikidataEditListener.setAuthenticationStateListener(this);
}

@Override
Expand All @@ -731,6 +738,7 @@ public void onDestroy() {
if (placesDisposable != null) {
placesDisposable.dispose();
}
wikidataEditListener.setAuthenticationStateListener(null);
if (placesDisposableCustom != null) {
placesDisposableCustom.dispose();
}
Expand All @@ -741,6 +749,7 @@ public void onDetach() {
super.onDetach();
snackbar = null;
broadcastReceiver = null;
wikidataEditListener.setAuthenticationStateListener(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void addNotifications() {
progressBar.setVisibility(View.GONE);
}, throwable -> {
Timber.e(throwable, "Error occurred while loading notifications");
ViewUtil.showSnackbar(relativeLayout, R.string.error_notifications);
ViewUtil.showShortSnackbar(relativeLayout, R.string.error_notifications);
progressBar.setVisibility(View.GONE);
});
} else {
Expand All @@ -123,7 +123,7 @@ private void handleUrl(String url) {

private void setAdapter(List<Notification> notificationList) {
if (notificationList == null || notificationList.isEmpty()) {
ViewUtil.showSnackbar(relativeLayout, R.string.no_notifications);
ViewUtil.showShortSnackbar(relativeLayout, R.string.no_notifications);
return;
}
notificationAdapterFactory = new NotificationAdapterFactory(notification -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ public static boolean addAndCommitFragmentWithImmediateExecution(
}
return false;
}

/**
* Utility function to check whether the fragment UI is still active or not
* @param fragment
* @return
*/
public static boolean isFragmentUIActive(Fragment fragment) {
return fragment.getActivity() != null && fragment.isAdded() && !fragment.isDetached() && !fragment.isRemoving();
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/utils/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public static boolean isInternetConnectionEstablished(Context context) {
ConnectivityManager cm =
(ConnectivityManager)context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);

if (cm == null) {
return false;
}
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
Expand Down
Loading