diff --git a/Pocket/src/main/java/com/pocket/app/PocketUiPlaygroundActivity.java b/Pocket/src/main/java/com/pocket/app/PocketUiPlaygroundActivity.java index 2420dde..14f3c36 100644 --- a/Pocket/src/main/java/com/pocket/app/PocketUiPlaygroundActivity.java +++ b/Pocket/src/main/java/com/pocket/app/PocketUiPlaygroundActivity.java @@ -65,7 +65,7 @@ public class PocketUiPlaygroundActivity extends AbsPocketActivity { private ViewGroup fullscreenView; - private View.OnClickListener badgeClickListener = view -> { + private final View.OnClickListener badgeClickListener = view -> { String message; if (view instanceof TextView) { message = ((TextView) view).getText().toString(); @@ -155,8 +155,8 @@ private void bindExamples() { } PreviousNextButtons continuousReading = findViewById(com.pocket.ui.R.id.continuous_reading); - continuousReading.onPreviousClick(v -> QuickToast.show("Previous")); - continuousReading.onNextClick(v -> QuickToast.show("Next")); + continuousReading.onPreviousClick(v -> Toast.makeText(this, "Previous", Toast.LENGTH_LONG).show()); + continuousReading.onNextClick(v -> Toast.makeText(this, "Next", Toast.LENGTH_LONG).show()); final String discTitle = "A Simple Way to Map Out your Career Ambitions"; final String discDomain = "Ted Ideas"; @@ -327,7 +327,7 @@ public void onClick(View v1) { .bindGroup("Best Of", "Best Of", BadgeUtil.getGroupTextColor(this, 1), BadgeUtil.getGroupBadgeColor(this, 1), badgeClickListener) .bindTags(Collections.singletonList("Very long tag that doesn't quite exactly fit"), badgeClickListener); - View.OnClickListener onClick = v -> QuickToast.show("Tapped " + v); + View.OnClickListener onClick = v -> Toast.makeText(this, "Tapped " + v, Toast.LENGTH_LONG).show(); ItemSnackbarView itemSnackbar = findViewById(com.pocket.ui.R.id.item_snackbar); itemSnackbar.bind().clear() diff --git a/Pocket/src/main/java/com/pocket/app/PocketUrlHandlerActivity.java b/Pocket/src/main/java/com/pocket/app/PocketUrlHandlerActivity.java index b99352e..a7082ac 100644 --- a/Pocket/src/main/java/com/pocket/app/PocketUrlHandlerActivity.java +++ b/Pocket/src/main/java/com/pocket/app/PocketUrlHandlerActivity.java @@ -136,7 +136,9 @@ private void onNoDeepLinkFound(final ArrayList urls) { @Override public void onTimeout(Timeout timeout) { if (!isFinishing()) { - mLoadingToast = QuickToast.show(R.string.dg_loading, mLoadingToast); + if (mLoadingToast == null) { + mLoadingToast = Toast.makeText(PocketUrlHandlerActivity.this, R.string.dg_loading, Toast.LENGTH_LONG); + } mLoadingToast.show(); } } diff --git a/Pocket/src/main/java/com/pocket/app/QuickToast.java b/Pocket/src/main/java/com/pocket/app/QuickToast.java deleted file mode 100644 index 4e87dfc..0000000 --- a/Pocket/src/main/java/com/pocket/app/QuickToast.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.pocket.app; - -import android.content.Context; -import android.view.ContextThemeWrapper; -import android.widget.Toast; - -import com.ideashower.readitlater.R; - -/** - * Less verbose methods for toasting a message and handling common use cases. All toasts made through this - * class use the pocket toast theme and use the application context. Also all toasts default to the long duration. - */ -public class QuickToast { - - private static final int DEFAULT_DURATION = Toast.LENGTH_LONG; - - private static Toast sSingleton; - - /** - * @param msg - * @return An unshown standardized style of Toast for the app. - */ - public static Toast make(int msg) { - return Toast.makeText(getContext(), msg, DEFAULT_DURATION); - } - - /** - * @param msg - * @return An unshown standardized style of Toast for the app. - */ - public static Toast make(CharSequence msg) { - return Toast.makeText(getContext(), msg, DEFAULT_DURATION); - } - - /** - * Show a standardized toast. Ok to invoke from off the ui thread, but in that case it will not return the toast. - * If you need the toast instance, invoke this from the ui thread. - * - * @param msg - * @param reuse Optional Toast to be reused instead of making a new one. This is helpful for updating the toast rather than waiting for it to hide and show again. - * @return The Toast or null if this was invoked off the ui thread and it had to be created/shown async. - */ - public static Toast show(final int msg, final Toast reuse) { - if (App.getApp().threads().isOnUIThread()) { - Toast toast; - if (reuse != null) { - reuse.setText(msg); - reuse.setDuration(DEFAULT_DURATION); - toast = reuse; - } else { - toast = make(msg); - } - toast.show(); - return toast; - - } else { - App.getApp().threads().runOrPostOnUiThread(() -> show(msg, reuse)); - return null; - } - } - - /** - * Show a standardized toast. Ok to invoke from off the ui thread, but in that case it will not return the toast. - * If you need the toast instance, invoke this from the ui thread. - * - * @param msg - * @param reuse Optional Toast to be reused instead of making a new one. This is helpful for updating the toast rather than waiting for it to hide and show again. - */ - public static void show(final CharSequence msg, final Toast reuse) { - App.getApp().threads().runOrPostOnUiThread(() -> { - Toast toast; - if (reuse != null) { - reuse.setText(msg); - reuse.setDuration(DEFAULT_DURATION); - toast = reuse; - } else { - toast = make(msg); - } - toast.show(); - }); - } - - /** - * Show a standardized toast. Ok to invoke from off the ui thread, but in that case it will not return the toast. - * If you need the toast instance, invoke this from the ui thread. - * - * @param msg - * @return The Toast or null if this was invoked off the ui thread and it had to be created/shown async. - */ - public static Toast show(final int msg) { - return show(msg, null); - } - - /** - * Show a standardized toast. Ok to invoke from off the ui thread, but in that case it will not return the toast. - * If you need the toast instance, invoke this from the ui thread. - * - * @param msg - * @return The Toast or null if this was invoked off the ui thread and it had to be created/shown async. - */ - public static void show(final CharSequence msg) { - show(msg, null); - } - - /** - * Same as {@link #show(int, android.widget.Toast)} where the reused toast is a static singleton - * shared by any other users of this method. If the toast is already visible, it will be updated - * with the new message. - * - * @param msg - */ - public static void showInSingleton(int msg) { - if (sSingleton == null) { - sSingleton = make(msg); - } - sSingleton.setText(msg); - sSingleton.setDuration(Toast.LENGTH_LONG); - sSingleton.show(); - } - - /** - * Same as {@link #show(CharSequence, android.widget.Toast)} where the reused toast is a static singleton - * shared by any other users of this method. If the toast is already visible, it will be updated - * with the new message. - * - * @param msg - */ - public static void showInSingleton(CharSequence msg) { - if (sSingleton == null) { - sSingleton = make(msg); - } - sSingleton.setText(msg); - sSingleton.setDuration(Toast.LENGTH_LONG); - sSingleton.show(); - } - - public static Toast getSingleton() { - if (sSingleton == null) { - sSingleton = make(""); - } - return sSingleton; - } - - /** - * @return The standardized context to use for all toast creation in this class. - */ - private static Context getContext() { - return new ContextThemeWrapper(App.getContext(), R.style.Theme_PocketDefault_Light); - } - - -} diff --git a/Pocket/src/main/java/com/pocket/app/listen/ListenView.kt b/Pocket/src/main/java/com/pocket/app/listen/ListenView.kt index cb0c3a1..cbcecb0 100644 --- a/Pocket/src/main/java/com/pocket/app/listen/ListenView.kt +++ b/Pocket/src/main/java/com/pocket/app/listen/ListenView.kt @@ -8,6 +8,7 @@ import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.widget.ImageView +import android.widget.Toast import androidx.recyclerview.widget.RecyclerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.ideashower.readitlater.R @@ -15,7 +16,6 @@ import com.ideashower.readitlater.databinding.ViewListenBinding import com.pocket.analytics.ItemContent import com.pocket.app.App import com.pocket.app.PocketApp -import com.pocket.app.QuickToast import com.pocket.sdk.api.generated.enums.CxtSection import com.pocket.sdk.api.generated.enums.CxtUi import com.pocket.sdk.api.generated.enums.CxtView @@ -249,7 +249,7 @@ class ListenView @JvmOverloads constructor(context: Context?, attrs: AttributeSe errorControls.pause() } ListenError.EMPTY_LIST -> { - QuickToast.show(R.string.tts_empty_list) + Toast.makeText(context, R.string.tts_empty_list, Toast.LENGTH_LONG).show() errorControls.off() } ListenError.NETWORK_ERROR, ListenError.TIMED_OUT -> { diff --git a/Pocket/src/main/java/com/pocket/app/settings/beta/BetaConfigFragment.java b/Pocket/src/main/java/com/pocket/app/settings/beta/BetaConfigFragment.java index 36c2d24..d206f22 100644 --- a/Pocket/src/main/java/com/pocket/app/settings/beta/BetaConfigFragment.java +++ b/Pocket/src/main/java/com/pocket/app/settings/beta/BetaConfigFragment.java @@ -8,12 +8,12 @@ import android.view.View; import android.widget.EditText; import android.widget.LinearLayout; +import android.widget.Toast; import com.ideashower.readitlater.BuildConfig; import com.ideashower.readitlater.R; import com.pocket.app.PocketSingleton; import com.pocket.app.PocketUiPlaygroundActivity; -import com.pocket.app.QuickToast; import com.pocket.app.settings.AbsPrefsFragment; import com.pocket.app.settings.view.preferences.ActionPreference; import com.pocket.app.settings.view.preferences.MultipleChoicePreference; @@ -30,7 +30,6 @@ import com.pocket.sdk.api.thing.AccountUtil; import com.pocket.sdk.api.value.Timestamp; import com.pocket.sdk.dev.AppTransplant; -import com.pocket.sdk.http.HttpClientDelegate; import com.pocket.sdk.network.eclectic.EclecticHttp; import com.pocket.sdk.preferences.AppPrefs; import com.pocket.ui.view.edittext.LabeledEditText; @@ -235,10 +234,10 @@ public void onItemSelectionChanged(int __) { .setOnItemSelectedListener(newValue -> { switch (newValue) { case 0: - QuickToast.show("Retrieving your latest account info from server..."); + toast("Retrieving your latest account info from server..."); pocket().syncRemote(AccountUtil.getuser(pocket().spec())) - .onSuccess(r -> QuickToast.show("Premium Status reset back to Actual")) - .onFailure(e -> QuickToast.show("Couldn't load actual status, make sure you are online and try again")); + .onSuccess(r -> toast("Premium Status reset back to Actual")) + .onFailure(e -> toast("Couldn't load actual status, make sure you are online and try again")); break; case 1: pocket().sync(null, pocket().spec().actions().fake_premium_status() @@ -247,7 +246,7 @@ public void onItemSelectionChanged(int __) { .premium_alltime_status(PremiumAllTimeStatus.ACTIVE) .time(Timestamp.now()) .build()); - QuickToast.show("Note: This does not effect your actual status. If the app syncs the latest account info, this fake status will be overridden back to the real one."); + toast("Note: This does not effect your actual status. If the app syncs the latest account info, this fake status will be overridden back to the real one."); break; case 2: pocket().sync(null, pocket().spec().actions().fake_premium_status() @@ -256,7 +255,7 @@ public void onItemSelectionChanged(int __) { .premium_alltime_status(PremiumAllTimeStatus.NEVER) .time(Timestamp.now()) .build()); - QuickToast.show("Note: This does not effect your actual status. If the app syncs the latest account info, this fake status will be overridden back to the real one."); + toast("Note: This does not effect your actual status. If the app syncs the latest account info, this fake status will be overridden back to the real one."); break; } }) @@ -272,7 +271,7 @@ public void onItemSelectionChanged(int __) { prefs.add(PreferenceViews.newToggleSwitchBuilder(this, appPrefs.DEVCONFIG_SNACKBAR_ALWAYS_SHOW_URL_CR, "Always show Continue Reading and URL Save") .setSummaryDefaultUnchecked("Always show the Continue Reading and URL Clipboard save snackbars on app start") - .setOnChangeListener(n -> QuickToast.show("Exit and restart the app to view.")) + .setOnChangeListener(n -> toast("Exit and restart the app to view.")) .build()); prefs.add(PreferenceViews.newActionBuilder(this, "Edit Fake Device Info for Login") @@ -441,16 +440,16 @@ public void setSelected(int index) { prefs.add(PreferenceViews.newActionBuilder(this, "App Transplant") .setOnClickListener( () -> { - QuickToast.show("Copying..."); + toast("Copying..."); new AppTransplant(getContext()).create(); - QuickToast.show("Copied. Be sure to tap Clear Transplant after sending it."); + toast("Copied. Be sure to tap Clear Transplant after sending it."); }) .build()); prefs.add(PreferenceViews.newActionBuilder(this, "Clear Transplant") .setOnClickListener(() -> { new AppTransplant(getContext()).clear(); - QuickToast.show("Cleared"); + toast("Cleared"); }) .build()); } @@ -467,6 +466,13 @@ private void requireRestart() { }) .show(); } + + private void toast(CharSequence text) { + var context = getContext(); + if (context != null) { + Toast.makeText(context, text, Toast.LENGTH_LONG).show(); + } + } @Override protected int getTitle() { diff --git a/Pocket/src/main/java/com/pocket/sdk/offline/cache/StorageErrorResolver.java b/Pocket/src/main/java/com/pocket/sdk/offline/cache/StorageErrorResolver.java index 4b3467b..5f883ac 100644 --- a/Pocket/src/main/java/com/pocket/sdk/offline/cache/StorageErrorResolver.java +++ b/Pocket/src/main/java/com/pocket/sdk/offline/cache/StorageErrorResolver.java @@ -1,10 +1,10 @@ package com.pocket.sdk.offline.cache; import android.app.AlertDialog; +import android.widget.Toast; import com.ideashower.readitlater.R; import com.pocket.app.AppThreads; -import com.pocket.app.QuickToast; import com.pocket.sdk.util.AbsPocketActivity; import com.pocket.sdk.util.dialog.ProgressDialogFragment; import com.pocket.sdk.util.file.AndroidStorageLocation; @@ -145,7 +145,7 @@ private void showRetryOrResetCacheDialog(final AbsPocketActivity context, final final ProgressDialogFragment progress = ProgressDialogFragment.getNew(R.string.dg_changing_data_location, false); progress.showOnCurrentActivity(); context.app().assets().clearOfflineContent(() -> { - QuickToast.show(context.getString(R.string.storage_location_changed)); + Toast.makeText(context, R.string.storage_location_changed, Toast.LENGTH_LONG).show(); callback(true, true); }, null); } catch (AssetDirectoryUnavailableException e) {