From 05e98307be89b2a04a57287750deca50f265cd22 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Tue, 4 Feb 2020 14:35:29 +0530 Subject: [PATCH] Fixes #3303 (#3322) * Fixes #3303 * Refactor Nearby to alig lifecycle methods * Pass updated place list to listfragment * Added default zoom rate to mapbox * Removed NearbyListFragmet and added the ui login to handle the same in NearbyParentFragment * More code refactor * Make BottomSheetList hideable * onFragmentHide, hide the bottom sheets * BigFix, Fragmet visibility, register/un-register camera move based on fragments lifecycke * More code refactor * Let the ExecutorUtil have non-ui thread * Add Location Marker on non-ui thread (the non-ui stuffs) * BugFixes * Removed configchanges "orientation" from MainActivity in Manifest (That was messing with the fragment lifecycle) * Some null checks * Initialise lastknown location in onMapReady * UI Fixes * Adjusted UI to support dark and no-dark themes both (in nearby) * Do not update map on Location Slightly changed * Fix failing test case, let TestCommonsApplication extend Application instead of CommonsApplication * start map view when nearby is visible * start the map when NearbyFragmet is visible * More bugfixes * Added DUMMY view for NearbyPresenter's onDetach State * Added a wrapper frame layout parent for MapView to preven it from drawing above other views * More bugfixes (Fixes #3287) * Gray out the un-selected markers from the nearby filter list * BugFix, search this area should search the nearby places for the current camera position * More BugFixes * Handle null primitives with proxy * Current location marker flow via permission flow * onCameraMove should have null-check on NearbyController.latestSearchLocation instead of currentLocation * Search for places around last focus location * Handle location updates * If the user is browsing the map, donot update the map with current location --- app/build.gradle | 3 +- app/src/main/AndroidManifest.xml | 2 +- .../free/nrw/commons/CommonsApplication.java | 2 + .../commons/contributions/MainActivity.java | 17 +- .../nrw/commons/di/FragmentBuilderModule.java | 8 - .../nrw/commons/nearby/CheckBoxTriStates.java | 14 +- .../commons/nearby/NearbyAdapterFactory.java | 4 - ...NearbyFilterSearchRecyclerViewAdapter.java | 25 +- .../nrw/commons/nearby/PlaceRenderer.java | 7 +- .../nearby/contract/NearbyMapContract.java | 36 - .../NearbyParentFragmentContract.java | 51 +- .../nearby/fragments/NearbyListFragment.java | 104 --- .../nearby/fragments/NearbyMapFragment.java | 596 ------------ .../fragments/NearbyParentFragment.java | 874 +++++++++++++----- .../NearbyParentFragmentPresenter.java | 278 +++--- .../free/nrw/commons/utils/ExecutorUtils.java | 9 + app/src/main/res/layout-v21/drawer_view.xml | 10 + .../main/res/layout/bottom_sheet_details.xml | 2 +- .../main/res/layout/bottom_sheet_nearby.xml | 57 +- app/src/main/res/layout/drawer_view.xml | 1 + .../main/res/layout/fragment_nearby_list.xml | 1 + .../res/layout/fragment_nearby_parent.xml | 24 +- .../res/layout/nearby_search_list_item.xml | 11 +- .../layout/nearby_search_list_item_dark.xml | 19 + app/src/main/res/values/strings.xml | 2 +- 25 files changed, 909 insertions(+), 1248 deletions(-) delete mode 100644 app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyMapContract.java create mode 100644 app/src/main/res/layout-v21/drawer_view.xml create mode 100644 app/src/main/res/layout/nearby_search_list_item_dark.xml diff --git a/app/build.gradle b/app/build.gradle index 36280e48a0..c2e618c177 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,7 +36,7 @@ dependencies { implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar' implementation 'com.github.chrisbanes:PhotoView:2.0.0' implementation 'com.github.pedrovgs:renderers:3.3.3' - implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.2.0' + implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.1' implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.7.0' implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0' implementation 'com.dinuscxj:circleprogressbar:1.1.1' @@ -102,6 +102,7 @@ dependencies { //swipe_layout implementation 'com.daimajia.swipelayout:library:1.2.0@aar' + implementation 'com.squareup.retrofit2:retrofit:2.7.1' } android { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ad88b720cf..458db48be3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -78,7 +78,7 @@ android:name=".contributions.MainActivity" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:configChanges="orientation|screenSize|keyboard" /> + android:configChanges="screenSize|keyboard" /> diff --git a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java index 2efc433001..c0bc11ba92 100644 --- a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java +++ b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java @@ -19,6 +19,7 @@ import com.facebook.imagepipeline.producers.FetchState; import com.facebook.imagepipeline.producers.NetworkFetcher; import com.facebook.imagepipeline.producers.ProducerContext; +import com.mapbox.mapboxsdk.Mapbox; import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.RefWatcher; @@ -134,6 +135,7 @@ public void onCreate() { INSTANCE = this; ACRA.init(this); + Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token)); ApplicationlessInjection .getInstance(this) diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java index 67e67fbf3b..1d1e560d38 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java @@ -35,7 +35,6 @@ import fr.free.nrw.commons.location.LocationServiceManager; import fr.free.nrw.commons.nearby.NearbyNotificationCardView; import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment; -import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter; import fr.free.nrw.commons.notification.Notification; import fr.free.nrw.commons.notification.NotificationActivity; import fr.free.nrw.commons.notification.NotificationController; @@ -78,6 +77,7 @@ public class MainActivity extends NavigationBaseActivity implements FragmentMana private MenuItem notificationsMenuItem; private TextView notificationCount; + private NearbyParentFragment nearbyParentFragment; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -188,8 +188,6 @@ public void onPageSelected(int position) { tabLayout.getTabAt(NEARBY_TAB_POSITION).select(); isContributionsFragmentVisible = false; updateMenuItem(); - // Do all permission and GPS related tasks on tab selected, not on create - NearbyParentFragmentPresenter.getInstance().onTabSelected(); break; default: tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select(); @@ -265,7 +263,9 @@ public void onBackPressed() { } } else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) { // Means that nearby fragment is visible (not contributions fragment) - NearbyParentFragmentPresenter.getInstance().backButtonClicked(); + if (null != nearbyParentFragment) { + nearbyParentFragment.backButtonClicked(); + } } else { super.onBackPressed(); } @@ -380,12 +380,13 @@ public Fragment getItem(int position) { } case 1: - NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1); - if (retainedNearbyFragment != null) { - return retainedNearbyFragment; + nearbyParentFragment = getNearbyFragment(1); + if (nearbyParentFragment != null) { + return nearbyParentFragment; } else { // If we reach here, retainedNearbyFragment is null - return new NearbyParentFragment(); + nearbyParentFragment=new NearbyParentFragment(); + return nearbyParentFragment; } default: return null; diff --git a/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java b/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java index 15b8e6026c..e2be74d0f4 100644 --- a/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java +++ b/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java @@ -13,8 +13,6 @@ import fr.free.nrw.commons.explore.recentsearches.RecentSearchesFragment; import fr.free.nrw.commons.media.MediaDetailFragment; import fr.free.nrw.commons.media.MediaDetailPagerFragment; -import fr.free.nrw.commons.nearby.fragments.NearbyListFragment; -import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment; import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment; import fr.free.nrw.commons.review.ReviewImageFragment; import fr.free.nrw.commons.settings.SettingsFragment; @@ -40,9 +38,6 @@ public abstract class FragmentBuilderModule { @ContributesAndroidInjector abstract MediaDetailPagerFragment bindMediaDetailPagerFragment(); - @ContributesAndroidInjector - abstract NearbyListFragment bindNearbyListFragment(); - @ContributesAndroidInjector abstract SettingsFragment bindSettingsFragment(); @@ -64,9 +59,6 @@ public abstract class FragmentBuilderModule { @ContributesAndroidInjector abstract ContributionsFragment bindContributionsFragment(); - @ContributesAndroidInjector - abstract NearbyMapFragment bindNearbyMapFragment(); - @ContributesAndroidInjector abstract NearbyParentFragment bindNearbyParentFragment(); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java b/app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java index d95c1dd163..e8fc70873d 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java @@ -9,6 +9,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatCheckBox; +import java.util.List; + import fr.free.nrw.commons.R; import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter; @@ -25,6 +27,16 @@ public class CheckBoxTriStates extends AppCompatCheckBox { private int state; + private Callback callback; + + public interface Callback{ + void filterByMarkerType(@Nullable List