add 'security' settings

This commit is contained in:
Daniel Gultsch 2023-02-21 12:01:48 +01:00
parent 1f22c5f534
commit 0727b0aba6
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
11 changed files with 131 additions and 3 deletions

View file

@ -36,6 +36,12 @@ public class InterfaceSettingsFragment extends PreferenceFragmentCompat {
});
}
@Override
public void onStart() {
super.onStart();
requireActivity().setTitle(R.string.pref_title_interface);
}
public SettingsActivity requireSettingsActivity() {
final var activity = requireActivity();
if (activity instanceof SettingsActivity) {

View file

@ -11,4 +11,10 @@ public class MainSettingsFragment extends PreferenceFragmentCompat {
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.preferences_main, rootKey);
}
@Override
public void onStart() {
super.onStart();
requireActivity().setTitle(R.string.title_activity_settings);
}
}

View file

@ -0,0 +1,49 @@
package im.conversations.android.ui.fragment.settings;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceFragmentCompat;
import com.google.common.base.Strings;
import im.conversations.android.R;
public class SecuritySettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.preferences_security, rootKey);
final var omemo = findPreference("omemo");
if (omemo == null) {
throw new IllegalStateException("The preference resource file did not contain omemo");
}
omemo.setSummaryProvider(
preference -> {
final var sharedPreferences = preference.getSharedPreferences();
final String value;
if (sharedPreferences == null) {
value = null;
} else {
value =
sharedPreferences.getString(
preference.getKey(),
requireContext().getString(R.string.omemo_setting_default));
}
switch (Strings.nullToEmpty(value)) {
case "always":
return requireContext()
.getString(R.string.pref_omemo_setting_summary_always);
case "default_off":
return requireContext()
.getString(R.string.pref_omemo_setting_summary_default_off);
default:
return requireContext()
.getString(R.string.pref_omemo_setting_summary_default_on);
}
});
}
@Override
public void onStart() {
super.onStart();
requireActivity().setTitle(R.string.pref_title_security);
}
}

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z" />
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM10,17l-4,-4 1.41,-1.41L10,14.17l6.59,-6.59L18,9l-8,8z" />
</vector>

View file

@ -31,7 +31,6 @@
android:id="@+id/material_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="@string/title_activity_settings"
app:navigationIcon="@drawable/ic_arrow_back_24dp"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.fragment.app.FragmentContainerView

View file

@ -3,4 +3,6 @@
<bool name="scroll_to_bottom">true</bool>
<bool name="enter_is_send">false</bool>
<bool name="allow_screenshots">true</bool>
<bool name="btbv">true</bool>
<string translatable="false" name="omemo_setting_default">default_on</string>
</resources>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="omemo_setting_entry_values">
<item>always</item>
<item>default_on</item>
<item>default_off</item>
</string-array>
<string-array name="omemo_setting_entries">
<item>@string/always</item>
<item>@string/default_on</item>
<item>@string/default_off</item>
</string-array>
</resources>

View file

@ -1026,5 +1026,9 @@
<string name="pref_light_dark_mode">Light/dark mode</string>
<string name="appearance">Appearance</string>
<string name="pref_allow_screenshots">Allow screenshots</string>
<string name="pref_category_e2ee">End-to-end encryption</string>
<string name="pref_category_server_connection">Server connection</string>
<string name="detect_mim">Require channel binding</string>
<string name="detect_mim_summary">Channel binding can detect some machine-in-the-middle attacks</string>
</resources>

View file

@ -10,7 +10,7 @@
app:title="@string/pref_title_security"
app:summary="@string/pref_summary_security"
android:icon="@drawable/ic_security_24dp"
app:fragment="im.conversations.android.ui.fragment.MainSettingsFragment"/>
app:fragment="im.conversations.android.ui.fragment.settings.SecuritySettingsFragment"/>
<Preference
app:title="@string/unified_push_distributor"
app:summary="@string/unified_push_summary"

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="@string/pref_category_e2ee">
<ListPreference
android:icon="@drawable/ic_lock_24dp"
android:defaultValue="@string/omemo_setting_default"
android:entries="@array/omemo_setting_entries"
android:entryValues="@array/omemo_setting_entry_values"
android:key="omemo"
android:summary="@string/pref_omemo_setting_summary_default_on"
android:title="@string/pref_omemo_setting" />
<SwitchPreferenceCompat
android:icon="@drawable/ic_verified_user_24dp"
android:defaultValue="@bool/btbv"
android:key="btbv"
android:summary="@string/pref_blind_trust_before_verification_summary"
android:title="@string/pref_blind_trust_before_verification" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_server_connection">
<SwitchPreferenceCompat android:title="@string/detect_mim"
android:summary="@string/detect_mim_summary"
android:key="channel_binding_required"/>
</PreferenceCategory>
</PreferenceScreen>