diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java index 2df9f4d9b..21eb6dee2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java @@ -33,6 +33,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; +import android.support.annotation.Nullable; import android.support.annotation.RequiresApi; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; @@ -49,6 +50,7 @@ import com.kunzisoft.keepass.adapters.NodeAdapter; import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.autofill.AutofillHelper; import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroupId; @@ -56,8 +58,10 @@ import com.kunzisoft.keepass.database.PwIcon; import com.kunzisoft.keepass.database.PwIconStandard; import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.action.AddGroupRunnable; +import com.kunzisoft.keepass.database.action.AfterActionNodeOnFinish; import com.kunzisoft.keepass.database.action.DeleteEntryRunnable; import com.kunzisoft.keepass.database.action.DeleteGroupRunnable; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; import com.kunzisoft.keepass.database.action.UpdateGroupRunnable; import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment; @@ -67,6 +71,7 @@ import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.search.SearchResultsActivity; import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UIToastTask; import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; import com.kunzisoft.keepass.view.AddNodeButtonView; @@ -78,8 +83,6 @@ public class GroupActivity extends ListNodesActivity private static final String TAG = GroupActivity.class.getName(); - private static final String GROUP_ID_KEY = "GROUP_ID_KEY"; - private Toolbar toolbar; private ImageView iconView; @@ -162,6 +165,7 @@ public class GroupActivity extends ListNodesActivity toolbar = findViewById(R.id.toolbar); toolbar.setTitle(""); setSupportActionBar(toolbar); + groupNameView = findViewById(R.id.group_name); addNodeButtonView.setAddGroupClickListener(v -> { GroupEditDialogFragment.build() @@ -178,14 +182,30 @@ public class GroupActivity extends ListNodesActivity } } - protected PwGroup initializeListNodesFragment() { - PwGroup currentGroup; + @Override + protected void onSaveInstanceState(Bundle outState) { + outState.putSerializable(GROUP_ID_KEY, mCurrentGroup.getId()); + outState.putSerializable(OLD_GROUP_TO_UPDATE_KEY, oldGroupToUpdate); + super.onSaveInstanceState(outState); + } + + protected PwGroup retrieveCurrentGroup(@Nullable Bundle savedInstanceState) { + + PwGroupId pwGroupId = null; // TODO Parcelable + if (savedInstanceState != null + && savedInstanceState.containsKey(GROUP_ID_KEY)) { + pwGroupId = (PwGroupId) savedInstanceState.getSerializable(GROUP_ID_KEY); + } else { + if (getIntent() != null) + pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY); + } + Database db = App.getDB(); readOnly = db.isReadOnly(); PwGroup root = db.getPwDatabase().getRootGroup(); Log.w(TAG, "Creating tree view"); - PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY); + PwGroup currentGroup; if ( pwGroupId == null ) { currentGroup = root; } else { @@ -200,8 +220,6 @@ public class GroupActivity extends ListNodesActivity addEntryEnabled = !isRoot && addEntryEnabled; } - listNodesFragment = ListNodesFragment.newInstance(currentGroup); - return currentGroup; } @@ -221,10 +239,12 @@ public class GroupActivity extends ListNodesActivity App.getDB().getDrawFactory().assignDatabaseIconTo(this, iconView, mCurrentGroup.getIcon()); } - if ( mCurrentGroup.getParent() != null ) - toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp); - else { - toolbar.setNavigationIcon(null); + if (toolbar != null) { + if ( mCurrentGroup.containsParent() ) + toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp); + else { + toolbar.setNavigationIcon(null); + } } } } @@ -273,8 +293,6 @@ public class GroupActivity extends ListNodesActivity @Override protected void onResume() { super.onResume(); - // Refresh the group icon - assignToolbarElements(); // Show button on resume if (addNodeButtonView != null) addNodeButtonView.showButton(); @@ -590,10 +608,91 @@ public class GroupActivity extends ListNodesActivity } } - @Override - protected void onSaveInstanceState(Bundle outState) { - outState.putSerializable(OLD_GROUP_TO_UPDATE_KEY, oldGroupToUpdate); - super.onSaveInstanceState(outState); + class AfterAddNode extends AfterActionNodeOnFinish { + AfterAddNode(Handler handler) { + super(handler); + } + + public void run(PwNode oldNode, PwNode newNode) { + super.run(); + + runOnUiThread(() -> { + if (mSuccess) { + if (listNodesFragment != null) + listNodesFragment.addNode(newNode); + } else { + displayMessage(GroupActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(GroupActivity.this); + }); + } + } + + class AfterUpdateNode extends AfterActionNodeOnFinish { + AfterUpdateNode(Handler handler) { + super(handler); + } + + public void run(PwNode oldNode, PwNode newNode) { + super.run(); + + runOnUiThread(() -> { + if (mSuccess) { + if (listNodesFragment != null) + listNodesFragment.updateNode(oldNode, newNode); + } else { + displayMessage(GroupActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(GroupActivity.this); + }); + } + } + + class AfterDeleteNode extends OnFinishRunnable { + private PwNode pwNode; + + AfterDeleteNode(Handler handler, PwNode pwNode) { + super(handler); + this.pwNode = pwNode; + } + + @Override + public void run() { + super.run(); + + runOnUiThread(() -> { + if ( mSuccess) { + + if (listNodesFragment != null) + listNodesFragment.removeNode(pwNode); + + PwGroup parent = pwNode.getParent(); + Database db = App.getDB(); + PwDatabase database = db.getPwDatabase(); + if (db.isRecycleBinAvailable() && + db.isRecycleBinEnabled()) { + PwGroup recycleBin = database.getRecycleBin(); + // Add trash if it doesn't exists + if (parent.equals(recycleBin) + && mCurrentGroup != null + && mCurrentGroup.getParent() == null + && !mCurrentGroup.equals(recycleBin)) { + + if (listNodesFragment != null) + listNodesFragment.addNode(parent); + } + } + } else { + mHandler.post(new UIToastTask(GroupActivity.this, "Unrecoverable error: " + mMessage)); + App.setShutdown(); + finish(); + } + + SaveDatabaseProgressTaskDialogFragment.stop(GroupActivity.this); + }); + } } @Override diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java index ccd3bd1ed..ecbf42252 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java @@ -25,7 +25,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Handler; +import android.support.annotation.Nullable; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -35,19 +35,13 @@ import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.adapters.NodeAdapter; import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.autofill.AutofillHelper; -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.SortNodeEnum; -import com.kunzisoft.keepass.database.action.AfterActionNodeOnFinish; -import com.kunzisoft.keepass.database.action.OnFinishRunnable; import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.SortDialogFragment; import com.kunzisoft.keepass.password.AssignPasswordHelper; -import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; -import com.kunzisoft.keepass.tasks.UIToastTask; import com.kunzisoft.keepass.utils.MenuUtil; public abstract class ListNodesActivity extends LockingActivity @@ -55,10 +49,13 @@ public abstract class ListNodesActivity extends LockingActivity NodeAdapter.NodeClickCallback, SortDialogFragment.SortSelectionListener { + protected static final String GROUP_ID_KEY = "GROUP_ID_KEY"; + protected static final String LIST_NODES_FRAGMENT_TAG = "LIST_NODES_FRAGMENT_TAG"; protected ListNodesFragment listNodesFragment; protected PwGroup mCurrentGroup; + protected TextView groupNameView; protected AutofillHelper autofillHelper; @@ -78,7 +75,9 @@ public abstract class ListNodesActivity extends LockingActivity invalidateOptionsMenu(); - mCurrentGroup = initializeListNodesFragment(); + mCurrentGroup = retrieveCurrentGroup(savedInstanceState); + + initializeListNodesFragment(mCurrentGroup); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { autofillHelper = new AutofillHelper(); @@ -86,7 +85,21 @@ public abstract class ListNodesActivity extends LockingActivity } } - protected abstract PwGroup initializeListNodesFragment(); + protected abstract PwGroup retrieveCurrentGroup(@Nullable Bundle savedInstanceState); + + @Override + protected void onResume() { + super.onResume(); + // Refresh the title + assignToolbarElements(); + } + + protected void initializeListNodesFragment(PwGroup currentGroup) { + listNodesFragment = (ListNodesFragment) getSupportFragmentManager() + .findFragmentByTag(LIST_NODES_FRAGMENT_TAG); + if (listNodesFragment == null) + listNodesFragment = ListNodesFragment.newInstance(currentGroup); + } /** * Attach the fragment's list of node. @@ -104,16 +117,15 @@ public abstract class ListNodesActivity extends LockingActivity public void assignToolbarElements() { if (mCurrentGroup != null) { String title = mCurrentGroup.getName(); - TextView tv = findViewById(R.id.group_name); if (title != null && title.length() > 0) { - if (tv != null) { - tv.setText(title); - tv.invalidate(); + if (groupNameView != null) { + groupNameView.setText(title); + groupNameView.invalidate(); } } else { - if (tv != null) { - tv.setText(getText(R.string.root)); - tv.invalidate(); + if (groupNameView != null) { + groupNameView.setText(getText(R.string.root)); + groupNameView.invalidate(); } } } @@ -239,100 +251,13 @@ public abstract class ListNodesActivity extends LockingActivity } } - class AfterAddNode extends AfterActionNodeOnFinish { - AfterAddNode(Handler handler) { - super(handler); - } - - public void run(PwNode oldNode, PwNode newNode) { - super.run(); - - runOnUiThread(() -> { - if (mSuccess) { - if (listNodesFragment != null) - listNodesFragment.addNode(newNode); - } else { - displayMessage(ListNodesActivity.this); - } - - SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); - }); - } - } - - class AfterUpdateNode extends AfterActionNodeOnFinish { - AfterUpdateNode(Handler handler) { - super(handler); - } - - public void run(PwNode oldNode, PwNode newNode) { - super.run(); - - runOnUiThread(() -> { - if (mSuccess) { - if (listNodesFragment != null) - listNodesFragment.updateNode(oldNode, newNode); - } else { - displayMessage(ListNodesActivity.this); - } - - SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); - }); - } - } - - class AfterDeleteNode extends OnFinishRunnable { - private PwNode pwNode; - - AfterDeleteNode(Handler handler, PwNode pwNode) { - super(handler); - this.pwNode = pwNode; - } - - @Override - public void run() { - super.run(); - - runOnUiThread(() -> { - if ( mSuccess) { - - if (listNodesFragment != null) - listNodesFragment.removeNode(pwNode); - - PwGroup parent = pwNode.getParent(); - Database db = App.getDB(); - PwDatabase database = db.getPwDatabase(); - if (db.isRecycleBinAvailable() && - db.isRecycleBinEnabled()) { - PwGroup recycleBin = database.getRecycleBin(); - // Add trash if it doesn't exists - if (parent.equals(recycleBin) - && mCurrentGroup != null - && mCurrentGroup.getParent() == null - && !mCurrentGroup.equals(recycleBin)) { - - if (listNodesFragment != null) - listNodesFragment.addNode(parent); - } - } - } else { - mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage)); - App.setShutdown(); - finish(); - } - - SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); - }); - } - } - @Override public void onBackPressed() { super.onBackPressed(); listNodesFragment = (ListNodesFragment) getSupportFragmentManager().findFragmentByTag(LIST_NODES_FRAGMENT_TAG); // to refresh fragment - listNodesFragment.onResume(); + listNodesFragment.rebuildList(); mCurrentGroup = listNodesFragment.getMainGroup(); assignToolbarElements(); } diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesFragment.java b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesFragment.java index e5e728dac..74a3eab7e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesFragment.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesFragment.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -29,8 +28,9 @@ import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.SortNodeEnum; import com.kunzisoft.keepass.dialogs.SortDialogFragment; import com.kunzisoft.keepass.settings.PreferencesUtil; +import com.kunzisoft.keepass.stylish.StylishFragment; -public class ListNodesFragment extends Fragment implements +public class ListNodesFragment extends StylishFragment implements SortDialogFragment.SortSelectionListener { private static final String TAG = ListNodesFragment.class.getName(); @@ -104,7 +104,7 @@ public class ListNodesFragment extends Fragment implements setHasOptionsMenu(true); mCurrentGroup = initCurrentGroup(); - mAdapter = new NodeAdapter(getContext()); + mAdapter = new NodeAdapter(getContextThemed()); mAdapter.setOnNodeClickListener(nodeClickCallback); if (nodeMenuListener != null) { @@ -115,16 +115,18 @@ public class ListNodesFragment extends Fragment implements prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); } - protected PwGroup initCurrentGroup() { + protected PwGroup initCurrentGroup() { // TODO Change by parcelable Database db = App.getDB(); PwGroup root = db.getPwDatabase().getRootGroup(); - PwGroup currentGroup = null; + PwGroup currentGroup = null; if (getArguments() != null) { + // Contains all the group in element if (getArguments().containsKey(GROUP_KEY)) { currentGroup = (PwGroup) getArguments().getSerializable(GROUP_KEY); } + // Contains only the group id, so the group must be retrieve if (getArguments().containsKey(GROUP_ID_KEY)) { PwGroupId pwGroupId = (PwGroupId) getArguments().getSerializable(GROUP_ID_KEY); if ( pwGroupId != null ) @@ -142,8 +144,11 @@ public class ListNodesFragment extends Fragment implements @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); - View rootView = inflater.inflate(R.layout.list_nodes_fragment, container, false); + // To apply theme + View rootView = inflater.cloneInContext(getContextThemed()) + .inflate(R.layout.list_nodes_fragment, container, false); listView = rootView.findViewById(R.id.nodes_list); if (onScrollListener != null) { @@ -163,6 +168,10 @@ public class ListNodesFragment extends Fragment implements public void onResume() { super.onResume(); + rebuildList(); + } + + public void rebuildList() { // Add elements to the list mAdapter.rebuildList(mCurrentGroup); assignListToNodeAdapter(listView); diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryViewHolder.java b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryViewHolder.java index 79fbd23ed..d70fc48c6 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryViewHolder.java +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryViewHolder.java @@ -20,8 +20,6 @@ package com.kunzisoft.keepass.adapters; import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; import com.kunzisoft.keepass.R; @@ -30,7 +28,7 @@ class EntryViewHolder extends BasicViewHolder { EntryViewHolder(View itemView) { super(itemView); container = itemView.findViewById(R.id.entry_container); - icon = (ImageView) itemView.findViewById(R.id.entry_icon); - text = (TextView) itemView.findViewById(R.id.entry_text); + icon = itemView.findViewById(R.id.entry_icon); + text = itemView.findViewById(R.id.entry_text); } } diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/GroupViewHolder.java b/app/src/main/java/com/kunzisoft/keepass/adapters/GroupViewHolder.java index 8722835b6..33b2a4063 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/GroupViewHolder.java +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/GroupViewHolder.java @@ -20,8 +20,6 @@ package com.kunzisoft.keepass.adapters; import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; import com.kunzisoft.keepass.R; @@ -30,7 +28,7 @@ class GroupViewHolder extends BasicViewHolder { GroupViewHolder(View itemView) { super(itemView); container = itemView.findViewById(R.id.group_container); - icon = (ImageView) itemView.findViewById(R.id.group_icon); - text = (TextView) itemView.findViewById(R.id.group_text); + icon = itemView.findViewById(R.id.group_icon); + text = itemView.findViewById(R.id.group_text); } } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/PwNode.java b/app/src/main/java/com/kunzisoft/keepass/database/PwNode.java index 69512069d..3f530a7a4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwNode.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwNode.java @@ -119,6 +119,13 @@ public abstract class PwNode implements ISmallTimeLogger parent = prt; } + /** + * @return true if parent is present (can be a root or a detach element) + */ + public boolean containsParent() { + return getParent() != null; + } + public PwDate getCreationTime() { return creation; } diff --git a/app/src/main/java/com/kunzisoft/keepass/search/SearchResultsActivity.java b/app/src/main/java/com/kunzisoft/keepass/search/SearchResultsActivity.java index 4d17c6a2a..4d081f474 100644 --- a/app/src/main/java/com/kunzisoft/keepass/search/SearchResultsActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/search/SearchResultsActivity.java @@ -30,12 +30,13 @@ import android.view.View; import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.activities.ListNodesActivity; -import com.kunzisoft.keepass.activities.ListNodesFragment; import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.utils.MenuUtil; +import javax.annotation.Nullable; + public class SearchResultsActivity extends ListNodesActivity { @Override @@ -50,6 +51,7 @@ public class SearchResultsActivity extends ListNodesActivity { assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); + groupNameView = findViewById(R.id.group_name); attachFragmentToContentView(); @@ -66,15 +68,13 @@ public class SearchResultsActivity extends ListNodesActivity { } @Override - protected PwGroup initializeListNodesFragment() { + protected PwGroup retrieveCurrentGroup(@Nullable Bundle savedInstanceState) { Database mDb = App.getDB(); // Likely the app has been killed exit the activity if ( ! mDb.getLoaded() ) { finish(); } - PwGroup group = mDb.search(getSearchStr(getIntent()).trim()); - listNodesFragment = ListNodesFragment.newInstance(group); - return group; + return mDb.search(getSearchStr(getIntent()).trim()); } @Override diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/SettingsActivity.java b/app/src/main/java/com/kunzisoft/keepass/settings/SettingsActivity.java index 94361d000..f123b2a2e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/SettingsActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/SettingsActivity.java @@ -112,8 +112,8 @@ public class SettingsActivity extends LockingActivity implements MainPreferenceF @Override public void onNestedPreferenceSelected(NestedSettingsFragment.Screen key) { getSupportFragmentManager().beginTransaction() - .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, - R.anim.slide_in_left, R.anim.slide_out_right) + .setCustomAnimations(R.anim.slide_alpha_in_right, R.anim.slide_alpha_out_left, + R.anim.slide_alpha_in_left, R.anim.slide_alpha_out_right) .replace(R.id.fragment_container, NestedSettingsFragment.newInstance(key), TAG_NESTED) .addToBackStack(TAG_NESTED) .commit(); diff --git a/app/src/main/java/com/kunzisoft/keepass/stylish/StylishFragment.java b/app/src/main/java/com/kunzisoft/keepass/stylish/StylishFragment.java new file mode 100644 index 000000000..78824839c --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/stylish/StylishFragment.java @@ -0,0 +1,71 @@ +/* + * 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.stylish; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.StyleRes; +import android.support.v4.app.Fragment; +import android.support.v7.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; + +public abstract class StylishFragment extends Fragment { + + protected @StyleRes int themeId; + protected Context contextThemed; // TODO small ref + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context != null) { + this.themeId = Stylish.getThemeId(context); + } + contextThemed = new ContextThemeWrapper(context, themeId); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + // To fix status bar color + if (getActivity() != null + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Window window = getActivity().getWindow(); + + int[] attrColorPrimaryDark = {android.R.attr.colorPrimaryDark}; + TypedArray taColorPrimaryDark = contextThemed.getTheme().obtainStyledAttributes(attrColorPrimaryDark); + window.setStatusBarColor(taColorPrimaryDark.getColor(0, Color.BLACK)); + taColorPrimaryDark.recycle(); + } + + return super.onCreateView(inflater, container, savedInstanceState); + } + + public Context getContextThemed() { + return contextThemed; + } +} diff --git a/app/src/main/res/anim/slide_alpha_in_left.xml b/app/src/main/res/anim/slide_alpha_in_left.xml new file mode 100644 index 000000000..9a585f5b7 --- /dev/null +++ b/app/src/main/res/anim/slide_alpha_in_left.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/app/src/main/res/anim/slide_alpha_in_right.xml b/app/src/main/res/anim/slide_alpha_in_right.xml new file mode 100644 index 000000000..125060e43 --- /dev/null +++ b/app/src/main/res/anim/slide_alpha_in_right.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/app/src/main/res/anim/slide_alpha_out_left.xml b/app/src/main/res/anim/slide_alpha_out_left.xml new file mode 100644 index 000000000..73337d4f9 --- /dev/null +++ b/app/src/main/res/anim/slide_alpha_out_left.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/app/src/main/res/anim/slide_alpha_out_right.xml b/app/src/main/res/anim/slide_alpha_out_right.xml new file mode 100644 index 000000000..de8c512c5 --- /dev/null +++ b/app/src/main/res/anim/slide_alpha_out_right.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/app/src/main/res/anim/slide_in_left.xml b/app/src/main/res/anim/slide_in_left.xml index 9a585f5b7..dfc9493af 100644 --- a/app/src/main/res/anim/slide_in_left.xml +++ b/app/src/main/res/anim/slide_in_left.xml @@ -19,8 +19,6 @@ --> - - diff --git a/app/src/main/res/anim/slide_in_right.xml b/app/src/main/res/anim/slide_in_right.xml index 125060e43..d43a0adb9 100644 --- a/app/src/main/res/anim/slide_in_right.xml +++ b/app/src/main/res/anim/slide_in_right.xml @@ -19,8 +19,6 @@ --> - - diff --git a/app/src/main/res/anim/slide_out_left.xml b/app/src/main/res/anim/slide_out_left.xml index 73337d4f9..f6cc284ef 100644 --- a/app/src/main/res/anim/slide_out_left.xml +++ b/app/src/main/res/anim/slide_out_left.xml @@ -19,8 +19,6 @@ --> - - diff --git a/app/src/main/res/anim/slide_out_right.xml b/app/src/main/res/anim/slide_out_right.xml index de8c512c5..fc13e590d 100644 --- a/app/src/main/res/anim/slide_out_right.xml +++ b/app/src/main/res/anim/slide_out_right.xml @@ -19,8 +19,6 @@ --> - - diff --git a/app/src/main/res/layout/list_nodes_fragment.xml b/app/src/main/res/layout/list_nodes_fragment.xml index 4aecac136..26ace3d6d 100644 --- a/app/src/main/res/layout/list_nodes_fragment.xml +++ b/app/src/main/res/layout/list_nodes_fragment.xml @@ -2,4 +2,5 @@ \ No newline at end of file + android:layout_height="match_parent" + android:background="?android:attr/colorBackground" /> \ No newline at end of file diff --git a/app/src/main/res/layout/search_results.xml b/app/src/main/res/layout/search_results.xml index 59fd4987b..ee1489ff4 100644 --- a/app/src/main/res/layout/search_results.xml +++ b/app/src/main/res/layout/search_results.xml @@ -50,7 +50,7 @@ + android:layout_height="match_parent" /> \ No newline at end of file