From c7b7522edd1c453b9254331694f805320cdda99c Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Thu, 6 Dec 2018 14:17:27 +0300 Subject: [PATCH 1/4] Add a boolean to enable refresh after orientation changed --- .../java/fr/free/nrw/commons/nearby/NearbyFragment.java | 3 +-- .../fr/free/nrw/commons/nearby/NearbyMapFragment.java | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java index 58943b0b5c..f3e2011406 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java @@ -428,8 +428,7 @@ private void lockNearbyView(boolean lock) { } private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { - - if (nearbyMapFragment.searchThisAreaModeOn) { + if (nearbyMapFragment.checkingAround) { return; } /* diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java index 6e92c9da23..98dfcf8709 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java @@ -130,6 +130,7 @@ public class NearbyMapFragment extends DaggerFragment { private boolean isMapReady; public boolean searchThisAreaModeOn = false; + public boolean checkingAround = false; private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location private boolean searchedAroundCurrentLocation = true; @@ -556,6 +557,7 @@ public void onCameraMove() { , NearbyController.currentLocation.getLongitude())); if (distance > NearbyController.searchedRadius*1000*3/4) { //Convert to meter, and compare if our distance is bigger than 3/4 or our searched area + checkingAround = true; if (!searchThisAreaModeOn) { // If we are changing mode, then change click action searchThisAreaModeOn = true; searchThisAreaButton.setOnClickListener(new View.OnClickListener() { @@ -575,6 +577,7 @@ public void onClick(View view) { } } else { + checkingAround = false; if (searchThisAreaModeOn) { searchThisAreaModeOn = false; // This flag will help us to understand should we folor users location or not searchThisAreaButton.setOnClickListener(new View.OnClickListener() { @@ -1002,6 +1005,12 @@ public void onResume() { if (mapView != null) { mapView.onResume(); } + if (mapboxMap != null) { + mapboxMap.getUiSettings().setAllGesturesEnabled(true); + } + searchThisAreaModeOn = false; + checkingAround = false; + searchedAroundCurrentLocation = true; initViews(); setListeners(); transparentView.setClickable(false); From b180824382cd53342b55d3f527a9e0a00936c53e Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Fri, 7 Dec 2018 17:12:37 +0300 Subject: [PATCH 2/4] Prevent unnecessary refreshview calls --- .../nrw/commons/nearby/NearbyFragment.java | 47 +++++++++++++++---- .../nrw/commons/nearby/NearbyMapFragment.java | 1 + 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java index f3e2011406..39a1baf33d 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java @@ -99,6 +99,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment private boolean onOrientationChanged = false; private boolean populateForCurrentLocation = false; + private boolean isNetworkErrorOccured = false; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -126,7 +127,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); if (savedInstanceState != null) { onOrientationChanged = true; - refreshView(LOCATION_SIGNIFICANTLY_CHANGED); + Log.d("deneme","onViewCreated"); + //refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } } @@ -218,17 +220,22 @@ public void prepareViewsForSheetPosition(int bottomSheetState) { @Override public void onLocationChangedSignificantly(LatLng latLng) { + Log.d("deneme","onLocationChangedSignificantly"); refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } @Override public void onLocationChangedSlightly(LatLng latLng) { - refreshView(LOCATION_SLIGHTLY_CHANGED); + Log.d("deneme","onLocationChangedSlightly"); + + refreshView(LOCATION_SLIGHTLY_CHANGED); } @Override public void onLocationChangedMedium(LatLng latLng) { + Log.d("deneme","onLocationChangedMedium"); + // For nearby map actions, there are no differences between 500 meter location change (aka medium change) and slight change refreshView(LOCATION_SLIGHTLY_CHANGED); } @@ -237,6 +244,7 @@ public void onLocationChangedMedium(LatLng latLng) { public void onWikidataEditSuccessful() { // Do not refresh nearby map if we are checking other areas with search this area button if (!nearbyMapFragment.searchThisAreaModeOn) { + Log.d("deneme","onWikidateEditSuccesful"); refreshView(MAP_UPDATED); } } @@ -247,6 +255,7 @@ public void onWikidataEditSuccessful() { * @param locationChangeType defines if location shanged significantly or slightly */ public void refreshView(LocationServiceManager.LocationChangeType locationChangeType) { + Log.d("deneme","refreshView"); Timber.d("Refreshing nearby places"); if (lockNearbyView) { return; @@ -298,6 +307,7 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange bundle.clear(); bundle.putString("CurLatLng", gsonCurLatLng); + Log.d("deneme","popuate places is called from here"); placesDisposable = Observable.fromCallable(() -> nearbyController .loadAttractionsFromLocation(curLatLng, curLatLng, false, true)) .subscribeOn(Schedulers.io()) @@ -331,7 +341,7 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange * @param customLatLng Custom area which we will search around */ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) { - + Log.d("deneme","refreshViewForCutomLocatiom"); if (customLatLng == null) { // If null, return return; @@ -360,6 +370,7 @@ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshFor * @param nearbyPlacesInfo This variable has place list information and distances. */ private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { + Log.d("deneme","populatePlacesFromCustomLocation"); //NearbyMapFragment nearbyMapFragment = getMapFragment(); if (nearbyMapFragment != null) { nearbyMapFragment.searchThisAreaButtonProgressBar.setVisibility(View.GONE); @@ -376,6 +387,8 @@ private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo } private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { + Log.d("deneme","populatePlaces"); + Timber.d("Populating nearby places"); List placeList = nearbyPlacesInfo.placeList; LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates; @@ -428,6 +441,9 @@ private void lockNearbyView(boolean lock) { } private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { + Log.d("deneme","update Map fragment"+" updateViaButton:"+updateViaButton+", isSlightUpdate:"+isSlightUpdate); + Log.d("deneme","update Map fragment status"+" checking around:"+nearbyMapFragment.checkingAround+", searchThisAreaModeOn:"+nearbyMapFragment.searchThisAreaModeOn+", onOrientationChanged:"+onOrientationChanged); + if (nearbyMapFragment.checkingAround) { return; } @@ -446,11 +462,15 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, * If we are close to nearby places boundaries, we need a significant update to * get new nearby places. Check order is south, north, west, east * */ - if (nearbyMapFragment.boundaryCoordinates != null && !nearbyMapFragment.searchThisAreaModeOn - && (curLatLng.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude() - || curLatLng.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude() - || curLatLng.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude() - || curLatLng.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) { + if (nearbyMapFragment.boundaryCoordinates != null + && !nearbyMapFragment.checkingAround + && !nearbyMapFragment.searchThisAreaModeOn + && !onOrientationChanged + && (curLatLng.getLatitude() < nearbyMapFragment.boundaryCoordinates[0].getLatitude() + || curLatLng.getLatitude() > nearbyMapFragment.boundaryCoordinates[1].getLatitude() + || curLatLng.getLongitude() < nearbyMapFragment.boundaryCoordinates[2].getLongitude() + || curLatLng.getLongitude() > nearbyMapFragment.boundaryCoordinates[3].getLongitude())) { + Log.d("deneme","boundary is working"); // populate places placesDisposable = Observable.fromCallable(() -> nearbyController .loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton)) @@ -637,6 +657,7 @@ private void checkLocationPermission() { Timber.d("Checking location permission"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (locationManager.isLocationPermissionGranted()) { + Log.d("deneme","Check location permission if"); refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } else { // Should we show an explanation? @@ -663,6 +684,7 @@ private void checkLocationPermission() { } } } else { + Log.d("deneme","Check location permission else"); refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } } @@ -681,9 +703,16 @@ private void addNetworkBroadcastReceiver() { public void onReceive(Context context, Intent intent) { if (snackbar != null) { if (NetworkUtils.isInternetConnectionEstablished(getActivity())) { - refreshView(LOCATION_SIGNIFICANTLY_CHANGED); + Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())"); + if (isNetworkErrorOccured) { + Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())"); + Log.d("deneme","isNetworkErrorOccured refreshed"); + refreshView(LOCATION_SIGNIFICANTLY_CHANGED); + isNetworkErrorOccured = false; + } snackbar.dismiss(); } else { + isNetworkErrorOccured = true; snackbar.show(); } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java index 98dfcf8709..49004fd3b2 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java @@ -1011,6 +1011,7 @@ public void onResume() { searchThisAreaModeOn = false; checkingAround = false; searchedAroundCurrentLocation = true; + boundaryCoordinates = null; initViews(); setListeners(); transparentView.setClickable(false); From ccd9e8672cd7decebc6dea06e70961cb0e8ff6e8 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Fri, 7 Dec 2018 17:42:40 +0300 Subject: [PATCH 3/4] Remove unnecessary performNearbyOperations call on orientation changed. --- .../java/fr/free/nrw/commons/contributions/MainActivity.java | 5 ++--- .../main/java/fr/free/nrw/commons/nearby/NearbyFragment.java | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) 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 9b8035e5d5..2f24362aad 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 @@ -83,9 +83,9 @@ public void onCreate(Bundle savedInstanceState) { onOrientationChanged = true; // Will be used in nearby fragment to determine significant update of map //If nearby map was visible, call on Tab Selected to call all nearby operations - if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) { + /*if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) { ((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged); - } + }*/ } } @@ -187,7 +187,6 @@ public void onPageSelected(int position) { updateMenuItem(); // Do all permission and GPS related tasks on tab selected, not on create ((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged); - break; default: tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select(); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java index 39a1baf33d..86ab2761f7 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java @@ -731,6 +731,7 @@ public void onResume() { } public void onTabSelected(boolean onOrientationChanged) { + Log.d("deneme***","onTabSelected"); Timber.d("On nearby tab selected"); this.onOrientationChanged = onOrientationChanged; performNearbyOperations(); From 520c303b53a2925490e2e93e2087d3f1c87b7f01 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Fri, 7 Dec 2018 17:45:13 +0300 Subject: [PATCH 4/4] Remove dabug logs --- .../commons/contributions/MainActivity.java | 2 +- .../nrw/commons/nearby/NearbyFragment.java | 24 ------------------- 2 files changed, 1 insertion(+), 25 deletions(-) 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 2f24362aad..5d1bf7a2ad 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 @@ -186,7 +186,7 @@ public void onPageSelected(int position) { isContributionsFragmentVisible = false; updateMenuItem(); // Do all permission and GPS related tasks on tab selected, not on create - ((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged); + ((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged); break; default: tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select(); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java index 86ab2761f7..f326c78855 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java @@ -127,8 +127,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); if (savedInstanceState != null) { onOrientationChanged = true; - Log.d("deneme","onViewCreated"); - //refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } } @@ -220,22 +218,17 @@ public void prepareViewsForSheetPosition(int bottomSheetState) { @Override public void onLocationChangedSignificantly(LatLng latLng) { - Log.d("deneme","onLocationChangedSignificantly"); refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } @Override public void onLocationChangedSlightly(LatLng latLng) { - Log.d("deneme","onLocationChangedSlightly"); - refreshView(LOCATION_SLIGHTLY_CHANGED); } @Override public void onLocationChangedMedium(LatLng latLng) { - Log.d("deneme","onLocationChangedMedium"); - // For nearby map actions, there are no differences between 500 meter location change (aka medium change) and slight change refreshView(LOCATION_SLIGHTLY_CHANGED); } @@ -244,7 +237,6 @@ public void onLocationChangedMedium(LatLng latLng) { public void onWikidataEditSuccessful() { // Do not refresh nearby map if we are checking other areas with search this area button if (!nearbyMapFragment.searchThisAreaModeOn) { - Log.d("deneme","onWikidateEditSuccesful"); refreshView(MAP_UPDATED); } } @@ -255,7 +247,6 @@ public void onWikidataEditSuccessful() { * @param locationChangeType defines if location shanged significantly or slightly */ public void refreshView(LocationServiceManager.LocationChangeType locationChangeType) { - Log.d("deneme","refreshView"); Timber.d("Refreshing nearby places"); if (lockNearbyView) { return; @@ -307,7 +298,6 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange bundle.clear(); bundle.putString("CurLatLng", gsonCurLatLng); - Log.d("deneme","popuate places is called from here"); placesDisposable = Observable.fromCallable(() -> nearbyController .loadAttractionsFromLocation(curLatLng, curLatLng, false, true)) .subscribeOn(Schedulers.io()) @@ -341,7 +331,6 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange * @param customLatLng Custom area which we will search around */ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) { - Log.d("deneme","refreshViewForCutomLocatiom"); if (customLatLng == null) { // If null, return return; @@ -370,7 +359,6 @@ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshFor * @param nearbyPlacesInfo This variable has place list information and distances. */ private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { - Log.d("deneme","populatePlacesFromCustomLocation"); //NearbyMapFragment nearbyMapFragment = getMapFragment(); if (nearbyMapFragment != null) { nearbyMapFragment.searchThisAreaButtonProgressBar.setVisibility(View.GONE); @@ -387,8 +375,6 @@ private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo } private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { - Log.d("deneme","populatePlaces"); - Timber.d("Populating nearby places"); List placeList = nearbyPlacesInfo.placeList; LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates; @@ -441,9 +427,6 @@ private void lockNearbyView(boolean lock) { } private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { - Log.d("deneme","update Map fragment"+" updateViaButton:"+updateViaButton+", isSlightUpdate:"+isSlightUpdate); - Log.d("deneme","update Map fragment status"+" checking around:"+nearbyMapFragment.checkingAround+", searchThisAreaModeOn:"+nearbyMapFragment.searchThisAreaModeOn+", onOrientationChanged:"+onOrientationChanged); - if (nearbyMapFragment.checkingAround) { return; } @@ -470,7 +453,6 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, || curLatLng.getLatitude() > nearbyMapFragment.boundaryCoordinates[1].getLatitude() || curLatLng.getLongitude() < nearbyMapFragment.boundaryCoordinates[2].getLongitude() || curLatLng.getLongitude() > nearbyMapFragment.boundaryCoordinates[3].getLongitude())) { - Log.d("deneme","boundary is working"); // populate places placesDisposable = Observable.fromCallable(() -> nearbyController .loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton)) @@ -657,7 +639,6 @@ private void checkLocationPermission() { Timber.d("Checking location permission"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (locationManager.isLocationPermissionGranted()) { - Log.d("deneme","Check location permission if"); refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } else { // Should we show an explanation? @@ -684,7 +665,6 @@ private void checkLocationPermission() { } } } else { - Log.d("deneme","Check location permission else"); refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } } @@ -703,10 +683,7 @@ private void addNetworkBroadcastReceiver() { public void onReceive(Context context, Intent intent) { if (snackbar != null) { if (NetworkUtils.isInternetConnectionEstablished(getActivity())) { - Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())"); if (isNetworkErrorOccured) { - Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())"); - Log.d("deneme","isNetworkErrorOccured refreshed"); refreshView(LOCATION_SIGNIFICANTLY_CHANGED); isNetworkErrorOccured = false; } @@ -731,7 +708,6 @@ public void onResume() { } public void onTabSelected(boolean onOrientationChanged) { - Log.d("deneme***","onTabSelected"); Timber.d("On nearby tab selected"); this.onOrientationChanged = onOrientationChanged; performNearbyOperations();