let omemoOnly config overwrite OmemoSetting
This commit is contained in:
parent
5735bca517
commit
d435c1f2ae
|
@ -15,10 +15,9 @@ import eu.siacs.conversations.xmpp.chatstate.ChatState;
|
|||
public final class Config {
|
||||
private static final int UNENCRYPTED = 1;
|
||||
private static final int OPENPGP = 2;
|
||||
private static final int OTR = 4;
|
||||
private static final int OMEMO = 8;
|
||||
|
||||
private static final int ENCRYPTION_MASK = UNENCRYPTED | OPENPGP | OTR | OMEMO;
|
||||
private static final int ENCRYPTION_MASK = UNENCRYPTED | OPENPGP | OMEMO;
|
||||
|
||||
public static boolean supportUnencrypted() {
|
||||
return (ENCRYPTION_MASK & UNENCRYPTED) != 0;
|
||||
|
@ -32,6 +31,10 @@ public final class Config {
|
|||
return (ENCRYPTION_MASK & OMEMO) != 0;
|
||||
}
|
||||
|
||||
public static boolean omemoOnly() {
|
||||
return !multipleEncryptionChoices() && supportOmemo();
|
||||
}
|
||||
|
||||
public static boolean multipleEncryptionChoices() {
|
||||
return (ENCRYPTION_MASK & (ENCRYPTION_MASK - 1)) != 0;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.ui.SettingsActivity;
|
||||
|
@ -52,8 +55,13 @@ public class OmemoSetting {
|
|||
}
|
||||
|
||||
public static void load(final Context context, final SharedPreferences sharedPreferences) {
|
||||
if (Config.omemoOnly()) {
|
||||
always = true;
|
||||
encryption = Message.ENCRYPTION_AXOLOTL;
|
||||
return;
|
||||
}
|
||||
final String value = sharedPreferences.getString(SettingsActivity.OMEMO_SETTING, context.getResources().getString(R.string.omemo_setting_default));
|
||||
switch (value) {
|
||||
switch (Strings.nullToEmpty(value)) {
|
||||
case "always":
|
||||
always = true;
|
||||
encryption = Message.ENCRYPTION_AXOLOTL;
|
||||
|
|
|
@ -298,26 +298,33 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
|
|||
deleteOmemoPreference.setOnPreferenceClickListener(
|
||||
preference -> deleteOmemoIdentities());
|
||||
}
|
||||
if (Config.omemoOnly()) {
|
||||
final PreferenceCategory privacyCategory =
|
||||
(PreferenceCategory) mSettingsFragment.findPreference("privacy");
|
||||
final Preference omemoPreference =mSettingsFragment.findPreference(OMEMO_SETTING);
|
||||
if (omemoPreference != null) {
|
||||
privacyCategory.removePreference(omemoPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void changeOmemoSettingSummary() {
|
||||
ListPreference omemoPreference =
|
||||
final ListPreference omemoPreference =
|
||||
(ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING);
|
||||
if (omemoPreference != null) {
|
||||
String value = omemoPreference.getValue();
|
||||
switch (value) {
|
||||
case "always":
|
||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
|
||||
break;
|
||||
case "default_on":
|
||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
|
||||
break;
|
||||
case "default_off":
|
||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, "unable to find preference named " + OMEMO_SETTING);
|
||||
if (omemoPreference == null) {
|
||||
return;
|
||||
}
|
||||
final String value = omemoPreference.getValue();
|
||||
switch (value) {
|
||||
case "always":
|
||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
|
||||
break;
|
||||
case "default_on":
|
||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
|
||||
break;
|
||||
case "default_off":
|
||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
android:targetPackage="com.huawei.systemmanager" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_privacy">
|
||||
<PreferenceCategory android:title="@string/pref_privacy"
|
||||
android:key="privacy">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@bool/confirm_messages"
|
||||
android:key="confirm_messages"
|
||||
|
|
Loading…
Reference in a new issue