mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 08:23:00 +01:00
Simplify archiving in chat list, fixing unarchive bug.
This commit is contained in:
@@ -24,8 +24,6 @@ import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import org.signal.core.ui.compose.Snackbars;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -39,8 +37,6 @@ import org.thoughtcrime.securesms.main.MainNavigationListLocation;
|
||||
import org.thoughtcrime.securesms.main.MainSnackbarHostKey;
|
||||
import org.thoughtcrime.securesms.util.ConversationUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.core.Completable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
@@ -100,28 +96,11 @@ public class ConversationListArchiveFragment extends ConversationListFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @StringRes int getArchivedSnackbarTitleRes() {
|
||||
return R.plurals.ConversationListFragment_moved_conversations_to_inbox;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @DrawableRes int getArchiveIconRes() {
|
||||
return R.drawable.symbol_archive_up_24;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WorkerThread
|
||||
protected void archiveThreads(Set<Long> threadIds) {
|
||||
SignalDatabase.threads().setArchived(threadIds, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WorkerThread
|
||||
protected void reverseArchiveThreads(Set<Long> threadIds) {
|
||||
SignalDatabase.threads().setArchived(threadIds, true);
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Override
|
||||
protected void onItemSwiped(long threadId, int unreadCount, int unreadSelfMentionsCount) {
|
||||
|
||||
@@ -39,7 +39,6 @@ import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import org.signal.core.ui.compose.Snackbars;
|
||||
@@ -1012,7 +1011,7 @@ public class ConversationListFragment extends MainFragment implements Conversati
|
||||
private void handleArchive(@NonNull Collection<Long> ids) {
|
||||
Set<Long> selectedConversations = new HashSet<>(ids);
|
||||
int count = selectedConversations.size();
|
||||
String snackBarTitle = getResources().getQuantityString(getArchivedSnackbarTitleRes(), count, count);
|
||||
String snackBarTitle = getResources().getQuantityString(R.plurals.ConversationListFragment_conversations_archived, count, count);
|
||||
boolean showProgress = count > 1;
|
||||
|
||||
dismissProgressDialog();
|
||||
@@ -1021,7 +1020,7 @@ public class ConversationListFragment extends MainFragment implements Conversati
|
||||
}
|
||||
|
||||
lifecycleDisposable.add(Completable
|
||||
.fromAction(() -> archiveThreads(selectedConversations))
|
||||
.fromAction(() -> SignalDatabase.threads().setArchived(selectedConversations, true))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(() -> {
|
||||
@@ -1046,17 +1045,38 @@ public class ConversationListFragment extends MainFragment implements Conversati
|
||||
}
|
||||
|
||||
private void handleUnarchive(@NonNull Set<Long> threadIds) {
|
||||
boolean showProgress = threadIds.size() > 1;
|
||||
int count = threadIds.size();
|
||||
String snackBarTitle = getResources().getQuantityString(R.plurals.ConversationListFragment_moved_conversations_to_inbox, count, count);
|
||||
boolean showProgress = count > 1;
|
||||
|
||||
dismissProgressDialog();
|
||||
if (showProgress) {
|
||||
progressDialog = SignalProgressDialog.show(requireContext(), null, null, true, false, null);
|
||||
}
|
||||
|
||||
SignalExecutors.BOUNDED_IO.execute(() -> {
|
||||
reverseArchiveThreads(threadIds);
|
||||
ThreadUtil.runOnMain(this::dismissProgressDialog);
|
||||
});
|
||||
lifecycleDisposable.add(Completable
|
||||
.fromAction(() -> SignalDatabase.threads().setArchived(threadIds, false))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(() -> {
|
||||
dismissProgressDialog();
|
||||
endActionModeIfActive();
|
||||
|
||||
mainNavigationViewModel.getSnackbarRegistry().emit(new SnackbarState(
|
||||
snackBarTitle,
|
||||
new SnackbarState.ActionState(
|
||||
getString(R.string.ConversationListFragment_undo),
|
||||
R.color.amber_500,
|
||||
() -> {
|
||||
handleArchive(threadIds);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
),
|
||||
Snackbars.Duration.LONG,
|
||||
MainSnackbarHostKey.MainChrome.INSTANCE,
|
||||
null
|
||||
));
|
||||
}));
|
||||
}
|
||||
|
||||
private void dismissProgressDialog() {
|
||||
@@ -1436,7 +1456,7 @@ public class ConversationListFragment extends MainFragment implements Conversati
|
||||
}
|
||||
|
||||
if (isArchived()) {
|
||||
items.add(new ActionItem(R.drawable.symbol_archive_up_24, getResources().getString(R.string.ConversationListFragment_unarchive), () -> handleArchive(selectionIds)));
|
||||
items.add(new ActionItem(R.drawable.symbol_archive_up_24, getResources().getString(R.string.ConversationListFragment_unarchive), () -> handleUnarchive(selectionIds)));
|
||||
} else {
|
||||
items.add(new ActionItem(R.drawable.symbol_archive_24, getResources().getString(R.string.ConversationListFragment_archive), () -> handleArchive(selectionIds)));
|
||||
}
|
||||
@@ -1464,24 +1484,10 @@ public class ConversationListFragment extends MainFragment implements Conversati
|
||||
return ((Callback) requireActivity());
|
||||
}
|
||||
|
||||
protected @PluralsRes int getArchivedSnackbarTitleRes() {
|
||||
return R.plurals.ConversationListFragment_conversations_archived;
|
||||
}
|
||||
|
||||
protected @DrawableRes int getArchiveIconRes() {
|
||||
return R.drawable.symbol_archive_24;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
protected void archiveThreads(Set<Long> threadIds) {
|
||||
SignalDatabase.threads().setArchived(threadIds, true);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
protected void reverseArchiveThreads(Set<Long> threadIds) {
|
||||
SignalDatabase.threads().setArchived(threadIds, false);
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
protected void onItemSwiped(long threadId, int unreadCount, int unreadSelfMentionsCount) {
|
||||
archiveDecoration.onArchiveStarted();
|
||||
|
||||
Reference in New Issue
Block a user