Merge 2.9 release with master (#2174)

* Fix memory leak due to wikidata edit listener (#2048)

* Fix bookmark crash fix (#2047)

* Fix bookmark crash fix

* Fix check for bookmark creator

* Bug fix #2042 (#2056)

* Bug fix #2042
* Added a snack with retry when api in AA fails
* Increased connection timeouts in okhttpclient builder

* added missing string resource

* Bugfix/duplicate categories (#2080)

* Increased timeout to 60 seconds

* Bug fix #1550
* filter duplicate categories

* Fix crash because of inactive fragment UI (#2046)

* Fix crash because of inactive fragment UI

* Add java docs

* Add information icon action Fiixes #2055 2.9.0: the 'i' icon in nearby doesn't do anything (#2057)

* Localisation updates from https://translatewiki.net.

* Remove unused mediawiki api dependency (#1991)

* Categories with pipe suffix (#1873)

* Bug fix issue #1826
Changes made :
-Certain category names used to show suffixed with strings prefixed with pipe '|'. Removed everything after the pipe. As per the discussion on the thread, its safe to remove everything after the pipe, including the pipe

* review suggested changes
*Code formatting
*Extracted out the index of pipe in a variable
*Added issue link in comments

* Remove libraries section from README (#1988)

* Remove libraries section from README

* Add wiki link to "libraries used" to README

* Localisation updates from https://translatewiki.net.

* Localisation updates from https://translatewiki.net.

* Use alert dialog instead of popup window, for nearby information

* Revert irrelevant changes, sorry
This commit is contained in:
Vivek Maskara 2018-12-19 22:29:49 +05:30 committed by neslihanturan
parent 21edcb7cbe
commit f3b450e020
19 changed files with 91 additions and 65 deletions

View file

@ -185,6 +185,7 @@ public class AchievementsActivity extends NavigationBaseActivity {
* 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)
@ -195,17 +196,23 @@ public class AchievementsActivity extends NavigationBaseActivity {
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
*/

View file

@ -64,7 +64,7 @@ public abstract class AuthenticatedActivity extends NavigationBaseActivity {
.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)
);
}
}

View file

@ -36,7 +36,7 @@ public class BookmarkPicturesController {
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;
}

View file

@ -129,7 +129,7 @@ public class BookmarkPicturesFragment extends DaggerFragment {
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);
}
}
@ -140,7 +140,7 @@ public class BookmarkPicturesFragment extends DaggerFragment {
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();

View file

@ -124,7 +124,7 @@ public class CategoryImagesListFragment extends DaggerFragment {
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);
}
}
@ -135,7 +135,7 @@ public class CategoryImagesListFragment extends DaggerFragment {
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();

View file

@ -135,10 +135,10 @@ public class SubCategoryListFragment extends CommonsDaggerSupportFragment {
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);
}
}
@ -161,6 +161,6 @@ public class SubCategoryListFragment extends CommonsDaggerSupportFragment {
*/
private void handleNoInternet() {
progressBar.setVisibility(GONE);
ViewUtil.showSnackbar(categoriesRecyclerView, R.string.no_internet);
ViewUtil.showShortSnackbar(categoriesRecyclerView, R.string.no_internet);
}
}

View file

@ -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;
@ -119,22 +120,19 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
// 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();
}
});

View file

@ -9,6 +9,7 @@ import com.google.gson.GsonBuilder;
import java.io.File;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
@ -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

View file

@ -196,7 +196,7 @@ public class SearchCategoryFragment extends CommonsDaggerSupportFragment {
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();
}
@ -217,6 +217,6 @@ public class SearchCategoryFragment extends CommonsDaggerSupportFragment {
*/
private void handleNoInternet() {
progressBar.setVisibility(GONE);
ViewUtil.showSnackbar(categoriesRecyclerView, R.string.no_internet);
ViewUtil.showShortSnackbar(categoriesRecyclerView, R.string.no_internet);
}
}

View file

