From 7080c3a94376e13fb9cdd25b9253618dfa0b6609 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Wed, 22 May 2019 21:30:23 +0300 Subject: [PATCH] Make sure updateMAoAndList method is called when everything ready --- .../contributions/ContributionsFragment.java | 6 +++--- .../commons/contributions/MainActivity.java | 4 ++-- .../location/LocationServiceManager.java | 4 +++- .../nrw/commons/nearby/NearbyFragment.java | 4 ++-- .../mvp/fragments/NearbyMapFragment.java | 2 +- .../mvp/fragments/NearbyParentFragment.java | 21 +++++++++++-------- .../NearbyParentFragmentPresenter.java | 14 +++++++++---- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java index 6f95581b5..0359e8f98 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java @@ -359,7 +359,7 @@ public class ContributionsFragment if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Timber.d("Location permission granted, refreshing view"); // No need to display permission request button anymore - locationManager.registerLocationManager(); + locationManager.registerLocationManager(getActivity()); } else { if (store.getBoolean("displayLocationPermissionForCardView", true)) { // Still ask for permission @@ -535,7 +535,7 @@ public class ContributionsFragment if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (locationManager.isLocationPermissionGranted(requireContext())) { nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.NO_PERMISSION_NEEDED; - locationManager.registerLocationManager(); + locationManager.registerLocationManager(getActivity()); } else { nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_LOCATION_PERMISSION; // If user didn't selected Don't ask again @@ -553,7 +553,7 @@ public class ContributionsFragment } else { // If device is under Marshmallow, we already checked for GPS nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.NO_PERMISSION_NEEDED; - locationManager.registerLocationManager(); + locationManager.registerLocationManager(getActivity()); } } 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 abf3e778c..bd9fbf00d 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 @@ -408,7 +408,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag } case 1: - Log.d("deneme","case 1"); + Log.d("deneme1","case 1"); NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1); if (retainedNearbyFragment != null) { return retainedNearbyFragment; @@ -480,7 +480,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Timber.d("Location permission given"); ((ContributionsFragment)contributionsActivityPagerAdapter - .getItem(0)).locationManager.registerLocationManager(); + .getItem(0)).locationManager.registerLocationManager(this); } else { // If nearby fragment is visible and location permission is not given, send user back to contrib fragment if (!isContributionsFragmentVisible) { diff --git a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java index 68b7c742d..107df0b14 100644 --- a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java +++ b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java @@ -9,6 +9,7 @@ import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; +import android.util.Log; import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; @@ -126,7 +127,8 @@ public class LocationServiceManager implements LocationListener { /** * Registers a LocationManager to listen for current location. */ - public void registerLocationManager() { + public void registerLocationManager(Context context) { + Log.d("deneme1","registerLocationManager2"); if (!isLocationManagerRegistered) { isLocationManagerRegistered = requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER) && requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER); 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 100ca733b..adf217bff 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 @@ -570,7 +570,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment private void registerLocationUpdates() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (locationManager.isLocationPermissionGranted(requireContext())) { - locationManager.registerLocationManager(); + locationManager.registerLocationManager(getActivity()); } else { // Should we show an explanation? if (locationManager.isPermissionExplanationRequired(getActivity())) { @@ -593,7 +593,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment } } } else { - locationManager.registerLocationManager(); + locationManager.registerLocationManager(getActivity()); } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java index 84d846263..cec3aa505 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java @@ -223,7 +223,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N @Override public void setViewsAreReady(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) { - Log.d("deneme","setViewsAreReady"); + Log.d("deneme1","setViewsAreReady"); this.viewsAreReadyCallback = viewsAreReadyCallback; this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady(); } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java index a54130659..2180f34f0 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java @@ -98,7 +98,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); - Log.d("deneme","onCreate"); + Log.d("deneme1","onCreate"); } @@ -108,7 +108,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment View view = inflater.inflate(R.layout.fragment_nearby, container, false); ButterKnife.bind(this, view); this.view = view; - Log.d("deneme","onCreateView"); + Log.d("deneme1","onCreateView"); return view; } @@ -124,7 +124,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment * it is attached. */ public void childMapFragmentAttached() { - Log.d("deneme","childMapFragmentAttached"); + Log.d("deneme1","childMapFragmentAttached"); nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter (this, nearbyMapFragment, locationManager); } @@ -146,7 +146,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment * Resume fragments if they exists */ private void resumeFragment() { - Log.d("deneme","resumeFragment"); + Log.d("deneme1","resumeFragment"); // Find the retained fragment on activity restarts nearbyMapFragment = getMapFragment(); nearbyListFragment = getListFragment(); @@ -181,17 +181,17 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment @Override public void onLocationChangedSignificantly(LatLng latLng) { - Log.d("deneme","location changed significantly"); + Log.d("deneme1","location changed significantly"); } @Override public void onLocationChangedSlightly(LatLng latLng) { - Log.d("deneme","location changed significantly"); + Log.d("deneme1","location changed significantly"); } @Override public void onLocationChangedMedium(LatLng latLng) { - Log.d("deneme","location changed significantly"); + Log.d("deneme1","location changed significantly"); } @Override @@ -217,9 +217,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment */ @Override public void registerLocationUpdates(LocationServiceManager locationServiceManager) { + Log.d("deneme1","registerLocationUpdates"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (locationServiceManager.isLocationPermissionGranted(requireContext())) { - locationServiceManager.registerLocationManager(); + locationServiceManager.registerLocationManager(getActivity()); } else { // Should we show an explanation? if (locationServiceManager.isPermissionExplanationRequired(getActivity())) { @@ -242,7 +243,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } } } else { - locationServiceManager.registerLocationManager(); + locationServiceManager.registerLocationManager(getActivity()); } } @@ -286,6 +287,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment */ @Override public void checkGps(LocationServiceManager locationServiceManager) { + Log.d("deneme1","checkGPS"); Timber.d("checking GPS"); if (!locationServiceManager.isProviderEnabled()) { Timber.d("GPS is not enabled"); @@ -319,6 +321,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment */ @Override public void checkLocationPermission(LocationServiceManager locationServiceManager) { + Log.d("deneme1","checkLocationPermission"); Timber.d("Checking location permission"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (locationServiceManager.isLocationPermissionGranted(requireContext())) { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java index 132deb215..cb704a381 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java @@ -50,7 +50,7 @@ public class NearbyParentFragmentPresenter */ @Override public void onTabSelected() { - Log.d("deneme","onTabSelected"); + Log.d("deneme1","onTabSelected"); onTabSelected = true; if (nearbyViewsAreReady) { initializeNearbyOperations(); @@ -63,7 +63,7 @@ public class NearbyParentFragmentPresenter */ @Override public void nearbyFragmentAndMapViewReady() { - Log.d("deneme","nearbyFragmentAndMapViewReady"); + Log.d("deneme1","nearbyFragmentAndMapViewReady"); nearbyViewsAreReady = true; if (onTabSelected) { initializeNearbyOperations(); @@ -76,9 +76,11 @@ public class NearbyParentFragmentPresenter */ @Override public void initializeNearbyOperations() { - Log.d("deneme","initializeNearbyOperations"); + Log.d("deneme1","initializeNearbyOperations"); locationServiceManager.addLocationListener(this); nearbyParentFragmentView.registerLocationUpdates(locationServiceManager); + Log.d("deneme1","initializeNearbyOperations2"); + // Nearby buttons should be active, they should be deactive only during update lockNearby(false); //This will start a consequence to check GPS depending on different API @@ -111,6 +113,7 @@ public class NearbyParentFragmentPresenter */ @Override public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType) { + Log.d("deneme1","updateMapAndList"); if (isNearbyLocked) { Timber.d("Nearby is locked, so updateMapAndList returns"); return; @@ -123,6 +126,7 @@ public class NearbyParentFragmentPresenter //nearbyParentFragmentView.registerLocationUpdates(locationServiceManager); LatLng lastLocation = locationServiceManager.getLastLocation(); + Log.d("deneme1","locationServiceManager.getLastLocation():"+locationServiceManager.getLastLocation().toString()); if (curLatLng != null) { // TODO figure out what is happening here about orientation change @@ -155,17 +159,19 @@ public class NearbyParentFragmentPresenter @Override public void onLocationChangedSignificantly(LatLng latLng) { + Log.d("deneme1","onLocationChangedSignificantly"); } @Override public void onLocationChangedSlightly(LatLng latLng) { + Log.d("deneme1","onLocationChangedSlightly"); } @Override public void onLocationChangedMedium(LatLng latLng) { - + Log.d("deneme1","onLocationChangedMedium"); } }