jenkins-bot has submitted this change and it was merged.
Change subject: Always clear pending image download
......................................................................
Always clear pending image download
• Clear pending image download when external storage write permission is
already given.
• Move call to super to default case.
• Annotate pendingDownloadImage as @Nullable to hint at expected usage.
• Rename Constants.WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST to
ACTIVITY_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION to match what's
what's used in other MainActivity request codes.
• Remove unused interface, PermissionUtil.Callback.
• Miscellaneous minor clean up.
Change-Id: Ib19ddea539477d1bee1b5567d14c5a7dcbec21f8
---
M app/src/main/java/org/wikipedia/Constants.java
M app/src/main/java/org/wikipedia/MainActivity.java
M app/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
M app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
M app/src/main/java/org/wikipedia/util/PermissionUtil.java
5 files changed, 32 insertions(+), 41 deletions(-)
Approvals:
Mholloway: Looks good to me, but someone else must approve
Dbrant: Looks good to me, approved
jenkins-bot: Verified
diff --git a/app/src/main/java/org/wikipedia/Constants.java
b/app/src/main/java/org/wikipedia/Constants.java
index c24e121..f1a2fdf 100644
--- a/app/src/main/java/org/wikipedia/Constants.java
+++ b/app/src/main/java/org/wikipedia/Constants.java
@@ -9,7 +9,7 @@
public static final String WIKIPEDIA_URL = "https://wikipedia.org/";
- public static final int WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST = 44;
+ public static final int ACTIVITY_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION
= 44;
public static final int MAX_SUGGESTION_RESULTS = 3;
public static final int SUGGESTION_REQUEST_ITEMS = 5;
diff --git a/app/src/main/java/org/wikipedia/MainActivity.java
b/app/src/main/java/org/wikipedia/MainActivity.java
index a2af67e..4e9f973 100644
--- a/app/src/main/java/org/wikipedia/MainActivity.java
+++ b/app/src/main/java/org/wikipedia/MainActivity.java
@@ -59,8 +59,8 @@
import org.wikipedia.events.ThemeChangeEvent;
import org.wikipedia.events.WikipediaZeroStateChangeEvent;
import org.wikipedia.feed.FeedFragment;
-import org.wikipedia.feed.image.FeaturedImageCard;
import org.wikipedia.feed.image.FeaturedImage;
+import org.wikipedia.feed.image.FeaturedImageCard;
import org.wikipedia.feed.news.NewsItemCard;
import org.wikipedia.history.HistoryEntry;
import org.wikipedia.interlanguage.LangLinksActivity;
@@ -103,9 +103,9 @@
import static org.wikipedia.util.DeviceUtil.hideSoftKeyboard;
import static org.wikipedia.util.DeviceUtil.isBackKeyUp;
-import static org.wikipedia.util.UriUtil.visitInExternalBrowser;
import static
org.wikipedia.util.PermissionUtil.hasWriteExternalStoragePermission;
import static
org.wikipedia.util.PermissionUtil.requestWriteStorageRuntimePermissions;
+import static org.wikipedia.util.UriUtil.visitInExternalBrowser;
public class MainActivity extends ThemedActionBarActivity implements
FeedFragment.Callback {
@@ -157,7 +157,7 @@
// The permissions request API doesn't take a callback, so in the event we
have to
// ask for permission to download a featured image from the feed, we'll
have to hold
// the image we're waiting for permission to download as a bit of state
here. :(
- private FeaturedImage pendingDownloadImage;
+ @Nullable private FeaturedImage pendingDownloadImage;
private DialogInterface.OnDismissListener listDialogDismissListener = new
DialogInterface.OnDismissListener() {
@Override
@@ -919,12 +919,13 @@
}
private void download(@NonNull FeaturedImage image) {
+ setPendingDownload(null);
new MediaDownloadReceiver(MainActivity.this).download(image);
}
private void requestWriteExternalStoragePermission() {
requestWriteStorageRuntimePermissions(this,
- Constants.WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST);
+ Constants.ACTIVITY_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION);
}
private void loadMainPageIfNoTabs() {
@@ -1127,6 +1128,28 @@
searchBarHideHandler.setForceNoFade(false);
}
+ @Override
+ public void onRequestPermissionsResult(int requestCode,
+ @NonNull String[] permissions,
+ @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case Constants.ACTIVITY_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION:
+ if (PermissionUtil.isPermitted(grantResults)) {
+ if (pendingDownloadImage != null) {
+ download(pendingDownloadImage);
+ }
+ } else {
+ setPendingDownload(null);
+ L.i("Write permission was denied by user");
+ FeedbackUtil.showMessage(this,
+
R.string.gallery_save_image_write_permission_rationale);
+ }
+ break;
+ default:
+ super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
+ }
+ }
+
private <T> void conditionallyInjectCustomCabMenu(T mode) {
currentActionMode = new CompatActionMode(mode);
if (currentActionMode.shouldInjectCustomMenu(MainActivity.this)) {
@@ -1220,31 +1243,6 @@
new ComponentName(this, WidgetProviderFeaturedPage.class));
widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
sendBroadcast(widgetIntent);
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode,
- @NonNull String[] permissions,
- @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
-
- switch (requestCode) {
- case Constants.WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST:
- if (PermissionUtil.isPermitted(grantResults)) {
- if (pendingDownloadImage != null) {
- new
MediaDownloadReceiver(this).download(pendingDownloadImage);
- setPendingDownload(null);
- }
- } else {
- setPendingDownload(null);
- L.i("Write permission was denied by user");
- FeedbackUtil.showMessage(this,
-
R.string.gallery_save_image_write_permission_rationale);
- }
- break;
- default:
- // Do nothing, this is coming from an attached fragment and
will be handled there
- }
}
private void setPendingDownload(@Nullable FeaturedImage image) {
diff --git
a/app/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
b/app/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
index c97669c..e5d26ee 100644
---
a/app/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
+++
b/app/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
@@ -374,7 +374,7 @@
readMoreList.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
- PageTitle title = ((SearchResult)
adapter.getItem(position)).getPageTitle();
+ PageTitle title = adapter.getItem(position).getPageTitle();
HistoryEntry historyEntry = new HistoryEntry(title,
HistoryEntry.SOURCE_INTERNAL_LINK);
activity.loadPage(title, historyEntry);
funnel.logSuggestionClicked(pageTitle, results.getResults(),
position);
diff --git
a/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
b/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
index 0622208..d76a571 100644
--- a/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
+++ b/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
@@ -82,9 +82,6 @@
return f;
}
- public GalleryItemFragment() {
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -223,7 +220,7 @@
private void requestWriteExternalStoragePermission() {
requestWriteStorageRuntimePermissions(this,
- Constants.WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST);
+ Constants.ACTIVITY_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION);
}
/**
@@ -427,7 +424,7 @@
@NonNull String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
- case Constants.WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST:
+ case Constants.ACTIVITY_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION:
if (PermissionUtil.isPermitted(grantResults)) {
saveImage();
} else {
diff --git a/app/src/main/java/org/wikipedia/util/PermissionUtil.java
b/app/src/main/java/org/wikipedia/util/PermissionUtil.java
index 9542fcf..24ec2bc 100644
--- a/app/src/main/java/org/wikipedia/util/PermissionUtil.java
+++ b/app/src/main/java/org/wikipedia/util/PermissionUtil.java
@@ -35,9 +35,5 @@
// once permission is granted/denied it will continue with
onRequestPermissionsResult
}
- public interface Callback {
- void hasPermission();
- }
-
private PermissionUtil() { }
-}
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/298328
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib19ddea539477d1bee1b5567d14c5a7dcbec21f8
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits