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

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

View File

@@ -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,9 +508,11 @@ public class EntryEditActivity extends LockingHideActivity
@Override
protected void onSaveInstanceState(Bundle outState) {
if (mSelectedIconID != UNDEFINED_ICON_ID) {
outState.putInt(IconPickerDialogFragment.KEY_ICON_ID, mSelectedIconID);
super.onSaveInstanceState(outState);
}
}
@Override
public void acceptPassword(Bundle bundle) {

View File

@@ -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");

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -141,7 +141,8 @@ 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);
Stylish.assignStyle(styleString);
if (getActivity() != null)
getActivity().recreate();
return true;
});

View File

@@ -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;
}

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/white"
tools:targetApi="lollipop">
<item>
<layer-list>
<item android:bottom="2dp" android:left="2dp">
<shape>
<corners
android:radius="2dp" />
<padding
android:left="14dp"
android:right="14dp"
android:top="4dp"
android:bottom="6dp"/>
<solid android:color="@color/orange"/>
</shape>
</item>
</layer-list>
</item>
</ripple>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="2dp" android:left="2dp">
<shape>
<corners
android:radius="2dp" />
<padding
android:left="14dp"
android:right="14dp"
android:top="4dp"
android:bottom="6dp"/>
<solid android:color="@color/orange"/>
</shape>
</item>
</layer-list>

View File

@@ -69,7 +69,7 @@
android:id="@+id/icon_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:layout_margin="4dp"
android:src="@drawable/ic_blank_32dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>

View File

@@ -303,8 +303,10 @@
<string name="style_choose_title">Choisir un thème</string>
<string name="style_choose_summary">Changer le thème de l\'application en modifiant les couleurs</string>
<string-array name="list_style_names">
<item>Light Theme</item>
<item>Night Theme</item>
<item>Thème Jour</item>
<item>Thème Nuit</item>
<item>Thème Foncé Classique</item>
<item>Thème Pro</item>
</string-array>
<string name="icon_pack_choose_title">Choisir un pack d\'icones</string>
<string name="icon_pack_choose_summary">Changer le pack d\'icones de l\'application</string>

View File

@@ -14,9 +14,6 @@
<style name="KeepassDXStyle.v21.Button" parent="Base.TextAppearance.AppCompat.Button" >
<item name="android:elevation">4dp</item>
</style>
<style name="KeepassDXStyle.v21.ImageButton" parent="Base.Widget.AppCompat.ImageButton">
<item name="android:elevation">4dp</item>
</style>
<!-- FAB -->
<style name="KeepassDXStyle.v21.Fab" parent="Theme.AppCompat">

View File

@@ -30,9 +30,18 @@
<color name="green">#43a047</color>
<color name="green_dark">#388e3c</color>
<color name="red_light">#f44336</color>
<color name="red">#e53935</color>
<color name="purple_lighter">#ce93d8</color>
<color name="purple_light">#8E24AA</color>
<color name="purple">#7B1FA2</color>
<color name="purple_dark">#6A1B9A</color>
<color name="background_light">#FAFAFA</color>
<color name="background_night">#303030</color>
<color name="background_dark">#000000</color>
<color name="background_purple">#e3cfff</color>
<color name="icon_background">#555555</color>
<color name="icon_text">#000000</color>

View File

@@ -141,9 +141,13 @@
<string name="list_style_name_light" translatable="false">KeepassDXStyle_Light</string>
<string name="list_style_name_night" translatable="false">KeepassDXStyle_Night</string>
<string name="list_style_name_dark" translatable="false">KeepassDXStyle_Dark</string>
<string name="list_style_name_purple" translatable="false">KeepassDXStyle_Purple</string>
<string-array name="list_style_values">
<item translatable="false">@string/list_style_name_light</item>
<item translatable="false">@string/list_style_name_night</item>
<item translatable="false">@string/list_style_name_dark</item>
<item translatable="false">@string/list_style_name_purple</item>
</string-array>
<string name="setting_icon_pack_choose_default" translatable="false">@string/classic_resource_prefix</string>

View File

@@ -309,6 +309,8 @@
<string-array name="list_style_names">
<item>Light Theme</item>
<item>Night Theme</item>
<item>Classic Dark Theme</item>
<item>Pro Theme</item>
</string-array>
<string name="icon_pack_choose_title">Select an icon pack</string>
<string name="icon_pack_choose_summary">Change the icon pack of the application</string>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses/>.
-->
<resources>
<!-- Dark Style -->
<style name="KeepassDXStyle.Dark" parent="KeepassDXStyle.Night.v21" >
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#757575</item>
<item name="colorAccentCompat">#757575</item>
<item name="colorControlActivated">#59585a</item>
<item name="android:textColorPrimary">#b2dfdb</item>
<item name="android:textColorHintInverse">#b2dfdb</item>
<item name="android:windowBackground">@color/background_dark</item>
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Dark</item>
<item name="android:alertDialogTheme">@style/KeepassDXStyle.Dark.Dialog</item>
<item name="alertDialogTheme">@style/KeepassDXStyle.Dark.Dialog</item>
</style>
<!-- Toolbar Style Green -->
<style name="KeepassDXStyle.Toolbar.Dark" parent="KeepassDXStyle.Toolbar">
<item name="colorPrimary">#212121</item>
</style>
<!-- Dialog -->
<style name="KeepassDXStyle.Dark.Dialog" parent="KeepassDXStyle.Night.Dialog">
<item name="colorAccent">#fefefe</item>
<item name="android:textColorPrimary">#fefefe</item>
</style>
<!-- File Picker Theme -->
<style name="KeepassDXStyle.FilePickerStyle.Dark" parent="KeepassDXStyle.FilePickerStyle.Night">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#59585a</item>
</style>
</resources>

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses/>.
-->
<resources>
<!-- Purple Style -->
<style name="KeepassDXStyle.Purple" parent="KeepassDXStyle.Light.v21" >
<item name="colorPrimary">@color/purple</item>
<item name="colorPrimaryDark">@color/purple_dark</item>
<item name="colorAccent">@color/red</item>
<item name="colorAccentCompat">@color/red</item>
<item name="colorControlActivated">@color/green</item>
<item name="android:textColorPrimary">@color/purple_light</item>
<item name="android:textColorHintInverse">@color/purple_lighter</item>
<item name="android:windowBackground">@color/background_purple</item>
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Purple</item>
</style>
<!-- Toolbar Style Purple -->
<style name="KeepassDXStyle.Toolbar.Purple" parent="KeepassDXStyle.Toolbar">
<item name="colorPrimary">@color/purple</item>
</style>
<!-- File Picker Theme -->
<style name="KeepassDXStyle.FilePickerStyle.Purple" parent="KeepassDXStyle.FilePickerStyle.Light">
<item name="colorPrimary">@color/purple</item>
<item name="colorPrimaryDark">@color/purple_dark</item>
<item name="colorAccent">@color/red</item>
</style>
</resources>

View File

@@ -28,8 +28,6 @@
<item name="android:buttonStyle">@style/KeepassDXStyle.Button</item>
<item name="buttonStyle">@style/KeepassDXStyle.Button</item>
<item name="android:imageButtonStyle">@style/KeepassDXStyle.ImageButton</item>
<item name="imageButtonStyle">@style/KeepassDXStyle.ImageButton</item>
<item name="android:checkboxStyle">@style/KeepassDXStyle.CheckBox</item>
@@ -78,8 +76,6 @@
<item name="android:buttonStyle">@style/KeepassDXStyle.Button</item>
<item name="buttonStyle">@style/KeepassDXStyle.Button</item>
<item name="android:imageButtonStyle">@style/KeepassDXStyle.ImageButton</item>
<item name="imageButtonStyle">@style/KeepassDXStyle.ImageButton</item>
<item name="android:checkboxStyle">@style/KeepassDXStyle.CheckBox</item>
@@ -220,11 +216,6 @@
<item name="android:background">@drawable/button_background</item>
<item name="android:gravity">center</item>
</style>
<style name="KeepassDXStyle.v21.ImageButton" parent="Base.Widget.AppCompat.ImageButton" />
<style name="KeepassDXStyle.ImageButton" parent="KeepassDXStyle.v21.ImageButton">
<item name="android:background">@drawable/image_button_background</item>
<item name="android:gravity">center</item>
</style>
<!-- FAB -->
<style name="KeepassDXStyle.v21.Fab" parent="Theme.AppCompat" />