mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Prevent unnecessary refreshview calls
This commit is contained in:
parent
c7b7522edd
commit
b180824382
2 changed files with 39 additions and 9 deletions
|
|
@ -99,6 +99,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
private boolean onOrientationChanged = false;
|
private boolean onOrientationChanged = false;
|
||||||
private boolean populateForCurrentLocation = false;
|
private boolean populateForCurrentLocation = false;
|
||||||
|
private boolean isNetworkErrorOccured = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
|
@ -126,7 +127,8 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
onOrientationChanged = true;
|
onOrientationChanged = true;
|
||||||
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
Log.d("deneme","onViewCreated");
|
||||||
|
//refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,17 +220,22 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChangedSignificantly(LatLng latLng) {
|
public void onLocationChangedSignificantly(LatLng latLng) {
|
||||||
|
Log.d("deneme","onLocationChangedSignificantly");
|
||||||
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChangedSlightly(LatLng latLng) {
|
public void onLocationChangedSlightly(LatLng latLng) {
|
||||||
refreshView(LOCATION_SLIGHTLY_CHANGED);
|
Log.d("deneme","onLocationChangedSlightly");
|
||||||
|
|
||||||
|
refreshView(LOCATION_SLIGHTLY_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChangedMedium(LatLng latLng) {
|
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
|
// For nearby map actions, there are no differences between 500 meter location change (aka medium change) and slight change
|
||||||
refreshView(LOCATION_SLIGHTLY_CHANGED);
|
refreshView(LOCATION_SLIGHTLY_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
@ -237,6 +244,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
public void onWikidataEditSuccessful() {
|
public void onWikidataEditSuccessful() {
|
||||||
// Do not refresh nearby map if we are checking other areas with search this area button
|
// Do not refresh nearby map if we are checking other areas with search this area button
|
||||||
if (!nearbyMapFragment.searchThisAreaModeOn) {
|
if (!nearbyMapFragment.searchThisAreaModeOn) {
|
||||||
|
Log.d("deneme","onWikidateEditSuccesful");
|
||||||
refreshView(MAP_UPDATED);
|
refreshView(MAP_UPDATED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -247,6 +255,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
* @param locationChangeType defines if location shanged significantly or slightly
|
* @param locationChangeType defines if location shanged significantly or slightly
|
||||||
*/
|
*/
|
||||||
public void refreshView(LocationServiceManager.LocationChangeType locationChangeType) {
|
public void refreshView(LocationServiceManager.LocationChangeType locationChangeType) {
|
||||||
|
Log.d("deneme","refreshView");
|
||||||
Timber.d("Refreshing nearby places");
|
Timber.d("Refreshing nearby places");
|
||||||
if (lockNearbyView) {
|
if (lockNearbyView) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -298,6 +307,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
bundle.clear();
|
bundle.clear();
|
||||||
bundle.putString("CurLatLng", gsonCurLatLng);
|
bundle.putString("CurLatLng", gsonCurLatLng);
|
||||||
|
|
||||||
|
Log.d("deneme","popuate places is called from here");
|
||||||
placesDisposable = Observable.fromCallable(() -> nearbyController
|
placesDisposable = Observable.fromCallable(() -> nearbyController
|
||||||
.loadAttractionsFromLocation(curLatLng, curLatLng, false, true))
|
.loadAttractionsFromLocation(curLatLng, curLatLng, false, true))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
@ -331,7 +341,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
* @param customLatLng Custom area which we will search around
|
* @param customLatLng Custom area which we will search around
|
||||||
*/
|
*/
|
||||||
public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) {
|
public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) {
|
||||||
|
Log.d("deneme","refreshViewForCutomLocatiom");
|
||||||
if (customLatLng == null) {
|
if (customLatLng == null) {
|
||||||
// If null, return
|
// If null, return
|
||||||
return;
|
return;
|
||||||
|
|
@ -360,6 +370,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
* @param nearbyPlacesInfo This variable has place list information and distances.
|
* @param nearbyPlacesInfo This variable has place list information and distances.
|
||||||
*/
|
*/
|
||||||
private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
||||||
|
Log.d("deneme","populatePlacesFromCustomLocation");
|
||||||
//NearbyMapFragment nearbyMapFragment = getMapFragment();
|
//NearbyMapFragment nearbyMapFragment = getMapFragment();
|
||||||
if (nearbyMapFragment != null) {
|
if (nearbyMapFragment != null) {
|
||||||
nearbyMapFragment.searchThisAreaButtonProgressBar.setVisibility(View.GONE);
|
nearbyMapFragment.searchThisAreaButtonProgressBar.setVisibility(View.GONE);
|
||||||
|
|
@ -376,6 +387,8 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
||||||
|
Log.d("deneme","populatePlaces");
|
||||||
|
|
||||||
Timber.d("Populating nearby places");
|
Timber.d("Populating nearby places");
|
||||||
List<Place> placeList = nearbyPlacesInfo.placeList;
|
List<Place> placeList = nearbyPlacesInfo.placeList;
|
||||||
LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates;
|
LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates;
|
||||||
|
|
@ -428,6 +441,9 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
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) {
|
if (nearbyMapFragment.checkingAround) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -446,11 +462,15 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
* If we are close to nearby places boundaries, we need a significant update to
|
* 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
|
* get new nearby places. Check order is south, north, west, east
|
||||||
* */
|
* */
|
||||||
if (nearbyMapFragment.boundaryCoordinates != null && !nearbyMapFragment.searchThisAreaModeOn
|
if (nearbyMapFragment.boundaryCoordinates != null
|
||||||
&& (curLatLng.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude()
|
&& !nearbyMapFragment.checkingAround
|
||||||
|| curLatLng.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude()
|
&& !nearbyMapFragment.searchThisAreaModeOn
|
||||||
|| curLatLng.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude()
|
&& !onOrientationChanged
|
||||||
|| curLatLng.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
|
&& (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
|
// populate places
|
||||||
placesDisposable = Observable.fromCallable(() -> nearbyController
|
placesDisposable = Observable.fromCallable(() -> nearbyController
|
||||||
.loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton))
|
.loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton))
|
||||||
|
|
@ -637,6 +657,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
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 (locationManager.isLocationPermissionGranted()) {
|
if (locationManager.isLocationPermissionGranted()) {
|
||||||
|
Log.d("deneme","Check location permission if");
|
||||||
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
||||||
} else {
|
} else {
|
||||||
// Should we show an explanation?
|
// Should we show an explanation?
|
||||||
|
|
@ -663,6 +684,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Log.d("deneme","Check location permission else");
|
||||||
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -681,9 +703,16 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (snackbar != null) {
|
if (snackbar != null) {
|
||||||
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
|
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();
|
snackbar.dismiss();
|
||||||
} else {
|
} else {
|
||||||
|
isNetworkErrorOccured = true;
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1011,6 +1011,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
||||||
searchThisAreaModeOn = false;
|
searchThisAreaModeOn = false;
|
||||||
checkingAround = false;
|
checkingAround = false;
|
||||||
searchedAroundCurrentLocation = true;
|
searchedAroundCurrentLocation = true;
|
||||||
|
boundaryCoordinates = null;
|
||||||
initViews();
|
initViews();
|
||||||
setListeners();
|
setListeners();
|
||||||
transparentView.setClickable(false);
|
transparentView.setClickable(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue