|
| 1 | +package org.thoughtcrime.securesms.conversation; |
| 2 | + |
| 3 | +import android.app.Dialog; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.view.LayoutInflater; |
| 6 | +import android.view.View; |
| 7 | +import android.widget.TextView; |
| 8 | + |
| 9 | +import androidx.annotation.NonNull; |
| 10 | +import androidx.fragment.app.DialogFragment; |
| 11 | +import androidx.fragment.app.FragmentManager; |
| 12 | + |
| 13 | +import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
| 14 | + |
| 15 | +import org.signal.core.util.logging.Log; |
| 16 | +import org.thoughtcrime.securesms.R; |
| 17 | +import org.thoughtcrime.securesms.database.model.MessageRecord; |
| 18 | +import org.thoughtcrime.securesms.recipients.Recipient; |
| 19 | +import org.thoughtcrime.securesms.recipients.RecipientId; |
| 20 | + |
| 21 | +/** |
| 22 | + * A dialog fragment that shows when you click 'learn more' on a {@link MessageRecord#isBadDecryptType()}. |
| 23 | + */ |
| 24 | +public final class BadDecryptLearnMoreDialog extends DialogFragment { |
| 25 | + |
| 26 | + private static final String TAG = Log.tag(BadDecryptLearnMoreDialog.class); |
| 27 | + private static final String FRAGMENT_TAG = "BadDecryptLearnMoreDialog"; |
| 28 | + |
| 29 | + private static final String KEY_DISPLAY_NAME = "display_name"; |
| 30 | + private static final String KEY_GROUP_CHAT = "group_chat"; |
| 31 | + |
| 32 | + public static void show(@NonNull FragmentManager fragmentManager, @NonNull String displayName, boolean isGroupChat) { |
| 33 | + if (fragmentManager.findFragmentByTag(FRAGMENT_TAG) != null) { |
| 34 | + Log.i(TAG, "Already shown!"); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + Bundle args = new Bundle(); |
| 39 | + args.putString(KEY_DISPLAY_NAME, displayName); |
| 40 | + args.putBoolean(KEY_GROUP_CHAT, isGroupChat); |
| 41 | + |
| 42 | + BadDecryptLearnMoreDialog fragment = new BadDecryptLearnMoreDialog(); |
| 43 | + fragment.setArguments(args); |
| 44 | + fragment.show(fragmentManager, FRAGMENT_TAG); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 49 | + MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(requireContext()); |
| 50 | + |
| 51 | + View view = LayoutInflater.from(requireContext()).inflate(R.layout.bad_decrypt_learn_more_dialog_fragment, null); |
| 52 | + TextView body = view.findViewById(R.id.bad_decrypt_dialog_body); |
| 53 | + |
| 54 | + String displayName = requireArguments().getString(KEY_DISPLAY_NAME); |
| 55 | + boolean isGroup = requireArguments().getBoolean(KEY_GROUP_CHAT); |
| 56 | + |
| 57 | + if (isGroup) { |
| 58 | + body.setText(getString(R.string.BadDecryptLearnMoreDialog_couldnt_be_delivered_group, displayName)); |
| 59 | + } else { |
| 60 | + body.setText(getString(R.string.BadDecryptLearnMoreDialog_couldnt_be_delivered_individual, displayName)); |
| 61 | + } |
| 62 | + |
| 63 | + dialogBuilder.setView(view) |
| 64 | + .setPositiveButton(android.R.string.ok, null); |
| 65 | + |
| 66 | + return dialogBuilder.create(); |
| 67 | + } |
| 68 | +} |
0 commit comments