Skip to content

Commit

Permalink
Merge pull request #180 from Pocket/clean-up-quick-toast
Browse files Browse the repository at this point in the history
refactor: migrate off of bespoke toast apis
  • Loading branch information
marcin-kozinski authored Feb 5, 2025
2 parents d4899cd + f684985 commit 075791a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ private void onNoDeepLinkFound(final ArrayList<String> 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();
}
}
Expand Down
152 changes: 0 additions & 152 deletions Pocket/src/main/java/com/pocket/app/QuickToast.java

This file was deleted.

4 changes: 2 additions & 2 deletions Pocket/src/main/java/com/pocket/app/listen/ListenView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ 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
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
Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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;
}
})
Expand All @@ -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")
Expand Down Expand Up @@ -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());
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 075791a

Please sign in to comment.