mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
* Resolved merged conflicts * Resolved merge conflicts and updated workflow * Updated Location Flow and merged conflicts * Update flow and merge conflicts * Fixed LocationPicker's location flow * Removed redundant code from LocationPermissionsHelper * Fixed Explore fragment crashing and incorrect behaviour * Updated LocationPicker Flow * Fixed Nearby not working as intended * Final update to location flow of all maps * Added the reqested changes and fixed bugs * Resolved requested change in in-app camera location flow * Fixed In-app camera location flow * Resolved conflicts in ContributionsListFragment * Updated java doc as requested * Resolved nearby card dialog not being shown * Optimised LocationPermissionsHelper javadoc * Made requested changes for preference check * Added javadoc and requested comment for later reference * Implemented requested code changes * Fixed failing test due to changes made during PR * Added string resource for ExploreMapFragment * Changed string resource for rationale dialog * Added standard location flow information in LocationPermissionsHelper * Added javadoc for doNotAskForLocationPermission * Removed unused import * Updated javadoc * Removed values-yue-hant * Fix some merge conflict errors * Fix minor errors due to mergre conflicts * Fix some refactor errors * Fixed minor bug due to merging conflicts * Delete app/src/main/res/values-yue-hant directory * Final changes to NearbyParentFragment * Fixes #5686 map coordinates set to image coords * Removed some redundant code from recenterMap * Removed one test whose method no longer exists * Removed unused method from contract of nearby * Removed redundant method from NearbyParentFragment * nearby: add a FIXME about the possibly redudant code --------- Co-authored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
This commit is contained in:
parent
1f2e31d45b
commit
04f9ef4819
16 changed files with 421 additions and 297 deletions
|
|
@ -24,7 +24,7 @@ public interface NearbyParentFragmentContract {
|
|||
|
||||
boolean isListBottomSheetExpanded();
|
||||
|
||||
void checkPermissionsAndPerformAction();
|
||||
void askForLocationPermission();
|
||||
|
||||
void displayLoginSkippedWarning();
|
||||
|
||||
|
|
@ -36,8 +36,6 @@ public interface NearbyParentFragmentContract {
|
|||
|
||||
void recenterMap(LatLng currentLatLng);
|
||||
|
||||
void showLocationOffDialog();
|
||||
|
||||
void openLocationSettings();
|
||||
|
||||
void hideBottomSheet();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import static fr.free.nrw.commons.location.LocationServiceManager.LocationChange
|
|||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED;
|
||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
|
||||
|
||||
import android.Manifest;
|
||||
import android.Manifest.permission;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
|
|
@ -67,6 +66,8 @@ import fr.free.nrw.commons.contributions.MainActivity.ActiveFragment;
|
|||
import fr.free.nrw.commons.databinding.FragmentNearbyParentBinding;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.location.LocationPermissionsHelper;
|
||||
import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
import fr.free.nrw.commons.location.LocationUpdateListener;
|
||||
|
|
@ -84,9 +85,9 @@ import fr.free.nrw.commons.upload.FileUtils;
|
|||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
import fr.free.nrw.commons.utils.ExecutorUtils;
|
||||
import fr.free.nrw.commons.utils.LayoutUtils;
|
||||
import fr.free.nrw.commons.utils.MapUtils;
|
||||
import fr.free.nrw.commons.utils.NearbyFABUtils;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
import fr.free.nrw.commons.utils.PermissionUtils;
|
||||
import fr.free.nrw.commons.utils.SystemThemeUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import fr.free.nrw.commons.wikidata.WikidataEditListener;
|
||||
|
|
@ -130,7 +131,8 @@ import timber.log.Timber;
|
|||
|
||||
public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||
implements NearbyParentFragmentContract.View,
|
||||
WikidataEditListener.WikidataP18EditListener, LocationUpdateListener {
|
||||
WikidataEditListener.WikidataP18EditListener, LocationUpdateListener,
|
||||
LocationPermissionCallback {
|
||||
|
||||
|
||||
FragmentNearbyParentBinding binding;
|
||||
|
|
@ -152,6 +154,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
SystemThemeUtils systemThemeUtils;
|
||||
@Inject
|
||||
CommonPlaceClickActions commonPlaceClickActions;
|
||||
private LocationPermissionsHelper locationPermissionsHelper;
|
||||
private NearbyFilterSearchRecyclerViewAdapter nearbyFilterSearchRecyclerViewAdapter;
|
||||
private BottomSheetBehavior bottomSheetListBehavior;
|
||||
private BottomSheetBehavior bottomSheetDetailsBehavior;
|
||||
|
|
@ -201,7 +204,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
controller.locationPermissionCallback.onLocationPermissionGranted();
|
||||
} else {
|
||||
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
|
||||
controller.handleShowRationaleFlowCameraLocation(getActivity());
|
||||
controller.handleShowRationaleFlowCameraLocation(getActivity(), inAppCameraLocationPermissionLauncher);
|
||||
} else {
|
||||
controller.locationPermissionCallback.onLocationPermissionDenied(
|
||||
getActivity().getString(
|
||||
|
|
@ -223,15 +226,17 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
getActivity().getString(android.R.string.ok),
|
||||
getActivity().getString(android.R.string.cancel),
|
||||
() -> {
|
||||
if (!(locationManager.isNetworkProviderEnabled()
|
||||
|| locationManager.isGPSProviderEnabled())) {
|
||||
showLocationOffDialog();
|
||||
}
|
||||
askForLocationPermission();
|
||||
},
|
||||
() -> isPermissionDenied = true,
|
||||
null,
|
||||
null,
|
||||
false);
|
||||
} else {
|
||||
if (isPermissionDenied) {
|
||||
locationPermissionsHelper.showAppSettingsDialog(getActivity(),
|
||||
R.string.nearby_needs_location);
|
||||
}
|
||||
Timber.d("The user checked 'Don't ask again' or denied the permission twice");
|
||||
isPermissionDenied = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -323,7 +328,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
} else {
|
||||
binding.rlContainerWlmMonthMessage.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
locationPermissionsHelper = new LocationPermissionsHelper(getActivity(), locationManager,
|
||||
this);
|
||||
presenter.attachView(this);
|
||||
isPermissionDenied = false;
|
||||
recenterToUserLocation = false;
|
||||
|
|
@ -426,7 +432,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
initNearbyFilter();
|
||||
addCheckBoxCallback();
|
||||
performMapReadyActions();
|
||||
moveCameraToPosition(lastMapFocus);
|
||||
initRvNearbyList();
|
||||
onResume();
|
||||
|
|
@ -471,6 +476,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
|
||||
binding.tvLearnMore.setOnClickListener(v ->onLearnMoreClicked());
|
||||
binding.nearbyFilter.ivToggleChips.setOnClickListener(v -> onToggleChipsClicked());
|
||||
|
||||
if (!locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
||||
askForLocationPermission();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -527,14 +536,18 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
|
||||
private void performMapReadyActions() {
|
||||
if (((MainActivity) getActivity()).activeFragment == ActiveFragment.NEARBY) {
|
||||
if (!applicationKvStore.getBoolean("doNotAskForLocationPermission", false) ||
|
||||
PermissionUtils.hasPermission(getActivity(),
|
||||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION})) {
|
||||
checkPermissionsAndPerformAction();
|
||||
} else {
|
||||
if (applicationKvStore.getBoolean("doNotAskForLocationPermission", false) &&
|
||||
!locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
||||
isPermissionDenied = true;
|
||||
}
|
||||
}
|
||||
presenter.onMapReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void askForLocationPermission() {
|
||||
Timber.d("Asking for location permission");
|
||||
locationPermissionLauncher.launch(permission.ACCESS_FINE_LOCATION);
|
||||
}
|
||||
|
||||
private void locationPermissionGranted() {
|
||||
|
|
@ -554,8 +567,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
locationManager.requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER);
|
||||
setProgressBarVisibility(true);
|
||||
} else {
|
||||
Toast.makeText(getContext(), getString(R.string.nearby_location_not_available),
|
||||
Toast.LENGTH_LONG).show();
|
||||
locationPermissionsHelper.showLocationOffDialog(getActivity(), R.string.ask_to_turn_location_on_text);
|
||||
}
|
||||
presenter.onMapReady();
|
||||
registerUnregisterLocationListener(false);
|
||||
|
|
@ -568,15 +580,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
presenter.attachView(this);
|
||||
registerNetworkReceiver();
|
||||
if (isResumed() && ((MainActivity) getActivity()).activeFragment == ActiveFragment.NEARBY) {
|
||||
if (!isPermissionDenied && !applicationKvStore.getBoolean(
|
||||
"doNotAskForLocationPermission", false)) {
|
||||
if (!locationManager.isGPSProviderEnabled()) {
|
||||
startMapWithCondition("Without GPS");
|
||||
} else {
|
||||
startTheMap();
|
||||
}
|
||||
if (locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
||||
locationPermissionGranted();
|
||||
} else {
|
||||
startMapWithCondition("Without Permission");
|
||||
startMapWithoutPermission();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -586,12 +593,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
* coordinates, other than that it points to the last known location which can be get by the key
|
||||
* "LastLocation" from applicationKvStore
|
||||
*
|
||||
* @param condition : for which condition the map should start
|
||||
*/
|
||||
private void startMapWithCondition(final String condition) {
|
||||
if (condition.equals("Without Permission")) {
|
||||
applicationKvStore.putBoolean("doNotAskForLocationPermission", true);
|
||||
}
|
||||
private void startMapWithoutPermission() {
|
||||
if (applicationKvStore.getString("LastLocation") != null) {
|
||||
final String[] locationLatLng
|
||||
= applicationKvStore.getString("LastLocation").split(",");
|
||||
|
|
@ -599,12 +602,13 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
= new fr.free.nrw.commons.location.LatLng(Double.parseDouble(locationLatLng[0]),
|
||||
Double.parseDouble(locationLatLng[1]), 1f);
|
||||
} else {
|
||||
lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,
|
||||
-0.07520, 1f);
|
||||
lastKnownLocation = MapUtils.defaultLatLng;
|
||||
}
|
||||
if (binding.map != null) {
|
||||
recenterMap(lastKnownLocation);
|
||||
moveCameraToPosition(
|
||||
new GeoPoint(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()));
|
||||
}
|
||||
presenter.onMapReady();
|
||||
}
|
||||
|
||||
private void registerNetworkReceiver() {
|
||||
|
|
@ -1426,12 +1430,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermissionsAndPerformAction() {
|
||||
Timber.d("Checking permission and perfoming action");
|
||||
locationPermissionLauncher.launch(permission.ACCESS_FINE_LOCATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts animation of fab plus (turning on opening) and other FABs
|
||||
*/
|
||||
|
|
@ -1559,6 +1557,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
return presenter.backButtonClicked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationPermissionDenied(String toastMessage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationPermissionGranted() {
|
||||
}
|
||||
|
||||
/**
|
||||
* onLogoutComplete is called after shared preferences and data stored in local database are
|
||||
* cleared.
|
||||
|
|
@ -1856,18 +1862,37 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
|
||||
@Override
|
||||
public void recenterMap(fr.free.nrw.commons.location.LatLng currentLatLng) {
|
||||
if (isPermissionDenied || currentLatLng == null) {
|
||||
recenterToUserLocation = true;
|
||||
checkPermissionsAndPerformAction();
|
||||
if (!isPermissionDenied && !(locationManager.isNetworkProviderEnabled()
|
||||
|| locationManager.isGPSProviderEnabled())) {
|
||||
showLocationOffDialog();
|
||||
// if user has denied permission twice, then show dialog
|
||||
if (isPermissionDenied) {
|
||||
if (locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
||||
// this will run when user has given permission by opening app's settings
|
||||
isPermissionDenied = false;
|
||||
locationPermissionGranted();
|
||||
return;
|
||||
} else {
|
||||
askForLocationPermission();
|
||||
}
|
||||
} else {
|
||||
if (!locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
||||
askForLocationPermission();
|
||||
} else {
|
||||
locationPermissionGranted();
|
||||
}
|
||||
}
|
||||
if (currentLatLng == null) {
|
||||
recenterToUserLocation = true;
|
||||
return;
|
||||
}
|
||||
addCurrentLocationMarker(currentLatLng);
|
||||
binding.map.getController()
|
||||
.animateTo(new GeoPoint(currentLatLng.getLatitude(), currentLatLng.getLongitude()));
|
||||
|
||||
/*
|
||||
* FIXME: With the revamp of the location permission helper in the MR
|
||||
* #5494[1], there is a doubt that the following code is redundant.
|
||||
* If we could confirm the same, the following code can be removed. If it
|
||||
* turns out to be necessary, we could replace this with a comment
|
||||
* clarifying why it is necessary.
|
||||
*
|
||||
* Ref: https://github.com/commons-app/apps-android-commons/pull/5494#discussion_r1560404794
|
||||
*/
|
||||
if (lastMapFocus != null) {
|
||||
Location mylocation = new Location("");
|
||||
Location dest_location = new Location("");
|
||||
|
|
@ -1890,15 +1915,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLocationOffDialog() {
|
||||
// This creates a dialog box that prompts the user to enable location
|
||||
DialogUtil
|
||||
.showAlertDialog(getActivity(), getString(R.string.ask_to_turn_location_on),
|
||||
getString(R.string.nearby_needs_location),
|
||||
getString(R.string.yes), getString(R.string.no), this::openLocationSettings, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openLocationSettings() {
|
||||
// This method opens the location settings of the device along with a followup toast.
|
||||
|
|
@ -2103,7 +2119,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
super.setUserVisibleHint(isVisibleToUser);
|
||||
this.isVisibleToUser = isVisibleToUser;
|
||||
if (isResumed() && isVisibleToUser) {
|
||||
startTheMap();
|
||||
performMapReadyActions();
|
||||
} else {
|
||||
if (null != bottomSheetListBehavior) {
|
||||
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||
|
|
@ -2115,10 +2131,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
}
|
||||
|
||||
private void startTheMap() {
|
||||
performMapReadyActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all markers from the map and resets certain map overlays and gestures. After clearing
|
||||
* markers, it re-adds a scale bar overlay and rotation gesture overlay to the map.
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ public class NearbyParentFragmentPresenter
|
|||
public void initializeMapOperations() {
|
||||
lockUnlockNearby(false);
|
||||
updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED);
|
||||
this.nearbyParentFragmentView.addSearchThisAreaButtonAction();
|
||||
nearbyParentFragmentView.setCheckBoxAction();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue