Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parneet-guraya 2024-10-18 09:52:14 +05:30
parent 3d1c4c9a30
commit c53ad43520
No known key found for this signature in database
GPG key ID: 63B807C4B2A9064B
14 changed files with 49 additions and 83 deletions

View file

@ -35,14 +35,16 @@ public class BookmarkLocationsFragment extends DaggerFragment {
@Inject CommonPlaceClickActions commonPlaceClickActions;
private PlaceAdapter adapter;
private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> cameraPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
contributionController.handleActivityResultWithCallback(requireActivity(),callbacks -> {
contributionController.onPictureReturnedFromCamera(result,requireActivity(),callbacks);
});
});
private ActivityResultLauncher<Intent> galleryPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> galleryPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
contributionController.handleActivityResultWithCallback(requireActivity(),callbacks -> {
contributionController.onPictureReturnedFromGallery(result,requireActivity(),callbacks);

View file

@ -266,6 +266,7 @@ public class ContributionController {
}
public void onPictureReturnedFromGallery(ActivityResult result, Activity activity, FilePicker.Callbacks callbacks){
if(isDocumentPhotoPickerPreferred()){
FilePicker.onPictureReturnedFromDocuments(result, activity, callbacks);
} else {
@ -288,25 +289,25 @@ public class ContributionController {
handleActivityResult.onHandleActivityResult(new DefaultCallback() {
@Override
public void onCanceled(final ImageSource source, final int type) {
super.onCanceled(source, type);
defaultKvStore.remove(PLACE_OBJECT);
}
@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 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);
}
});
@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,

View file

@ -98,21 +98,24 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
private int contributionsSize;
private String userName;
private ActivityResultLauncher<Intent> galleryPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> galleryPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
controller.onPictureReturnedFromGallery(result,requireActivity(),callbacks);
});
});
private ActivityResultLauncher<Intent> customSelectorLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> customSelectorLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
controller.onPictureReturnedFromCustomSelector(result,requireActivity(),callbacks);
});
});
private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> cameraPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
controller.onPictureReturnedFromCamera(result,requireActivity(),callbacks);

View file

@ -1,10 +1,13 @@
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;
@ -13,8 +16,10 @@ 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;
@ -36,8 +41,10 @@ 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;

View file

@ -230,7 +230,7 @@ class CustomSelectorActivity :
/**
* When data will be send from full screen mode, it will be passed to fragment
*/
fun onFullScreenDataReceived(result: ActivityResult){
private fun onFullScreenDataReceived(result: ActivityResult){
if (result.resultCode == Activity.RESULT_OK) {
val selectedImages: ArrayList<Image> =
result.data!!

View file

@ -72,11 +72,9 @@ class DescriptionEditActivity :
private lateinit var binding: ActivityDescriptionEditBinding
private val requestCodeForVoiceInput = 1213
private var descriptionAndCaptions: ArrayList<UploadMediaDetail>? = null
private val voiceInputResultLauncher = registerForActivityResult<Intent, ActivityResult>(
private val voiceInputResultLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result: ActivityResult ->
onVoiceInput(result)
@ -310,22 +308,6 @@ 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 onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)

View file

@ -9,8 +9,6 @@ public interface Constants {
interface RequestCodes {
int LOCATION = 1;
int STORAGE = 2;
int RECEIVE_DATA_FROM_FULL_SCREEN_MODE = 1 << 9;
}
/**

View file

@ -1,13 +1,10 @@
package fr.free.nrw.commons.media;
import static android.app.Activity.RESULT_CANCELED;
import static android.app.Activity.RESULT_OK;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static fr.free.nrw.commons.category.CategoryClientKt.CATEGORY_NEEDING_CATEGORIES;
import static fr.free.nrw.commons.category.CategoryClientKt.CATEGORY_UNCATEGORISED;
import static fr.free.nrw.commons.description.EditDescriptionConstants.LIST_OF_DESCRIPTION_AND_CAPTION;
import static fr.free.nrw.commons.description.EditDescriptionConstants.UPDATED_WIKITEXT;
import static fr.free.nrw.commons.description.EditDescriptionConstants.WIKITEXT;
import static fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.LAST_LOCATION;
import static fr.free.nrw.commons.utils.LangCodeUtils.getLocalizedResources;
@ -112,7 +109,6 @@ import timber.log.Timber;
public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
CategoryEditHelper.Callback {
private static final int REQUEST_CODE = 1001;
private static final String IMAGE_BACKGROUND_COLOR = "image_background_color";
static final int DEFAULT_IMAGE_BACKGROUND_COLOR = 0;

View file

@ -227,21 +227,24 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private List<BottomSheetItem> dataList;
private BottomSheetAdapter bottomSheetAdapter;
private ActivityResultLauncher<Intent> galleryPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> galleryPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
controller.onPictureReturnedFromGallery(result,requireActivity(),callbacks);
});
});
private ActivityResultLauncher<Intent> customSelectorLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> customSelectorLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
controller.onPictureReturnedFromCustomSelector(result,requireActivity(),callbacks);
});
});
private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(),
private final ActivityResultLauncher<Intent> cameraPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
controller.handleActivityResultWithCallback(requireActivity(),callbacks -> {
controller.onPictureReturnedFromCamera(result,requireActivity(),callbacks);

View file

@ -87,7 +87,8 @@ public class SettingsFragment extends PreferenceFragmentCompat {
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(),
private final ActivityResultLauncher<Intent> cameraPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
contributionController.handleActivityResultWithCallback(requireActivity(),callbacks -> {
contributionController.onPictureReturnedFromCamera(result,requireActivity(),callbacks);

View file

@ -58,9 +58,8 @@ public class UploadMediaDetailAdapter extends
private int currentPosition;
private Fragment fragment;
private Activity activity;
private ActivityResultLauncher<Intent> voiceInputResultLauncher;
private final ActivityResultLauncher<Intent> voiceInputResultLauncher;
private SelectedVoiceIcon selectedVoiceIcon;
private static final int REQUEST_CODE_FOR_VOICE_INPUT = 1213;
private RowItemDescriptionBinding binding;

View file

@ -63,9 +63,6 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
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);
@ -706,7 +703,6 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
}
private void onEditActivityResult(ActivityResult result){
//TODO[Parry] Doubtful how it works, understand it....
if (result.getResultCode() == RESULT_OK) {
String path = result.getData().getStringExtra("editedImageFilePath");
@ -727,28 +723,6 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
}
}
/**
* 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
*/

View file

@ -100,7 +100,7 @@ class CustomSelectorActivityTest {
}
/**
* Test onActivityResult function.
* Test callback when result received.
*/
@Test
@Throws(Exception::class)

View file

@ -349,7 +349,7 @@ class UploadMediaDetailFragmentUnitTest {
@Test
@Throws(Exception::class)
fun testOnActivityResultOnMapIconClicked() {
fun testOnCameraPositionCallbackOnMapIconClicked() {
shadowOf(Looper.getMainLooper()).idle()
Mockito.mock(LocationPicker::class.java)
val intent = Mockito.mock(Intent::class.java)
@ -375,7 +375,7 @@ class UploadMediaDetailFragmentUnitTest {
@Test
@Throws(Exception::class)
fun testOnActivityResultAddLocationDialog() {
fun testOnCameraPositionCallbackAddLocationDialog() {
shadowOf(Looper.getMainLooper()).idle()
Mockito.mock(LocationPicker::class.java)
val intent = Mockito.mock(Intent::class.java)