Fix #5104: popup shown when tapping an already uploaded image in Medi… (#5127)

* Fix #5104: popup shown when tapping an already uploaded image in Media Details

* Small Changes

* JavaDoc Changes

* Javadoc Changes

* Coding Standards Changes
This commit is contained in:
Arin Modi 2023-01-30 19:11:41 +05:30 committed by GitHub
parent 3e073583ea
commit 191186a474
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 10 deletions

View file

@ -11,6 +11,9 @@ import static fr.free.nrw.commons.description.EditDescriptionConstants.UPDATED_W
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;
import android.Manifest;
import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
@ -81,6 +84,7 @@ import fr.free.nrw.commons.ui.widget.HtmlTextView;
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment;
import fr.free.nrw.commons.upload.depicts.DepictsFragment;
import fr.free.nrw.commons.upload.UploadMediaDetail;
import fr.free.nrw.commons.utils.PermissionUtils;
import fr.free.nrw.commons.utils.ViewUtilWrapper;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -356,11 +360,38 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
}
@OnClick(R.id.mediaDetailImageViewSpacer)
public void launchZoomActivity(View view) {
public void launchZoomActivity(final View view) {
final boolean permission = PermissionUtils.
hasPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE);
if (permission) {
launchZoomActivityAfterPermissionCheck(view);
}
else {
PermissionUtils.checkPermissionsAndPerformAction(getActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE,
() -> {
launchZoomActivityAfterPermissionCheck(view);
},
R.string.storage_permission_title,
R.string.read_storage_permission_rationale
);
}
}
/**
* launch zoom acitivity after permission check
* @param view as ImageView
*/
private void launchZoomActivityAfterPermissionCheck(final View view) {
if (media.getImageUrl() != null) {
Context ctx = view.getContext();
final Context ctx = view.getContext();
final Intent zoomableIntent = new Intent(ctx, ZoomableActivity.class);
zoomableIntent.setData(Uri.parse(media.getImageUrl()));
zoomableIntent.putExtra(
ZoomableActivity.ZoomableActivityConstants.ORIGIN, "MediaDetails");
ctx.startActivity(
new Intent(ctx, ZoomableActivity.class).setData(Uri.parse(media.getImageUrl()))
zoomableIntent
);
}
}

View file

@ -163,13 +163,22 @@ class ZoomableActivity : BaseActivity() {
handleResult(it)
}
if(prefs.getBoolean(CustomSelectorConstants.FULL_SCREEN_MODE_FIRST_LUNCH, true)) {
// show welcome dialog on first launch
showWelcomeDialog()
prefs.edit().putBoolean(
CustomSelectorConstants.FULL_SCREEN_MODE_FIRST_LUNCH,
false
).apply()
val origin = intent.getStringExtra(ZoomableActivityConstants.ORIGIN);
/**
* If origin is "null" it means that ZoomableActivity was created by the custom picker
* (rather than by MediaDetailsFragment) so we need to show the first time popup in
* full screen mode if needed.
*/
if (origin == null) {
if (prefs.getBoolean(CustomSelectorConstants.FULL_SCREEN_MODE_FIRST_LUNCH, true)) {
// show welcome dialog on first launch
showWelcomeDialog()
prefs.edit().putBoolean(
CustomSelectorConstants.FULL_SCREEN_MODE_FIRST_LUNCH,
false
).apply()
}
}
}
@ -650,4 +659,13 @@ class ZoomableActivity : BaseActivity() {
scope.cancel()
super.onDestroy()
}
object ZoomableActivityConstants {
/**
* Key for Accessing Intent Data Named "Origin", The value indicates what fragment
* ZoomableActivity was created by. It is null if ZoomableActivity was created by
* the custom picker.
*/
const val ORIGIN = "Origin";
}
}