From 3d584b76f7ae749330b7997ec1a42e8458c6aa61 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 28 Apr 2018 15:58:04 +0200 Subject: [PATCH] Choose kdf and encapsulate code --- .../keepass/crypto/keyDerivation/AesKdf.java | 15 +- .../crypto/keyDerivation/Argon2Kdf.java | 17 +- .../crypto/keyDerivation/KdfEngine.java | 8 +- .../kunzisoft/keepass/database/Database.java | 30 ++- .../keepass/database/ObjectNameResource.java | 29 +++ .../keepass/database/PwDatabase.java | 10 +- .../keepass/database/PwDatabaseV3.java | 20 +- .../keepass/database/PwDatabaseV4.java | 45 +++-- .../database/PwEncryptionAlgorithm.java | 8 +- .../settings/NestedSettingsFragment.java | 18 +- ...a => DialogListExplanationPreference.java} | 10 +- ...gorithmPreferenceDialogFragmentCompat.java | 180 ------------------ ...riptionPreferenceDialogFragmentCompat.java | 19 ++ ...gorithmPreferenceDialogFragmentCompat.java | 115 +++++++++++ ...ivationPreferenceDialogFragmentCompat.java | 122 ++++++++++++ ...aseNamePreferenceDialogFragmentCompat.java | 19 ++ ...aseSavePreferenceDialogFragmentCompat.java | 19 ++ ...aseSavePreferenceDialogFragmentCompat.java | 19 ++ .../InputPreferenceDialogFragmentCompat.java | 19 ++ .../adapter/ListRadioItemAdapter.java | 109 +++++++++++ .../adapter/ListRadioViewHolder.java | 37 ++++ app/src/main/res/values-ca/strings.xml | 4 +- app/src/main/res/values-cs/strings.xml | 4 +- app/src/main/res/values-da/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values-el/strings.xml | 4 +- app/src/main/res/values-es/strings.xml | 4 +- app/src/main/res/values-eu/strings.xml | 4 +- app/src/main/res/values-fi/strings.xml | 4 +- app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values-hu/strings.xml | 4 +- app/src/main/res/values-it/strings.xml | 4 +- app/src/main/res/values-ja/strings.xml | 4 +- app/src/main/res/values-lv/strings.xml | 4 +- app/src/main/res/values-nl/strings.xml | 4 +- app/src/main/res/values-nn/strings.xml | 4 +- app/src/main/res/values-pl/strings.xml | 4 +- app/src/main/res/values-pt-rBR/strings.xml | 4 +- app/src/main/res/values-pt-rPT/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 4 +- app/src/main/res/values-sk/strings.xml | 4 +- app/src/main/res/values-sv/strings.xml | 4 +- app/src/main/res/values-uk/strings.xml | 4 +- app/src/main/res/values-zh-rCN/strings.xml | 4 +- app/src/main/res/values-zh-rTW/strings.xml | 4 +- app/src/main/res/values/strings.xml | 12 +- app/src/main/res/xml/database_preferences.xml | 4 +- 47 files changed, 702 insertions(+), 278 deletions(-) create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/ObjectNameResource.java rename app/src/main/java/com/kunzisoft/keepass/settings/preference/{AlgorithmListPreference.java => DialogListExplanationPreference.java} (56%) delete mode 100644 app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseAlgorithmPreferenceDialogFragmentCompat.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseKeyDerivationPreferenceDialogFragmentCompat.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioItemAdapter.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioViewHolder.java diff --git a/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/AesKdf.java b/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/AesKdf.java index 51ade4257..c1d54ff96 100644 --- a/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/AesKdf.java +++ b/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/AesKdf.java @@ -19,6 +19,9 @@ */ package com.kunzisoft.keepass.crypto.keyDerivation; +import android.content.res.Resources; + +import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.crypto.CryptoUtil; import com.kunzisoft.keepass.crypto.finalkey.FinalKey; import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory; @@ -45,8 +48,11 @@ public class AesKdf extends KdfEngine { uuid = CIPHER_UUID; } - public String getName() { - return DEFAULT_NAME; + @Override + public String getName(Resources resources) { + if (resources == null) + return DEFAULT_NAME; + return resources.getString(R.string.kdf_AES); } @Override @@ -93,4 +99,9 @@ public class AesKdf extends KdfEngine { public void setKeyRounds(KdfParameters p, long keyRounds) { p.setUInt64(ParamRounds, keyRounds); } + + @Override + public long getDefaultKeyRounds() { + return DEFAULT_ROUNDS; + } } diff --git a/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/Argon2Kdf.java b/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/Argon2Kdf.java index 5b6353fc9..eee1b3494 100644 --- a/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/Argon2Kdf.java +++ b/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/Argon2Kdf.java @@ -19,6 +19,9 @@ */ package com.kunzisoft.keepass.crypto.keyDerivation; +import android.content.res.Resources; + +import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.utils.Types; import java.io.IOException; @@ -26,6 +29,7 @@ import java.security.SecureRandom; import java.util.UUID; public class Argon2Kdf extends KdfEngine { + public static final UUID CIPHER_UUID = Types.bytestoUUID( new byte[]{(byte) 0xEF, (byte) 0x63, (byte) 0x6D, (byte) 0xDF, (byte) 0x8C, (byte) 0x29, (byte) 0x44, (byte) 0x4B, (byte) 0x91, (byte) 0xF7, (byte) 0xA9, (byte) 0xA4, (byte)0x03, (byte) 0xE3, (byte) 0x0A, (byte) 0x0C @@ -58,13 +62,17 @@ public class Argon2Kdf extends KdfEngine { private static final long DefaultMemory = 1024 * 1024; private static final long DefaultParallelism = 2; + private static final String DEFAULT_NAME = "Argon2"; + public Argon2Kdf() { uuid = CIPHER_UUID; } @Override - public String getName() { - return "Argon2"; + public String getName(Resources resources) { + if (resources == null) + return DEFAULT_NAME; + return resources.getString(R.string.kdf_Argon2); } @Override @@ -113,4 +121,9 @@ public class Argon2Kdf extends KdfEngine { p.setUInt64(ParamIterations, keyRounds); } + @Override + public long getDefaultKeyRounds() { + return DefaultIterations; + } + } diff --git a/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/KdfEngine.java b/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/KdfEngine.java index 52f52f910..fd67a900a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/KdfEngine.java +++ b/app/src/main/java/com/kunzisoft/keepass/crypto/keyDerivation/KdfEngine.java @@ -19,10 +19,12 @@ */ package com.kunzisoft.keepass.crypto.keyDerivation; +import com.kunzisoft.keepass.database.ObjectNameResource; + import java.io.IOException; import java.util.UUID; -public abstract class KdfEngine { +public abstract class KdfEngine implements ObjectNameResource{ public UUID uuid; public KdfParameters getDefaultParameters() { @@ -33,10 +35,10 @@ public abstract class KdfEngine { public abstract void randomize(KdfParameters p); - public abstract String getName(); - public abstract long getKeyRounds(KdfParameters p); public abstract void setKeyRounds(KdfParameters p, long keyRounds); + public abstract long getDefaultKeyRounds(); + } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/Database.java b/app/src/main/java/com/kunzisoft/keepass/database/Database.java index fc7e00054..a1517b56f 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/Database.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/Database.java @@ -27,6 +27,7 @@ import android.preference.PreferenceManager; import android.util.Log; import com.kunzisoft.keepass.R; +import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine; import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException; import com.kunzisoft.keepass.database.exception.InvalidDBException; import com.kunzisoft.keepass.database.exception.InvalidPasswordException; @@ -354,7 +355,7 @@ public class Database { return getPwDatabase().getEncryptionAlgorithm(); } - public List getAvailableEncryptionAlgorithm() { + public List getAvailableEncryptionAlgorithms() { switch (getPwDatabase().getVersion()) { case V4: return ((PwDatabaseV4) getPwDatabase()).getAvailableEncryptionAlgorithms(); @@ -378,8 +379,31 @@ public class Database { return getPwDatabase().getEncryptionAlgorithm().getName(resources); } - public String getKeyDerivationName() { - return getPwDatabase().getKeyDerivationName(); + public List getAvailableKdfEngines() { + switch (getPwDatabase().getVersion()) { + case V4: + return ((PwDatabaseV4) getPwDatabase()).getAvailableKdfEngines(); + case V3: + return ((PwDatabaseV3) getPwDatabase()).getAvailableKdfEngines(); + } + return new ArrayList<>(); + } + + public KdfEngine getKdfEngine() { + return getPwDatabase().getKdfEngine(); + } + + public void assignKdfEngine(KdfEngine kdfEngine) { + switch (getPwDatabase().getVersion()) { + case V4: + ((PwDatabaseV4) getPwDatabase()).setKdfEngine(kdfEngine); + ((PwDatabaseV4) getPwDatabase()).setKdfParameters(kdfEngine.getDefaultParameters()); + ((PwDatabaseV4) getPwDatabase()).setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds()); + } + } + + public String getKeyDerivationName(Resources resources) { + return getPwDatabase().getKeyDerivationName(resources); } public String getNumberKeyEncryptionRoundsAsString() { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/ObjectNameResource.java b/app/src/main/java/com/kunzisoft/keepass/database/ObjectNameResource.java new file mode 100644 index 000000000..745d605e2 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/ObjectNameResource.java @@ -0,0 +1,29 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ +package com.kunzisoft.keepass.database; + +import android.content.res.Resources; + +/** + * Interface to generify items with a name resource, that can be (for example) visible in a list + */ +public interface ObjectNameResource { + String getName(Resources resources); +} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java index 7ceb3404d..69d9104f2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java @@ -19,8 +19,11 @@ */ package com.kunzisoft.keepass.database; +import android.content.res.Resources; + import com.kunzisoft.keepass.crypto.finalkey.FinalKey; import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory; +import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.KeyFileEmptyException; import com.kunzisoft.keepass.stream.NullOutputStream; @@ -34,7 +37,6 @@ import java.io.UnsupportedEncodingException; import java.security.DigestOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -283,7 +285,11 @@ public abstract class PwDatabase getAvailableEncryptionAlgorithms(); - public abstract String getKeyDerivationName(); + public abstract List getAvailableKdfEngines(); + + public abstract KdfEngine getKdfEngine(); + + public abstract String getKeyDerivationName(Resources resources); public abstract List getGrpRoots(); diff --git a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV3.java b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV3.java index e3465122f..01abe1d32 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV3.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV3.java @@ -45,7 +45,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA package com.kunzisoft.keepass.database; +import android.content.res.Resources; + import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf; +import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import java.io.IOException; @@ -62,6 +65,7 @@ import java.util.Random; public class PwDatabaseV3 extends PwDatabase { private static final int DEFAULT_ENCRYPTION_ROUNDS = 300; + private KdfEngine kdfEngine = new AesKdf(); // Always the same // all entries private List entries = new ArrayList<>(); @@ -96,8 +100,20 @@ public class PwDatabaseV3 extends PwDatabase { } @Override - public String getKeyDerivationName() { - return AesKdf.DEFAULT_NAME; + public KdfEngine getKdfEngine() { + return kdfEngine; + } + + @Override + public List getAvailableKdfEngines() { + List list = new ArrayList<>(); + list.add(kdfEngine); + return list; + } + + @Override + public String getKeyDerivationName(Resources resources) { + return kdfEngine.getName(resources); } @Override diff --git a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java index 09a7f5b4c..136641607 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java @@ -19,6 +19,7 @@ */ package com.kunzisoft.keepass.database; +import android.content.res.Resources; import android.webkit.URLUtil; import com.kunzisoft.keepass.collections.VariantDictionary; @@ -150,6 +151,33 @@ public class PwDatabaseV4 extends PwDatabase { this.compressionAlgorithm = compressionAlgorithm; } + @Override + public KdfEngine getKdfEngine() { + return kdfEngine; + } + + public void setKdfEngine(KdfEngine kdfEngine) { + this.kdfEngine = kdfEngine; + } + + @Override + public String getKeyDerivationName(Resources resources) { + return kdfEngine.getName(resources); + } + + @Override + public List getAvailableKdfEngines() { + return KdfFactory.kdfList; + } + + public KdfParameters getKdfParameters() { + return kdfParameters; + } + + public void setKdfParameters(KdfParameters kdfParameters) { + this.kdfParameters = kdfParameters; + } + @Override public long getNumberKeyEncryptionRounds() { if (getKdfEngine() != null && getKdfParameters() != null) @@ -334,15 +362,6 @@ public class PwDatabaseV4 extends PwDatabase { this.customData.put(label, value); } - public KdfEngine getKdfEngine() { - return kdfEngine; - } - - @Override - public String getKeyDerivationName() { - return kdfEngine.getName(); - } - @Override public byte[] getMasterKey(String key, InputStream keyInputStream) throws InvalidKeyFileException, IOException { @@ -703,14 +722,6 @@ public class PwDatabaseV4 extends PwDatabase { return groups.get(recycleId); } - public KdfParameters getKdfParameters() { - return kdfParameters; - } - - public void setKdfParameters(KdfParameters kdfParameters) { - this.kdfParameters = kdfParameters; - } - public VariantDictionary getPublicCustomData() { return publicCustomData; } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/PwEncryptionAlgorithm.java b/app/src/main/java/com/kunzisoft/keepass/database/PwEncryptionAlgorithm.java index b27085564..32c6a8dba 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwEncryptionAlgorithm.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwEncryptionAlgorithm.java @@ -29,7 +29,7 @@ import com.kunzisoft.keepass.crypto.engine.TwofishEngine; import java.util.UUID; -public enum PwEncryptionAlgorithm { +public enum PwEncryptionAlgorithm implements ObjectNameResource { AES_Rijndael, Twofish, @@ -39,11 +39,11 @@ public enum PwEncryptionAlgorithm { switch (this) { default: case AES_Rijndael: - return resources.getString(R.string.rijndael); + return resources.getString(R.string.encryption_rijndael); case Twofish: - return resources.getString(R.string.twofish); + return resources.getString(R.string.encryption_twofish); case ChaCha20: - return resources.getString(R.string.chacha20); + return resources.getString(R.string.encryption_chacha20); } } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/NestedSettingsFragment.java b/app/src/main/java/com/kunzisoft/keepass/settings/NestedSettingsFragment.java index 5dccca619..d5c1d8850 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/NestedSettingsFragment.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/NestedSettingsFragment.java @@ -51,8 +51,9 @@ import com.kunzisoft.keepass.dialogs.UnavailableFeatureDialogFragment; import com.kunzisoft.keepass.dialogs.UnderDevelopmentFeatureDialogFragment; import com.kunzisoft.keepass.fingerprint.FingerPrintHelper; import com.kunzisoft.keepass.icons.IconPackChooser; -import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseAlgorithmPreferenceDialogFragmentCompat; +import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat; import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseDescriptionPreferenceDialogFragmentCompat; +import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseKeyDerivationPreferenceDialogFragmentCompat; import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseNamePreferenceDialogFragmentCompat; import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsPreferenceDialogFragmentCompat; import com.kunzisoft.keepass.stylish.Stylish; @@ -70,6 +71,8 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat private int count = 0; + private Preference roundPref; + public static NestedSettingsFragment newInstance(Screen key) { NestedSettingsFragment fragment = new NestedSettingsFragment(); // supply arguments to bundle. @@ -321,11 +324,10 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat // Key derivation function Preference kdfPref = findPreference(getString(R.string.key_derivation_function_key)); - kdfPref.setSummary(db.getKeyDerivationName()); - preferenceInDevelopment(kdfPref); + kdfPref.setSummary(db.getKeyDerivationName(getResources())); // Round encryption - Preference roundPref = findPreference(getString(R.string.transform_rounds_key)); + roundPref = findPreference(getString(R.string.transform_rounds_key)); roundPref.setSummary(db.getNumberKeyEncryptionRoundsAsString()); } else { @@ -432,7 +434,13 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat dialogFragment = DatabaseDescriptionPreferenceDialogFragmentCompat.newInstance(preference.getKey()); } else if (preference.getKey().equals(getString(R.string.encryption_algorithm_key))) { - dialogFragment = DatabaseAlgorithmPreferenceDialogFragmentCompat.newInstance(preference.getKey()); + dialogFragment = DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.newInstance(preference.getKey()); + } + else if (preference.getKey().equals(getString(R.string.key_derivation_function_key))) { + DatabaseKeyDerivationPreferenceDialogFragmentCompat keyDerivationDialogFragment = DatabaseKeyDerivationPreferenceDialogFragmentCompat.newInstance(preference.getKey()); + if (roundPref != null) + keyDerivationDialogFragment.setRoundPreference(roundPref); + dialogFragment = keyDerivationDialogFragment; } else if (preference.getKey().equals(getString(R.string.transform_rounds_key))) { dialogFragment = RoundsPreferenceDialogFragmentCompat.newInstance(preference.getKey()); diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preference/AlgorithmListPreference.java b/app/src/main/java/com/kunzisoft/keepass/settings/preference/DialogListExplanationPreference.java similarity index 56% rename from app/src/main/java/com/kunzisoft/keepass/settings/preference/AlgorithmListPreference.java rename to app/src/main/java/com/kunzisoft/keepass/settings/preference/DialogListExplanationPreference.java index 509d7d271..46a7ac64a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preference/AlgorithmListPreference.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preference/DialogListExplanationPreference.java @@ -6,21 +6,21 @@ import android.util.AttributeSet; import com.kunzisoft.keepass.R; -public class AlgorithmListPreference extends DialogPreference { +public class DialogListExplanationPreference extends DialogPreference { - public AlgorithmListPreference(Context context) { + public DialogListExplanationPreference(Context context) { this(context, null); } - public AlgorithmListPreference(Context context, AttributeSet attrs) { + public DialogListExplanationPreference(Context context, AttributeSet attrs) { this(context, attrs, R.attr.dialogPreferenceStyle); } - public AlgorithmListPreference(Context context, AttributeSet attrs, int defStyleAttr) { + public DialogListExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr) { this(context, attrs, defStyleAttr, defStyleAttr); } - public AlgorithmListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + public DialogListExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseAlgorithmPreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseAlgorithmPreferenceDialogFragmentCompat.java deleted file mode 100644 index 6c7073747..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseAlgorithmPreferenceDialogFragmentCompat.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.kunzisoft.keepass.settings.preferenceDialogFragment; - -import android.content.Context; -import android.os.Bundle; -import android.os.Handler; -import android.support.annotation.NonNull; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.RadioButton; - -import com.kunzisoft.keepass.R; -import com.kunzisoft.keepass.database.PwEncryptionAlgorithm; -import com.kunzisoft.keepass.database.edit.OnFinish; - -import java.util.ArrayList; -import java.util.List; - -public class DatabaseAlgorithmPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { - - private AlgorithmAdapter algorithmAdapter; - private PwEncryptionAlgorithm algorithmSelected; - - public static DatabaseAlgorithmPreferenceDialogFragmentCompat newInstance( - String key) { - final DatabaseAlgorithmPreferenceDialogFragmentCompat - fragment = new DatabaseAlgorithmPreferenceDialogFragmentCompat(); - final Bundle b = new Bundle(1); - b.putString(ARG_KEY, key); - fragment.setArguments(b); - - return fragment; - } - - @Override - protected void onBindDialogView(View view) { - super.onBindDialogView(view); - - RecyclerView recyclerView = view.findViewById(R.id.pref_dialog_list); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - algorithmAdapter = new AlgorithmAdapter(); - recyclerView.setAdapter(algorithmAdapter); - - setAlgorithm(database.getAvailableEncryptionAlgorithm(), database.getEncryptionAlgorithm()); - } - - public void setAlgorithm(List algorithmList, PwEncryptionAlgorithm algorithm) { - if (algorithmAdapter != null) - algorithmAdapter.setAlgorithms(algorithmList, algorithm); - algorithmSelected = algorithm; - } - - private class AlgorithmAdapter extends RecyclerView.Adapter { - - private LayoutInflater inflater; - - private List algorithms; - private PwEncryptionAlgorithm algorithmUsed; - - AlgorithmAdapter() { - this.inflater = LayoutInflater.from(getContext()); - this.algorithms = new ArrayList<>(); - this.algorithmUsed = null; - } - - @NonNull - @Override - public AlgorithmViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = inflater.inflate(R.layout.pref_dialog_list_radio_item, parent, false); - return new AlgorithmViewHolder(view); - } - - @Override - public void onBindViewHolder(@NonNull AlgorithmViewHolder holder, int position) { - PwEncryptionAlgorithm algorithm = this.algorithms.get(position); - holder.radioButton.setText(algorithm.getName(getResources())); - if (algorithmUsed != null && algorithmUsed.equals(algorithm)) - holder.radioButton.setChecked(true); - else - holder.radioButton.setChecked(false); - holder.radioButton.setOnClickListener(new OnAlgorithmClickListener(algorithm)); - } - - @Override - public int getItemCount() { - return algorithms.size(); - } - - public void setAlgorithms(List algorithms, PwEncryptionAlgorithm algorithmUsed) { - this.algorithms.clear(); - this.algorithms.addAll(algorithms); - this.algorithmUsed = algorithmUsed; - } - - void setAlgorithmUsed(PwEncryptionAlgorithm algorithmUsed) { - this.algorithmUsed = algorithmUsed; - } - } - - private class AlgorithmViewHolder extends RecyclerView.ViewHolder { - - RadioButton radioButton; - - public AlgorithmViewHolder(View itemView) { - super(itemView); - - radioButton = itemView.findViewById(R.id.pref_dialog_list_radio); - } - } - - private class OnAlgorithmClickListener implements View.OnClickListener { - - private PwEncryptionAlgorithm algorithmClicked; - - public OnAlgorithmClickListener(PwEncryptionAlgorithm algorithm) { - this.algorithmClicked = algorithm; - } - - @Override - public void onClick(View view) { - algorithmSelected = algorithmClicked; - algorithmAdapter.setAlgorithmUsed(algorithmSelected); - algorithmAdapter.notifyDataSetChanged(); - } - } - - - public PwEncryptionAlgorithm getAlgorithmSelected() { - return algorithmSelected; - } - - @Override - public void onDialogClosed(boolean positiveResult) { - if ( positiveResult ) { - assert getContext() != null; - - if (getAlgorithmSelected() != null) { - PwEncryptionAlgorithm newAlgorithm = getAlgorithmSelected(); - PwEncryptionAlgorithm oldAlgorithm = database.getEncryptionAlgorithm(); - database.assignEncryptionAlgorithm(newAlgorithm); - - Handler handler = new Handler(); - setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, newAlgorithm, oldAlgorithm)); - } - } - - super.onDialogClosed(positiveResult); - } - - private class AfterDescriptionSave extends OnFinish { - - private PwEncryptionAlgorithm mNewAlgorithm; - private PwEncryptionAlgorithm mOldAlgorithm; - private Context mCtx; - - AfterDescriptionSave(Context ctx, Handler handler, PwEncryptionAlgorithm newAlgorithm, PwEncryptionAlgorithm oldAlgorithm) { - super(handler); - - mCtx = ctx; - mNewAlgorithm = newAlgorithm; - mOldAlgorithm = oldAlgorithm; - } - - @Override - public void run() { - PwEncryptionAlgorithm algorithmToShow = mNewAlgorithm; - - if (!mSuccess) { - displayMessage(mCtx); - database.assignEncryptionAlgorithm(mOldAlgorithm); - } - - getPreference().setSummary(algorithmToShow.getName(mCtx.getResources())); - - super.run(); - } - } -} diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java index 73ece86c1..983879c61 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java @@ -1,3 +1,22 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ package com.kunzisoft.keepass.settings.preferenceDialogFragment; import android.content.Context; diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.java new file mode 100644 index 000000000..fe506d88d --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.java @@ -0,0 +1,115 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ +package com.kunzisoft.keepass.settings.preferenceDialogFragment; + +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +import com.kunzisoft.keepass.R; +import com.kunzisoft.keepass.database.PwEncryptionAlgorithm; +import com.kunzisoft.keepass.database.edit.OnFinish; +import com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter.ListRadioItemAdapter; + +public class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat + implements ListRadioItemAdapter.RadioItemSelectedCallback { + + private PwEncryptionAlgorithm algorithmSelected; + + public static DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat newInstance( + String key) { + final DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat + fragment = new DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat(); + final Bundle b = new Bundle(1); + b.putString(ARG_KEY, key); + fragment.setArguments(b); + + return fragment; + } + + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + RecyclerView recyclerView = view.findViewById(R.id.pref_dialog_list); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + ListRadioItemAdapter encryptionAlgorithmAdapter = new ListRadioItemAdapter<>(getActivity()); + encryptionAlgorithmAdapter.setRadioItemSelectedCallback(this); + recyclerView.setAdapter(encryptionAlgorithmAdapter); + + algorithmSelected = database.getEncryptionAlgorithm(); + encryptionAlgorithmAdapter.setItems(database.getAvailableEncryptionAlgorithms(), algorithmSelected); + } + + @Override + public void onDialogClosed(boolean positiveResult) { + if ( positiveResult ) { + assert getContext() != null; + + if (algorithmSelected != null) { + PwEncryptionAlgorithm newAlgorithm = algorithmSelected; + PwEncryptionAlgorithm oldAlgorithm = database.getEncryptionAlgorithm(); + database.assignEncryptionAlgorithm(newAlgorithm); + + Handler handler = new Handler(); + setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, newAlgorithm, oldAlgorithm)); + } + } + + super.onDialogClosed(positiveResult); + } + + @Override + public void onItemSelected(PwEncryptionAlgorithm item) { + this.algorithmSelected = item; + } + + private class AfterDescriptionSave extends OnFinish { + + private PwEncryptionAlgorithm mNewAlgorithm; + private PwEncryptionAlgorithm mOldAlgorithm; + private Context mCtx; + + AfterDescriptionSave(Context ctx, Handler handler, PwEncryptionAlgorithm newAlgorithm, PwEncryptionAlgorithm oldAlgorithm) { + super(handler); + + mCtx = ctx; + mNewAlgorithm = newAlgorithm; + mOldAlgorithm = oldAlgorithm; + } + + @Override + public void run() { + PwEncryptionAlgorithm algorithmToShow = mNewAlgorithm; + + if (!mSuccess) { + displayMessage(mCtx); + database.assignEncryptionAlgorithm(mOldAlgorithm); + } + + getPreference().setSummary(algorithmToShow.getName(mCtx.getResources())); + + super.run(); + } + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseKeyDerivationPreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseKeyDerivationPreferenceDialogFragmentCompat.java new file mode 100644 index 000000000..edbaa22e5 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseKeyDerivationPreferenceDialogFragmentCompat.java @@ -0,0 +1,122 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ +package com.kunzisoft.keepass.settings.preferenceDialogFragment; + +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.preference.Preference; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +import com.kunzisoft.keepass.R; +import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine; +import com.kunzisoft.keepass.database.edit.OnFinish; +import com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter.ListRadioItemAdapter; + +public class DatabaseKeyDerivationPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat + implements ListRadioItemAdapter.RadioItemSelectedCallback { + + private KdfEngine kdfEngineSelected; + private Preference roundPreference; + + public static DatabaseKeyDerivationPreferenceDialogFragmentCompat newInstance( + String key) { + final DatabaseKeyDerivationPreferenceDialogFragmentCompat + fragment = new DatabaseKeyDerivationPreferenceDialogFragmentCompat(); + final Bundle b = new Bundle(1); + b.putString(ARG_KEY, key); + fragment.setArguments(b); + + return fragment; + } + + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + RecyclerView recyclerView = view.findViewById(R.id.pref_dialog_list); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + ListRadioItemAdapter kdfAdapter = new ListRadioItemAdapter<>(getActivity()); + kdfAdapter.setRadioItemSelectedCallback(this); + recyclerView.setAdapter(kdfAdapter); + + kdfEngineSelected = database.getKdfEngine(); + kdfAdapter.setItems(database.getAvailableKdfEngines(), kdfEngineSelected); + } + + @Override + public void onDialogClosed(boolean positiveResult) { + if ( positiveResult ) { + assert getContext() != null; + + if (kdfEngineSelected != null) { + KdfEngine newKdfEngine = kdfEngineSelected; + KdfEngine oldKdfEngine = database.getKdfEngine(); + database.assignKdfEngine(newKdfEngine); + + Handler handler = new Handler(); + setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, newKdfEngine, oldKdfEngine)); + } + } + + super.onDialogClosed(positiveResult); + } + + public void setRoundPreference(Preference preference) { + this.roundPreference = preference; + } + + @Override + public void onItemSelected(KdfEngine item) { + kdfEngineSelected = item; + } + + private class AfterDescriptionSave extends OnFinish { + + private KdfEngine mNewKdfEngine; + private KdfEngine mOldKdfEngine; + private Context mCtx; + + AfterDescriptionSave(Context ctx, Handler handler, KdfEngine newKdfEngine, KdfEngine oldKdfEngine) { + super(handler); + + this.mCtx = ctx; + this.mNewKdfEngine = newKdfEngine; + this.mOldKdfEngine = oldKdfEngine; + } + + @Override + public void run() { + KdfEngine kdfEngineToShow = mNewKdfEngine; + + if (!mSuccess) { + displayMessage(mCtx); + database.assignKdfEngine(mOldKdfEngine); + } + + getPreference().setSummary(kdfEngineToShow.getName(mCtx.getResources())); + roundPreference.setSummary(String.valueOf(kdfEngineToShow.getDefaultKeyRounds())); + + super.run(); + } + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java index 602af572e..5241de323 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java @@ -1,3 +1,22 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ package com.kunzisoft.keepass.settings.preferenceDialogFragment; import android.content.Context; diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java index 950c2dd9f..c85b4f56a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java @@ -1,3 +1,22 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ package com.kunzisoft.keepass.settings.preferenceDialogFragment; import android.view.View; diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputDatabaseSavePreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputDatabaseSavePreferenceDialogFragmentCompat.java index d0d61b869..571b6c5e4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputDatabaseSavePreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputDatabaseSavePreferenceDialogFragmentCompat.java @@ -1,3 +1,22 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ package com.kunzisoft.keepass.settings.preferenceDialogFragment; import android.view.View; diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputPreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputPreferenceDialogFragmentCompat.java index f6db89d21..0f81dd37b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputPreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/InputPreferenceDialogFragmentCompat.java @@ -1,3 +1,22 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ package com.kunzisoft.keepass.settings.preferenceDialogFragment; import android.support.v7.preference.PreferenceDialogFragmentCompat; diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioItemAdapter.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioItemAdapter.java new file mode 100644 index 000000000..b8b606cb1 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioItemAdapter.java @@ -0,0 +1,109 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ +package com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.kunzisoft.keepass.R; +import com.kunzisoft.keepass.database.ObjectNameResource; + +import java.util.ArrayList; +import java.util.List; + +public class ListRadioItemAdapter extends RecyclerView.Adapter { + + private Context context; + private LayoutInflater inflater; + + private List radioItemList; + private T radioItemUsed; + + private RadioItemSelectedCallback radioItemSelectedCallback; + + public ListRadioItemAdapter(Context context) { + this.context = context; + this.inflater = LayoutInflater.from(context); + this.radioItemList = new ArrayList<>(); + this.radioItemUsed = null; + } + + @NonNull + @Override + public ListRadioViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = inflater.inflate(R.layout.pref_dialog_list_radio_item, parent, false); + return new ListRadioViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ListRadioViewHolder holder, int position) { + T item = this.radioItemList.get(position); + holder.radioButton.setText(item.getName(context.getResources())); + if (radioItemUsed != null && radioItemUsed.equals(item)) + holder.radioButton.setChecked(true); + else + holder.radioButton.setChecked(false); + holder.radioButton.setOnClickListener(new OnItemClickListener(item)); + } + + @Override + public int getItemCount() { + return radioItemList.size(); + } + + public void setItems(List algorithms, T algorithmUsed) { + this.radioItemList.clear(); + this.radioItemList.addAll(algorithms); + this.radioItemUsed = algorithmUsed; + } + + private void setRadioItemUsed(T radioItemUsed) { + this.radioItemUsed = radioItemUsed; + } + + private class OnItemClickListener implements View.OnClickListener { + + private T itemClicked; + + OnItemClickListener(T item) { + this.itemClicked = item; + } + + @Override + public void onClick(View view) { + if (radioItemSelectedCallback != null) + radioItemSelectedCallback.onItemSelected(itemClicked); + setRadioItemUsed(itemClicked); + notifyDataSetChanged(); + } + } + + public void setRadioItemSelectedCallback(RadioItemSelectedCallback radioItemSelectedCallback) { + this.radioItemSelectedCallback = radioItemSelectedCallback; + } + + public interface RadioItemSelectedCallback { + void onItemSelected(T item); + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioViewHolder.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioViewHolder.java new file mode 100644 index 000000000..fa0f6b7df --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/adapter/ListRadioViewHolder.java @@ -0,0 +1,37 @@ +/* + * Copyright 2018 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ +package com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.RadioButton; + +import com.kunzisoft.keepass.R; + +public class ListRadioViewHolder extends RecyclerView.ViewHolder { + + public RadioButton radioButton; + + public ListRadioViewHolder(View itemView) { + super(itemView); + + radioButton = itemView.findViewById(R.id.pref_dialog_list_radio); + } +} diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index 537a124c5..cc6efdd1b 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -123,7 +123,7 @@ Recorda la localització d\'arxius clau Guarda arxiu clau Elimina - Rijndael (AES) + Rijndael (AES) Arrel Passades d\'encriptació Més passades d\'encriptació dónen protecció adicional contra atacs de força bruta, però poden alentir molt carregar i guardar la base de dades. @@ -135,7 +135,7 @@ Especial Títol/descripció d\'entrada Resultats de cerca - Twofish + Twofish Subratllat Versió de la base de dades no suportada. Majúscules diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 244d42784..42795cd52 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -139,7 +139,7 @@ Pamatovat si umístění klíčového souboru Uložit klíčový soubor Odstranit - Rijndael (AES) + Rijndael (AES) Kořen Počet zašifrování Vyšší počet opakování šifrování zvýší bezpečnost proti hrubému útoku, ale může výrazně zpomalit načítání a ukládání. @@ -151,7 +151,7 @@ Speciální Zadejte název/popis Výsledky hledání - Twofish + Twofish Podtrženo Nepodporovaná verze databáze. Velká písmena diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 52be7f18c..d7f54f2f1 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -138,7 +138,7 @@ Husker placeringen af nøglefiler Gem nøglefil Fjern - Rijndael (AES) + Rijndael (AES) Root Krypterings-gentagelser Højere krypterings-gentagelser giver øget beskyttelse imod brute-force angreb, men kan påvirke læsnings- og skrivehastigheden betydentligt. @@ -150,7 +150,7 @@ Speciel Post titel/beskrivelse Søgeresultater - Twofish + Twofish Understreget Database-versionen er ikke understøttet. Store bogstaver diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 58b10d367..d84417c27 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -144,7 +144,7 @@ Den Pfad der Schlüsseldatei merken. Schlüsselquelle merken Löschen - Rijndael (AES) + Rijndael (AES) Start Schlüsseltransformationen Je höher die Anzahl der Schlüsseltransformationen, desto besser ist der Schutz gegen Wörterbuch- oder Brute-Force-Angriffe. Allerdings dauert dann auch das Laden und Speichern der Datenbank entsprechend länger. @@ -159,7 +159,7 @@ Spezialsymbole Titel/Beschreibung des Eintrags Suchergebnisse - Twofish + Twofish Unterstrichen Datenbankversion wird nicht unterstützt. Großbuchstaben diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index a4f6e6ea5..2d57e05f5 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -136,7 +136,7 @@ Να θυμάσαι την τοποθεσία των αρχείων κλειδιών Αποθήκευση αρχείου κλειδιού Απομάκρυνση - Rijndael (AES) + Rijndael (AES) Ριζικός Κατάλογος Κύκλοι Κρυπτογράφησης Μεγαλύτεροι κύκλοι κρυπτογράφησης παρέχουν πρόσθετη προστασία ενάντια σε επιθέσεις brute force, αλλά μπορεί να επιβραδύνει πολύ την φόρτωση και την αποθήκευση. @@ -148,7 +148,7 @@ Ειδικοί Τίτλος/περιγραφή εγγραφής Αποτελέσματα αναζήτησης - Twofish + Twofish Υπογράμμιση Μη υποστηριζόμενη έκδοση βάσης δεδομένων. Κεφαλαία diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 6c6a01eb5..e43b168e9 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -124,7 +124,7 @@ Spanish translation by José I. Paños. Updated by David García-Abad (23-09-201 Recordar la ubicación de archivos de clave Guardando archivo de clave Borrar - Rijndael (AES) + Rijndael (AES) Raíz Pasadas de Cifrado Un alto número de pasadas de cifrado proporciona protección adicional contra ataques de fuerza bruta, pero puede ralentizar mucho el cargado y el guardado. @@ -135,7 +135,7 @@ Spanish translation by José I. Paños. Updated by David García-Abad (23-09-201 Orden de BD Especial Título/descripción de entrada - Twofish + Twofish Subrayado Versión de base de datos no soportada. Mayúsculas diff --git a/app/src/main/res/values-eu/strings.xml b/app/src/main/res/values-eu/strings.xml index a62ea32d5..d39a3ac41 100644 --- a/app/src/main/res/values-eu/strings.xml +++ b/app/src/main/res/values-eu/strings.xml @@ -136,7 +136,7 @@ Gogoratu gako fitxategien kokapenak Gako fitxategia gorde Ezabatu - Rijndael (AES) + Rijndael (AES) Root Enkriptatzeko Rondak Enkriptatzeko ronda gehiago indar gordineko atakeen kontrako babes gehiago ematen dute, baina kargatzea eta gordetzea moteldu dezakete modu nabarmenean. @@ -148,7 +148,7 @@ Berezia Sarreraren Izena / Deskribapena Bilaketaren emaitzak - Twofish + Twofish Azpimarratu Euskarririk gabeko datubase bertsioa. Maiuskulak diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 4a4c9939c..b080194a0 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -134,7 +134,7 @@ Muista avaintiedostojen sijainti Tallenna avaintiedosto Poista - Rijndael (AES) + Rijndael (AES) Juuri Salauskierroksia Suurempi kierrosten määrä parantaa suojausta raa\'alla voimalla tehdyiltä murtoyrityksiltä, mutta voi todella hidastaa lataamista ja tallentamista. @@ -146,7 +146,7 @@ Erityistä Tietueen otsikko/kuvaus Hakutulokset - Twofish + Twofish Alleviivattu Ei-tuettu salasanatietokannan versio. Isot kirjaimet diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 891acfcb4..1652bba15 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -148,7 +148,7 @@ Mémoriser le répertoire de stockage des fichiers de clés Mémoriser le fichier de clé Effacer - Rijndael (AES) + Rijndael (AES) Racine Tours de transformation Un niveau de chiffrement supérieur assure une protection supplémentaire contre les attaques de force brute, mais peut considérablement ralentir l\'ouverture et l\'enregistrement. @@ -172,7 +172,7 @@ Spécial Nom/description Résultats - Twofish + Twofish Souligné Version de la base de données non supportée. Majuscule diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index c0e24bef0..b7aff7e44 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -134,7 +134,7 @@ Jegyezze meg a kulcsfájlok helyét Kulcsfájl mentése Eltávolítás - Rijndael (AES) + Rijndael (AES) Gyökérkönyvár Titkosítási menetek száma A titkosítási menetek számának növelésével extra védelemet kaphat a brute force támadások ellen, ugyanakkor jelentősen lassíthatja az adatbázis betöltését vagy mentését. @@ -146,7 +146,7 @@ Speciális Bejegyzés név/leírás Keresés eredménye - Twofish + Twofish Aláhúzás Nem támogatott adatbázis. Nagybetűk diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 26fdbc89e..02df6a4a4 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -123,7 +123,7 @@ Ricorda la posizione dei file chiave Salva il file chiave Elimina - Rijndael (AES) + Rijndael (AES) Principale Livello cifratura Un livello di cifratura elevato fornisce una protezione maggiore contro attacchi di tipo "forza brutta", ma può veramente rallentare il caricamento e il salvataggio. @@ -134,7 +134,7 @@ Ordinamento DB Speciale Titolo/descrizione voce - Twofish + Twofish Sottolinea Versione database non supportata. Maiuscolo diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index fbe1306a6..75b8495b5 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -120,7 +120,7 @@ 前回使用したキーファイルを次回も表示します キーファイルを記憶 消去 - Rijndael (AES) + Rijndael (AES) Root 暗号化レベル 暗号化レベルを高く設定するとブルートフォース(総当り)攻撃に強くなりますが、保存や読込に時間が掛かります。 @@ -131,7 +131,7 @@ 並べ替え 記号 キーワードを入力 - Twofish + Twofish アンダーライン (_) このバージョンのデータベースはサポートされていません。 英数大文字 diff --git a/app/src/main/res/values-lv/strings.xml b/app/src/main/res/values-lv/strings.xml index b99425e2d..2c4048ed7 100644 --- a/app/src/main/res/values-lv/strings.xml +++ b/app/src/main/res/values-lv/strings.xml @@ -114,7 +114,7 @@ Atcerēties šo atslēgas faila vietu Saglabāt atslēgas failu Noņemt - Rijndael (AES) + Rijndael (AES) Root Šifrēšanas līmeņi Augstākā līmeņa šifrēšana sniedz lielāku aizsardzību, bet palēnina darbības ar datu bāzēm. @@ -126,7 +126,7 @@ Speciālie Ieraksta nosaukums/apraksts Meklēšanas rezultāti - Twofish + Twofish Pasvītrojums Neatbalstīta datu bāzes versija. Lielie burti diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index b390713c0..17b7ba782 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -122,7 +122,7 @@ Onthoudt de locatie van de sleutelbestanden Sleutelbestand opslaan Verwijder - Rijndael (AES) + Rijndael (AES) Top Encryptie-cycli Een hoger aantal encryptie-cycli geeft bijkomende bescherming tegen brute-force aanvallen, maar kan het laden en opslaan sterk vertragen. @@ -133,7 +133,7 @@ Sorteringsvolgorde DB Speciaal Record titel/beschrijving - Twofish + Twofish Onderlijnen Niet-ondersteunde databaseversie. Hoofdletters diff --git a/app/src/main/res/values-nn/strings.xml b/app/src/main/res/values-nn/strings.xml index 08684b7a2..02e97dfd6 100644 --- a/app/src/main/res/values-nn/strings.xml +++ b/app/src/main/res/values-nn/strings.xml @@ -120,7 +120,7 @@ Hugsar staden til nøkkelfilene Lagra nøkkelfila Ta vekk - Rijndael (AES) + Rijndael (AES) Rot Krypteringsomgangar Fleire krypteringsomgangar gjev tilleggsvern mot rå makt-åtak, men kan òg gjera lasting og lagring mykje tregare. @@ -131,7 +131,7 @@ DB-sortering Spesial Oppføringa sin tittel/skildring - Twofish + Twofish Understreking Kan ikkje bruka databaseutgåva. Store bokstavar diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 5feb79430..441fa799b 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -120,7 +120,7 @@ along with KeePass DX. If not, see . Zapamiętaj lokację plików kluczy Zapisz plik klucza Usuń - Rijndael (AES) + Rijndael (AES) Root Złożoność szyfrowania Większa złożoność szyfrowania zapewnia dodatkowe zabezpieczenie przed atakiem brute force, ale może spowolnić wczytywanie i zapisywanie bazy danych. @@ -133,7 +133,7 @@ along with KeePass DX. If not, see . Sortuj wg daty Znaki specjalne Tytuł/opis wpisu - Twofish + Twofish Podkreślenie Nieobsługiwana wersja bazy danych. Wielkie litery diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index f0d3b13bb..3a62cf2f1 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -123,7 +123,7 @@ Lembrar o local dos arquivos de chave Salvar arquivo de chave Remover - Rijndael (AES) + Rijndael (AES) Raiz Rodadas de criptografia Maior número de rodadas de criptografia adiciona mais proteção contra ataques de força bruta, porém pode tornar o processo de carregar e salvar mais lentos. @@ -134,7 +134,7 @@ Ordenação do banco de dados Caracteres Especiais Título/Descrição da entrada - Twofish + Twofish Underline Versão de banco de dados não suportada. Letras maiúsculas diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 69110b125..4c28764df 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -141,7 +141,7 @@ Relembra a localização dos ficheiros chave Guardar ficheiro chave Remover - Rijndael (AES) + Rijndael (AES) Raiz Rondas de encriptação Rondas de encriptação altas providenciam proteção adicional contra ataques de força bruta, mas podem atrasar o tempo de carregamento e armazenamento. @@ -153,7 +153,7 @@ Especiais Título/descrição da entrada Resultados da pesquisa - Twofish + Twofish Sublinhado Versão da base de dados não suportada. Maiúsculas diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 0a44a2da4..1d88ab132 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -136,7 +136,7 @@ Хранить пути к файлам-ключам Предлагать ключи Убрать из списка - Rijndael (AES) + Rijndael (AES) База Проходы шифрования Больше проходов – выше стойкость базы к подбору пароля, но медленнее открытие и сохранение @@ -150,7 +150,7 @@ $пеци@льные название, комментарий Результаты поиска - Twofish + Twofish _Подчёркивание_ Неподдерживаемая версия базы ЗАГЛАВНЫЕ diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index ab4ef4a3a..546e4b343 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -120,7 +120,7 @@ Zapamätať si umiestnenie keyfile Uložiť keyfile Odstrániť - Rijndael (AES) + Rijndael (AES) Root Šifrovacie opakovania Vyššie opakovania šifrovania dávajú vyššiu ochranu proti útokom hrubou silou, ale môžu spomaliť načítavanie a ukladanie. @@ -131,7 +131,7 @@ DB zoradenie poradia Špeciálne Záznam názov/popis - Twofish + Twofish Podčiarknuté Nepodporovaná verzia databázy. Veľké písmená diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 1c77b53b9..5a868c7cf 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -133,7 +133,7 @@ Sparar sökvägar till nyckelfiler Spara nyckelfil Ta bort - Rijndael (AES) + Rijndael (AES) Root Krypteringsrundor Högre antal krypteringsrundor ger ytterligare skydd mot "brute force"-attacker, men kan göra att ladda och spara går betydligt långsammare. @@ -145,7 +145,7 @@ Specialtecken Postens titel/beskrivning Sökresultat - Twofish + Twofish Understreck Databasversionen stöds ej. Versaler diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 3b6d0c4fe..03e26dcef 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -120,7 +120,7 @@ Запам’ятати розташування файла ключа Збережіть файл ключа Вилучити - Rijndael (AES) + Rijndael (AES) Корінь Циклів шифрування Велика кількість циклів шифрування забезпечує додатковий захист від грубих атак, але може дійсно уповільнити завантаження та захист. @@ -131,7 +131,7 @@ Упорядкування БД Спеціальний Введіть заголовок/опис - Twofish + Twofish Підкреслення Непідтримувана версія бази даних. Верхній регістр diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index f83bac13e..f8018bc9a 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -117,7 +117,7 @@ 记住密钥文件的位置 保存密钥文件 移除 - Rijndael加密(AES) + Rijndael加密(AES) Root 加密次数 更高级的加密次数对暴力攻击能提供额外保护,但也会增加加载和保存的时间。 @@ -128,7 +128,7 @@ 数据库的排序顺序 特别 条目名称/说明 - Twofish算法 + Twofish算法 强调 不支持的数据库版本。 大写 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 1f91457cb..7ec3259ad 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -117,7 +117,7 @@ 記住密鑰檔的位置 保存密鑰檔 移除 - Rijndael加密(AES) + Rijndael加密(AES) Root 加密次數 更高級的加密次數對暴力攻擊能提供額外保護,但也會增加載入和保存的時間。 @@ -128,7 +128,7 @@ 資料庫的排序順序 特別 條目名稱/說明 - Twofish演算法 + Twofish演算法 強調 不支援的資料庫版本。 大寫 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5c0f738c4..b61df37e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -150,7 +150,6 @@ Remember the location of keyfiles Save keyfile Remove - Rijndael (AES) Root Transform Rounds Higher encryption rounds provide additional protection against brute force attacks, but can really slow down loading and saving. @@ -174,8 +173,6 @@ Special Search Search results - Twofish - ChaCha20 Underline Unsupported database version. Upper-case @@ -309,6 +306,15 @@ Download Contribute + + Rijndael (AES) + Twofish + ChaCha20 + + + AES-KDF + Argon2 + 5 seconds 10 seconds diff --git a/app/src/main/res/xml/database_preferences.xml b/app/src/main/res/xml/database_preferences.xml index 7624113ad..3487760fa 100644 --- a/app/src/main/res/xml/database_preferences.xml +++ b/app/src/main/res/xml/database_preferences.xml @@ -52,11 +52,11 @@ - -