mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Kotlinized Preference
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
package com.kunzisoft.keepass.settings.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
public class DialogListExplanationPreference extends DialogPreference {
|
||||
|
||||
public DialogListExplanationPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public DialogListExplanationPreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.dialogPreferenceStyle);
|
||||
}
|
||||
|
||||
public DialogListExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, defStyleAttr);
|
||||
}
|
||||
|
||||
public DialogListExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogLayoutResource() {
|
||||
return R.layout.pref_dialog_list_explanation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.kunzisoft.keepass.settings.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.preference.DialogPreference
|
||||
import android.util.AttributeSet
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class DialogListExplanationPreference @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.dialogPreferenceStyle,
|
||||
defStyleRes: Int = defStyleAttr)
|
||||
: DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
override fun getDialogLayoutResource(): Int {
|
||||
return R.layout.pref_dialog_list_explanation
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.kunzisoft.keepass.settings.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.icons.IconPack;
|
||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IconPackListPreference extends ListPreference {
|
||||
|
||||
public IconPackListPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public IconPackListPreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.dialogPreferenceStyle);
|
||||
}
|
||||
|
||||
public IconPackListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, defStyleAttr);
|
||||
}
|
||||
|
||||
public IconPackListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
|
||||
List<String> entries = new ArrayList<>();
|
||||
List<String> values = new ArrayList<>();
|
||||
for (IconPack iconPack : IconPackChooser.getIconPackList(context)) {
|
||||
entries.add(iconPack.getName());
|
||||
values.add(iconPack.getId());
|
||||
}
|
||||
|
||||
setEntries(entries.toArray(new String[0]));
|
||||
setEntryValues(values.toArray(new String[0]));
|
||||
setDefaultValue(IconPackChooser.getSelectedIconPack(context).getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.kunzisoft.keepass.settings.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.preference.ListPreference
|
||||
import android.util.AttributeSet
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.icons.IconPack
|
||||
import com.kunzisoft.keepass.icons.IconPackChooser
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
class IconPackListPreference @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.dialogPreferenceStyle,
|
||||
defStyleRes: Int = defStyleAttr)
|
||||
: ListPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
init {
|
||||
val entries = ArrayList<String>()
|
||||
val values = ArrayList<String>()
|
||||
for (iconPack in IconPackChooser.getIconPackList(context)) {
|
||||
entries.add(iconPack.name)
|
||||
values.add(iconPack.id)
|
||||
}
|
||||
|
||||
setEntries(entries.toTypedArray())
|
||||
entryValues = values.toTypedArray()
|
||||
setDefaultValue(IconPackChooser.getSelectedIconPack(context).id)
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.settings.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
||||
|
||||
public class InputNumberPreference extends InputTextExplanationPreference {
|
||||
|
||||
private long mNumber;
|
||||
|
||||
public InputNumberPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public InputNumberPreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.dialogPreferenceStyle);
|
||||
}
|
||||
|
||||
public InputNumberPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, defStyleAttr);
|
||||
}
|
||||
|
||||
public InputNumberPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogLayoutResource() {
|
||||
return R.layout.pref_dialog_numbers;
|
||||
}
|
||||
|
||||
public long getNumber() {
|
||||
return mNumber;
|
||||
}
|
||||
|
||||
public void setNumber(long number) {
|
||||
this.mNumber = number;
|
||||
// Save to Shared Preferences
|
||||
persistLong(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(CharSequence summary) {
|
||||
|
||||
if (summary.equals(KdfEngine.UNKNOW_VALUE_STRING)) {
|
||||
setEnabled(false);
|
||||
super.setSummary("");
|
||||
}
|
||||
else {
|
||||
setEnabled(true);
|
||||
super.setSummary(summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
// Default value from attribute. Fallback value is set to 0.
|
||||
return a.getInt(index, 0);
|
||||
}
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restorePersistedValue,
|
||||
Object defaultValue) {
|
||||
// Read the value. Use the default value if it is not possible.
|
||||
long number;
|
||||
if (!restorePersistedValue) {
|
||||
number = 100000;
|
||||
if (defaultValue instanceof String) {
|
||||
number = Long.parseLong((String) defaultValue);
|
||||
}
|
||||
if (defaultValue instanceof Integer) {
|
||||
number = (Integer) defaultValue;
|
||||
}
|
||||
try {
|
||||
number = (long) defaultValue;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
number = getPersistedLong(mNumber);
|
||||
}
|
||||
|
||||
setNumber(number);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2019 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.settings.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.TypedArray
|
||||
import android.util.AttributeSet
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
|
||||
class InputNumberPreference @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.dialogPreferenceStyle,
|
||||
defStyleRes: Int = defStyleAttr)
|
||||
: InputTextExplanationPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
// Save to Shared Preferences
|
||||
var number: Long = 0
|
||||
set(number) {
|
||||
field = number
|
||||
persistLong(number)
|
||||
}
|
||||
|
||||
override fun getDialogLayoutResource(): Int {
|
||||
return R.layout.pref_dialog_numbers
|
||||
}
|
||||
|
||||
override fun setSummary(summary: CharSequence) {
|
||||
if (summary == KdfEngine.UNKNOW_VALUE_STRING) {
|
||||
isEnabled = false
|
||||
super.setSummary("")
|
||||
} else {
|
||||
isEnabled = true
|
||||
super.setSummary(summary)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onGetDefaultValue(a: TypedArray?, index: Int): Any {
|
||||
// Default value from attribute. Fallback value is set to 0.
|
||||
return a?.getInt(index, 0) ?: 0
|
||||
}
|
||||
|
||||
override fun onSetInitialValue(restorePersistedValue: Boolean,
|
||||
defaultValue: Any?) {
|
||||
// Read the value. Use the default value if it is not possible.
|
||||
var numberValue: Long
|
||||
if (!restorePersistedValue) {
|
||||
numberValue = 100000
|
||||
if (defaultValue is String) {
|
||||
numberValue = java.lang.Long.parseLong(defaultValue as String?)
|
||||
}
|
||||
if (defaultValue is Int) {
|
||||
numberValue = defaultValue.toLong()
|
||||
}
|
||||
try {
|
||||
numberValue = defaultValue as Long
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
} else {
|
||||
numberValue = getPersistedLong(this.number)
|
||||
}
|
||||
|
||||
number = numberValue
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.kunzisoft.keepass.settings.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
public class InputTextExplanationPreference extends DialogPreference {
|
||||
|
||||
protected String explanation;
|
||||
|
||||
public InputTextExplanationPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public InputTextExplanationPreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.dialogPreferenceStyle);
|
||||
}
|
||||
|
||||
public InputTextExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, defStyleAttr);
|
||||
}
|
||||
|
||||
public InputTextExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.explanationDialog,
|
||||
0, 0);
|
||||
try {
|
||||
setExplanation(a.getString(R.styleable.explanationDialog_explanations));
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogLayoutResource() {
|
||||
return R.layout.pref_dialog_input_text_explanation;
|
||||
}
|
||||
|
||||
public String getExplanation() {
|
||||
return explanation;
|
||||
}
|
||||
|
||||
public void setExplanation(String explanation) {
|
||||
this.explanation = explanation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.kunzisoft.keepass.settings.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.preference.DialogPreference
|
||||
import android.util.AttributeSet
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
open class InputTextExplanationPreference @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.dialogPreferenceStyle,
|
||||
defStyleRes: Int = defStyleAttr)
|
||||
: DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
var explanation: String? = null
|
||||
|
||||
init {
|
||||
val styleAttributes = context.theme.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.explanationDialog,
|
||||
0, 0)
|
||||
try {
|
||||
explanation = styleAttributes.getString(R.styleable.explanationDialog_explanations)
|
||||
} finally {
|
||||
styleAttributes.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDialogLayoutResource(): Int {
|
||||
return R.layout.pref_dialog_input_text_explanation
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.kunzisoft.keepass.settings.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
public class InputTextPreference extends DialogPreference {
|
||||
|
||||
public InputTextPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public InputTextPreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.dialogPreferenceStyle);
|
||||
}
|
||||
|
||||
public InputTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, defStyleAttr);
|
||||
}
|
||||
|
||||
public InputTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogLayoutResource() {
|
||||
return R.layout.pref_dialog_input_text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.kunzisoft.keepass.settings.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.preference.DialogPreference
|
||||
import android.util.AttributeSet
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class InputTextPreference @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.dialogPreferenceStyle,
|
||||
defStyleRes: Int = defStyleAttr)
|
||||
: DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
override fun getDialogLayoutResource(): Int {
|
||||
return R.layout.pref_dialog_input_text
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
@@ -17,10 +17,10 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.tasks;
|
||||
package com.kunzisoft.keepass.tasks
|
||||
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.annotation.StringRes
|
||||
|
||||
public interface ProgressTaskUpdater {
|
||||
void updateMessage(@StringRes int resId);
|
||||
interface ProgressTaskUpdater {
|
||||
fun updateMessage(@StringRes resId: Int)
|
||||
}
|
||||
Reference in New Issue
Block a user