From a96aa2ff485584b966dcd369c7204833d73fedba Mon Sep 17 00:00:00 2001 From: Hocuri Date: Sat, 2 Jan 2021 19:19:23 +0100 Subject: [PATCH] Show controls on small screens Using both `setMessage()` and `setView()` on the same AlertDialog, on small screens the "OK" and "Cancel" buttons were not be show. So, put the message into our custom view. --- res/layout/autodel_confirm.xml | 43 +++++++++++++------ .../preferences/ChatsPreferenceFragment.java | 22 ++++++---- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/res/layout/autodel_confirm.xml b/res/layout/autodel_confirm.xml index 3123f1463..144757c4f 100644 --- a/res/layout/autodel_confirm.xml +++ b/res/layout/autodel_confirm.xml @@ -1,19 +1,34 @@ - + xmlns:tools="http://schemas.android.com/tools"> - + android:paddingLeft="25dp" + android:paddingRight="25dp" + android:paddingTop="10dp" + android:paddingBottom="10dp" + android:orientation="vertical"> + + + + + + - \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java index 87ceb8abe..aa2615586 100644 --- a/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java @@ -4,17 +4,17 @@ import android.Manifest; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.NonNull; +import android.view.View; +import android.widget.CheckBox; +import android.widget.TextView; +import android.widget.Toast; + import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.preference.CheckBoxPreference; import androidx.preference.ListPreference; import androidx.preference.Preference; -import android.view.View; -import android.widget.CheckBox; -import android.widget.Toast; - import com.b44t.messenger.DcContext; import org.thoughtcrime.securesms.ApplicationPreferencesActivity; @@ -165,13 +165,16 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment { View gl = View.inflate(getActivity(), R.layout.autodel_confirm, null); CheckBox confirmCheckbox = gl.findViewById(R.id.i_understand); - String msg = String.format(context.getString(fromServer? + TextView msg = gl.findViewById(R.id.autodel_ask_msg); + + // If we'd use both `setMessage()` and `setView()` on the same AlertDialog, on small screens the + // "OK" and "Cancel" buttons would not be show. So, put the message into our custom view: + msg.setText(String.format(context.getString(fromServer? R.string.autodel_server_ask : R.string.autodel_device_ask), - delCount, getSelectedSummary(preference, newValue)); + delCount, getSelectedSummary(preference, newValue))); new AlertDialog.Builder(context) .setTitle(preference.getTitle()) - .setMessage(msg) .setView(gl) .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { if (confirmCheckbox.isChecked()) { @@ -182,7 +185,8 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment { } }) .setNegativeButton(android.R.string.cancel, (dialog, whichButton) -> initAutodelFromCore()) - .setCancelable(false) + .setCancelable(true) // Enable the user to quickly cancel if they are intimidated by the warnings :) + .setOnCancelListener(dialog -> initAutodelFromCore()) .show(); } else { updateListSummary(preference, newValue);