From d1339569dd0c644d149d34283f6b0ce7588a6abd Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 27 Jul 2020 15:56:08 +0200 Subject: [PATCH] implement custom view for ephemeral messages dialog (#1503) implement custom view for ephemeral messages dialog showing a hint about the implications of this feature --- res/layout/dialog_extended_options.xml | 25 +++++++++++ res/values/strings.xml | 1 + .../securesms/EphemeralMessagesDialog.java | 43 +++++++++++++++++-- 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 res/layout/dialog_extended_options.xml diff --git a/res/layout/dialog_extended_options.xml b/res/layout/dialog_extended_options.xml new file mode 100644 index 000000000..9ccd69ae8 --- /dev/null +++ b/res/layout/dialog_extended_options.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 1873f3f32..4e7ba3230 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -26,6 +26,7 @@ Unarchive Mute Disappearing messages + These settings apply to all participants using Delta Chat. However, they may copy, save and forward messages or use other e-mail clients. Save Chat Media diff --git a/src/org/thoughtcrime/securesms/EphemeralMessagesDialog.java b/src/org/thoughtcrime/securesms/EphemeralMessagesDialog.java index 3bc95ff6c..cf6de6a90 100644 --- a/src/org/thoughtcrime/securesms/EphemeralMessagesDialog.java +++ b/src/org/thoughtcrime/securesms/EphemeralMessagesDialog.java @@ -2,9 +2,17 @@ package org.thoughtcrime.securesms; import android.content.Context; import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; +import androidx.core.widget.TextViewCompat; + +import org.thoughtcrime.securesms.util.ViewUtil; import java.util.concurrent.TimeUnit; @@ -17,8 +25,38 @@ public class EphemeralMessagesDialog { int preselected = getPreselection(currentSelectedTime); final int[] selectedChoice = new int[]{preselected}; + View dialogView = View.inflate(context, R.layout.dialog_extended_options, null); + RadioGroup container = dialogView.findViewById(R.id.optionsContainer); + for (CharSequence choice : choices) { + + RadioButton radioButton = new RadioButton(context); + radioButton.setText(choice); + TextViewCompat.setTextAppearance(radioButton, android.R.style.TextAppearance_Medium); + + RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + params.setMargins(0, 0, 0, ViewUtil.dpToPx(context, 8)); + radioButton.setLayoutParams(params); + container.addView(radioButton); + } + + container.setOnCheckedChangeListener((group, checkedId) -> { + int childCount = group.getChildCount(); + for (int x = 0; x < childCount; x++) { + RadioButton btn = (RadioButton) group.getChildAt(x); + if (btn.getId() == checkedId) { + selectedChoice[0] = x; + } + } + }); + container.check(container.getChildAt(preselected).getId()); + + TextView messageView = dialogView.findViewById(R.id.description); + messageView.setText(context.getString(R.string.ephemeral_messages_hint)); + + AlertDialog.Builder builder = new AlertDialog.Builder(context) .setTitle(R.string.ephemeral_messages) + .setView(dialogView) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.ok, (dialog, which) -> { final long burnAfter; @@ -32,10 +70,7 @@ public class EphemeralMessagesDialog { default: burnAfter = 0; break; } listener.onTimeSelected(burnAfter); - }) - .setSingleChoiceItems(choices, preselected, ((dialog, which) -> { - selectedChoice[0] = which; - })); + }); builder.show(); }