-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show unblock dialog when tap blocked contact.
- Loading branch information
1 parent
48c33f3
commit e9c92bd
Showing
3 changed files
with
109 additions
and
97 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
app/src/main/java/org/thoughtcrime/securesms/BlockUnblockDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.thoughtcrime.securesms; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.lifecycle.Lifecycle; | ||
|
||
import org.thoughtcrime.securesms.database.DatabaseFactory; | ||
import org.thoughtcrime.securesms.recipients.Recipient; | ||
import org.thoughtcrime.securesms.recipients.RecipientId; | ||
import org.thoughtcrime.securesms.recipients.RecipientUtil; | ||
import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; | ||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask; | ||
|
||
public final class BlockUnblockDialog { | ||
|
||
private BlockUnblockDialog() { | ||
} | ||
|
||
public static void handleBlock(@NonNull Context context, | ||
@NonNull Lifecycle lifecycle, | ||
@NonNull RecipientId recipientId) | ||
{ | ||
SimpleTask.run( | ||
lifecycle, | ||
() -> { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(context); | ||
Recipient resolved = Recipient.resolved(recipientId); | ||
|
||
if (resolved.isGroup()) { | ||
if (DatabaseFactory.getGroupDatabase(context).isActive(resolved.requireGroupId())) { | ||
builder.setTitle(R.string.RecipientPreferenceActivity_block_and_leave_group); | ||
} else { | ||
builder.setTitle(R.string.RecipientPreferenceActivity_block_group); | ||
} | ||
builder.setMessage(R.string.RecipientPreferenceActivity_block_and_leave_group_description); | ||
} else { | ||
builder.setTitle(R.string.RecipientPreferenceActivity_block_this_contact_question) | ||
.setMessage(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact); | ||
} | ||
|
||
return builder.setCancelable(true) | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.setPositiveButton(R.string.RecipientPreferenceActivity_block, (dialog, which) -> setBlocked(context, resolved, true)); | ||
}, | ||
AlertDialog.Builder::show); | ||
} | ||
|
||
public static void handleUnblock(@NonNull Context context, | ||
@NonNull Lifecycle lifecycle, | ||
@NonNull RecipientId recipientId, | ||
@Nullable Runnable postUnblock) | ||
{ | ||
SimpleTask.run( | ||
lifecycle, | ||
() -> { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(context); | ||
Recipient resolved = Recipient.resolved(recipientId); | ||
|
||
if (resolved.isGroup()) { | ||
builder.setTitle(R.string.RecipientPreferenceActivity_unblock_this_group_question) | ||
.setMessage(R.string.RecipientPreferenceActivity_unblock_this_group_description); | ||
} else { | ||
builder.setTitle(R.string.RecipientPreferenceActivity_unblock_this_contact_question) | ||
.setMessage(R.string.RecipientPreferenceActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact); | ||
} | ||
|
||
return builder.setCancelable(true) | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.setPositiveButton(R.string.RecipientPreferenceActivity_unblock, (dialog, which) -> { | ||
setBlocked(context, resolved, false); | ||
if (postUnblock != null) postUnblock.run(); | ||
}); | ||
}, | ||
AlertDialog.Builder::show); | ||
} | ||
|
||
private static void setBlocked(@NonNull final Context context, final Recipient recipient, final boolean blocked) { | ||
SignalExecutors.BOUNDED.execute(() -> { | ||
if (blocked) { | ||
RecipientUtil.block(context, recipient); | ||
} else { | ||
RecipientUtil.unblock(context, recipient); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters