mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add recycle bin setting, remove version, encapsulate field
This commit is contained in:
@@ -54,16 +54,12 @@ import com.keepassdroid.compat.ActivityCompat;
|
||||
import com.keepassdroid.database.Database;
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwEntry;
|
||||
import com.keepassdroid.database.PwEntryV4;
|
||||
import com.keepassdroid.database.exception.SamsungClipboardException;
|
||||
import com.keepassdroid.database.security.ProtectedString;
|
||||
import com.keepassdroid.intents.Intents;
|
||||
import com.keepassdroid.settings.PrefsUtil;
|
||||
import com.keepassdroid.tasks.UIToastTask;
|
||||
import com.keepassdroid.utils.EmptyUtils;
|
||||
import com.keepassdroid.utils.MenuUtil;
|
||||
import com.keepassdroid.utils.SprEngine;
|
||||
import com.keepassdroid.utils.SprEngineV4;
|
||||
import com.keepassdroid.utils.Types;
|
||||
import com.keepassdroid.utils.Util;
|
||||
import com.keepassdroid.view.EntryContentsView;
|
||||
@@ -265,20 +261,8 @@ public class EntryActivity extends LockCloseHideActivity {
|
||||
|
||||
// Assign custom fields
|
||||
entryContentsView.clearExtraFields();
|
||||
if (mEntry.getVersion() == 4) {
|
||||
PwEntryV4 entry = (PwEntryV4) mEntry;
|
||||
SprEngine spr = SprEngineV4.getInstance(pm);
|
||||
// Display custom strings
|
||||
if (entry.strings.size() > 0) {
|
||||
for (Map.Entry<String, ProtectedString> pair : entry.strings.entrySet()) {
|
||||
String key = pair.getKey();
|
||||
|
||||
if (!PwEntryV4.IsStandardString(key)) {
|
||||
String text = pair.getValue().toString();
|
||||
entryContentsView.addExtraField(key, spr.compile(text, entry, pm));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, String> field : mEntry.getExtraFields(pm).entrySet()) {
|
||||
entryContentsView.addExtraField(field.getKey(), field.getValue());
|
||||
}
|
||||
|
||||
// Assign dates
|
||||
|
||||
@@ -246,7 +246,7 @@ public abstract class PwDatabase {
|
||||
|
||||
public abstract void setNumRounds(long rounds) throws NumberFormatException;
|
||||
|
||||
public abstract boolean appSettingsEnabled();
|
||||
public abstract boolean algorithmSettingsEnabled();
|
||||
|
||||
public abstract PwEncryptionAlgorithm getEncAlgorithm();
|
||||
|
||||
@@ -332,6 +332,22 @@ public abstract class PwDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if RecycleBin is available or not for this version of database
|
||||
* @return true if RecycleBin enable
|
||||
*/
|
||||
public boolean isRecycleBinAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if RecycleBin is enable or not
|
||||
* @return true if RecycleBin enable, false if is not available or not enable
|
||||
*/
|
||||
public boolean isRecycleBinEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define if a Group must be delete or recycle
|
||||
* @param group Group to remove
|
||||
|
||||
@@ -262,7 +262,7 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appSettingsEnabled() {
|
||||
public boolean algorithmSettingsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appSettingsEnabled() {
|
||||
public boolean algorithmSettingsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -361,6 +361,16 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecycleBinAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecycleBinEnable() {
|
||||
return recycleBinEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRecycle(PwGroup group) {
|
||||
if (!recycleBinEnabled) {
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import com.keepassdroid.database.iterator.EntrySearchStringIterator;
|
||||
import com.keepassdroid.database.security.ProtectedString;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
@@ -69,11 +72,6 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
return Type.ENTRY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of entry, (ie: 4 if kdbx database version is 4)
|
||||
*/
|
||||
public abstract int getVersion();
|
||||
|
||||
public void assign(PwEntry source) {
|
||||
icon = source.icon;
|
||||
}
|
||||
@@ -142,6 +140,14 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve extra fields to show, key is the label, value is the value of field
|
||||
* @param pm Database
|
||||
* @return Map of label/value
|
||||
*/
|
||||
public Map<String, String> getExtraFields(PwDatabase pm) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public boolean isMetaStream() {
|
||||
return false;
|
||||
|
||||
@@ -193,11 +193,6 @@ public class PwEntryV3 extends PwEntry {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actual password byte array.
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
*/
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import com.keepassdroid.database.security.ProtectedBinary;
|
||||
import com.keepassdroid.database.security.ProtectedString;
|
||||
import com.keepassdroid.utils.SprEngine;
|
||||
import com.keepassdroid.utils.SprEngineV4;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
@@ -29,10 +34,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.keepassdroid.database.security.ProtectedBinary;
|
||||
import com.keepassdroid.database.security.ProtectedString;
|
||||
import com.keepassdroid.utils.SprEngine;
|
||||
|
||||
public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
public static final String STR_TITLE = "Title";
|
||||
public static final String STR_USERNAME = "UserName";
|
||||
@@ -124,10 +125,6 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@@ -439,6 +436,23 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtraFields(PwDatabase pm) {
|
||||
Map<String, String> fields = super.getExtraFields(pm);
|
||||
SprEngine spr = SprEngine.getInstance(pm);
|
||||
// Display custom strings
|
||||
if (strings.size() > 0) {
|
||||
for (Map.Entry<String, ProtectedString> pair : strings.entrySet()) {
|
||||
String key = pair.getKey();
|
||||
// TODO Add hidden style for protection field
|
||||
if (!PwEntryV4.IsStandardString(key)) {
|
||||
String text = pair.getValue().toString();
|
||||
fields.put(key, spr.compile(text, this, pm));
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
private static final long FIXED_LENGTH_SIZE = 128; // Approximate fixed length size
|
||||
public long getSize() {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.keepassdroid.database;
|
||||
|
||||
public enum PwVersion {
|
||||
V3, V4
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
|
||||
@@ -69,11 +70,9 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Boolean value = (Boolean) newValue;
|
||||
|
||||
if (!value) {
|
||||
App.getFileHistory().deleteAllKeys();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -83,15 +82,12 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat {
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Boolean value = (Boolean) newValue;
|
||||
|
||||
if (value == null) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
App.getFileHistory().deleteAll();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -142,6 +138,7 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat {
|
||||
.setPositiveButton(
|
||||
getResources().getString(android.R.string.yes),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) {
|
||||
@@ -178,15 +175,11 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat {
|
||||
setPreferencesFromResource(R.xml.db_preferences, rootKey);
|
||||
|
||||
Database db = App.getDB();
|
||||
Preference algorithmPref = findPreference(getString(R.string.algorithm_key));
|
||||
if (db.Loaded()) {
|
||||
if (db.pm.algorithmSettingsEnabled()) {
|
||||
|
||||
Preference roundPref = findPreference(getString(R.string.rounds_key));
|
||||
|
||||
if (!(db.Loaded() && db.pm.appSettingsEnabled())) {
|
||||
algorithmPref.setEnabled(false);
|
||||
roundPref.setEnabled(false);
|
||||
}
|
||||
|
||||
if (db.Loaded() && db.pm.appSettingsEnabled()) {
|
||||
roundPref.setEnabled(true);
|
||||
roundPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
setRounds(App.getDB(), preference);
|
||||
@@ -194,11 +187,26 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat {
|
||||
}
|
||||
});
|
||||
setRounds(db, roundPref);
|
||||
|
||||
// TODO Algo
|
||||
Preference algorithmPref = findPreference(getString(R.string.algorithm_key));
|
||||
// algorithmPref.setEnabled(true);
|
||||
setAlgorithm(db, algorithmPref);
|
||||
}
|
||||
|
||||
if (db.pm.isRecycleBinAvailable()) {
|
||||
SwitchPreference recycleBinPref = (SwitchPreference) findPreference(getString(R.string.recycle_bin_key));
|
||||
// TODO Recycle
|
||||
//recycleBinPref.setEnabled(true);
|
||||
recycleBinPref.setChecked(db.pm.isRecycleBinEnable());
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.e(getClass().getName(), "Database isn't ready");
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -239,6 +239,8 @@
|
||||
<string name="bytes">Octets</string>
|
||||
<string name="full_file_path_enable_title">Chemin de fichier</string>
|
||||
<string name="full_file_path_enable_summary">Afficher le chemin complet des fichiers</string>
|
||||
<string name="recycle_bin_title">Utiliser la corbeille</string>
|
||||
<string name="recycle_bin_summary">Déplace un groupe ou une entrée dans la Corbeille avant la suppression</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 secondes</item>
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
<string name="fingerprint_enable_key" translatable="true">fingerprint_enable_key</string>
|
||||
<string name="full_file_path_enable_key" translatable="true">full_file_path_enable_key</string>
|
||||
<string name="fingerprint_delete_all_key" translatable="true">fingerprint_delete_all_key</string>
|
||||
<string name="recycle_bin_key" translatable="true">recycle_bin_key</string>
|
||||
|
||||
<bool name="maskpass_default" translatable="false">true</bool>
|
||||
<bool name="keyfile_default" translatable="false">true</bool>
|
||||
|
||||
@@ -240,6 +240,8 @@
|
||||
<string name="bytes">Bytes</string>
|
||||
<string name="full_file_path_enable_title">File Path</string>
|
||||
<string name="full_file_path_enable_summary">View the full file path</string>
|
||||
<string name="recycle_bin_title">Use Recycle Bin</string>
|
||||
<string name="recycle_bin_summary">Move a group or entry to the Recycle Bin before deleting</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 seconds</item>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
<android.support.v7.preference.Preference
|
||||
android:key="@string/algorithm_key"
|
||||
android:persistent="false"
|
||||
android:title="@string/algorithm"
|
||||
android:enabled="false"/>
|
||||
<com.keepassdroid.settings.RoundsPreference
|
||||
@@ -32,7 +33,15 @@
|
||||
android:persistent="false"
|
||||
android:title="@string/rounds"
|
||||
android:positiveButtonText="@string/entry_save"
|
||||
android:negativeButtonText="@string/entry_cancel"/>
|
||||
android:negativeButtonText="@string/entry_cancel"
|
||||
android:enabled="false"/>
|
||||
<android.support.v14.preference.SwitchPreference
|
||||
android:key="@string/recycle_bin_key"
|
||||
android:persistent="false"
|
||||
android:title="@string/recycle_bin_title"
|
||||
android:summary="@string/recycle_bin_summary"
|
||||
android:enabled="false"
|
||||
android:checked="false"/>
|
||||
|
||||
</android.support.v7.preference.PreferenceCategory>
|
||||
</android.support.v7.preference.PreferenceScreen>
|
||||
|
||||
Reference in New Issue
Block a user