mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Migrated ContributionController
This commit is contained in:
parent
bdcc02be1a
commit
7efed21241
2 changed files with 316 additions and 247 deletions
|
|
@ -1,94 +1,104 @@
|
||||||
package fr.free.nrw.commons.contributions;
|
package fr.free.nrw.commons.contributions
|
||||||
|
|
||||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
|
import android.Manifest.permission
|
||||||
|
import android.app.Activity
|
||||||
import android.Manifest.permission;
|
import android.content.Context
|
||||||
import android.app.Activity;
|
import android.content.Intent
|
||||||
import android.content.Context;
|
import android.widget.Toast
|
||||||
import android.content.Intent;
|
import androidx.activity.result.ActivityResult
|
||||||
import android.widget.Toast;
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.ActivityResult;
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.paging.LivePagedListBuilder
|
||||||
import androidx.annotation.NonNull;
|
import androidx.paging.PagedList
|
||||||
import androidx.lifecycle.LiveData;
|
import fr.free.nrw.commons.R
|
||||||
import androidx.paging.DataSource.Factory;
|
import fr.free.nrw.commons.filepicker.DefaultCallback
|
||||||
import androidx.paging.LivePagedListBuilder;
|
import fr.free.nrw.commons.filepicker.FilePicker
|
||||||
import androidx.paging.PagedList;
|
import fr.free.nrw.commons.filepicker.FilePicker.HandleActivityResult
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.filepicker.FilePicker.configuration
|
||||||
import fr.free.nrw.commons.filepicker.DefaultCallback;
|
import fr.free.nrw.commons.filepicker.FilePicker.handleExternalImagesPicked
|
||||||
import fr.free.nrw.commons.filepicker.FilePicker;
|
import fr.free.nrw.commons.filepicker.FilePicker.onPictureReturnedFromDocuments
|
||||||
import fr.free.nrw.commons.filepicker.FilePicker.ImageSource;
|
import fr.free.nrw.commons.filepicker.FilePicker.openCameraForImage
|
||||||
import fr.free.nrw.commons.filepicker.UploadableFile;
|
import fr.free.nrw.commons.filepicker.FilePicker.openCustomSelector
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
import fr.free.nrw.commons.filepicker.FilePicker.openGallery
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.filepicker.UploadableFile
|
||||||
import fr.free.nrw.commons.location.LocationPermissionsHelper;
|
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
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.LocationPermissionsHelper
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback
|
||||||
import fr.free.nrw.commons.upload.UploadActivity;
|
import fr.free.nrw.commons.location.LocationServiceManager
|
||||||
import fr.free.nrw.commons.utils.DialogUtil;
|
import fr.free.nrw.commons.nearby.Place
|
||||||
import fr.free.nrw.commons.utils.PermissionUtils;
|
import fr.free.nrw.commons.upload.UploadActivity
|
||||||
import fr.free.nrw.commons.utils.ViewUtil;
|
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||||
import java.util.ArrayList;
|
import fr.free.nrw.commons.utils.PermissionUtils.PERMISSIONS_STORAGE
|
||||||
import java.util.Arrays;
|
import fr.free.nrw.commons.utils.PermissionUtils.checkPermissionsAndPerformAction
|
||||||
import java.util.Collections;
|
import fr.free.nrw.commons.utils.ViewUtil.showLongToast
|
||||||
import java.util.List;
|
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||||
import javax.inject.Inject;
|
import fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT
|
||||||
import javax.inject.Named;
|
import java.util.Arrays
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Named
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ContributionController {
|
class ContributionController @Inject constructor(@param:Named("default_preferences") private val defaultKvStore: JsonKvStore) {
|
||||||
|
private var locationBeforeImageCapture: LatLng? = null
|
||||||
|
private var isInAppCameraUpload = false
|
||||||
|
@JvmField
|
||||||
|
var locationPermissionCallback: LocationPermissionCallback? = null
|
||||||
|
private var locationPermissionsHelper: LocationPermissionsHelper? = null
|
||||||
|
|
||||||
public static final String ACTION_INTERNAL_UPLOADS = "internalImageUploads";
|
|
||||||
private final JsonKvStore defaultKvStore;
|
|
||||||
private LatLng locationBeforeImageCapture;
|
|
||||||
private boolean isInAppCameraUpload;
|
|
||||||
public LocationPermissionCallback locationPermissionCallback;
|
|
||||||
private LocationPermissionsHelper locationPermissionsHelper;
|
|
||||||
// Temporarily disabled, see issue [https://github.com/commons-app/apps-android-commons/issues/5847]
|
// Temporarily disabled, see issue [https://github.com/commons-app/apps-android-commons/issues/5847]
|
||||||
// LiveData<PagedList<Contribution>> failedAndPendingContributionList;
|
// LiveData<PagedList<Contribution>> failedAndPendingContributionList;
|
||||||
LiveData<PagedList<Contribution>> pendingContributionList;
|
@JvmField
|
||||||
LiveData<PagedList<Contribution>> failedContributionList;
|
var pendingContributionList: LiveData<PagedList<Contribution>>? = null
|
||||||
|
@JvmField
|
||||||
|
var failedContributionList: LiveData<PagedList<Contribution>>? = null
|
||||||
|
|
||||||
|
@JvmField
|
||||||
@Inject
|
@Inject
|
||||||
LocationServiceManager locationManager;
|
var locationManager: LocationServiceManager? = null
|
||||||
|
|
||||||
|
@JvmField
|
||||||
@Inject
|
@Inject
|
||||||
ContributionsRepository repository;
|
var repository: ContributionsRepository? = null
|
||||||
|
|
||||||
@Inject
|
|
||||||
public ContributionController(@Named("default_preferences") JsonKvStore defaultKvStore) {
|
|
||||||
this.defaultKvStore = defaultKvStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for permissions and initiate camera click
|
* Check for permissions and initiate camera click
|
||||||
*/
|
*/
|
||||||
public void initiateCameraPick(Activity activity,
|
fun initiateCameraPick(
|
||||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
activity: Activity,
|
||||||
ActivityResultLauncher<Intent> resultLauncher) {
|
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>,
|
||||||
boolean useExtStorage = defaultKvStore.getBoolean("useExternalStorage", true);
|
resultLauncher: ActivityResultLauncher<Intent>
|
||||||
|
) {
|
||||||
|
val useExtStorage = defaultKvStore.getBoolean("useExternalStorage", true)
|
||||||
if (!useExtStorage) {
|
if (!useExtStorage) {
|
||||||
initiateCameraUpload(activity, resultLauncher);
|
initiateCameraUpload(activity, resultLauncher)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
PermissionUtils.checkPermissionsAndPerformAction(activity,
|
checkPermissionsAndPerformAction(
|
||||||
() -> {
|
activity,
|
||||||
|
{
|
||||||
if (defaultKvStore.getBoolean("inAppCameraFirstRun")) {
|
if (defaultKvStore.getBoolean("inAppCameraFirstRun")) {
|
||||||
defaultKvStore.putBoolean("inAppCameraFirstRun", false);
|
defaultKvStore.putBoolean("inAppCameraFirstRun", false)
|
||||||
askUserToAllowLocationAccess(activity, inAppCameraLocationPermissionLauncher, resultLauncher);
|
askUserToAllowLocationAccess(
|
||||||
|
activity,
|
||||||
|
inAppCameraLocationPermissionLauncher,
|
||||||
|
resultLauncher
|
||||||
|
)
|
||||||
} else if (defaultKvStore.getBoolean("inAppCameraLocationPref")) {
|
} else if (defaultKvStore.getBoolean("inAppCameraLocationPref")) {
|
||||||
createDialogsAndHandleLocationPermissions(activity,
|
createDialogsAndHandleLocationPermissions(
|
||||||
inAppCameraLocationPermissionLauncher, resultLauncher);
|
activity,
|
||||||
|
inAppCameraLocationPermissionLauncher, resultLauncher
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
initiateCameraUpload(activity, resultLauncher);
|
initiateCameraUpload(activity, resultLauncher)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
R.string.storage_permission_title,
|
R.string.storage_permission_title,
|
||||||
R.string.write_storage_permission_rationale,
|
R.string.write_storage_permission_rationale,
|
||||||
PermissionUtils.getPERMISSIONS_STORAGE());
|
*PERMISSIONS_STORAGE
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -96,310 +106,369 @@ public class ContributionController {
|
||||||
*
|
*
|
||||||
* @param activity
|
* @param activity
|
||||||
*/
|
*/
|
||||||
private void createDialogsAndHandleLocationPermissions(Activity activity,
|
private fun createDialogsAndHandleLocationPermissions(
|
||||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
activity: Activity,
|
||||||
ActivityResultLauncher<Intent> resultLauncher) {
|
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>?,
|
||||||
locationPermissionCallback = new LocationPermissionCallback() {
|
resultLauncher: ActivityResultLauncher<Intent>
|
||||||
@Override
|
) {
|
||||||
public void onLocationPermissionDenied(String toastMessage) {
|
locationPermissionCallback = object : LocationPermissionCallback {
|
||||||
|
override fun onLocationPermissionDenied(toastMessage: String) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity,
|
activity,
|
||||||
toastMessage,
|
toastMessage,
|
||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show();
|
).show()
|
||||||
initiateCameraUpload(activity, resultLauncher);
|
initiateCameraUpload(activity, resultLauncher)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun onLocationPermissionGranted() {
|
||||||
public void onLocationPermissionGranted() {
|
if (!locationPermissionsHelper!!.isLocationAccessToAppsTurnedOn()) {
|
||||||
if (!locationPermissionsHelper.isLocationAccessToAppsTurnedOn()) {
|
showLocationOffDialog(
|
||||||
showLocationOffDialog(activity, R.string.in_app_camera_needs_location,
|
activity, R.string.in_app_camera_needs_location,
|
||||||
R.string.in_app_camera_location_unavailable, resultLauncher);
|
R.string.in_app_camera_location_unavailable, resultLauncher
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
initiateCameraUpload(activity, resultLauncher);
|
initiateCameraUpload(activity, resultLauncher)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
locationPermissionsHelper = new LocationPermissionsHelper(
|
|
||||||
activity, locationManager, locationPermissionCallback);
|
|
||||||
if (inAppCameraLocationPermissionLauncher != null) {
|
|
||||||
inAppCameraLocationPermissionLauncher.launch(
|
|
||||||
new String[]{permission.ACCESS_FINE_LOCATION});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locationPermissionsHelper = LocationPermissionsHelper(
|
||||||
|
activity, locationManager!!, locationPermissionCallback
|
||||||
|
)
|
||||||
|
inAppCameraLocationPermissionLauncher?.launch(
|
||||||
|
arrayOf(permission.ACCESS_FINE_LOCATION)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a dialog alerting the user about location services being off and asking them to turn it
|
* Shows a dialog alerting the user about location services being off and asking them to turn it
|
||||||
* on
|
* on
|
||||||
* TODO: Add a seperate callback in LocationPermissionsHelper for this.
|
* TODO: Add a seperate callback in LocationPermissionsHelper for this.
|
||||||
* Ref: https://github.com/commons-app/apps-android-commons/pull/5494/files#r1510553114
|
* Ref: https://github.com/commons-app/apps-android-commons/pull/5494/files#r1510553114
|
||||||
*
|
*
|
||||||
* @param activity Activity reference
|
* @param activity Activity reference
|
||||||
* @param dialogTextResource Resource id of text to be shown in dialog
|
* @param dialogTextResource Resource id of text to be shown in dialog
|
||||||
* @param toastTextResource Resource id of text to be shown in toast
|
* @param toastTextResource Resource id of text to be shown in toast
|
||||||
* @param resultLauncher
|
* @param resultLauncher
|
||||||
*/
|
*/
|
||||||
private void showLocationOffDialog(Activity activity, int dialogTextResource,
|
private fun showLocationOffDialog(
|
||||||
int toastTextResource, ActivityResultLauncher<Intent> resultLauncher) {
|
activity: Activity, dialogTextResource: Int,
|
||||||
DialogUtil
|
toastTextResource: Int, resultLauncher: ActivityResultLauncher<Intent>
|
||||||
.showAlertDialog(activity,
|
) {
|
||||||
activity.getString(R.string.ask_to_turn_location_on),
|
showAlertDialog(activity,
|
||||||
activity.getString(dialogTextResource),
|
activity.getString(R.string.ask_to_turn_location_on),
|
||||||
activity.getString(R.string.title_app_shortcut_setting),
|
activity.getString(dialogTextResource),
|
||||||
activity.getString(R.string.cancel),
|
activity.getString(R.string.title_app_shortcut_setting),
|
||||||
() -> locationPermissionsHelper.openLocationSettings(activity),
|
activity.getString(R.string.cancel),
|
||||||
() -> {
|
{ locationPermissionsHelper!!.openLocationSettings(activity) },
|
||||||
Toast.makeText(activity, activity.getString(toastTextResource),
|
{
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.makeText(
|
||||||
initiateCameraUpload(activity, resultLauncher);
|
activity, activity.getString(toastTextResource),
|
||||||
}
|
Toast.LENGTH_LONG
|
||||||
);
|
).show()
|
||||||
|
initiateCameraUpload(activity, resultLauncher)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleShowRationaleFlowCameraLocation(Activity activity,
|
fun handleShowRationaleFlowCameraLocation(
|
||||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
activity: Activity,
|
||||||
ActivityResultLauncher<Intent> resultLauncher) {
|
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>?,
|
||||||
DialogUtil.showAlertDialog(activity, activity.getString(R.string.location_permission_title),
|
resultLauncher: ActivityResultLauncher<Intent>
|
||||||
|
) {
|
||||||
|
showAlertDialog(
|
||||||
|
activity, activity.getString(R.string.location_permission_title),
|
||||||
activity.getString(R.string.in_app_camera_location_permission_rationale),
|
activity.getString(R.string.in_app_camera_location_permission_rationale),
|
||||||
activity.getString(android.R.string.ok),
|
activity.getString(android.R.string.ok),
|
||||||
activity.getString(android.R.string.cancel),
|
activity.getString(android.R.string.cancel),
|
||||||
() -> {
|
{
|
||||||
createDialogsAndHandleLocationPermissions(activity,
|
createDialogsAndHandleLocationPermissions(
|
||||||
inAppCameraLocationPermissionLauncher, resultLauncher);
|
activity,
|
||||||
|
inAppCameraLocationPermissionLauncher, resultLauncher
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
locationPermissionCallback!!.onLocationPermissionDenied(
|
||||||
|
activity.getString(R.string.in_app_camera_location_permission_denied)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
() -> locationPermissionCallback.onLocationPermissionDenied(
|
|
||||||
activity.getString(R.string.in_app_camera_location_permission_denied)),
|
|
||||||
null
|
null
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suggest user to attach location information with pictures. If the user selects "Yes", then:
|
* Suggest user to attach location information with pictures. If the user selects "Yes", then:
|
||||||
* <p>
|
*
|
||||||
|
*
|
||||||
* Location is taken from the EXIF if the default camera application does not redact location
|
* Location is taken from the EXIF if the default camera application does not redact location
|
||||||
* tags.
|
* tags.
|
||||||
* <p>
|
*
|
||||||
|
*
|
||||||
* Otherwise, if the EXIF metadata does not have location information, then location captured by
|
* Otherwise, if the EXIF metadata does not have location information, then location captured by
|
||||||
* the app is used
|
* the app is used
|
||||||
*
|
*
|
||||||
* @param activity
|
* @param activity
|
||||||
*/
|
*/
|
||||||
private void askUserToAllowLocationAccess(Activity activity,
|
private fun askUserToAllowLocationAccess(
|
||||||
ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher,
|
activity: Activity,
|
||||||
ActivityResultLauncher<Intent> resultLauncher) {
|
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>,
|
||||||
DialogUtil.showAlertDialog(activity,
|
resultLauncher: ActivityResultLauncher<Intent>
|
||||||
|
) {
|
||||||
|
showAlertDialog(
|
||||||
|
activity,
|
||||||
activity.getString(R.string.in_app_camera_location_permission_title),
|
activity.getString(R.string.in_app_camera_location_permission_title),
|
||||||
activity.getString(R.string.in_app_camera_location_access_explanation),
|
activity.getString(R.string.in_app_camera_location_access_explanation),
|
||||||
activity.getString(R.string.option_allow),
|
activity.getString(R.string.option_allow),
|
||||||
activity.getString(R.string.option_dismiss),
|
activity.getString(R.string.option_dismiss),
|
||||||
() -> {
|
{
|
||||||
defaultKvStore.putBoolean("inAppCameraLocationPref", true);
|
defaultKvStore.putBoolean("inAppCameraLocationPref", true)
|
||||||
createDialogsAndHandleLocationPermissions(activity,
|
createDialogsAndHandleLocationPermissions(
|
||||||
inAppCameraLocationPermissionLauncher, resultLauncher);
|
activity,
|
||||||
|
inAppCameraLocationPermissionLauncher, resultLauncher
|
||||||
|
)
|
||||||
},
|
},
|
||||||
() -> {
|
{
|
||||||
ViewUtil.showLongToast(activity, R.string.in_app_camera_location_permission_denied);
|
showLongToast(activity, R.string.in_app_camera_location_permission_denied)
|
||||||
defaultKvStore.putBoolean("inAppCameraLocationPref", false);
|
defaultKvStore.putBoolean("inAppCameraLocationPref", false)
|
||||||
initiateCameraUpload(activity, resultLauncher);
|
initiateCameraUpload(activity, resultLauncher)
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiate gallery picker
|
* Initiate gallery picker
|
||||||
*/
|
*/
|
||||||
public void initiateGalleryPick(final Activity activity, ActivityResultLauncher<Intent> resultLauncher, final boolean allowMultipleUploads) {
|
fun initiateGalleryPick(
|
||||||
initiateGalleryUpload(activity, resultLauncher, allowMultipleUploads);
|
activity: Activity,
|
||||||
|
resultLauncher: ActivityResultLauncher<Intent>,
|
||||||
|
allowMultipleUploads: Boolean
|
||||||
|
) {
|
||||||
|
initiateGalleryUpload(activity, resultLauncher, allowMultipleUploads)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiate gallery picker with permission
|
* Initiate gallery picker with permission
|
||||||
*/
|
*/
|
||||||
public void initiateCustomGalleryPickWithPermission(final Activity activity, ActivityResultLauncher<Intent> resultLauncher) {
|
fun initiateCustomGalleryPickWithPermission(
|
||||||
setPickerConfiguration(activity, true);
|
activity: Activity,
|
||||||
|
resultLauncher: ActivityResultLauncher<Intent>
|
||||||
|
) {
|
||||||
|
setPickerConfiguration(activity, true)
|
||||||
|
|
||||||
PermissionUtils.checkPermissionsAndPerformAction(activity,
|
checkPermissionsAndPerformAction(
|
||||||
() -> FilePicker.openCustomSelector(activity, resultLauncher, 0),
|
activity,
|
||||||
|
{ openCustomSelector(activity, resultLauncher, 0) },
|
||||||
R.string.storage_permission_title,
|
R.string.storage_permission_title,
|
||||||
R.string.write_storage_permission_rationale,
|
R.string.write_storage_permission_rationale,
|
||||||
PermissionUtils.getPERMISSIONS_STORAGE());
|
*PERMISSIONS_STORAGE
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open chooser for gallery uploads
|
* Open chooser for gallery uploads
|
||||||
*/
|
*/
|
||||||
private void initiateGalleryUpload(final Activity activity, ActivityResultLauncher<Intent> resultLauncher,
|
private fun initiateGalleryUpload(
|
||||||
final boolean allowMultipleUploads) {
|
activity: Activity, resultLauncher: ActivityResultLauncher<Intent>,
|
||||||
setPickerConfiguration(activity, allowMultipleUploads);
|
allowMultipleUploads: Boolean
|
||||||
FilePicker.openGallery(activity, resultLauncher, 0, isDocumentPhotoPickerPreferred());
|
) {
|
||||||
|
setPickerConfiguration(activity, allowMultipleUploads)
|
||||||
|
openGallery(activity, resultLauncher, 0, isDocumentPhotoPickerPreferred)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets configuration for file picker
|
* Sets configuration for file picker
|
||||||
*/
|
*/
|
||||||
private void setPickerConfiguration(Activity activity,
|
private fun setPickerConfiguration(
|
||||||
boolean allowMultipleUploads) {
|
activity: Activity,
|
||||||
boolean copyToExternalStorage = defaultKvStore.getBoolean("useExternalStorage", true);
|
allowMultipleUploads: Boolean
|
||||||
FilePicker.configuration(activity)
|
) {
|
||||||
|
val copyToExternalStorage = defaultKvStore.getBoolean("useExternalStorage", true)
|
||||||
|
configuration(activity)
|
||||||
.setCopyTakenPhotosToPublicGalleryAppFolder(copyToExternalStorage)
|
.setCopyTakenPhotosToPublicGalleryAppFolder(copyToExternalStorage)
|
||||||
.setAllowMultiplePickInGallery(allowMultipleUploads);
|
.setAllowMultiplePickInGallery(allowMultipleUploads)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiate camera upload by opening camera
|
* Initiate camera upload by opening camera
|
||||||
*/
|
*/
|
||||||
private void initiateCameraUpload(Activity activity, ActivityResultLauncher<Intent> resultLauncher) {
|
private fun initiateCameraUpload(
|
||||||
setPickerConfiguration(activity, false);
|
activity: Activity,
|
||||||
|
resultLauncher: ActivityResultLauncher<Intent>
|
||||||
|
) {
|
||||||
|
setPickerConfiguration(activity, false)
|
||||||
if (defaultKvStore.getBoolean("inAppCameraLocationPref", false)) {
|
if (defaultKvStore.getBoolean("inAppCameraLocationPref", false)) {
|
||||||
locationBeforeImageCapture = locationManager.getLastLocation();
|
locationBeforeImageCapture = locationManager!!.getLastLocation()
|
||||||
}
|
}
|
||||||
isInAppCameraUpload = true;
|
isInAppCameraUpload = true
|
||||||
FilePicker.openCameraForImage(activity, resultLauncher, 0);
|
openCameraForImage(activity, resultLauncher, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDocumentPhotoPickerPreferred(){
|
private val isDocumentPhotoPickerPreferred: Boolean
|
||||||
return defaultKvStore.getBoolean(
|
get() = defaultKvStore.getBoolean(
|
||||||
"openDocumentPhotoPickerPref", true);
|
"openDocumentPhotoPickerPref", true
|
||||||
}
|
)
|
||||||
|
|
||||||
public void onPictureReturnedFromGallery(ActivityResult result, Activity activity, FilePicker.Callbacks callbacks){
|
fun onPictureReturnedFromGallery(
|
||||||
|
result: ActivityResult,
|
||||||
if(isDocumentPhotoPickerPreferred()){
|
activity: Activity,
|
||||||
FilePicker.onPictureReturnedFromDocuments(result, activity, callbacks);
|
callbacks: FilePicker.Callbacks
|
||||||
|
) {
|
||||||
|
if (isDocumentPhotoPickerPreferred) {
|
||||||
|
onPictureReturnedFromDocuments(result, activity, callbacks)
|
||||||
} else {
|
} else {
|
||||||
FilePicker.onPictureReturnedFromGallery(result, activity, callbacks);
|
FilePicker.onPictureReturnedFromGallery(result, activity, callbacks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPictureReturnedFromCustomSelector(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) {
|
fun onPictureReturnedFromCustomSelector(
|
||||||
FilePicker.onPictureReturnedFromCustomSelector(result, activity, callbacks);
|
result: ActivityResult,
|
||||||
|
activity: Activity,
|
||||||
|
callbacks: FilePicker.Callbacks
|
||||||
|
) {
|
||||||
|
FilePicker.onPictureReturnedFromCustomSelector(result, activity, callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPictureReturnedFromCamera(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) {
|
fun onPictureReturnedFromCamera(
|
||||||
FilePicker.onPictureReturnedFromCamera(result, activity, callbacks);
|
result: ActivityResult,
|
||||||
|
activity: Activity,
|
||||||
|
callbacks: FilePicker.Callbacks
|
||||||
|
) {
|
||||||
|
FilePicker.onPictureReturnedFromCamera(result, activity, callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches callback for file picker.
|
* Attaches callback for file picker.
|
||||||
*/
|
*/
|
||||||
public void handleActivityResultWithCallback(Activity activity, FilePicker.HandleActivityResult handleActivityResult) {
|
fun handleActivityResultWithCallback(
|
||||||
|
activity: Activity,
|
||||||
|
handleActivityResult: HandleActivityResult
|
||||||
|
) {
|
||||||
|
handleActivityResult.onHandleActivityResult(object : DefaultCallback() {
|
||||||
|
override fun onCanceled(source: FilePicker.ImageSource, type: Int) {
|
||||||
|
super.onCanceled(source, type)
|
||||||
|
defaultKvStore.remove(PLACE_OBJECT)
|
||||||
|
}
|
||||||
|
|
||||||
handleActivityResult.onHandleActivityResult(new DefaultCallback() {
|
override fun onImagePickerError(
|
||||||
|
e: Exception, source: FilePicker.ImageSource,
|
||||||
|
type: Int
|
||||||
|
) {
|
||||||
|
showShortToast(activity, R.string.error_occurred_in_picking_images)
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
override fun onImagesPicked(
|
||||||
public void onCanceled(final ImageSource source, final int type) {
|
imagesFiles: List<UploadableFile>,
|
||||||
super.onCanceled(source, type);
|
source: FilePicker.ImageSource, type: Int
|
||||||
defaultKvStore.remove(PLACE_OBJECT);
|
) {
|
||||||
}
|
val 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UploadableFile> handleExternalImagesPicked(Activity activity,
|
fun handleExternalImagesPicked(
|
||||||
Intent data) {
|
activity: Activity,
|
||||||
return FilePicker.handleExternalImagesPicked(data, activity);
|
data: Intent?
|
||||||
|
): List<UploadableFile> {
|
||||||
|
return handleExternalImagesPicked(data, activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns intent to be passed to upload activity Attaches place object for nearby uploads and
|
* Returns intent to be passed to upload activity Attaches place object for nearby uploads and
|
||||||
* location before image capture if in-app camera is used
|
* location before image capture if in-app camera is used
|
||||||
*/
|
*/
|
||||||
private Intent handleImagesPicked(Context context,
|
private fun handleImagesPicked(
|
||||||
List<UploadableFile> imagesFiles) {
|
context: Context,
|
||||||
Intent shareIntent = new Intent(context, UploadActivity.class);
|
imagesFiles: List<UploadableFile>
|
||||||
shareIntent.setAction(ACTION_INTERNAL_UPLOADS);
|
): Intent {
|
||||||
|
val shareIntent = Intent(context, UploadActivity::class.java)
|
||||||
|
shareIntent.setAction(ACTION_INTERNAL_UPLOADS)
|
||||||
shareIntent
|
shareIntent
|
||||||
.putParcelableArrayListExtra(UploadActivity.EXTRA_FILES, new ArrayList<>(imagesFiles));
|
.putParcelableArrayListExtra(UploadActivity.EXTRA_FILES, ArrayList(imagesFiles))
|
||||||
Place place = defaultKvStore.getJson(PLACE_OBJECT, Place.class);
|
val place = defaultKvStore.getJson<Place>(PLACE_OBJECT, Place::class.java)
|
||||||
|
|
||||||
if (place != null) {
|
if (place != null) {
|
||||||
shareIntent.putExtra(PLACE_OBJECT, place);
|
shareIntent.putExtra(PLACE_OBJECT, place)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locationBeforeImageCapture != null) {
|
if (locationBeforeImageCapture != null) {
|
||||||
shareIntent.putExtra(
|
shareIntent.putExtra(
|
||||||
UploadActivity.LOCATION_BEFORE_IMAGE_CAPTURE,
|
UploadActivity.LOCATION_BEFORE_IMAGE_CAPTURE,
|
||||||
locationBeforeImageCapture);
|
locationBeforeImageCapture
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
shareIntent.putExtra(
|
shareIntent.putExtra(
|
||||||
UploadActivity.IN_APP_CAMERA_UPLOAD,
|
UploadActivity.IN_APP_CAMERA_UPLOAD,
|
||||||
isInAppCameraUpload
|
isInAppCameraUpload
|
||||||
);
|
)
|
||||||
isInAppCameraUpload = false; // reset the flag for next use
|
isInAppCameraUpload = false // reset the flag for next use
|
||||||
return shareIntent;
|
return shareIntent
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
val pendingContributions: Unit
|
||||||
* Fetches the contributions with the state "IN_PROGRESS", "QUEUED" and "PAUSED" and then it
|
/**
|
||||||
* populates the `pendingContributionList`.
|
* Fetches the contributions with the state "IN_PROGRESS", "QUEUED" and "PAUSED" and then it
|
||||||
**/
|
* populates the `pendingContributionList`.
|
||||||
void getPendingContributions() {
|
*/
|
||||||
final PagedList.Config pagedListConfig =
|
get() {
|
||||||
(new PagedList.Config.Builder())
|
val pagedListConfig =
|
||||||
.setPrefetchDistance(50)
|
(PagedList.Config.Builder())
|
||||||
.setPageSize(10).build();
|
.setPrefetchDistance(50)
|
||||||
Factory<Integer, Contribution> factory;
|
.setPageSize(10).build()
|
||||||
factory = repository.fetchContributionsWithStates(
|
val factory = repository!!.fetchContributionsWithStates(
|
||||||
Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
|
Arrays.asList(
|
||||||
Contribution.STATE_PAUSED));
|
Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
|
||||||
|
Contribution.STATE_PAUSED
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
val livePagedListBuilder = LivePagedListBuilder(factory, pagedListConfig)
|
||||||
pagedListConfig);
|
pendingContributionList = livePagedListBuilder.build()
|
||||||
pendingContributionList = livePagedListBuilder.build();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
val failedContributions: Unit
|
||||||
* Fetches the contributions with the state "FAILED" and populates the
|
/**
|
||||||
* `failedContributionList`.
|
* Fetches the contributions with the state "FAILED" and populates the
|
||||||
**/
|
* `failedContributionList`.
|
||||||
void getFailedContributions() {
|
*/
|
||||||
final PagedList.Config pagedListConfig =
|
get() {
|
||||||
(new PagedList.Config.Builder())
|
val pagedListConfig =
|
||||||
.setPrefetchDistance(50)
|
(PagedList.Config.Builder())
|
||||||
.setPageSize(10).build();
|
.setPrefetchDistance(50)
|
||||||
Factory<Integer, Contribution> factory;
|
.setPageSize(10).build()
|
||||||
factory = repository.fetchContributionsWithStates(
|
val factory = repository!!.fetchContributionsWithStates(
|
||||||
Collections.singletonList(Contribution.STATE_FAILED));
|
listOf(Contribution.STATE_FAILED)
|
||||||
|
)
|
||||||
|
|
||||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
val livePagedListBuilder = LivePagedListBuilder(factory, pagedListConfig)
|
||||||
pagedListConfig);
|
failedContributionList = livePagedListBuilder.build()
|
||||||
failedContributionList = livePagedListBuilder.build();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporarily disabled, see issue [https://github.com/commons-app/apps-android-commons/issues/5847]
|
* Temporarily disabled, see issue [https://github.com/commons-app/apps-android-commons/issues/5847]
|
||||||
* Fetches the contributions with the state "IN_PROGRESS", "QUEUED", "PAUSED" and "FAILED" and
|
* Fetches the contributions with the state "IN_PROGRESS", "QUEUED", "PAUSED" and "FAILED" and
|
||||||
* then it populates the `failedAndPendingContributionList`.
|
* then it populates the `failedAndPendingContributionList`.
|
||||||
**/
|
*/
|
||||||
// void getFailedAndPendingContributions() {
|
// void getFailedAndPendingContributions() {
|
||||||
// final PagedList.Config pagedListConfig =
|
// final PagedList.Config pagedListConfig =
|
||||||
// (new PagedList.Config.Builder())
|
// (new PagedList.Config.Builder())
|
||||||
// .setPrefetchDistance(50)
|
// .setPrefetchDistance(50)
|
||||||
// .setPageSize(10).build();
|
// .setPageSize(10).build();
|
||||||
// Factory<Integer, Contribution> factory;
|
// Factory<Integer, Contribution> factory;
|
||||||
// factory = repository.fetchContributionsWithStates(
|
// factory = repository.fetchContributionsWithStates(
|
||||||
// Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
|
// Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
|
||||||
// Contribution.STATE_PAUSED, Contribution.STATE_FAILED));
|
// Contribution.STATE_PAUSED, Contribution.STATE_FAILED));
|
||||||
//
|
//
|
||||||
// LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
// LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||||
// pagedListConfig);
|
// pagedListConfig);
|
||||||
// failedAndPendingContributionList = livePagedListBuilder.build();
|
// failedAndPendingContributionList = livePagedListBuilder.build();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ACTION_INTERNAL_UPLOADS: String = "internalImageUploads"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -679,7 +679,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun receiveExternalSharedItems() {
|
private fun receiveExternalSharedItems() {
|
||||||
uploadableFiles = contributionController!!.handleExternalImagesPicked(this, intent)
|
uploadableFiles = contributionController!!.handleExternalImagesPicked(this, intent).toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun receiveInternalSharedItems() {
|
private fun receiveInternalSharedItems() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue