Make sure updateMAoAndList method is called when everything ready

This commit is contained in:
neslihanturan 2019-05-22 21:30:23 +03:00
parent 771a9ecda3
commit 7080c3a943
7 changed files with 33 additions and 22 deletions

View file

@ -359,7 +359,7 @@ public class ContributionsFragment
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Timber.d("Location permission granted, refreshing view"); Timber.d("Location permission granted, refreshing view");
// No need to display permission request button anymore // No need to display permission request button anymore
locationManager.registerLocationManager(); locationManager.registerLocationManager(getActivity());
} else { } else {
if (store.getBoolean("displayLocationPermissionForCardView", true)) { if (store.getBoolean("displayLocationPermissionForCardView", true)) {
// Still ask for permission // Still ask for permission
@ -535,7 +535,7 @@ public class ContributionsFragment
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (locationManager.isLocationPermissionGranted(requireContext())) { if (locationManager.isLocationPermissionGranted(requireContext())) {
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.NO_PERMISSION_NEEDED; nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.NO_PERMISSION_NEEDED;
locationManager.registerLocationManager(); locationManager.registerLocationManager(getActivity());
} else { } else {
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_LOCATION_PERMISSION; nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_LOCATION_PERMISSION;
// If user didn't selected Don't ask again // If user didn't selected Don't ask again
@ -553,7 +553,7 @@ public class ContributionsFragment
} else { } else {
// If device is under Marshmallow, we already checked for GPS // If device is under Marshmallow, we already checked for GPS
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.NO_PERMISSION_NEEDED; nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.NO_PERMISSION_NEEDED;
locationManager.registerLocationManager(); locationManager.registerLocationManager(getActivity());
} }
} }

View file

@ -408,7 +408,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
} }
case 1: case 1:
Log.d("deneme","case 1"); Log.d("deneme1","case 1");
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1); NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
if (retainedNearbyFragment != null) { if (retainedNearbyFragment != null) {
return retainedNearbyFragment; return retainedNearbyFragment;
@ -480,7 +480,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Timber.d("Location permission given"); Timber.d("Location permission given");
((ContributionsFragment)contributionsActivityPagerAdapter ((ContributionsFragment)contributionsActivityPagerAdapter
.getItem(0)).locationManager.registerLocationManager(); .getItem(0)).locationManager.registerLocationManager(this);
} else { } else {
// If nearby fragment is visible and location permission is not given, send user back to contrib fragment // If nearby fragment is visible and location permission is not given, send user back to contrib fragment
if (!isContributionsFragmentVisible) { if (!isContributionsFragmentVisible) {

View file

@ -9,6 +9,7 @@ import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
@ -126,7 +127,8 @@ public class LocationServiceManager implements LocationListener {
/** /**
* Registers a LocationManager to listen for current location. * Registers a LocationManager to listen for current location.
*/ */
public void registerLocationManager() { public void registerLocationManager(Context context) {
Log.d("deneme1","registerLocationManager2");
if (!isLocationManagerRegistered) { if (!isLocationManagerRegistered) {
isLocationManagerRegistered = requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER) isLocationManagerRegistered = requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER)
&& requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER); && requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER);

View file

@ -570,7 +570,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
private void registerLocationUpdates() { private void registerLocationUpdates() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (locationManager.isLocationPermissionGranted(requireContext())) { if (locationManager.isLocationPermissionGranted(requireContext())) {
locationManager.registerLocationManager(); locationManager.registerLocationManager(getActivity());
} else { } else {
// Should we show an explanation? // Should we show an explanation?
if (locationManager.isPermissionExplanationRequired(getActivity())) { if (locationManager.isPermissionExplanationRequired(getActivity())) {
@ -593,7 +593,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
} }
} }
} else { } else {
locationManager.registerLocationManager(); locationManager.registerLocationManager(getActivity());
} }
} }

View file

@ -223,7 +223,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
@Override @Override
public void setViewsAreReady(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) { public void setViewsAreReady(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
Log.d("deneme","setViewsAreReady"); Log.d("deneme1","setViewsAreReady");
this.viewsAreReadyCallback = viewsAreReadyCallback; this.viewsAreReadyCallback = viewsAreReadyCallback;
this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady(); this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
} }

View file

@ -98,7 +98,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setRetainInstance(true); 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); View view = inflater.inflate(R.layout.fragment_nearby, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
this.view = view; this.view = view;
Log.d("deneme","onCreateView"); Log.d("deneme1","onCreateView");
return view; return view;
} }
@ -124,7 +124,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
* it is attached. * it is attached.
*/ */
public void childMapFragmentAttached() { public void childMapFragmentAttached() {
Log.d("deneme","childMapFragmentAttached"); Log.d("deneme1","childMapFragmentAttached");
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter
(this, nearbyMapFragment, locationManager); (this, nearbyMapFragment, locationManager);
} }
@ -146,7 +146,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
* Resume fragments if they exists * Resume fragments if they exists
*/ */
private void resumeFragment() { private void resumeFragment() {
Log.d("deneme","resumeFragment"); Log.d("deneme1","resumeFragment");
// Find the retained fragment on activity restarts // Find the retained fragment on activity restarts
nearbyMapFragment = getMapFragment(); nearbyMapFragment = getMapFragment();
nearbyListFragment = getListFragment(); nearbyListFragment = getListFragment();
@ -181,17 +181,17 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override @Override
public void onLocationChangedSignificantly(LatLng latLng) { public void onLocationChangedSignificantly(LatLng latLng) {
Log.d("deneme","location changed significantly"); Log.d("deneme1","location changed significantly");
} }
@Override @Override
public void onLocationChangedSlightly(LatLng latLng) { public void onLocationChangedSlightly(LatLng latLng) {
Log.d("deneme","location changed significantly"); Log.d("deneme1","location changed significantly");
} }
@Override @Override
public void onLocationChangedMedium(LatLng latLng) { public void onLocationChangedMedium(LatLng latLng) {
Log.d("deneme","location changed significantly"); Log.d("deneme1","location changed significantly");
} }
@Override @Override
@ -217,9 +217,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
*/ */
@Override @Override
public void registerLocationUpdates(LocationServiceManager locationServiceManager) { public void registerLocationUpdates(LocationServiceManager locationServiceManager) {
Log.d("deneme1","registerLocationUpdates");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (locationServiceManager.isLocationPermissionGranted(requireContext())) { if (locationServiceManager.isLocationPermissionGranted(requireContext())) {
locationServiceManager.registerLocationManager(); locationServiceManager.registerLocationManager(getActivity());
} else { } else {
// Should we show an explanation? // Should we show an explanation?
if (locationServiceManager.isPermissionExplanationRequired(getActivity())) { if (locationServiceManager.isPermissionExplanationRequired(getActivity())) {
@ -242,7 +243,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
} }
} else { } else {
locationServiceManager.registerLocationManager(); locationServiceManager.registerLocationManager(getActivity());
} }
} }
@ -286,6 +287,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
*/ */
@Override @Override
public void checkGps(LocationServiceManager locationServiceManager) { public void checkGps(LocationServiceManager locationServiceManager) {
Log.d("deneme1","checkGPS");
Timber.d("checking GPS"); Timber.d("checking GPS");
if (!locationServiceManager.isProviderEnabled()) { if (!locationServiceManager.isProviderEnabled()) {
Timber.d("GPS is not enabled"); Timber.d("GPS is not enabled");
@ -319,6 +321,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
*/ */
@Override @Override
public void checkLocationPermission(LocationServiceManager locationServiceManager) { public void checkLocationPermission(LocationServiceManager locationServiceManager) {
Log.d("deneme1","checkLocationPermission");
Timber.d("Checking location permission"); Timber.d("Checking location permission");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (locationServiceManager.isLocationPermissionGranted(requireContext())) { if (locationServiceManager.isLocationPermissionGranted(requireContext())) {

View file

@ -50,7 +50,7 @@ public class NearbyParentFragmentPresenter
*/ */
@Override @Override
public void onTabSelected() { public void onTabSelected() {
Log.d("deneme","onTabSelected"); Log.d("deneme1","onTabSelected");
onTabSelected = true; onTabSelected = true;
if (nearbyViewsAreReady) { if (nearbyViewsAreReady) {
initializeNearbyOperations(); initializeNearbyOperations();
@ -63,7 +63,7 @@ public class NearbyParentFragmentPresenter
*/ */
@Override @Override
public void nearbyFragmentAndMapViewReady() { public void nearbyFragmentAndMapViewReady() {
Log.d("deneme","nearbyFragmentAndMapViewReady"); Log.d("deneme1","nearbyFragmentAndMapViewReady");
nearbyViewsAreReady = true; nearbyViewsAreReady = true;
if (onTabSelected) { if (onTabSelected) {
initializeNearbyOperations(); initializeNearbyOperations();
@ -76,9 +76,11 @@ public class NearbyParentFragmentPresenter
*/ */
@Override @Override
public void initializeNearbyOperations() { public void initializeNearbyOperations() {
Log.d("deneme","initializeNearbyOperations"); Log.d("deneme1","initializeNearbyOperations");
locationServiceManager.addLocationListener(this); locationServiceManager.addLocationListener(this);
nearbyParentFragmentView.registerLocationUpdates(locationServiceManager); nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
Log.d("deneme1","initializeNearbyOperations2");
// Nearby buttons should be active, they should be deactive only during update // Nearby buttons should be active, they should be deactive only during update
lockNearby(false); lockNearby(false);
//This will start a consequence to check GPS depending on different API //This will start a consequence to check GPS depending on different API
@ -111,6 +113,7 @@ public class NearbyParentFragmentPresenter
*/ */
@Override @Override
public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType) { public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType) {
Log.d("deneme1","updateMapAndList");
if (isNearbyLocked) { if (isNearbyLocked) {
Timber.d("Nearby is locked, so updateMapAndList returns"); Timber.d("Nearby is locked, so updateMapAndList returns");
return; return;
@ -123,6 +126,7 @@ public class NearbyParentFragmentPresenter
//nearbyParentFragmentView.registerLocationUpdates(locationServiceManager); //nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
LatLng lastLocation = locationServiceManager.getLastLocation(); LatLng lastLocation = locationServiceManager.getLastLocation();
Log.d("deneme1","locationServiceManager.getLastLocation():"+locationServiceManager.getLastLocation().toString());
if (curLatLng != null) { if (curLatLng != null) {
// TODO figure out what is happening here about orientation change // TODO figure out what is happening here about orientation change
@ -155,17 +159,19 @@ public class NearbyParentFragmentPresenter
@Override @Override
public void onLocationChangedSignificantly(LatLng latLng) { public void onLocationChangedSignificantly(LatLng latLng) {
Log.d("deneme1","onLocationChangedSignificantly");
} }
@Override @Override
public void onLocationChangedSlightly(LatLng latLng) { public void onLocationChangedSlightly(LatLng latLng) {
Log.d("deneme1","onLocationChangedSlightly");
} }
@Override @Override
public void onLocationChangedMedium(LatLng latLng) { public void onLocationChangedMedium(LatLng latLng) {
Log.d("deneme1","onLocationChangedMedium");
} }
} }