@ -206,7 +206,7 @@ public class SearchImageFragment extends CommonsDaggerSupportFragment {
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();
}
@ -226,7 +226,7 @@ public class SearchImageFragment extends CommonsDaggerSupportFragment {
*/
private void handleNoInternet() {
progressBar.setVisibility(GONE);
ViewUtil.showSnackbar(imagesRecyclerView, R.string.no_internet);
ViewUtil.showShortSnackbar(imagesRecyclerView, R.string.no_internet);
}
/**

View file

@ -261,7 +261,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
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;
}

View file

@ -355,6 +355,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
@Override
@NonNull
public Observable<String> searchCategories(String filterValue, int searchCatsLimit) {
List<String> categories = new ArrayList<>();
return Single.fromCallable(() -> {
List<CustomApiResult> categoryNodes = null;
try {
@ -375,11 +376,12 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
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;

View file

@ -16,7 +16,6 @@ import android.support.v4.app.FragmentTransaction;
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;
@ -38,6 +37,7 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
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;
@ -116,7 +116,6 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
resumeFragment();*/
bundle = new Bundle();
initBottomSheetBehaviour();
wikidataEditListener.setAuthenticationStateListener(this);
this.view = view;
return view;
}
@ -387,7 +386,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
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);
@ -673,14 +672,17 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
}
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();
@ -691,6 +693,10 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
}
};
if (getActivity() == null) {
return;
}
getActivity().registerReceiver(broadcastReceiver, intentFilter);
}
@ -723,6 +729,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
@Override
public void onAttach(Context context) {
super.onAttach(context);
wikidataEditListener.setAuthenticationStateListener(this);
}
@Override
@ -731,6 +738,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
if (placesDisposable != null) {
placesDisposable.dispose();
}
wikidataEditListener.setAuthenticationStateListener(null);
if (placesDisposableCustom != null) {
placesDisposableCustom.dispose();
}
@ -741,6 +749,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
super.onDetach();
snackbar = null;
broadcastReceiver = null;
wikidataEditListener.setAuthenticationStateListener(null);
}
@Override

View file

@ -106,7 +106,7 @@ public class NotificationActivity extends NavigationBaseActivity {
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 {
@ -123,7 +123,7 @@ public class NotificationActivity extends NavigationBaseActivity {
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 -> {

View file

@ -28,4 +28,13 @@ public class FragmentUtils {
}
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();
}
}

View file

@ -11,6 +11,9 @@ public class NetworkUtils {
ConnectivityManager cm =
(ConnectivityManager)context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) {
return false;
}
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();

View file

@ -17,7 +17,12 @@ public class ViewUtil {
public static final String SHOWCASE_VIEW_ID_2 = "SHOWCASE_VIEW_ID_2";
public static final String SHOWCASE_VIEW_ID_3 = "SHOWCASE_VIEW_ID_3";
public static void showSnackbar(View view, int messageResourceId) {
/**
* Utility function to show short snack bar
* @param view
* @param messageResourceId
*/
public static void showShortSnackbar(View view, int messageResourceId) {
if (view.getContext() == null) {
return;
}
@ -76,15 +81,23 @@ public class ViewUtil {
}
}
public static void displayPopupWindow(View anchorView, Context context, View popupWindowLayout, String text) {
PopupWindow popup = new PopupWindow(context);
popup.setContentView(popupWindowLayout);
// Closes the popup window when touch outside of it - when looses focus
popup.setOutsideTouchable(true);
popup.setFocusable(true);
// Show anchored to button
popup.showAsDropDown(anchorView);
/**
* A snack bar which has an action button which on click dismisses the snackbar and invokes the
* listener passed
*/
public static void showDismissibleSnackBar(View view, int messageResourceId,
int actionButtonResourceId, View.OnClickListener onClickListener) {
if (view.getContext() == null) {
return;
}
ExecutorUtils.uiExecutor().execute(() -> {
Snackbar snackbar = Snackbar.make(view, view.getContext().getString(messageResourceId),
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(view.getContext().getString(actionButtonResourceId), v -> {
snackbar.dismiss();
onClickListener.onClick(v);
});
snackbar.show();
});
}
}

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/mainTabBackground"
>
<TextView
android:id="@+id/info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="16dp"
android:layout_marginHorizontal="8dp"
android:gravity="center"
android:textColor="@color/white"
android:text="@string/showcase_view_whole_nearby_activity" />
</LinearLayout>

View file

@ -437,6 +437,7 @@ Upload your first media by touching the camera or gallery icon above.</string>
<string name="never_ask_again">Never ask this again</string>
<string name="display_location_permission_title">Display location permission</string>
<string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string>
<string name="achievements_fetch_failed">Something went wrong, We could not fetch your achievements</string>
<string name="ends_on">Ends on:</string>
<string name="display_campaigns">Display campaigns</string>
<string name="display_campaigns_explanation">Tap here to see the ongoing campaigns</string>