From 44ac7190a90d704b59c8bc73c1f10edc13b9116e Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 23 Feb 2023 13:41:35 +0100 Subject: [PATCH] add notifications and attachments settings screens --- .../ui/activity/result/PickRingtone.java | 41 ++++++++++ .../settings/AttachmentsSettingsFragment.java | 20 +++++ .../settings/MainSettingsFragment.java | 7 ++ .../NotificationsSettingsFragment.java | 80 +++++++++++++++++++ .../fragment/settings/UpSettingsFragment.java | 20 +++++ .../main/res/drawable/ic_attachment_24dp.xml | 10 +++ .../main/res/drawable/ic_download_24dp.xml | 10 +++ app/src/main/res/drawable/ic_movie_24dp.xml | 10 +++ .../res/drawable/ic_notifications_24dp.xml | 10 +++ .../drawable/ic_notifications_paused_24dp.xml | 10 +++ app/src/main/res/drawable/ic_phone_24dp.xml | 10 +++ app/src/main/res/drawable/ic_photo_24dp.xml | 10 +++ app/src/main/res/values/defaults.xml | 6 +- app/src/main/res/values/settings.xml | 63 +++++++++++++++ app/src/main/res/values/strings.xml | 6 ++ .../main/res/xml/preferences_attachments.xml | 32 ++++++++ app/src/main/res/xml/preferences_main.xml | 31 ++++--- .../res/xml/preferences_notifications.xml | 36 +++++++++ app/src/main/res/xml/preferences_up.xml | 4 + 19 files changed, 406 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/im/conversations/android/ui/activity/result/PickRingtone.java create mode 100644 app/src/main/java/im/conversations/android/ui/fragment/settings/AttachmentsSettingsFragment.java create mode 100644 app/src/main/java/im/conversations/android/ui/fragment/settings/NotificationsSettingsFragment.java create mode 100644 app/src/main/java/im/conversations/android/ui/fragment/settings/UpSettingsFragment.java create mode 100644 app/src/main/res/drawable/ic_attachment_24dp.xml create mode 100644 app/src/main/res/drawable/ic_download_24dp.xml create mode 100644 app/src/main/res/drawable/ic_movie_24dp.xml create mode 100644 app/src/main/res/drawable/ic_notifications_24dp.xml create mode 100644 app/src/main/res/drawable/ic_notifications_paused_24dp.xml create mode 100644 app/src/main/res/drawable/ic_phone_24dp.xml create mode 100644 app/src/main/res/drawable/ic_photo_24dp.xml create mode 100644 app/src/main/res/xml/preferences_attachments.xml create mode 100644 app/src/main/res/xml/preferences_notifications.xml create mode 100644 app/src/main/res/xml/preferences_up.xml diff --git a/app/src/main/java/im/conversations/android/ui/activity/result/PickRingtone.java b/app/src/main/java/im/conversations/android/ui/activity/result/PickRingtone.java new file mode 100644 index 000000000..b4f33d695 --- /dev/null +++ b/app/src/main/java/im/conversations/android/ui/activity/result/PickRingtone.java @@ -0,0 +1,41 @@ +package im.conversations.android.ui.activity.result; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; +import androidx.activity.result.contract.ActivityResultContract; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class PickRingtone extends ActivityResultContract { + + private static final Uri NONE = Uri.parse("about:blank"); + + @NonNull + @Override + public Intent createIntent(@NonNull final Context context, final Uri existing) { + final Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); + if (existing != null) { + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, existing); + } + return intent; + } + + @Override + public Uri parseResult(int resultCode, @Nullable Intent data) { + if (resultCode != Activity.RESULT_OK || data == null) { + return null; + } + final Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); + return pickedUri == null ? NONE : pickedUri; + } + + public static Uri noneToNull(final Uri uri) { + return uri == null || NONE.equals(uri) ? null : uri; + } +} diff --git a/app/src/main/java/im/conversations/android/ui/fragment/settings/AttachmentsSettingsFragment.java b/app/src/main/java/im/conversations/android/ui/fragment/settings/AttachmentsSettingsFragment.java new file mode 100644 index 000000000..fdac2e60d --- /dev/null +++ b/app/src/main/java/im/conversations/android/ui/fragment/settings/AttachmentsSettingsFragment.java @@ -0,0 +1,20 @@ +package im.conversations.android.ui.fragment.settings; + +import android.os.Bundle; +import androidx.annotation.Nullable; +import androidx.preference.PreferenceFragmentCompat; +import im.conversations.android.R; + +public class AttachmentsSettingsFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { + setPreferencesFromResource(R.xml.preferences_attachments, rootKey); + } + + @Override + public void onStart() { + super.onStart(); + requireActivity().setTitle(R.string.pref_attachments); + } +} diff --git a/app/src/main/java/im/conversations/android/ui/fragment/settings/MainSettingsFragment.java b/app/src/main/java/im/conversations/android/ui/fragment/settings/MainSettingsFragment.java index a96a7ebe0..f2bd8329c 100644 --- a/app/src/main/java/im/conversations/android/ui/fragment/settings/MainSettingsFragment.java +++ b/app/src/main/java/im/conversations/android/ui/fragment/settings/MainSettingsFragment.java @@ -3,6 +3,7 @@ package im.conversations.android.ui.fragment.settings; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.preference.PreferenceFragmentCompat; +import im.conversations.android.BuildConfig; import im.conversations.android.R; public class MainSettingsFragment extends PreferenceFragmentCompat { @@ -10,6 +11,12 @@ public class MainSettingsFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { setPreferencesFromResource(R.xml.preferences_main, rootKey); + final var about = findPreference("about"); + if (about == null) { + throw new IllegalStateException("The preference resource file did not 'about'"); + } + about.setTitle(getString(R.string.title_activity_about_x, BuildConfig.APP_NAME)); + about.setSummary(String.format("%s %s", BuildConfig.APP_NAME, BuildConfig.VERSION_NAME)); } @Override diff --git a/app/src/main/java/im/conversations/android/ui/fragment/settings/NotificationsSettingsFragment.java b/app/src/main/java/im/conversations/android/ui/fragment/settings/NotificationsSettingsFragment.java new file mode 100644 index 000000000..709de54cf --- /dev/null +++ b/app/src/main/java/im/conversations/android/ui/fragment/settings/NotificationsSettingsFragment.java @@ -0,0 +1,80 @@ +package im.conversations.android.ui.fragment.settings; + +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Bundle; +import androidx.activity.result.ActivityResultLauncher; +import androidx.annotation.Nullable; +import androidx.preference.Preference; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceManager; +import com.google.common.base.Strings; +import im.conversations.android.R; +import im.conversations.android.ui.activity.result.PickRingtone; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NotificationsSettingsFragment extends PreferenceFragmentCompat { + + private static final String RINGTONE_PREFERENCE_KEY = "call_ringtone"; + + private static final Logger LOGGER = + LoggerFactory.getLogger(NotificationsSettingsFragment.class); + + private final ActivityResultLauncher pickRingtoneLauncher = + registerForActivityResult( + new PickRingtone(), + result -> { + if (result == null) { + // do nothing. user aborted + return; + } + final Uri uri = PickRingtone.noneToNull(result); + setRingtone(uri); + LOGGER.info("User set ringtone to {}", uri); + }); + + @Override + public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { + setPreferencesFromResource(R.xml.preferences_notifications, rootKey); + } + + @Override + public void onStart() { + super.onStart(); + requireActivity().setTitle(R.string.notifications); + } + + @Override + public boolean onPreferenceTreeClick(final Preference preference) { + if (RINGTONE_PREFERENCE_KEY.equals(preference.getKey())) { + pickRingtone(); + return true; + } + return super.onPreferenceTreeClick(preference); + } + + private void pickRingtone() { + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()); + final String incomingCallRingtone = + sharedPreferences.getString( + RINGTONE_PREFERENCE_KEY, + requireContext().getString(R.string.incoming_call_ringtone)); + final Uri uri = + Strings.isNullOrEmpty(incomingCallRingtone) + ? null + : Uri.parse(incomingCallRingtone); + LOGGER.info("current ringtone {}", uri); + this.pickRingtoneLauncher.launch(uri); + } + + private void setRingtone(final Uri uri) { + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()); + sharedPreferences + .edit() + .putString(RINGTONE_PREFERENCE_KEY, uri == null ? null : uri.toString()) + .apply(); + } +} diff --git a/app/src/main/java/im/conversations/android/ui/fragment/settings/UpSettingsFragment.java b/app/src/main/java/im/conversations/android/ui/fragment/settings/UpSettingsFragment.java new file mode 100644 index 000000000..703bf6a89 --- /dev/null +++ b/app/src/main/java/im/conversations/android/ui/fragment/settings/UpSettingsFragment.java @@ -0,0 +1,20 @@ +package im.conversations.android.ui.fragment.settings; + +import android.os.Bundle; +import androidx.annotation.Nullable; +import androidx.preference.PreferenceFragmentCompat; +import im.conversations.android.R; + +public class UpSettingsFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { + setPreferencesFromResource(R.xml.preferences_up, rootKey); + } + + @Override + public void onStart() { + super.onStart(); + requireActivity().setTitle(R.string.unified_push_distributor); + } +} diff --git a/app/src/main/res/drawable/ic_attachment_24dp.xml b/app/src/main/res/drawable/ic_attachment_24dp.xml new file mode 100644 index 000000000..7607bd195 --- /dev/null +++ b/app/src/main/res/drawable/ic_attachment_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_download_24dp.xml b/app/src/main/res/drawable/ic_download_24dp.xml new file mode 100644 index 000000000..0964bd62d --- /dev/null +++ b/app/src/main/res/drawable/ic_download_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_movie_24dp.xml b/app/src/main/res/drawable/ic_movie_24dp.xml new file mode 100644 index 000000000..2e44e1402 --- /dev/null +++ b/app/src/main/res/drawable/ic_movie_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_notifications_24dp.xml b/app/src/main/res/drawable/ic_notifications_24dp.xml new file mode 100644 index 000000000..726ba1ec0 --- /dev/null +++ b/app/src/main/res/drawable/ic_notifications_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_notifications_paused_24dp.xml b/app/src/main/res/drawable/ic_notifications_paused_24dp.xml new file mode 100644 index 000000000..037fd15ba --- /dev/null +++ b/app/src/main/res/drawable/ic_notifications_paused_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_phone_24dp.xml b/app/src/main/res/drawable/ic_phone_24dp.xml new file mode 100644 index 000000000..cffd1b6c8 --- /dev/null +++ b/app/src/main/res/drawable/ic_phone_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_photo_24dp.xml b/app/src/main/res/drawable/ic_photo_24dp.xml new file mode 100644 index 000000000..306717a9f --- /dev/null +++ b/app/src/main/res/drawable/ic_photo_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/defaults.xml b/app/src/main/res/values/defaults.xml index a2b3bce49..85b959357 100644 --- a/app/src/main/res/values/defaults.xml +++ b/app/src/main/res/values/defaults.xml @@ -5,6 +5,10 @@ false true true - default_on + default_on content://settings/system/ringtone + 144 + 524288 + auto + 360 diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index 7b01760cb..f08dbb9a4 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -1,6 +1,8 @@ + + always default_on @@ -12,4 +14,65 @@ @string/default_off + + + + + @string/gp_disable + @string/gp_short + @string/gp_medium + @string/gp_long + + + + 0 + 144 + 610 + 2584 + + + + + + @string/never + 256 KiB + 512 KiB + 1 MiB + 5 MiB + 10 MiB + + + 0 + 262144 + 524288 + 1048576 + 5242880 + 10485760 + + + + + never + auto + always + + + + @string/never + @string/large_images_only + @string/always + + + + 360 + 720 + uncompressed + + + + @string/video_360p + @string/video_720p + @string/video_original + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f92d89c8a..a83f20128 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1032,5 +1032,11 @@ Server connection Require channel binding Channel binding can detect some machine-in-the-middle attacks + Notifications + File size, Image compression, Video quality + Grace period, Ringtone, Vibration, Strangers + Automatic download + Sending + Receiving diff --git a/app/src/main/res/xml/preferences_attachments.xml b/app/src/main/res/xml/preferences_attachments.xml new file mode 100644 index 000000000..a61a92139 --- /dev/null +++ b/app/src/main/res/xml/preferences_attachments.xml @@ -0,0 +1,32 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_main.xml b/app/src/main/res/xml/preferences_main.xml index c60d4b281..10260d300 100644 --- a/app/src/main/res/xml/preferences_main.xml +++ b/app/src/main/res/xml/preferences_main.xml @@ -2,19 +2,32 @@ + app:fragment="im.conversations.android.ui.fragment.settings.InterfaceSettingsFragment" + app:summary="@string/pref_summary_appearance" + app:title="@string/pref_title_interface" /> + app:fragment="im.conversations.android.ui.fragment.settings.SecuritySettingsFragment" + app:summary="@string/pref_summary_security" + app:title="@string/pref_title_security" /> + + + app:fragment="im.conversations.android.ui.fragment.settings.UpSettingsFragment" + app:summary="@string/unified_push_summary" + app:title="@string/unified_push_distributor" /> + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_notifications.xml b/app/src/main/res/xml/preferences_notifications.xml new file mode 100644 index 000000000..79c570bb2 --- /dev/null +++ b/app/src/main/res/xml/preferences_notifications.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_up.xml b/app/src/main/res/xml/preferences_up.xml new file mode 100644 index 000000000..624ed13ae --- /dev/null +++ b/app/src/main/res/xml/preferences_up.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file