mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 22:34:02 +01:00
initial refactor to new result api, wip
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parent
fb9c88026b
commit
6a98923a83
16 changed files with 357 additions and 176 deletions
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
|||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
|
@ -33,6 +34,19 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
|||
@Inject BookmarkLocationsDao bookmarkLocationDao;
|
||||
@Inject CommonPlaceClickActions commonPlaceClickActions;
|
||||
private PlaceAdapter adapter;
|
||||
|
||||
private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
// TODO handle result from controller
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<Intent> galleryPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
contributionController.handleActivityResultWithCallback(requireActivity(),callbacks -> {
|
||||
contributionController.onPictureReturnedFromGallery(result,requireActivity(),callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
|
||||
@Override
|
||||
public void onActivityResult(Map<String, Boolean> result) {
|
||||
|
|
@ -45,7 +59,7 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
|||
contributionController.locationPermissionCallback.onLocationPermissionGranted();
|
||||
} else {
|
||||
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
|
||||
contributionController.handleShowRationaleFlowCameraLocation(getActivity(), inAppCameraLocationPermissionLauncher);
|
||||
contributionController.handleShowRationaleFlowCameraLocation(getActivity(), inAppCameraLocationPermissionLauncher,cameraPickLauncherForResult);
|
||||
} else {
|
||||
contributionController.locationPermissionCallback.onLocationPermissionDenied(getActivity().getString(R.string.in_app_camera_location_permission_denied));
|
||||
}
|
||||
|
|
@ -83,7 +97,11 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
|||
return Unit.INSTANCE;
|
||||
},
|
||||
commonPlaceClickActions,
|
||||
inAppCameraLocationPermissionLauncher
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
galleryPickLauncherForResult,
|
||||
//TODO[Parry] just a stub, make sure if this is actually the launcher we need!!
|
||||
cameraPickLauncherForResult
|
||||
|
||||
);
|
||||
binding.listView.setAdapter(adapter);
|
||||
}
|
||||
|
|
@ -109,9 +127,10 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO[Parr]: doubtful if it even used, check while testing
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
contributionController.handleActivityResult(getActivity(), requestCode, resultCode, data);
|
||||
// contributionController.handleActivityResult(getActivity(), resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
|
@ -64,10 +65,11 @@ public class ContributionController {
|
|||
* Check for permissions and initiate camera click
|
||||
*/
|
||||
public void initiateCameraPick(Activity activity,
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher) {
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
||||
ActivityResultLauncher<Intent> resultLauncher) {
|
||||
boolean useExtStorage = defaultKvStore.getBoolean("useExternalStorage", true);
|
||||
if (!useExtStorage) {
|
||||
initiateCameraUpload(activity);
|
||||
initiateCameraUpload(activity, resultLauncher);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -75,12 +77,12 @@ public class ContributionController {
|
|||
() -> {
|
||||
if (defaultKvStore.getBoolean("inAppCameraFirstRun")) {
|
||||
defaultKvStore.putBoolean("inAppCameraFirstRun", false);
|
||||
askUserToAllowLocationAccess(activity, inAppCameraLocationPermissionLauncher);
|
||||
askUserToAllowLocationAccess(activity, inAppCameraLocationPermissionLauncher, resultLauncher);
|
||||
} else if (defaultKvStore.getBoolean("inAppCameraLocationPref")) {
|
||||
createDialogsAndHandleLocationPermissions(activity,
|
||||
inAppCameraLocationPermissionLauncher);
|
||||
inAppCameraLocationPermissionLauncher, resultLauncher);
|
||||
} else {
|
||||
initiateCameraUpload(activity);
|
||||
initiateCameraUpload(activity,resultLauncher);
|
||||
}
|
||||
},
|
||||
R.string.storage_permission_title,
|
||||
|
|
@ -94,7 +96,8 @@ public class ContributionController {
|
|||
* @param activity
|
||||
*/
|
||||
private void createDialogsAndHandleLocationPermissions(Activity activity,
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher) {
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
||||
ActivityResultLauncher<Intent> resultLauncher) {
|
||||
locationPermissionCallback = new LocationPermissionCallback() {
|
||||
@Override
|
||||
public void onLocationPermissionDenied(String toastMessage) {
|
||||
|
|
@ -103,7 +106,7 @@ public class ContributionController {
|
|||
toastMessage,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
initiateCameraUpload(activity);
|
||||
initiateCameraUpload(activity, resultLauncher);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -112,7 +115,7 @@ public class ContributionController {
|
|||
showLocationOffDialog(activity, R.string.in_app_camera_needs_location,
|
||||
R.string.in_app_camera_location_unavailable);
|
||||
} else {
|
||||
initiateCameraUpload(activity);
|
||||
initiateCameraUpload(activity, resultLauncher);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -148,20 +151,22 @@ public class ContributionController {
|
|||
() -> {
|
||||
Toast.makeText(activity, activity.getString(toastTextResource),
|
||||
Toast.LENGTH_LONG).show();
|
||||
initiateCameraUpload(activity);
|
||||
//TODO [Parry] why do we need this call???
|
||||
// initiateCameraUpload(activity);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void handleShowRationaleFlowCameraLocation(Activity activity,
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher) {
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
||||
ActivityResultLauncher<Intent> resultLauncher) {
|
||||
DialogUtil.showAlertDialog(activity, activity.getString(R.string.location_permission_title),
|
||||
activity.getString(R.string.in_app_camera_location_permission_rationale),
|
||||
activity.getString(android.R.string.ok),
|
||||
activity.getString(android.R.string.cancel),
|
||||
() -> {
|
||||
createDialogsAndHandleLocationPermissions(activity,
|
||||
inAppCameraLocationPermissionLauncher);
|
||||
inAppCameraLocationPermissionLauncher, resultLauncher);
|
||||
},
|
||||
() -> locationPermissionCallback.onLocationPermissionDenied(
|
||||
activity.getString(R.string.in_app_camera_location_permission_denied)),
|
||||
|
|
@ -181,7 +186,8 @@ public class ContributionController {
|
|||
* @param activity
|
||||
*/
|
||||
private void askUserToAllowLocationAccess(Activity activity,
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher) {
|
||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
||||
ActivityResultLauncher<Intent> resultLauncher) {
|
||||
DialogUtil.showAlertDialog(activity,
|
||||
activity.getString(R.string.in_app_camera_location_permission_title),
|
||||
activity.getString(R.string.in_app_camera_location_access_explanation),
|
||||
|
|
@ -190,12 +196,12 @@ public class ContributionController {
|
|||
() -> {
|
||||
defaultKvStore.putBoolean("inAppCameraLocationPref", true);
|
||||
createDialogsAndHandleLocationPermissions(activity,
|
||||
inAppCameraLocationPermissionLauncher);
|
||||
inAppCameraLocationPermissionLauncher, resultLauncher);
|
||||
},
|
||||
() -> {
|
||||
ViewUtil.showLongToast(activity, R.string.in_app_camera_location_permission_denied);
|
||||
defaultKvStore.putBoolean("inAppCameraLocationPref", false);
|
||||
initiateCameraUpload(activity);
|
||||
initiateCameraUpload(activity, resultLauncher);
|
||||
},
|
||||
null,
|
||||
true);
|
||||
|
|
@ -204,18 +210,18 @@ public class ContributionController {
|
|||
/**
|
||||
* Initiate gallery picker
|
||||
*/
|
||||
public void initiateGalleryPick(final Activity activity, final boolean allowMultipleUploads) {
|
||||
initiateGalleryUpload(activity, allowMultipleUploads);
|
||||
public void initiateGalleryPick(final Activity activity,ActivityResultLauncher<Intent> resultLauncher ,final boolean allowMultipleUploads) {
|
||||
initiateGalleryUpload(activity,resultLauncher ,allowMultipleUploads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate gallery picker with permission
|
||||
*/
|
||||
public void initiateCustomGalleryPickWithPermission(final Activity activity) {
|
||||
public void initiateCustomGalleryPickWithPermission(final Activity activity, ActivityResultLauncher<Intent> resultLauncher) {
|
||||
setPickerConfiguration(activity, true);
|
||||
|
||||
PermissionUtils.checkPermissionsAndPerformAction(activity,
|
||||
() -> FilePicker.openCustomSelector(activity, 0),
|
||||
() -> FilePicker.openCustomSelector(activity, resultLauncher,0),
|
||||
R.string.storage_permission_title,
|
||||
R.string.write_storage_permission_rationale,
|
||||
PermissionUtils.PERMISSIONS_STORAGE);
|
||||
|
|
@ -225,12 +231,12 @@ public class ContributionController {
|
|||
/**
|
||||
* Open chooser for gallery uploads
|
||||
*/
|
||||
private void initiateGalleryUpload(final Activity activity,
|
||||
private void initiateGalleryUpload(final Activity activity, ActivityResultLauncher<Intent> resultLauncher,
|
||||
final boolean allowMultipleUploads) {
|
||||
setPickerConfiguration(activity, allowMultipleUploads);
|
||||
boolean openDocumentIntentPreferred = defaultKvStore.getBoolean(
|
||||
"openDocumentPhotoPickerPref", true);
|
||||
FilePicker.openGallery(activity, 0, openDocumentIntentPreferred);
|
||||
FilePicker.openGallery(activity, resultLauncher,0, openDocumentIntentPreferred);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -247,42 +253,72 @@ public class ContributionController {
|
|||
/**
|
||||
* Initiate camera upload by opening camera
|
||||
*/
|
||||
private void initiateCameraUpload(Activity activity) {
|
||||
private void initiateCameraUpload(Activity activity, ActivityResultLauncher<Intent> resultLauncher) {
|
||||
setPickerConfiguration(activity, false);
|
||||
if (defaultKvStore.getBoolean("inAppCameraLocationPref", false)) {
|
||||
locationBeforeImageCapture = locationManager.getLastLocation();
|
||||
}
|
||||
isInAppCameraUpload = true;
|
||||
FilePicker.openCameraForImage(activity, 0);
|
||||
FilePicker.openCameraForImage(activity, resultLauncher,0);
|
||||
}
|
||||
|
||||
public void onPictureReturnedFromGallery(ActivityResult result, Activity activity, FilePicker.Callbacks callbacks){
|
||||
FilePicker.onPictureReturnedFromGallery(result,activity,callbacks);
|
||||
}
|
||||
|
||||
public void onPictureReturnedFromCustomSelector(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) {
|
||||
FilePicker.onPictureReturnedFromCustomSelector(result,activity,callbacks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches callback for file picker.
|
||||
*/
|
||||
public void handleActivityResult(Activity activity, int requestCode, int resultCode,
|
||||
Intent data) {
|
||||
FilePicker.handleActivityResult(requestCode, resultCode, data, activity,
|
||||
new DefaultCallback() {
|
||||
public void handleActivityResultWithCallback(Activity activity, FilePicker.HandleActivityResult handleActivityResult) {
|
||||
|
||||
@Override
|
||||
public void onCanceled(final ImageSource source, final int type) {
|
||||
super.onCanceled(source, type);
|
||||
defaultKvStore.remove(PLACE_OBJECT);
|
||||
}
|
||||
handleActivityResult.onHandleActivityResult(new DefaultCallback() {
|
||||
|
||||
@Override
|
||||
public void onImagePickerError(Exception e, FilePicker.ImageSource source,
|
||||
int type) {
|
||||
ViewUtil.showShortToast(activity, R.string.error_occurred_in_picking_images);
|
||||
}
|
||||
@Override
|
||||
public void onCanceled(final ImageSource source, final int type) {
|
||||
super.onCanceled(source, type);
|
||||
defaultKvStore.remove(PLACE_OBJECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImagesPicked(@NonNull List<UploadableFile> imagesFiles,
|
||||
FilePicker.ImageSource source, int type) {
|
||||
Intent intent = handleImagesPicked(activity, imagesFiles);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onImagePickerError(Exception e, FilePicker.ImageSource source,
|
||||
int type) {
|
||||
ViewUtil.showShortToast(activity, R.string.error_occurred_in_picking_images);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImagesPicked(@NonNull List<UploadableFile> imagesFiles,
|
||||
FilePicker.ImageSource source, int type) {
|
||||
Intent intent = handleImagesPicked(activity, imagesFiles);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
// FilePicker.handleActivityResult(requestCode, resultCode, data, activity,
|
||||
// new DefaultCallback() {
|
||||
//
|
||||
// @Override
|
||||
// public void onCanceled(final ImageSource source, final int type) {
|
||||
// super.onCanceled(source, type);
|
||||
// defaultKvStore.remove(PLACE_OBJECT);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onImagePickerError(Exception e, FilePicker.ImageSource source,
|
||||
// int type) {
|
||||
// ViewUtil.showShortToast(activity, R.string.error_occurred_in_picking_images);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onImagesPicked(@NonNull List<UploadableFile> imagesFiles,
|
||||
// FilePicker.ImageSource source, int type) {
|
||||
// Intent intent = handleImagesPicked(activity, imagesFiles);
|
||||
// activity.startActivity(intent);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
public List<UploadableFile> handleExternalImagesPicked(Activity activity,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import static fr.free.nrw.commons.di.NetworkingModule.NAMED_LANGUAGE_WIKI_PEDIA_
|
|||
|
||||
import android.Manifest.permission;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -20,6 +21,7 @@ import android.widget.LinearLayout;
|
|||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
|
@ -96,6 +98,25 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
private int contributionsSize;
|
||||
private String userName;
|
||||
|
||||
private ActivityResultLauncher<Intent> galleryPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
|
||||
controller.onPictureReturnedFromGallery(result,requireActivity(),callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<Intent> customSelectorLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
|
||||
controller.onPictureReturnedFromCustomSelector(result,requireActivity(),callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
// TODO handle result from controller
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(
|
||||
new RequestMultiplePermissions(),
|
||||
new ActivityResultCallback<Map<String, Boolean>>() {
|
||||
|
|
@ -111,7 +132,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
} else {
|
||||
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
|
||||
controller.handleShowRationaleFlowCameraLocation(getActivity(),
|
||||
inAppCameraLocationPermissionLauncher);
|
||||
inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult);
|
||||
} else {
|
||||
controller.locationPermissionCallback.onLocationPermissionDenied(
|
||||
getActivity().getString(
|
||||
|
|
@ -322,7 +343,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
private void setListeners() {
|
||||
binding.fabPlus.setOnClickListener(view -> animateFAB(isFabOpen));
|
||||
binding.fabCamera.setOnClickListener(view -> {
|
||||
controller.initiateCameraPick(getActivity(), inAppCameraLocationPermissionLauncher);
|
||||
controller.initiateCameraPick(getActivity(), inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult);
|
||||
animateFAB(isFabOpen);
|
||||
});
|
||||
binding.fabCamera.setOnLongClickListener(view -> {
|
||||
|
|
@ -330,7 +351,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
return true;
|
||||
});
|
||||
binding.fabGallery.setOnClickListener(view -> {
|
||||
controller.initiateGalleryPick(getActivity(), true);
|
||||
controller.initiateGalleryPick(getActivity(), galleryPickLauncherForResult,true);
|
||||
animateFAB(isFabOpen);
|
||||
});
|
||||
binding.fabGallery.setOnLongClickListener(view -> {
|
||||
|
|
@ -343,7 +364,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
* Launch Custom Selector.
|
||||
*/
|
||||
protected void launchCustomSelector() {
|
||||
controller.initiateCustomGalleryPickWithPermission(getActivity());
|
||||
controller.initiateCustomGalleryPickWithPermission(getActivity(),customSelectorLauncherForResult);
|
||||
animateFAB(isFabOpen);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
package fr.free.nrw.commons.contributions;
|
||||
|
||||
import android.Manifest.permission;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -16,10 +13,8 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import androidx.work.ExistingWorkPolicy;
|
||||
import fr.free.nrw.commons.databinding.MainBinding;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.WelcomeActivity;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
|
|
@ -41,10 +36,8 @@ import fr.free.nrw.commons.notification.NotificationController;
|
|||
import fr.free.nrw.commons.quiz.QuizChecker;
|
||||
import fr.free.nrw.commons.settings.SettingsFragment;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.upload.UploadActivity;
|
||||
import fr.free.nrw.commons.upload.UploadProgressActivity;
|
||||
import fr.free.nrw.commons.upload.worker.WorkRequestHelper;
|
||||
import fr.free.nrw.commons.utils.PermissionUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtilWrapper;
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
|
@ -442,7 +435,9 @@ public class MainActivity extends BaseActivity
|
|||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Timber.d(data != null ? data.toString() : "onActivityResult data is null");
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
controller.handleActivityResult(this, requestCode, resultCode, data);
|
||||
//TODO [parr] This can be removed. since any screen that expects a result from launched activity
|
||||
// handles that in it's own respective place.
|
||||
// controller.handleActivityResult(this, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import android.view.Window
|
|||
import android.widget.Button
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
|
|
@ -146,6 +148,10 @@ class CustomSelectorActivity :
|
|||
|
||||
private var showPartialAccessIndicator by mutableStateOf(false)
|
||||
|
||||
private val startForResult = registerForActivityResult(StartActivityForResult()){ result ->
|
||||
onFullScreenDataReceived(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* onCreate Activity, sets theme, initialises the view model, setup view.
|
||||
*/
|
||||
|
|
@ -224,17 +230,10 @@ class CustomSelectorActivity :
|
|||
/**
|
||||
* When data will be send from full screen mode, it will be passed to fragment
|
||||
*/
|
||||
override fun onActivityResult(
|
||||
requestCode: Int,
|
||||
resultCode: Int,
|
||||
data: Intent?,
|
||||
) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == Constants.RequestCodes.RECEIVE_DATA_FROM_FULL_SCREEN_MODE &&
|
||||
resultCode == Activity.RESULT_OK
|
||||
) {
|
||||
fun onFullScreenDataReceived(result: ActivityResult){
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
val selectedImages: ArrayList<Image> =
|
||||
data!!
|
||||
result.data!!
|
||||
.getParcelableArrayListExtra(CustomSelectorConstants.NEW_SELECTED_IMAGES)!!
|
||||
viewModel?.selectedImages?.value = selectedImages
|
||||
}
|
||||
|
|
@ -509,7 +508,7 @@ class CustomSelectorActivity :
|
|||
selectedImages,
|
||||
)
|
||||
intent.putExtra(CustomSelectorConstants.BUCKET_ID, bucketId)
|
||||
startActivityForResult(intent, Constants.RequestCodes.RECEIVE_DATA_FROM_FULL_SCREEN_MODE)
|
||||
startForResult.launch(intent)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import android.os.Bundle
|
|||
import android.os.Parcelable
|
||||
import android.speech.RecognizerIntent
|
||||
import android.view.View
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
|
|
@ -74,6 +76,17 @@ class DescriptionEditActivity :
|
|||
|
||||
private var descriptionAndCaptions: ArrayList<UploadMediaDetail>? = null
|
||||
|
||||
private val voiceInputResultLauncher = registerForActivityResult<Intent, ActivityResult>(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result: ActivityResult ->
|
||||
if (result.resultCode == RESULT_OK && result.data != null) {
|
||||
val resultData = result.data!!.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
|
||||
uploadMediaDetailAdapter.handleSpeechResult(resultData!![0])
|
||||
} else {
|
||||
Timber.e("Error %s", result.resultCode)
|
||||
}
|
||||
}
|
||||
|
||||
@Inject lateinit var descriptionEditHelper: DescriptionEditHelper
|
||||
|
||||
@Inject lateinit var sessionManager: SessionManager
|
||||
|
|
@ -115,6 +128,7 @@ class DescriptionEditActivity :
|
|||
savedLanguageValue,
|
||||
descriptionAndCaptions,
|
||||
recentLanguagesDao,
|
||||
voiceInputResultLauncher
|
||||
)
|
||||
uploadMediaDetailAdapter.setCallback { titleStringID: Int, messageStringId: Int ->
|
||||
showInfoAlert(
|
||||
|
|
@ -292,21 +306,21 @@ class DescriptionEditActivity :
|
|||
progressDialog!!.show()
|
||||
}
|
||||
|
||||
override fun onActivityResult(
|
||||
requestCode: Int,
|
||||
resultCode: Int,
|
||||
data: Intent?,
|
||||
) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == requestCodeForVoiceInput) {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
val result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
|
||||
uploadMediaDetailAdapter.handleSpeechResult(result!![0])
|
||||
} else {
|
||||
Timber.e("Error %s", resultCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
// override fun onActivityResult(
|
||||
// requestCode: Int,
|
||||
// resultCode: Int,
|
||||
// data: Intent?,
|
||||
// ) {
|
||||
// super.onActivityResult(requestCode, resultCode, data)
|
||||
// if (requestCode == requestCodeForVoiceInput) {
|
||||
// if (resultCode == RESULT_OK && data != null) {
|
||||
// val result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
|
||||
// uploadMediaDetailAdapter.handleSpeechResult(result!![0])
|
||||
// } else {
|
||||
// Timber.e("Error %s", resultCode)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import android.content.pm.ResolveInfo;
|
|||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
|
@ -107,31 +109,35 @@ public class FilePicker implements Constants {
|
|||
*
|
||||
* @param type Custom type of your choice, which will be returned with the images
|
||||
*/
|
||||
public static void openGallery(Activity activity, int type, boolean openDocumentIntentPreferred) {
|
||||
public static void openGallery(Activity activity,ActivityResultLauncher<Intent> resultLauncher,int type, boolean openDocumentIntentPreferred) {
|
||||
Intent intent = createGalleryIntent(activity, type, openDocumentIntentPreferred);
|
||||
int requestCode = RequestCodes.PICK_PICTURE_FROM_GALLERY;
|
||||
|
||||
if(openDocumentIntentPreferred){
|
||||
requestCode = RequestCodes.PICK_PICTURE_FROM_DOCUMENTS;
|
||||
}
|
||||
|
||||
activity.startActivityForResult(intent, requestCode);
|
||||
// int requestCode = RequestCodes.PICK_PICTURE_FROM_GALLERY;
|
||||
//
|
||||
// if(openDocumentIntentPreferred){
|
||||
// requestCode = RequestCodes.PICK_PICTURE_FROM_DOCUMENTS;
|
||||
// }
|
||||
//
|
||||
// activity.startActivityForResult(intent, requestCode);
|
||||
resultLauncher.launch(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens Custom Selector
|
||||
*/
|
||||
public static void openCustomSelector(Activity activity, int type) {
|
||||
public static void openCustomSelector(Activity activity,ActivityResultLauncher<Intent> resultLauncher,int type) {
|
||||
Intent intent = createCustomSelectorIntent(activity, type);
|
||||
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR);
|
||||
// activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR);
|
||||
resultLauncher.launch(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the camera app to pick image clicked by user
|
||||
*/
|
||||
public static void openCameraForImage(Activity activity, int type) {
|
||||
public static void openCameraForImage(Activity activity, ActivityResultLauncher<Intent> resultLauncher, int type) {
|
||||
Intent intent = createCameraForImageIntent(activity, type);
|
||||
activity.startActivityForResult(intent, RequestCodes.TAKE_PICTURE);
|
||||
//TODO[Parry] we're not using the result anyways.
|
||||
// activity.startActivityForResult(intent, RequestCodes.TAKE_PICTURE);
|
||||
resultLauncher.launch(intent);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
@ -169,10 +175,11 @@ public class FilePicker implements Constants {
|
|||
if (requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS && !isPhoto(data)) {
|
||||
onPictureReturnedFromDocuments(data, activity, callbacks);
|
||||
} else if (requestCode == RequestCodes.PICK_PICTURE_FROM_GALLERY && !isPhoto(data)) {
|
||||
onPictureReturnedFromGallery(data, activity, callbacks);
|
||||
// onPictureReturnedFromGallery(data, activity, callbacks);
|
||||
} else if (requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR) {
|
||||
onPictureReturnedFromCustomSelector(data, activity, callbacks);
|
||||
// onPictureReturnedFromCustomSelector(data, activity, callbacks);
|
||||
} else if (requestCode == RequestCodes.TAKE_PICTURE) {
|
||||
//TODO[Parry] why handle the result , when not using it in the first place???
|
||||
onPictureReturnedFromCamera(activity, callbacks);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -262,14 +269,16 @@ public class FilePicker implements Constants {
|
|||
* onPictureReturnedFromCustomSelector.
|
||||
* Retrieve and forward the images to upload wizard through callback.
|
||||
*/
|
||||
private static void onPictureReturnedFromCustomSelector(Intent data, Activity activity, @NonNull FilePicker.Callbacks callbacks) {
|
||||
try {
|
||||
List<UploadableFile> files = getFilesFromCustomSelector(data, activity);
|
||||
callbacks.onImagesPicked(files, ImageSource.CUSTOM_SELECTOR, restoreType(activity));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
callbacks.onImagePickerError(e, ImageSource.CUSTOM_SELECTOR, restoreType(activity));
|
||||
}
|
||||
public static void onPictureReturnedFromCustomSelector(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) {
|
||||
if(result.getResultCode() == Activity.RESULT_OK){
|
||||
try {
|
||||
List<UploadableFile> files = getFilesFromCustomSelector(result.getData(), activity);
|
||||
callbacks.onImagesPicked(files, ImageSource.CUSTOM_SELECTOR, restoreType(activity));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
callbacks.onImagePickerError(e, ImageSource.CUSTOM_SELECTOR, restoreType(activity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -292,13 +301,17 @@ public class FilePicker implements Constants {
|
|||
return files;
|
||||
}
|
||||
|
||||
private static void onPictureReturnedFromGallery(Intent data, Activity activity, @NonNull FilePicker.Callbacks callbacks) {
|
||||
try {
|
||||
List<UploadableFile> files = getFilesFromGalleryPictures(data, activity);
|
||||
callbacks.onImagesPicked(files, FilePicker.ImageSource.GALLERY, restoreType(activity));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
callbacks.onImagePickerError(e, FilePicker.ImageSource.GALLERY, restoreType(activity));
|
||||
public static void onPictureReturnedFromGallery(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) {
|
||||
if(result.getResultCode() == Activity.RESULT_OK){
|
||||
try {
|
||||
List<UploadableFile> files = getFilesFromGalleryPictures(result.getData(), activity);
|
||||
callbacks.onImagesPicked(files, FilePicker.ImageSource.GALLERY, restoreType(activity));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
callbacks.onImagePickerError(e, FilePicker.ImageSource.GALLERY, restoreType(activity));
|
||||
}
|
||||
}else{
|
||||
callbacks.onCanceled(FilePicker.ImageSource.GALLERY, restoreType(activity));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -406,4 +419,8 @@ public class FilePicker implements Constants {
|
|||
|
||||
void onCanceled(FilePicker.ImageSource source, int type);
|
||||
}
|
||||
|
||||
public interface HandleActivityResult{
|
||||
void onHandleActivityResult(FilePicker.Callbacks callbacks);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1065,6 +1065,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
return captionList;
|
||||
}
|
||||
|
||||
// TODO[Parry]: Request code is never used to start an activity, so the result will never
|
||||
// be used, safely remove this.
|
||||
/**
|
||||
* Get the result from another activity and act accordingly.
|
||||
* @param requestCode
|
||||
|
|
|
|||
|
|
@ -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>>,
|
||||
resultLauncher: 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, resultLauncher) }
|
||||
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,26 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
private GridLayoutManager gridLayoutManager;
|
||||
private List<BottomSheetItem> dataList;
|
||||
private BottomSheetAdapter bottomSheetAdapter;
|
||||
|
||||
private ActivityResultLauncher<Intent> galleryPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
|
||||
controller.onPictureReturnedFromGallery(result,requireActivity(),callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<Intent> customSelectorLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
|
||||
controller.onPictureReturnedFromCustomSelector(result,requireActivity(),callbacks);
|
||||
});
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
// TODO handle result from controller
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(
|
||||
new RequestMultiplePermissions(),
|
||||
new ActivityResultCallback<Map<String, Boolean>>() {
|
||||
|
|
@ -240,7 +261,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 +591,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
return Unit.INSTANCE;
|
||||
},
|
||||
commonPlaceClickActions,
|
||||
inAppCameraLocationPermissionLauncher
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
galleryPickLauncherForResult,
|
||||
cameraPickLauncherForResult
|
||||
);
|
||||
binding.bottomSheetNearby.rvNearbyList.setAdapter(adapter);
|
||||
}
|
||||
|
|
@ -2201,7 +2224,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 +2233,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
Timber.d("Gallery button tapped. Place: %s", selectedPlace.toString());
|
||||
storeSharedPrefs(selectedPlace);
|
||||
controller.initiateGalleryPick(getActivity(),
|
||||
galleryPickLauncherForResult,
|
||||
false);
|
||||
}
|
||||
});
|
||||
|
|
@ -2218,7 +2242,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>,
|
||||
resultLauncherStub: ActivityResultLauncher<Intent>
|
||||
) : BaseDelegateAdapter<Place>(
|
||||
placeAdapterDelegate(
|
||||
bookmarkLocationsDao,
|
||||
|
|
@ -27,6 +30,8 @@ class PlaceAdapter(
|
|||
commonPlaceClickActions.onDirectionsClicked(),
|
||||
commonPlaceClickActions.onDirectionsLongPressed(),
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
resultLauncherStub,
|
||||
galleryPickLauncherForResult
|
||||
),
|
||||
areItemsTheSame = { oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId },
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import android.widget.TextView;
|
|||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.MultiSelectListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
|
@ -85,6 +86,12 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
private View separator;
|
||||
private ListView languageHistoryListView;
|
||||
private static final String GET_CONTENT_PICKER_HELP_URL = "https://commons-app.github.io/docs.html#get-content";
|
||||
|
||||
private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
|
||||
result -> {
|
||||
// TODO handle result from controller
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
|
||||
@Override
|
||||
public void onActivityResult(Map<String, Boolean> result) {
|
||||
|
|
@ -93,7 +100,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
areAllGranted = areAllGranted && b;
|
||||
}
|
||||
if (!areAllGranted && shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
|
||||
contributionController.handleShowRationaleFlowCameraLocation(getActivity(), inAppCameraLocationPermissionLauncher);
|
||||
contributionController.handleShowRationaleFlowCameraLocation(getActivity(), inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
|
@ -57,27 +58,30 @@ public class UploadMediaDetailAdapter extends
|
|||
private int currentPosition;
|
||||
private Fragment fragment;
|
||||
private Activity activity;
|
||||
private ActivityResultLauncher<Intent> voiceInputResultLauncher;
|
||||
private SelectedVoiceIcon selectedVoiceIcon;
|
||||
private static final int REQUEST_CODE_FOR_VOICE_INPUT = 1213;
|
||||
|
||||
private RowItemDescriptionBinding binding;
|
||||
|
||||
public UploadMediaDetailAdapter(Fragment fragment, String savedLanguageValue,
|
||||
RecentLanguagesDao recentLanguagesDao) {
|
||||
RecentLanguagesDao recentLanguagesDao, ActivityResultLauncher<Intent> voiceInputResultLauncher) {
|
||||
uploadMediaDetails = new ArrayList<>();
|
||||
selectedLanguages = new HashMap<>();
|
||||
this.savedLanguageValue = savedLanguageValue;
|
||||
this.recentLanguagesDao = recentLanguagesDao;
|
||||
this.fragment = fragment;
|
||||
this.voiceInputResultLauncher = voiceInputResultLauncher;
|
||||
}
|
||||
|
||||
public UploadMediaDetailAdapter(Activity activity, final String savedLanguageValue,
|
||||
List<UploadMediaDetail> uploadMediaDetails, RecentLanguagesDao recentLanguagesDao) {
|
||||
List<UploadMediaDetail> uploadMediaDetails, RecentLanguagesDao recentLanguagesDao, ActivityResultLauncher<Intent> voiceInputResultLauncher) {
|
||||
this.uploadMediaDetails = uploadMediaDetails;
|
||||
selectedLanguages = new HashMap<>();
|
||||
this.savedLanguageValue = savedLanguageValue;
|
||||
this.recentLanguagesDao = recentLanguagesDao;
|
||||
this.activity = activity;
|
||||
this.voiceInputResultLauncher = voiceInputResultLauncher;
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
|
|
@ -150,11 +154,7 @@ public class UploadMediaDetailAdapter extends
|
|||
);
|
||||
|
||||
try {
|
||||
if (activity == null) {
|
||||
fragment.startActivityForResult(intent, REQUEST_CODE_FOR_VOICE_INPUT);
|
||||
} else {
|
||||
activity.startActivityForResult(intent, REQUEST_CODE_FOR_VOICE_INPUT);
|
||||
}
|
||||
voiceInputResultLauncher.launch(intent);
|
||||
} catch (Exception e) {
|
||||
Timber.e(e.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ import android.view.ViewGroup;
|
|||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.exifinterface.media.ExifInterface;
|
||||
|
|
@ -58,9 +61,33 @@ import timber.log.Timber;
|
|||
public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||
UploadMediaDetailsContract.View, UploadMediaDetailAdapter.EventListener {
|
||||
|
||||
private static final int REQUEST_CODE = 1211;
|
||||
private static final int REQUEST_CODE_FOR_EDIT_ACTIVITY = 1212;
|
||||
private static final int REQUEST_CODE_FOR_VOICE_INPUT = 1213;
|
||||
private UploadMediaDetailAdapter uploadMediaDetailAdapter;
|
||||
|
||||
// private static final int REQUEST_CODE_FOR_EDIT_ACTIVITY = 1212;
|
||||
// private static final int REQUEST_CODE_FOR_VOICE_INPUT = 1213;
|
||||
|
||||
private final ActivityResultLauncher<Intent> startForResult = registerForActivityResult(
|
||||
new StartActivityForResult(), result -> {
|
||||
onCameraPosition(result);
|
||||
});
|
||||
|
||||
private final ActivityResultLauncher<Intent> startForEditActivityResult = registerForActivityResult(
|
||||
new StartActivityForResult(), result -> {
|
||||
onEditActivityResult(result);
|
||||
}
|
||||
);
|
||||
|
||||
private final ActivityResultLauncher<Intent> voiceInputResultLauncher = registerForActivityResult(
|
||||
new StartActivityForResult(), result -> {
|
||||
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
|
||||
ArrayList<String> resultData = result.getData().getStringArrayListExtra(
|
||||
RecognizerIntent.EXTRA_RESULTS);
|
||||
uploadMediaDetailAdapter.handleSpeechResult(resultData.get(0));
|
||||
}else {
|
||||
Timber.e("Error %s", result.getResultCode());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static Activity activity ;
|
||||
|
||||
|
|
@ -84,8 +111,6 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
private boolean hasUserRemovedLocation;
|
||||
|
||||
|
||||
private UploadMediaDetailAdapter uploadMediaDetailAdapter;
|
||||
|
||||
@Inject
|
||||
UploadMediaDetailsContract.UserActionListener presenter;
|
||||
|
||||
|
|
@ -279,7 +304,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
*/
|
||||
private void initRecyclerView() {
|
||||
uploadMediaDetailAdapter = new UploadMediaDetailAdapter(this,
|
||||
defaultKvStore.getString(Prefs.DESCRIPTION_LANGUAGE, ""), recentLanguagesDao);
|
||||
defaultKvStore.getString(Prefs.DESCRIPTION_LANGUAGE, ""), recentLanguagesDao, voiceInputResultLauncher);
|
||||
uploadMediaDetailAdapter.setCallback(this::showInfoAlert);
|
||||
uploadMediaDetailAdapter.setEventListener(this);
|
||||
binding.rvDescriptions.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
|
@ -600,7 +625,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
editableUploadItem = uploadItem;
|
||||
Intent intent = new Intent(getContext(), EditActivity.class);
|
||||
intent.putExtra("image", uploadableFile.getFilePath().toString());
|
||||
startActivityForResult(intent, REQUEST_CODE_FOR_EDIT_ACTIVITY);
|
||||
startForEditActivityResult.launch(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -615,6 +640,8 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
double defaultLongitude = -122.431297;
|
||||
double defaultZoom = 16.0;
|
||||
|
||||
final Intent locationPickerIntent;
|
||||
|
||||
/* Retrieve image location from EXIF if present or
|
||||
check if user has provided location while using the in-app camera.
|
||||
Use location of last UploadItem if none of them is available */
|
||||
|
|
@ -624,10 +651,11 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
.getDecLatitude();
|
||||
defaultLongitude = uploadItem.getGpsCoords().getDecLongitude();
|
||||
defaultZoom = uploadItem.getGpsCoords().getZoomLevel();
|
||||
startActivityForResult(new LocationPicker.IntentBuilder()
|
||||
|
||||
locationPickerIntent = new LocationPicker.IntentBuilder()
|
||||
.defaultLocation(new CameraPosition(defaultLatitude,defaultLongitude,defaultZoom))
|
||||
.activityKey("UploadActivity")
|
||||
.build(getActivity()), REQUEST_CODE);
|
||||
.build(getActivity());
|
||||
} else {
|
||||
if (defaultKvStore.getString(LAST_LOCATION) != null) {
|
||||
final String[] locationLatLng
|
||||
|
|
@ -638,27 +666,20 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
if (defaultKvStore.getString(LAST_ZOOM) != null) {
|
||||
defaultZoom = Double.parseDouble(defaultKvStore.getString(LAST_ZOOM));
|
||||
}
|
||||
startActivityForResult(new LocationPicker.IntentBuilder()
|
||||
|
||||
locationPickerIntent = new LocationPicker.IntentBuilder()
|
||||
.defaultLocation(new CameraPosition(defaultLatitude,defaultLongitude,defaultZoom))
|
||||
.activityKey("NoLocationUploadActivity")
|
||||
.build(getActivity()), REQUEST_CODE);
|
||||
.build(getActivity());
|
||||
}
|
||||
startForResult.launch(locationPickerIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the coordinates and update the existing coordinates.
|
||||
* @param requestCode code of request
|
||||
* @param resultCode code of result
|
||||
* @param data intent
|
||||
*/
|
||||
@Override
|
||||
public void onActivityResult(final int requestCode, final int resultCode,
|
||||
@Nullable final Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
|
||||
private void onCameraPosition(ActivityResult result){
|
||||
if (result.getResultCode() == RESULT_OK) {
|
||||
|
||||
assert data != null;
|
||||
final CameraPosition cameraPosition = LocationPicker.getCameraPosition(data);
|
||||
assert result.getData() != null;
|
||||
final CameraPosition cameraPosition = LocationPicker.getCameraPosition(result.getData());
|
||||
|
||||
if (cameraPosition != null) {
|
||||
|
||||
|
|
@ -678,8 +699,12 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
removeLocation();
|
||||
}
|
||||
}
|
||||
if (requestCode == REQUEST_CODE_FOR_EDIT_ACTIVITY && resultCode == RESULT_OK) {
|
||||
String result = data.getStringExtra("editedImageFilePath");
|
||||
}
|
||||
|
||||
private void onEditActivityResult(ActivityResult result){
|
||||
//TODO[Parry] Doubtful how it works, understand it....
|
||||
if (result.getResultCode() == RESULT_OK) {
|
||||
String path = result.getData().getStringExtra("editedImageFilePath");
|
||||
|
||||
if (Objects.equals(result, "Error")) {
|
||||
Timber.e("Error in rotating image");
|
||||
|
|
@ -687,26 +712,39 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
}
|
||||
try {
|
||||
if (binding != null){
|
||||
binding.backgroundImage.setImageURI(Uri.fromFile(new File(result)));
|
||||
binding.backgroundImage.setImageURI(Uri.fromFile(new File(path)));
|
||||
}
|
||||
editableUploadItem.setContentUri(Uri.fromFile(new File(result)));
|
||||
editableUploadItem.setContentUri(Uri.fromFile(new File(path)));
|
||||
callback.changeThumbnail(indexOfFragment,
|
||||
result);
|
||||
path);
|
||||
} catch (Exception e) {
|
||||
Timber.e(e);
|
||||
}
|
||||
}
|
||||
else if (requestCode == REQUEST_CODE_FOR_VOICE_INPUT) {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
ArrayList<String> result = data.getStringArrayListExtra(
|
||||
RecognizerIntent.EXTRA_RESULTS);
|
||||
uploadMediaDetailAdapter.handleSpeechResult(result.get(0));
|
||||
}else {
|
||||
Timber.e("Error %s", resultCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the coordinates and update the existing coordinates.
|
||||
* @param requestCode code of request
|
||||
* @param resultCode code of result
|
||||
* @param data intent
|
||||
*/
|
||||
// @Override
|
||||
// public void onActivityResult(final int requestCode, final int resultCode,
|
||||
// @Nullable final Intent data) {
|
||||
// super.onActivityResult(requestCode, resultCode, data);
|
||||
//
|
||||
// if (requestCode == REQUEST_CODE_FOR_VOICE_INPUT) {
|
||||
// if (resultCode == RESULT_OK && data != null) {
|
||||
// ArrayList<String> result = data.getStringArrayListExtra(
|
||||
// RecognizerIntent.EXTRA_RESULTS);
|
||||
// uploadMediaDetailAdapter.handleSpeechResult(result.get(0));
|
||||
// }else {
|
||||
// Timber.e("Error %s", resultCode);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Removes the location data from the image, by setting them to null
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ class UploadMediaDetailAdapterUnitTest {
|
|||
uploadMediaDetails = mutableListOf(uploadMediaDetail, uploadMediaDetail)
|
||||
activity = Robolectric.buildActivity(UploadActivity::class.java).get()
|
||||
fragment = mock(UploadMediaDetailFragment::class.java)
|
||||
adapter = UploadMediaDetailAdapter(fragment, "", recentLanguagesDao)
|
||||
//TODO[Parry] Adapt tests to new result api
|
||||
// adapter = UploadMediaDetailAdapter(fragment, "", recentLanguagesDao)
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
Whitebox.setInternalState(adapter, "uploadMediaDetails", uploadMediaDetails)
|
||||
Whitebox.setInternalState(adapter, "eventListener", eventListener)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue