kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add the ability to mute on the chat list.
rodzic
ea253a2e67
commit
0be1a30766
|
@ -33,22 +33,19 @@ public class MuteDialog extends AlertDialog {
|
|||
public static void show(final Context context, final @NonNull MuteSelectionListener listener, @Nullable Runnable cancelListener) {
|
||||
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(context);
|
||||
builder.setTitle(R.string.MuteDialog_mute_notifications);
|
||||
builder.setItems(R.array.mute_durations, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, final int which) {
|
||||
final long muteUntil;
|
||||
builder.setItems(R.array.mute_durations, (dialog, which) -> {
|
||||
final long muteUntil;
|
||||
|
||||
switch (which) {
|
||||
case 0: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break;
|
||||
case 1: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(8); break;
|
||||
case 2: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1); break;
|
||||
case 3: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(7); break;
|
||||
case 4: muteUntil = Long.MAX_VALUE; break;
|
||||
default: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break;
|
||||
}
|
||||
|
||||
listener.onMuted(muteUntil);
|
||||
switch (which) {
|
||||
case 0: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break;
|
||||
case 1: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(8); break;
|
||||
case 2: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1); break;
|
||||
case 3: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(7); break;
|
||||
case 4: muteUntil = Long.MAX_VALUE; break;
|
||||
default: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break;
|
||||
}
|
||||
|
||||
listener.onMuted(muteUntil);
|
||||
});
|
||||
|
||||
if (cancelListener != null) {
|
||||
|
|
|
@ -74,6 +74,7 @@ import org.signal.core.util.concurrent.SignalExecutors;
|
|||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.MainFragment;
|
||||
import org.thoughtcrime.securesms.MainNavigator;
|
||||
import org.thoughtcrime.securesms.MuteDialog;
|
||||
import org.thoughtcrime.securesms.NewConversationActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.RatingManager;
|
||||
|
@ -143,6 +144,7 @@ import org.thoughtcrime.securesms.util.ViewUtil;
|
|||
import org.thoughtcrime.securesms.util.WindowUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||
import org.thoughtcrime.securesms.util.task.SnackbarAsyncTask;
|
||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState;
|
||||
|
@ -158,6 +160,7 @@ import java.util.Locale;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
|
@ -923,6 +926,33 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||
});
|
||||
}
|
||||
|
||||
private void handleMute(@NonNull Collection<Conversation> conversations) {
|
||||
MuteDialog.show(requireContext(), until -> {
|
||||
updateMute(conversations, until);
|
||||
});
|
||||
}
|
||||
|
||||
private void handleUnmute(@NonNull Collection<Conversation> conversations) {
|
||||
updateMute(conversations, 0);
|
||||
}
|
||||
|
||||
private void updateMute(@NonNull Collection<Conversation> conversations, long until) {
|
||||
SimpleProgressDialog.DismissibleDialog dialog = SimpleProgressDialog.showDelayed(requireContext(), 250, 250);
|
||||
|
||||
SimpleTask.run(SignalExecutors.BOUNDED, () -> {
|
||||
List<RecipientId> recipientIds = conversations.stream()
|
||||
.map(conversation -> conversation.getThreadRecord().getRecipient().live().get())
|
||||
.filter(r -> r.getMuteUntil() != until)
|
||||
.map(Recipient::getId)
|
||||
.collect(Collectors.toList());
|
||||
DatabaseFactory.getRecipientDatabase(requireContext()).setMuted(recipientIds, until);
|
||||
return null;
|
||||
}, unused -> {
|
||||
endActionModeIfActive();
|
||||
dialog.dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
private void handleSelectAllThreads() {
|
||||
defaultAdapter.selectAllThreads();
|
||||
updateMultiSelectState();
|
||||
|
@ -1053,6 +1083,12 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||
} else {
|
||||
items.add(new ActionItem(R.drawable.ic_pin_24, R.string.ConversationListFragment_pin, () -> handlePin(Collections.singleton(conversation))));
|
||||
}
|
||||
|
||||
if (conversation.getThreadRecord().getRecipient().live().get().isMuted()) {
|
||||
items.add(new ActionItem(R.drawable.ic_unmute_24, R.string.ConversationListFragment_unmute, () -> handleUnmute(Collections.singleton(conversation))));
|
||||
} else {
|
||||
items.add(new ActionItem(R.drawable.ic_mute_24, R.string.ConversationListFragment_mute, () -> handleMute(Collections.singleton(conversation))));
|
||||
}
|
||||
}
|
||||
|
||||
items.add(new ActionItem(R.drawable.ic_select_24, R.string.ConversationListFragment_select, () -> {
|
||||
|
@ -1134,6 +1170,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||
int count = defaultAdapter.getBatchSelectionIds().size();
|
||||
boolean hasUnread = Stream.of(defaultAdapter.getBatchSelection()).anyMatch(conversation -> !conversation.getThreadRecord().isRead());
|
||||
boolean hasUnpinned = Stream.of(defaultAdapter.getBatchSelection()).anyMatch(conversation -> !conversation.getThreadRecord().isPinned());
|
||||
boolean hasUnmuted = Stream.of(defaultAdapter.getBatchSelection()).anyMatch(conversation -> !conversation.getThreadRecord().getRecipient().live().get().isMuted());
|
||||
boolean canPin = viewModel.getPinnedCount() < MAXIMUM_PINNED_CONVERSATIONS;
|
||||
|
||||
if (actionMode != null) {
|
||||
|
@ -1162,6 +1199,13 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||
|
||||
items.add(new ActionItem(R.drawable.ic_delete_24, R.string.ConversationListFragment_delete, () -> handleDelete(defaultAdapter.getBatchSelectionIds())));
|
||||
|
||||
|
||||
if (hasUnmuted) {
|
||||
items.add(new ActionItem(R.drawable.ic_mute_24, R.string.ConversationListFragment_mute, () -> handleMute(defaultAdapter.getBatchSelection())));
|
||||
} else {
|
||||
items.add(new ActionItem(R.drawable.ic_unmute_24, R.string.ConversationListFragment_unmute, () -> handleUnmute(defaultAdapter.getBatchSelection())));
|
||||
}
|
||||
|
||||
items.add(new ActionItem(R.drawable.ic_select_24, R.string.ConversationListFragment_select_all, this::handleSelectAllThreads));
|
||||
|
||||
bottomActionBar.setItems(items);
|
||||
|
|
|
@ -1614,6 +1614,33 @@ public class RecipientDatabase extends Database {
|
|||
StorageSyncHelper.scheduleSyncForDataChange();
|
||||
}
|
||||
|
||||
public void setMuted(@NonNull Collection<RecipientId> ids, long until) {
|
||||
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
|
||||
|
||||
db.beginTransaction();
|
||||
try {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MUTE_UNTIL, until);
|
||||
|
||||
SqlUtil.Query query = SqlUtil.buildCollectionQuery(ID, ids);
|
||||
db.update(TABLE_NAME, values, query.getWhere(), query.getWhereArgs());
|
||||
|
||||
for (RecipientId id : ids) {
|
||||
rotateStorageId(id);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
for (RecipientId id : ids) {
|
||||
Recipient.live(id).refresh();
|
||||
}
|
||||
|
||||
StorageSyncHelper.scheduleSyncForDataChange();
|
||||
}
|
||||
|
||||
public void setSeenFirstInviteReminder(@NonNull RecipientId id) {
|
||||
setInsightsBannerTier(id, InsightsBannerTier.TIER_ONE);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M21.057,4.1L20.1,2.944L17.314,5.262C16.7526,4.1617 15.8644,3.2622 14.7712,2.687C13.6781,2.1118 12.4337,1.8892 11.2089,2.0498C9.9841,2.2103 8.8391,2.7461 7.9312,3.5836C7.0232,4.4211 6.3968,5.5192 6.138,6.727L4.711,13.57C4.5703,14.9073 3.9916,16.1606 3.065,17.135L0.943,18.9L1.9,20.056L21.057,4.1Z"
|
||||
android:fillColor="@color/signal_icon_tint_action"/>
|
||||
<path
|
||||
android:pathData="M12,22.5C12.5763,22.5001 13.135,22.3011 13.5815,21.9367C14.0279,21.5722 14.3347,21.0647 14.45,20.5H9.55C9.6653,21.0647 9.9721,21.5722 10.4186,21.9367C10.865,22.3011 11.4237,22.5001 12,22.5Z"
|
||||
android:fillColor="@color/signal_icon_tint_action"/>
|
||||
<path
|
||||
android:pathData="M21.264,16.216C20.7668,15.9393 20.3337,15.5604 19.9933,15.1044C19.6529,14.6483 19.4129,14.1254 19.289,13.57L18.215,8.419L5.517,19H20.5C20.8267,18.9975 21.1436,18.8885 21.4027,18.6894C21.6617,18.4903 21.8487,18.2121 21.9351,17.897C22.0216,17.582 22.0028,17.2473 21.8817,16.9439C21.7605,16.6405 21.5437,16.3849 21.264,16.216Z"
|
||||
android:fillColor="@color/signal_icon_tint_action"/>
|
||||
</vector>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M14.45,20.5C14.3352,21.0651 14.0286,21.5732 13.5821,21.9382C13.1356,22.3031 12.5767,22.5025 12,22.5025C11.4233,22.5025 10.8644,22.3031 10.4179,21.9382C9.9714,21.5732 9.6648,21.0651 9.55,20.5H14.45ZM21.264,16.216C20.7667,15.9393 20.3337,15.5604 19.9933,15.1044C19.6529,14.6483 19.4129,14.1254 19.289,13.57L17.862,6.727C17.5701,5.3895 16.8295,4.192 15.7632,3.3333C14.6969,2.4746 13.369,2.0064 12,2.0064C10.631,2.0064 9.3031,2.4746 8.2368,3.3333C7.1705,4.192 6.4299,5.3895 6.138,6.727L4.711,13.57C4.5885,14.1197 4.3524,14.6376 4.0178,15.0906C3.6831,15.5435 3.2574,15.9214 2.768,16.2C2.4829,16.3641 2.2596,16.6174 2.1325,16.9209C2.0055,17.2244 1.9817,17.5612 2.0649,17.8795C2.1482,18.1978 2.3337,18.4799 2.593,18.6824C2.8523,18.8848 3.171,18.9965 3.5,19H20.5C20.8267,18.9975 21.1436,18.8884 21.4027,18.6894C21.6617,18.4903 21.8487,18.2121 21.9351,17.897C22.0216,17.582 22.0028,17.2473 21.8817,16.9439C21.7605,16.6405 21.5437,16.3849 21.264,16.216Z"
|
||||
android:fillColor="@color/signal_icon_tint_action"/>
|
||||
</vector>
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M21.057,4.1L20.1,2.944L17.314,5.262C16.7527,4.1617 15.8644,3.2622 14.7712,2.687C13.6781,2.1118 12.4337,1.8892 11.2089,2.0498C9.9841,2.2103 8.8391,2.7461 7.9312,3.5836C7.0232,4.4211 6.3968,5.5192 6.138,6.727L4.711,13.57C4.4847,14.9278 3.8783,16.1937 2.962,17.221L0.943,18.9L1.9,20.056L21.057,4.1ZM6.18,13.876L7.6,7.044C7.805,6.113 8.3004,5.2711 9.0147,4.6398C9.7291,4.0085 10.6255,3.6203 11.5747,3.5313C12.5239,3.4423 13.4768,3.6571 14.296,4.1446C15.1153,4.6322 15.7585,5.3673 16.133,6.244L5.81,14.849C5.9805,14.5446 6.1051,14.2167 6.18,13.876V13.876Z"
|
||||
android:fillColor="#000000"/>
|
||||
<path
|
||||
android:pathData="M21.264,16.216C20.7668,15.9393 20.3337,15.5604 19.9933,15.1044C19.6529,14.6483 19.4129,14.1254 19.289,13.57L18.215,8.419L16.909,9.507L17.824,13.894C17.9906,14.6482 18.3138,15.3589 18.7727,15.9802C19.2317,16.6014 19.8161,17.1192 20.488,17.5H7.313L5.517,19H20.5C20.8267,18.9975 21.1436,18.8885 21.4027,18.6894C21.6617,18.4903 21.8487,18.2121 21.9351,17.897C22.0216,17.582 22.0028,17.2473 21.8817,16.9439C21.7605,16.6405 21.5437,16.3849 21.264,16.216Z"
|
||||
android:fillColor="#000000"/>
|
||||
<path
|
||||
android:pathData="M12,22.5C12.5763,22.5001 13.135,22.3011 13.5815,21.9367C14.0279,21.5722 14.3347,21.0647 14.45,20.5H9.55C9.6653,21.0647 9.9721,21.5722 10.4186,21.9367C10.865,22.3011 11.4237,22.5001 12,22.5Z"
|
||||
android:fillColor="#000000"/>
|
||||
</vector>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M14.45,20.5C14.3352,21.0651 14.0286,21.5732 13.5821,21.9382C13.1356,22.3031 12.5767,22.5025 12,22.5025C11.4233,22.5025 10.8644,22.3031 10.4179,21.9382C9.9714,21.5732 9.6648,21.0651 9.55,20.5H14.45ZM12,3.5C10.9731,3.5032 9.978,3.8559 9.1782,4.5001C8.3785,5.1442 7.8219,6.0414 7.6,7.044L6.18,13.876C6.0131,14.6337 5.6888,15.3478 5.2281,15.9722C4.7675,16.5965 4.1807,17.117 3.506,17.5H20.488C19.8167,17.1198 19.2327,16.6029 18.7738,15.9828C18.3149,15.3627 17.9913,14.6531 17.824,13.9L16.393,7.033C16.1699,6.0332 15.6135,5.139 14.8153,4.4971C14.0171,3.8551 13.0243,3.5035 12,3.5V3.5ZM12,2C13.3699,2.0003 14.6985,2.4694 15.7649,3.3294C16.8313,4.1893 17.5713,5.3883 17.862,6.727L19.289,13.57C19.4129,14.1254 19.6529,14.6483 19.9933,15.1044C20.3337,15.5604 20.7668,15.9393 21.264,16.216C21.5437,16.3849 21.7606,16.6405 21.8817,16.9439C22.0028,17.2473 22.0216,17.582 21.9351,17.897C21.8487,18.2121 21.6617,18.4903 21.4027,18.6894C21.1436,18.8884 20.8267,18.9975 20.5,19H3.5C3.171,18.9965 2.8523,18.8848 2.593,18.6824C2.3337,18.4799 2.1482,18.1978 2.065,17.8795C1.9817,17.5612 2.0055,17.2244 2.1325,16.9209C2.2596,16.6174 2.4829,16.3641 2.768,16.2C3.2574,15.9214 3.6832,15.5435 4.0178,15.0906C4.3524,14.6376 4.5885,14.1197 4.711,13.57L6.138,6.727C6.4287,5.3883 7.1687,4.1893 8.2351,3.3294C9.3015,2.4694 10.6301,2.0003 12,2Z"
|
||||
android:fillColor="#000000"/>
|
||||
</vector>
|
Ładowanie…
Reference in New Issue