mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Use new result API (#5875)
* remove unused result expectancy for settings screen launch Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * initial refactor to new result api, wip Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * refactor camera launcher Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * revert callback for video handling Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * invoke callbacks when cancelled Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * handle gallery picker result based on preference Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * remove old method of refactoring for file picker Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * remove legacy result handling callback Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * request code used for handling result was never used for launching an activity, hence removed Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * extract voice result handling into function Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * refactor test Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * remove unused tests Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * cleanup Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * fix-docs Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * add space after , Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> --------- Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parent
f1205c19be
commit
1e7aabad16
26 changed files with 407 additions and 487 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.nearby
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.INVISIBLE
|
||||
|
|
@ -17,9 +18,9 @@ import fr.free.nrw.commons.databinding.ItemPlaceBinding
|
|||
fun placeAdapterDelegate(
|
||||
bookmarkLocationDao: BookmarkLocationsDao,
|
||||
onItemClick: ((Place) -> Unit)? = null,
|
||||
onCameraClicked: (Place, ActivityResultLauncher<Array<String>>) -> Unit,
|
||||
onCameraClicked: (Place, ActivityResultLauncher<Array<String>>, ActivityResultLauncher<Intent>) -> Unit,
|
||||
onCameraLongPressed: () -> Boolean,
|
||||
onGalleryClicked: (Place) -> Unit,
|
||||
onGalleryClicked: (Place, ActivityResultLauncher<Intent>) -> Unit,
|
||||
onGalleryLongPressed: () -> Boolean,
|
||||
onBookmarkClicked: (Place, Boolean) -> Unit,
|
||||
onBookmarkLongPressed: () -> Boolean,
|
||||
|
|
@ -28,6 +29,8 @@ fun placeAdapterDelegate(
|
|||
onDirectionsClicked: (Place) -> Unit,
|
||||
onDirectionsLongPressed: () -> Boolean,
|
||||
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>,
|
||||
cameraPickLauncherForResult: ActivityResultLauncher<Intent>,
|
||||
galleryPickLauncherForResult: ActivityResultLauncher<Intent>
|
||||
) = adapterDelegateViewBinding<Place, Place, ItemPlaceBinding>({ layoutInflater, parent ->
|
||||
ItemPlaceBinding.inflate(layoutInflater, parent, false)
|
||||
}) {
|
||||
|
|
@ -44,10 +47,10 @@ fun placeAdapterDelegate(
|
|||
onItemClick?.invoke(item)
|
||||
}
|
||||
}
|
||||
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher) }
|
||||
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult) }
|
||||
nearbyButtonLayout.cameraButton.setOnLongClickListener { onCameraLongPressed() }
|
||||
|
||||
nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item) }
|
||||
nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item, galleryPickLauncherForResult) }
|
||||
nearbyButtonLayout.galleryButton.setOnLongClickListener { onGalleryLongPressed() }
|
||||
bookmarkButtonImage.setOnClickListener {
|
||||
val isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item)
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@ class CommonPlaceClickActions
|
|||
private val activity: Activity,
|
||||
private val contributionController: ContributionController,
|
||||
) {
|
||||
fun onCameraClicked(): (Place, ActivityResultLauncher<Array<String>>) -> Unit =
|
||||
{ place, launcher ->
|
||||
fun onCameraClicked(): (Place, ActivityResultLauncher<Array<String>>, ActivityResultLauncher<Intent>) -> Unit =
|
||||
{ place, launcher, resultLauncher ->
|
||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||
showLoginDialog()
|
||||
} else {
|
||||
Timber.d("Camera button tapped. Image title: ${place.getName()}Image desc: ${place.longDescription}")
|
||||
storeSharedPrefs(place)
|
||||
contributionController.initiateCameraPick(activity, launcher)
|
||||
contributionController.initiateCameraPick(activity, launcher, resultLauncher)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,14 +72,14 @@ class CommonPlaceClickActions
|
|||
true
|
||||
}
|
||||
|
||||
fun onGalleryClicked(): (Place) -> Unit =
|
||||
{
|
||||
fun onGalleryClicked(): (Place, ActivityResultLauncher<Intent>) -> Unit =
|
||||
{place, galleryPickLauncherForResult ->
|
||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||
showLoginDialog()
|
||||
} else {
|
||||
Timber.d("Gallery button tapped. Image title: ${it.getName()}Image desc: ${it.getLongDescription()}")
|
||||
storeSharedPrefs(it)
|
||||
contributionController.initiateGalleryPick(activity, false)
|
||||
Timber.d("Gallery button tapped. Image title: ${place.getName()}Image desc: ${place.getLongDescription()}")
|
||||
storeSharedPrefs(place)
|
||||
contributionController.initiateGalleryPick(activity, galleryPickLauncherForResult, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import androidx.activity.result.ActivityResultCallback;
|
|||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -225,6 +226,31 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
private GridLayoutManager gridLayoutManager;
|
||||
private List<BottomSheetItem> dataList;
|
||||
private BottomSheetAdapter bottomSheetAdapter;
|
||||
|
||||
private final ActivityResultLauncher<Intent> galleryPickLauncherForResult =
|
||||
registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
controller.handleActivityResultWithCallback(requireActivity(), callbacks -> {
|
||||
controller.onPictureReturnedFromGallery(result, requireActivity(), callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private final ActivityResultLauncher<Intent> customSelectorLauncherForResult =
|
||||
registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
controller.handleActivityResultWithCallback(requireActivity(), callbacks -> {
|
||||
controller.onPictureReturnedFromCustomSelector(result, requireActivity(), callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private final ActivityResultLauncher<Intent> cameraPickLauncherForResult =
|
||||
registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
controller.handleActivityResultWithCallback(requireActivity(), callbacks -> {
|
||||
controller.onPictureReturnedFromCamera(result, requireActivity(), callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(
|
||||
new RequestMultiplePermissions(),
|
||||
new ActivityResultCallback<Map<String, Boolean>>() {
|
||||
|
|
@ -240,7 +266,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
} else {
|
||||
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
|
||||
controller.handleShowRationaleFlowCameraLocation(getActivity(),
|
||||
inAppCameraLocationPermissionLauncher);
|
||||
inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult);
|
||||
} else {
|
||||
controller.locationPermissionCallback.onLocationPermissionDenied(
|
||||
getActivity().getString(
|
||||
|
|
@ -570,7 +596,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
return Unit.INSTANCE;
|
||||
},
|
||||
commonPlaceClickActions,
|
||||
inAppCameraLocationPermissionLauncher
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
galleryPickLauncherForResult,
|
||||
cameraPickLauncherForResult
|
||||
);
|
||||
binding.bottomSheetNearby.rvNearbyList.setAdapter(adapter);
|
||||
}
|
||||
|
|
@ -2201,7 +2229,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
if (binding.fabCamera.isShown()) {
|
||||
Timber.d("Camera button tapped. Place: %s", selectedPlace.toString());
|
||||
storeSharedPrefs(selectedPlace);
|
||||
controller.initiateCameraPick(getActivity(), inAppCameraLocationPermissionLauncher);
|
||||
controller.initiateCameraPick(getActivity(), inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -2210,6 +2238,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
Timber.d("Gallery button tapped. Place: %s", selectedPlace.toString());
|
||||
storeSharedPrefs(selectedPlace);
|
||||
controller.initiateGalleryPick(getActivity(),
|
||||
galleryPickLauncherForResult,
|
||||
false);
|
||||
}
|
||||
});
|
||||
|
|
@ -2218,7 +2247,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
if (binding.fabCustomGallery.isShown()) {
|
||||
Timber.d("Gallery button tapped. Place: %s", selectedPlace.toString());
|
||||
storeSharedPrefs(selectedPlace);
|
||||
controller.initiateCustomGalleryPickWithPermission(getActivity());
|
||||
controller.initiateCustomGalleryPickWithPermission(getActivity(), customSelectorLauncherForResult);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.nearby.fragments
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
|
|
@ -12,6 +13,8 @@ class PlaceAdapter(
|
|||
onBookmarkClicked: (Place, Boolean) -> Unit,
|
||||
commonPlaceClickActions: CommonPlaceClickActions,
|
||||
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>,
|
||||
galleryPickLauncherForResult: ActivityResultLauncher<Intent>,
|
||||
cameraPickLauncherForResult: ActivityResultLauncher<Intent>
|
||||
) : BaseDelegateAdapter<Place>(
|
||||
placeAdapterDelegate(
|
||||
bookmarkLocationsDao,
|
||||
|
|
@ -27,6 +30,8 @@ class PlaceAdapter(
|
|||
commonPlaceClickActions.onDirectionsClicked(),
|
||||
commonPlaceClickActions.onDirectionsLongPressed(),
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
cameraPickLauncherForResult,
|
||||
galleryPickLauncherForResult
|
||||
),
|
||||
areItemsTheSame = { oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId },
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue