mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 06:08:33 +00:00
Add lifecycle check in SnackbarAsyncTask.
This commit is contained in:
parent
9dc33eff3a
commit
0271e4c918
@ -123,11 +123,13 @@ public class ConversationListArchiveFragment extends ConversationListFragment im
|
|||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
@Override
|
@Override
|
||||||
protected void onItemSwiped(long threadId, int unreadCount) {
|
protected void onItemSwiped(long threadId, int unreadCount) {
|
||||||
new SnackbarAsyncTask<Long>(getView(),
|
new SnackbarAsyncTask<Long>(getViewLifecycleOwner().getLifecycle(),
|
||||||
getResources().getQuantityString(R.plurals.ConversationListFragment_moved_conversations_to_inbox, 1, 1),
|
requireView(),
|
||||||
getString(R.string.ConversationListFragment_undo),
|
getResources().getQuantityString(R.plurals.ConversationListFragment_moved_conversations_to_inbox, 1, 1),
|
||||||
getResources().getColor(R.color.amber_500),
|
getString(R.string.ConversationListFragment_undo),
|
||||||
Snackbar.LENGTH_LONG, false)
|
getResources().getColor(R.color.amber_500),
|
||||||
|
Snackbar.LENGTH_LONG,
|
||||||
|
false)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void executeAction(@Nullable Long parameter) {
|
protected void executeAction(@Nullable Long parameter) {
|
||||||
|
@ -679,7 +679,8 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||||||
int count = selectedConversations.size();
|
int count = selectedConversations.size();
|
||||||
String snackBarTitle = getResources().getQuantityString(getArchivedSnackbarTitleRes(), count, count);
|
String snackBarTitle = getResources().getQuantityString(getArchivedSnackbarTitleRes(), count, count);
|
||||||
|
|
||||||
new SnackbarAsyncTask<Void>(getView(),
|
new SnackbarAsyncTask<Void>(getViewLifecycleOwner().getLifecycle(),
|
||||||
|
requireView(),
|
||||||
snackBarTitle,
|
snackBarTitle,
|
||||||
getString(R.string.ConversationListFragment_undo),
|
getString(R.string.ConversationListFragment_undo),
|
||||||
getResources().getColor(R.color.amber_500),
|
getResources().getColor(R.color.amber_500),
|
||||||
@ -1002,11 +1003,13 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
protected void onItemSwiped(long threadId, int unreadCount) {
|
protected void onItemSwiped(long threadId, int unreadCount) {
|
||||||
new SnackbarAsyncTask<Long>(getView(),
|
new SnackbarAsyncTask<Long>(getViewLifecycleOwner().getLifecycle(),
|
||||||
getResources().getQuantityString(R.plurals.ConversationListFragment_conversations_archived, 1, 1),
|
requireView(),
|
||||||
getString(R.string.ConversationListFragment_undo),
|
getResources().getQuantityString(R.plurals.ConversationListFragment_conversations_archived, 1, 1),
|
||||||
getResources().getColor(R.color.amber_500),
|
getString(R.string.ConversationListFragment_undo),
|
||||||
Snackbar.LENGTH_LONG, false)
|
getResources().getColor(R.color.amber_500),
|
||||||
|
Snackbar.LENGTH_LONG,
|
||||||
|
false)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void executeAction(@Nullable Long parameter) {
|
protected void executeAction(@Nullable Long parameter) {
|
||||||
|
@ -3,32 +3,42 @@ package org.thoughtcrime.securesms.util.task;
|
|||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
|
||||||
public abstract class SnackbarAsyncTask<Params>
|
public abstract class SnackbarAsyncTask<Params>
|
||||||
extends AsyncTask<Params, Void, Void>
|
extends AsyncTask<Params, Void, Void>
|
||||||
implements View.OnClickListener
|
implements View.OnClickListener
|
||||||
{
|
{
|
||||||
|
private static final String TAG = Log.tag(SnackbarAsyncTask.class);
|
||||||
|
|
||||||
private final View view;
|
private final Lifecycle lifecycle;
|
||||||
private final String snackbarText;
|
private final View view;
|
||||||
private final String snackbarActionText;
|
private final String snackbarText;
|
||||||
private final int snackbarActionColor;
|
private final String snackbarActionText;
|
||||||
private final int snackbarDuration;
|
private final int snackbarActionColor;
|
||||||
private final boolean showProgress;
|
private final int snackbarDuration;
|
||||||
|
private final boolean showProgress;
|
||||||
|
|
||||||
private @Nullable Params reversibleParameter;
|
private @Nullable Params reversibleParameter;
|
||||||
private @Nullable ProgressDialog progressDialog;
|
private @Nullable ProgressDialog progressDialog;
|
||||||
|
|
||||||
public SnackbarAsyncTask(View view,
|
public SnackbarAsyncTask(@NonNull Lifecycle lifecycle,
|
||||||
|
@NonNull View view,
|
||||||
String snackbarText,
|
String snackbarText,
|
||||||
String snackbarActionText,
|
String snackbarActionText,
|
||||||
int snackbarActionColor,
|
int snackbarActionColor,
|
||||||
int snackbarDuration,
|
int snackbarDuration,
|
||||||
boolean showProgress)
|
boolean showProgress)
|
||||||
{
|
{
|
||||||
|
this.lifecycle = lifecycle;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.snackbarText = snackbarText;
|
this.snackbarText = snackbarText;
|
||||||
this.snackbarActionText = snackbarActionText;
|
this.snackbarActionText = snackbarActionText;
|
||||||
@ -58,6 +68,11 @@ public abstract class SnackbarAsyncTask<Params>
|
|||||||
this.progressDialog = null;
|
this.progressDialog = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!lifecycle.getCurrentState().isAtLeast(Lifecycle.State.CREATED)) {
|
||||||
|
Log.w(TAG, "Not in at least created state. Refusing to show snack bar.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Snackbar.make(view, snackbarText, snackbarDuration)
|
Snackbar.make(view, snackbarText, snackbarDuration)
|
||||||
.setAction(snackbarActionText, this)
|
.setAction(snackbarActionText, this)
|
||||||
.setActionTextColor(snackbarActionColor)
|
.setActionTextColor(snackbarActionColor)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user