Fix visual bugs, add classic theme and pro theme #27

This commit is contained in:
J-Jamet committed 2018-04-14 19:58:26 +02:00
1 parent 7772db17ae
commit 8a40a4b3ae
17 files changed
+195 -83

No files matched your search

@@ -48,6 +48,7 @@ import com.kunzisoft.keepass.database.PwDate;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwGroupId;
import com.kunzisoft.keepass.database.PwIconStandard;
import com.kunzisoft.keepass.database.edit.AddEntry;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.edit.RunnableOnFinish;
@@ -65,6 +66,8 @@ import com.kunzisoft.keepass.view.EntryEditCustomField;
import java.util.UUID;
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.UNDEFINED_ICON_ID;
public class EntryEditActivity extends LockingHideActivity
implements IconPickerDialogFragment.IconPickerListener,
GeneratePasswordDialogFragment.GeneratePasswordListener {
@@ -84,7 +87,7 @@ public class EntryEditActivity extends LockingHideActivity
protected PwEntry mEntry;
protected PwEntry mCallbackNewEntry;
protected boolean mIsNew;
protected int mSelectedIconID = -1;
protected int mSelectedIconID = UNDEFINED_ICON_ID;
// Views
private ScrollView scrollView;
@@ -99,6 +102,7 @@ public class EntryEditActivity extends LockingHideActivity
private ViewGroup entryExtraFieldsContainer;
private View addNewFieldView;
private View saveView;
private int iconColor;
/**
* Launch EntryEditActivity to update an existing entry
@@ -162,6 +166,11 @@ public class EntryEditActivity extends LockingHideActivity
Intent intent = getIntent();
byte[] uuidBytes = intent.getByteArrayExtra(KEY_ENTRY);
// Retrieve the textColor to tint the icon
int[] attrs = {android.R.attr.textColorPrimary};
TypedArray ta = getTheme().obtainStyledAttributes(attrs);
iconColor = ta.getColor(0, Color.WHITE);
PwDatabase pm = db.getPwDatabase();
if ( uuidBytes == null ) {
PwGroupId parentId = (PwGroupId) intent.getSerializableExtra(KEY_PARENT);
@@ -170,10 +179,6 @@ public class EntryEditActivity extends LockingHideActivity
mIsNew = true;
// Add the default icon
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
// Retrieve the textColor to tint the icon
int[] attrs = {R.attr.textColorInverse};
TypedArray ta = getTheme().obtainStyledAttributes(attrs);
int iconColor = ta.getColor(0, Color.WHITE);
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(this, entryIconView, true, iconColor);
} else {
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(this, entryIconView);
@@ -391,17 +396,8 @@ public class EntryEditActivity extends LockingHideActivity
newEntry.setLastModificationTime(new PwDate());
newEntry.setTitle(entryTitleView.getText().toString());
if(mSelectedIconID != -1)
newEntry.setIcon(App.getDB().getPwDatabase().getIconFactory().getIcon(mSelectedIconID));
else {
if (mIsNew) {
newEntry.setIcon(App.getDB().getPwDatabase().getIconFactory().getFirstIcon());
}
else {
// Keep previous icon, if no new one was selected
newEntry.setIcon(mEntry.getIconStandard());
}
}
newEntry.setIcon(retrieveIcon());
newEntry.setUrl(entryUrlView.getText().toString());
newEntry.setUsername(entryUserNameView.getText().toString());
newEntry.setNotes(entryCommentView.getText().toString());
@@ -425,6 +421,24 @@ public class EntryEditActivity extends LockingHideActivity
return newEntry;
}
/**
* Retrieve the icon by the selection, or the first icon in the list if the entry is new or the last one
* @return
*/
private PwIconStandard retrieveIcon() {
if(mSelectedIconID != UNDEFINED_ICON_ID)
return App.getDB().getPwDatabase().getIconFactory().getIcon(mSelectedIconID);
else {
if (mIsNew) {
return App.getDB().getPwDatabase().getIconFactory().getFirstIcon();
}
else {
// Keep previous icon, if no new one was selected
return mEntry.getIconStandard();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -451,10 +465,6 @@ public class EntryEditActivity extends LockingHideActivity
protected void fillData() {
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
// Retrieve the textColor to tint the icon
int[] attrs = {R.attr.textColorInverse};
TypedArray ta = getTheme().obtainStyledAttributes(attrs);
int iconColor = ta.getColor(0, Color.WHITE);
App.getDB().getDrawFactory().assignDatabaseIconTo(this, entryIconView, mEntry.getIcon(), true, iconColor);
} else {
App.getDB().getDrawFactory().assignDatabaseIconTo(this, entryIconView, mEntry.getIcon());
@@ -498,8 +508,10 @@ public class EntryEditActivity extends LockingHideActivity
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt(IconPickerDialogFragment.KEY_ICON_ID, mSelectedIconID);
super.onSaveInstanceState(outState);
if (mSelectedIconID != UNDEFINED_ICON_ID) {
outState.putInt(IconPickerDialogFragment.KEY_ICON_ID, mSelectedIconID);
super.onSaveInstanceState(outState);
}
}
@Override
@@ -21,6 +21,8 @@ package com.kunzisoft.keepass.dialogs;
import android.app.Dialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
@@ -32,6 +34,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.icons.IconPackChooser;
@@ -90,7 +93,15 @@ public class GroupEditDialogFragment extends DialogFragment
populateIcon(getArguments().getInt(KEY_ICON_ID));
} else {
// populate the icon with the default one
iconButton.setImageResource(IconPackChooser.getSelectedIconPack(getContext()).getDefaultIconId());
if (IconPackChooser.getSelectedIconPack(getContext()).tintable()) {
// Retrieve the textColor to tint the icon
int[] attrs = {android.R.attr.textColorPrimary};
TypedArray ta = getContext().getTheme().obtainStyledAttributes(attrs);
int iconColor = ta.getColor(0, Color.WHITE);
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(getContext(), iconButton, true, iconColor);
} else {
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(getContext(), iconButton);
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@@ -116,7 +127,6 @@ public class GroupEditDialogFragment extends DialogFragment
GroupEditDialogFragment.this.getDialog().cancel();
});
final ImageView iconButton = root.findViewById(R.id.icon_button);
iconButton.setOnClickListener(v -> {
IconPickerDialogFragment iconPickerDialogFragment = new IconPickerDialogFragment();
iconPickerDialogFragment.show(getFragmentManager(), "IconPickerDialogFragment");
@@ -44,6 +44,7 @@ import com.kunzisoft.keepass.stylish.StylishActivity;
public class IconPickerDialogFragment extends DialogFragment {
public static final String KEY_ICON_ID = "icon_id";
public static final int UNDEFINED_ICON_ID = -1;
private IconPickerListener iconPickerListener;
private IconPack iconPack;
@@ -29,7 +29,9 @@ import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.stylish.Stylish;
import com.nononsenseapps.filepicker.FilePickerActivity;
/**
* FilePickerActivity class with a style compatibility
*/
public class FilePickerStylishActivity extends FilePickerActivity {
private @StyleRes
@@ -51,10 +53,17 @@ public class FilePickerStylishActivity extends FilePickerActivity {
}
}
/**
* Derived from the Stylish class, get the specific FilePickerStyle theme
*/
public static class FilePickerStylish extends Stylish {
public static @StyleRes int getThemeId(Context context) {
if (themeString.equals(context.getString(R.string.list_style_name_night)))
return R.style.KeepassDXStyle_FilePickerStyle_Night;
else if (themeString.equals(context.getString(R.string.list_style_name_dark)))
return R.style.KeepassDXStyle_FilePickerStyle_Dark;
else if (themeString.equals(context.getString(R.string.list_style_name_purple)))
return R.style.KeepassDXStyle_FilePickerStyle_Purple;
return R.style.KeepassDXStyle_FilePickerStyle_Light;
}
@@ -141,8 +141,9 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
Preference stylePreference = findPreference(getString(R.string.setting_style_key));
stylePreference.setOnPreferenceChangeListener((preference, newValue) -> {
String styleString = (String) newValue;
Stylish.assignStyle(getActivity(), styleString);
getActivity().recreate();
Stylish.assignStyle(styleString);
if (getActivity() != null)
getActivity().recreate();
return true;
});
@@ -26,26 +26,44 @@ import android.util.Log;
import com.kunzisoft.keepass.R;
/**
* Class that provides functions to retrieve and assign a theme to a module
*/
public class Stylish {
protected static String stylishPrefKey;
protected static String themeString;
/**
* Initialize the class with a theme preference
* @param context Context to retrieve the theme preference
*/
public static void init(Context context) {
stylishPrefKey = context.getString(R.string.setting_style_key);
String stylishPrefKey = context.getString(R.string.setting_style_key);
Log.d(Stylish.class.getName(), "Attatching to " + context.getPackageName());
themeString = PreferenceManager.getDefaultSharedPreferences(context).getString(stylishPrefKey, context.getString(R.string.list_style_name_light));
}
public static void assignStyle(Context context, String styleString) {
/**
* Assign the style to the class attribute
* @param styleString Style id String
*/
public static void assignStyle(String styleString) {
themeString = styleString;
}
/**
* Function that returns the current id of the style selected in the preference
* @param context Context to retrieve the id
* @return Id of the style
*/
public static @StyleRes int getThemeId(Context context) {
if (themeString.equals(context.getString(R.string.list_style_name_night)))
return R.style.KeepassDXStyle_Night;
else if (themeString.equals(context.getString(R.string.list_style_name_dark)))
return R.style.KeepassDXStyle_Dark;
else if (themeString.equals(context.getString(R.string.list_style_name_purple)))
return R.style.KeepassDXStyle_Purple;
return R.style.KeepassDXStyle_Light;
}