Cooltey has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378191 )
Change subject: Add App Shortcuts icons for the homescreen ...................................................................... Add App Shortcuts icons for the homescreen In this update: 1. Adds an intent filter on PageActivity for shortcut icons 2. Adjusts icon image width and height 3. Adds offline compilation for "Random" shortcut 4. Setup default opens "Main Page" for handling exceptions from "Radnom" and "Continue Reading" Discussion: - Should the app backs to the Feed page after clicking on the "X" (close) button? Right now it exists the app. Bug: T174308 Change-Id: I92da049871a7dd7036ea6d8f3edc3f96df81d950 --- M app/src/main/AndroidManifest.xml M app/src/main/java/org/wikipedia/appshortcuts/AppShortcuts.java M app/src/main/java/org/wikipedia/page/PageActivity.java M app/src/main/res/values/dimens.xml 4 files changed, 59 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/91/378191/1 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 252897e..1535034 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -104,6 +104,10 @@ <data android:host="*.wikipedia.org" android:pathPrefix="/wiki/" android:scheme="http" /> <data android:host="*.wikipedia.org" android:pathPrefix="/wiki/" android:scheme="https" /> </intent-filter> + <intent-filter> + <action android:name="org.wikipedia.app_shortcut" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> </activity> <activity android:name=".crash.CrashReportActivity" diff --git a/app/src/main/java/org/wikipedia/appshortcuts/AppShortcuts.java b/app/src/main/java/org/wikipedia/appshortcuts/AppShortcuts.java index a7d0b4d..2dabdab 100644 --- a/app/src/main/java/org/wikipedia/appshortcuts/AppShortcuts.java +++ b/app/src/main/java/org/wikipedia/appshortcuts/AppShortcuts.java @@ -29,7 +29,7 @@ ShortcutManager shortcutManager = app.getSystemService(ShortcutManager.class); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { - shortcutManager.setDynamicShortcuts(Arrays.asList(randomShortcut(), continueReadingShortcut(), searchShortcut())); + shortcutManager.setDynamicShortcuts(Arrays.asList(searchShortcut(), continueReadingShortcut(), randomShortcut())); } } } @@ -42,8 +42,7 @@ .setLongLabel(app.getString(R.string.app_shortcuts_random)) .setIcon(Icon.createWithResource(app, R.drawable.appshortcut_ic_random)) .setIntent( - new Intent(Intent.ACTION_MAIN, Uri.EMPTY, app, PageActivity.class) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + new Intent(PageActivity.ACTION_APP_SHORTCUT) .putExtra(Constants.INTENT_APP_SHORTCUT_RANDOM, true)) .build(); @@ -57,14 +56,9 @@ .setShortLabel(app.getString(R.string.app_shortcuts_continue_reading)) .setLongLabel(app.getString(R.string.app_shortcuts_continue_reading)) .setIcon(Icon.createWithResource(app, R.drawable.appshortcut_ic_continue_reading)) - .setIntents( - new Intent[]{ - new Intent(Intent.ACTION_MAIN, Uri.EMPTY, app, MainActivity.class) - .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), - new Intent(Intent.ACTION_MAIN, Uri.EMPTY, app, PageActivity.class) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(Constants.INTENT_APP_SHORTCUT_CONTINUE_READING, true) - }) + .setIntent( + new Intent(PageActivity.ACTION_APP_SHORTCUT) + .putExtra(Constants.INTENT_APP_SHORTCUT_CONTINUE_READING, true)) .build(); return shortcut; diff --git a/app/src/main/java/org/wikipedia/page/PageActivity.java b/app/src/main/java/org/wikipedia/page/PageActivity.java index 02b1841..e7eab48 100644 --- a/app/src/main/java/org/wikipedia/page/PageActivity.java +++ b/app/src/main/java/org/wikipedia/page/PageActivity.java @@ -45,6 +45,7 @@ import org.wikipedia.activity.BaseActivity; import org.wikipedia.analytics.IntentFunnel; import org.wikipedia.analytics.LinkPreviewFunnel; +import org.wikipedia.concurrency.CallbackTask; import org.wikipedia.dataclient.WikiSite; import org.wikipedia.dataclient.restbase.page.RbPageSummary; import org.wikipedia.descriptions.DescriptionEditRevertHelpView; @@ -57,11 +58,13 @@ import org.wikipedia.gallery.GalleryActivity; import org.wikipedia.history.HistoryEntry; import org.wikipedia.language.LangLinksActivity; +import org.wikipedia.offline.OfflineManager; import org.wikipedia.page.linkpreview.LinkPreviewDialog; import org.wikipedia.page.tabs.TabsProvider; import org.wikipedia.page.tabs.TabsProvider.TabPosition; import org.wikipedia.random.RandomSummaryClient; import org.wikipedia.readinglist.AddToReadingListDialog; +import org.wikipedia.readinglist.page.database.ReadingListPageDao; import org.wikipedia.search.SearchFragment; import org.wikipedia.search.SearchInvokeSource; import org.wikipedia.settings.SettingsActivity; @@ -75,6 +78,7 @@ import org.wikipedia.widgets.WidgetProviderFeaturedPage; import org.wikipedia.wiktionary.WiktionaryDialog; +import java.io.IOException; import java.util.List; import butterknife.BindView; @@ -94,6 +98,7 @@ public static final String ACTION_RESUME_READING = "org.wikipedia.resume_reading"; public static final String EXTRA_PAGETITLE = "org.wikipedia.pagetitle"; public static final String EXTRA_HISTORYENTRY = "org.wikipedia.history.historyentry"; + public static final String ACTION_APP_SHORTCUT = "org.wikipedia.app_shortcut"; private static final String LANGUAGE_CODE_BUNDLE_KEY = "language"; @@ -288,7 +293,7 @@ loadRandomPage(); } else if (intent.hasExtra(Constants.INTENT_APP_SHORTCUT_CONTINUE_READING)) { loadContinueReadingPage(); - } else { + } else { loadMainPageInCurrentTab(); } } @@ -398,22 +403,7 @@ loadPage(title, historyEntry, position); } - public void loadRandomPage() { - new RandomSummaryClient().request(app.getWikiSite(), new RandomSummaryClient.Callback() { - @Override - public void onSuccess(@NonNull Call<RbPageSummary> call, @NonNull PageTitle title) { - loadPageInForegroundTab(title, new HistoryEntry(title, HistoryEntry.SOURCE_APP_SHORTCUT_RANDOM)); - } - - @Override - public void onError(@NonNull Call<RbPageSummary> call, @NonNull Throwable t) { - // do we need to search offline compilation? - finish(); - } - }); - } - - public void loadContinueReadingPage() { + private void loadContinueReadingPage() { new ContinueReadingClient().request(this, app.getWikiSite(), 1, new FeedClient.Callback() { @Override public void success(@NonNull List<? extends Card> cards) { @@ -423,8 +413,48 @@ @Override public void error(@NonNull Throwable caught) { - // show message if we have not read articles? - finish(); + loadMainPageInForegroundTab(); + } + }); + } + + private void loadRandomPage() { + new RandomSummaryClient().request(app.getWikiSite(), new RandomSummaryClient.Callback() { + @Override + public void onSuccess(@NonNull Call<RbPageSummary> call, @NonNull PageTitle title) { + loadPageInForegroundTab(title, new HistoryEntry(title, HistoryEntry.SOURCE_APP_SHORTCUT_RANDOM)); + } + + @Override + public void onError(@NonNull Call<RbPageSummary> call, @NonNull Throwable t) { + // do we need to search offline compilation? + getRandomPageFromCompilation(t); + } + }); + } + + private void getRandomPageFromCompilation(@NonNull final Throwable throwableIfEmpty) { + if (OfflineManager.hasCompilation()) { + try { + PageTitle pageTitle = new PageTitle(OfflineManager.instance().getRandomTitle(), app.getWikiSite()); + loadPageInForegroundTab(pageTitle, new HistoryEntry(pageTitle, HistoryEntry.SOURCE_APP_SHORTCUT_CONTINUE_READING)); + } catch (IOException e) { + loadMainPageInForegroundTab(); // or call finish()? + } + } else { + getRandomPageFromReadingLists(throwableIfEmpty); + } + } + + private void getRandomPageFromReadingLists(@NonNull final Throwable throwableIfEmpty) { + ReadingListPageDao.instance().randomPage(new CallbackTask.DefaultCallback<PageTitle>() { + @Override + public void success(@Nullable PageTitle title) { + if (title != null) { + loadPageInForegroundTab(title, new HistoryEntry(title, HistoryEntry.SOURCE_APP_SHORTCUT_CONTINUE_READING)); + } else { + loadMainPageInForegroundTab(); // or call finish()? + } } }); } diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 7d8c72e..cc343e3 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -120,6 +120,6 @@ <!-- App shortcuts --> <dimen name="app_shortcut_icon_size">24dp</dimen> - <dimen name="app_shortcut_icon_margin">7dp</dimen> + <dimen name="app_shortcut_icon_margin">14dp</dimen> </resources> -- To view, visit https://gerrit.wikimedia.org/r/378191 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I92da049871a7dd7036ea6d8f3edc3f96df81d950 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Cooltey <cf...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits