Fix PwGroupV3 and PwEntryV3

This commit is contained in:
J-Jamet
2019-07-11 14:49:28 +02:00
parent 32537e85a2
commit 5cd8cbd514
2 changed files with 59 additions and 54 deletions

View File

@@ -105,19 +105,19 @@ class GroupActivity : LockingActivity(),
private var mDatabase: Database? = null private var mDatabase: Database? = null
private var listNodesFragment: ListNodesFragment? = null private var mListNodesFragment: ListNodesFragment? = null
private var currentGroupIsASearch: Boolean = false private var mCurrentGroupIsASearch: Boolean = false
// Nodes // Nodes
private var mRootGroup: GroupVersioned? = null private var mRootGroup: GroupVersioned? = null
private var mCurrentGroup: GroupVersioned? = null private var mCurrentGroup: GroupVersioned? = null
private var mOldGroupToUpdate: GroupVersioned? = null private var mOldGroupToUpdate: GroupVersioned? = null
private var nodeToCopy: NodeVersioned? = null private var mNodeToCopy: NodeVersioned? = null
private var nodeToMove: NodeVersioned? = null private var mNodeToMove: NodeVersioned? = null
private var searchSuggestionAdapter: SearchEntryCursorAdapter? = null private var mSearchSuggestionAdapter: SearchEntryCursorAdapter? = null
private var iconColor: Int = 0 private var mIconColor: Int = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -148,10 +148,10 @@ class GroupActivity : LockingActivity(),
if (savedInstanceState.containsKey(OLD_GROUP_TO_UPDATE_KEY)) if (savedInstanceState.containsKey(OLD_GROUP_TO_UPDATE_KEY))
mOldGroupToUpdate = savedInstanceState.getParcelable(OLD_GROUP_TO_UPDATE_KEY) mOldGroupToUpdate = savedInstanceState.getParcelable(OLD_GROUP_TO_UPDATE_KEY)
if (savedInstanceState.containsKey(NODE_TO_COPY_KEY)) { if (savedInstanceState.containsKey(NODE_TO_COPY_KEY)) {
nodeToCopy = savedInstanceState.getParcelable(NODE_TO_COPY_KEY) mNodeToCopy = savedInstanceState.getParcelable(NODE_TO_COPY_KEY)
toolbarPaste?.setOnMenuItemClickListener(OnCopyMenuItemClickListener()) toolbarPaste?.setOnMenuItemClickListener(OnCopyMenuItemClickListener())
} else if (savedInstanceState.containsKey(NODE_TO_MOVE_KEY)) { } else if (savedInstanceState.containsKey(NODE_TO_MOVE_KEY)) {
nodeToMove = savedInstanceState.getParcelable(NODE_TO_MOVE_KEY) mNodeToMove = savedInstanceState.getParcelable(NODE_TO_MOVE_KEY)
toolbarPaste?.setOnMenuItemClickListener(OnMoveMenuItemClickListener()) toolbarPaste?.setOnMenuItemClickListener(OnMoveMenuItemClickListener())
} }
} }
@@ -163,7 +163,7 @@ class GroupActivity : LockingActivity(),
} }
mCurrentGroup = retrieveCurrentGroup(intent, savedInstanceState) mCurrentGroup = retrieveCurrentGroup(intent, savedInstanceState)
currentGroupIsASearch = Intent.ACTION_SEARCH == intent.action mCurrentGroupIsASearch = Intent.ACTION_SEARCH == intent.action
Log.i(TAG, "Started creating tree") Log.i(TAG, "Started creating tree")
if (mCurrentGroup == null) { if (mCurrentGroup == null) {
@@ -181,28 +181,28 @@ class GroupActivity : LockingActivity(),
toolbarPaste?.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp) toolbarPaste?.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp)
toolbarPaste?.setNavigationOnClickListener { toolbarPaste?.setNavigationOnClickListener {
toolbarPasteExpandableLayout?.collapse() toolbarPasteExpandableLayout?.collapse()
nodeToCopy = null mNodeToCopy = null
nodeToMove = null mNodeToMove = null
} }
// Retrieve the textColor to tint the icon // Retrieve the textColor to tint the icon
val taTextColor = theme.obtainStyledAttributes(intArrayOf(R.attr.textColorInverse)) val taTextColor = theme.obtainStyledAttributes(intArrayOf(R.attr.textColorInverse))
iconColor = taTextColor.getColor(0, Color.WHITE) mIconColor = taTextColor.getColor(0, Color.WHITE)
taTextColor.recycle() taTextColor.recycle()
var fragmentTag = LIST_NODES_FRAGMENT_TAG var fragmentTag = LIST_NODES_FRAGMENT_TAG
if (currentGroupIsASearch) if (mCurrentGroupIsASearch)
fragmentTag = SEARCH_FRAGMENT_TAG fragmentTag = SEARCH_FRAGMENT_TAG
// Initialize the fragment with the list // Initialize the fragment with the list
listNodesFragment = supportFragmentManager.findFragmentByTag(fragmentTag) as ListNodesFragment? mListNodesFragment = supportFragmentManager.findFragmentByTag(fragmentTag) as ListNodesFragment?
if (listNodesFragment == null) if (mListNodesFragment == null)
listNodesFragment = ListNodesFragment.newInstance(mCurrentGroup, readOnly, currentGroupIsASearch) mListNodesFragment = ListNodesFragment.newInstance(mCurrentGroup, readOnly, mCurrentGroupIsASearch)
// Attach fragment to content view // Attach fragment to content view
supportFragmentManager.beginTransaction().replace( supportFragmentManager.beginTransaction().replace(
R.id.nodes_list_fragment_container, R.id.nodes_list_fragment_container,
listNodesFragment, mListNodesFragment,
fragmentTag) fragmentTag)
.commit() .commit()
@@ -220,7 +220,7 @@ class GroupActivity : LockingActivity(),
// Search suggestion // Search suggestion
mDatabase?.let { database -> mDatabase?.let { database ->
searchSuggestionAdapter = SearchEntryCursorAdapter(this, database) mSearchSuggestionAdapter = SearchEntryCursorAdapter(this, database)
} }
Log.i(TAG, "Finished creating tree") Log.i(TAG, "Finished creating tree")
@@ -229,7 +229,7 @@ class GroupActivity : LockingActivity(),
override fun onNewIntent(intent: Intent) { override fun onNewIntent(intent: Intent) {
Log.d(TAG, "setNewIntent: $intent") Log.d(TAG, "setNewIntent: $intent")
setIntent(intent) setIntent(intent)
currentGroupIsASearch = if (Intent.ACTION_SEARCH == intent.action) { mCurrentGroupIsASearch = if (Intent.ACTION_SEARCH == intent.action) {
// only one instance of search in backstack // only one instance of search in backstack
openSearchGroup(retrieveCurrentGroup(intent, null)) openSearchGroup(retrieveCurrentGroup(intent, null))
true true
@@ -278,7 +278,7 @@ class GroupActivity : LockingActivity(),
fragmentTransaction.addToBackStack(fragmentTag) fragmentTransaction.addToBackStack(fragmentTag)
fragmentTransaction.commit() fragmentTransaction.commit()
listNodesFragment = newListNodeFragment mListNodesFragment = newListNodeFragment
mCurrentGroup = group mCurrentGroup = group
assignGroupViewElements() assignGroupViewElements()
} }
@@ -291,10 +291,10 @@ class GroupActivity : LockingActivity(),
mOldGroupToUpdate?.let { mOldGroupToUpdate?.let {
outState.putParcelable(OLD_GROUP_TO_UPDATE_KEY, it) outState.putParcelable(OLD_GROUP_TO_UPDATE_KEY, it)
} }
nodeToCopy?.let { mNodeToCopy?.let {
outState.putParcelable(NODE_TO_COPY_KEY, it) outState.putParcelable(NODE_TO_COPY_KEY, it)
} }
nodeToMove?.let { mNodeToMove?.let {
outState.putParcelable(NODE_TO_MOVE_KEY, it) outState.putParcelable(NODE_TO_MOVE_KEY, it)
} }
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
@@ -346,14 +346,14 @@ class GroupActivity : LockingActivity(),
} }
} }
} }
if (currentGroupIsASearch) { if (mCurrentGroupIsASearch) {
searchTitleView?.visibility = View.VISIBLE searchTitleView?.visibility = View.VISIBLE
} else { } else {
searchTitleView?.visibility = View.GONE searchTitleView?.visibility = View.GONE
} }
// Assign icon // Assign icon
if (currentGroupIsASearch) { if (mCurrentGroupIsASearch) {
if (toolbar != null) { if (toolbar != null) {
toolbar?.navigationIcon = null toolbar?.navigationIcon = null
} }
@@ -362,7 +362,7 @@ class GroupActivity : LockingActivity(),
// Assign the group icon depending of IconPack or custom icon // Assign the group icon depending of IconPack or custom icon
iconView?.visibility = View.VISIBLE iconView?.visibility = View.VISIBLE
mCurrentGroup?.let { mCurrentGroup?.let {
mDatabase?.drawFactory?.assignDatabaseIconTo(this, iconView, it.icon, iconColor) mDatabase?.drawFactory?.assignDatabaseIconTo(this, iconView, it.icon, mIconColor)
if (toolbar != null) { if (toolbar != null) {
if (mCurrentGroup?.containsParent() == true) if (mCurrentGroup?.containsParent() == true)
@@ -385,8 +385,8 @@ class GroupActivity : LockingActivity(),
addNodeButtonView?.apply { addNodeButtonView?.apply {
// To enable add button // To enable add button
val addGroupEnabled = !readOnly && !currentGroupIsASearch val addGroupEnabled = !readOnly && !mCurrentGroupIsASearch
var addEntryEnabled = !readOnly && !currentGroupIsASearch var addEntryEnabled = !readOnly && !mCurrentGroupIsASearch
mCurrentGroup?.let { mCurrentGroup?.let {
val isRoot = it == mRootGroup val isRoot = it == mRootGroup
if (!it.allowAddEntryIfIsRoot()) if (!it.allowAddEntryIfIsRoot())
@@ -483,7 +483,7 @@ class GroupActivity : LockingActivity(),
override fun onCopyMenuClick(node: NodeVersioned): Boolean { override fun onCopyMenuClick(node: NodeVersioned): Boolean {
toolbarPasteExpandableLayout?.expand() toolbarPasteExpandableLayout?.expand()
nodeToCopy = node mNodeToCopy = node
toolbarPaste?.setOnMenuItemClickListener(OnCopyMenuItemClickListener()) toolbarPaste?.setOnMenuItemClickListener(OnCopyMenuItemClickListener())
return false return false
} }
@@ -494,15 +494,15 @@ class GroupActivity : LockingActivity(),
when (item.itemId) { when (item.itemId) {
R.id.menu_paste -> { R.id.menu_paste -> {
when (nodeToCopy?.type) { when (mNodeToCopy?.type) {
Type.GROUP -> Log.e(TAG, "Copy not allowed for group") Type.GROUP -> Log.e(TAG, "Copy not allowed for group")
Type.ENTRY -> { Type.ENTRY -> {
mCurrentGroup?.let { currentGroup -> mCurrentGroup?.let { currentGroup ->
copyEntry(nodeToCopy as EntryVersioned, currentGroup) copyEntry(mNodeToCopy as EntryVersioned, currentGroup)
} }
} }
} }
nodeToCopy = null mNodeToCopy = null
return true return true
} }
} }
@@ -522,7 +522,7 @@ class GroupActivity : LockingActivity(),
override fun onMoveMenuClick(node: NodeVersioned): Boolean { override fun onMoveMenuClick(node: NodeVersioned): Boolean {
toolbarPasteExpandableLayout?.expand() toolbarPasteExpandableLayout?.expand()
nodeToMove = node mNodeToMove = node
toolbarPaste?.setOnMenuItemClickListener(OnMoveMenuItemClickListener()) toolbarPaste?.setOnMenuItemClickListener(OnMoveMenuItemClickListener())
return false return false
} }
@@ -533,19 +533,19 @@ class GroupActivity : LockingActivity(),
when (item.itemId) { when (item.itemId) {
R.id.menu_paste -> { R.id.menu_paste -> {
when (nodeToMove?.type) { when (mNodeToMove?.type) {
Type.GROUP -> { Type.GROUP -> {
mCurrentGroup?.let { currentGroup -> mCurrentGroup?.let { currentGroup ->
moveGroup(nodeToMove as GroupVersioned, currentGroup) moveGroup(mNodeToMove as GroupVersioned, currentGroup)
} }
} }
Type.ENTRY -> { Type.ENTRY -> {
mCurrentGroup?.let { currentGroup -> mCurrentGroup?.let { currentGroup ->
moveEntry(nodeToMove as EntryVersioned, currentGroup) moveEntry(mNodeToMove as EntryVersioned, currentGroup)
} }
} }
} }
nodeToMove = null mNodeToMove = null
return true return true
} }
} }
@@ -609,7 +609,7 @@ class GroupActivity : LockingActivity(),
// Refresh the elements // Refresh the elements
assignGroupViewElements() assignGroupViewElements()
// Refresh suggestions to change preferences // Refresh suggestions to change preferences
searchSuggestionAdapter?.reInit(this) mSearchSuggestionAdapter?.reInit(this)
} }
override fun onStop() { override fun onStop() {
@@ -639,10 +639,10 @@ class GroupActivity : LockingActivity(),
setSearchableInfo(searchManager.getSearchableInfo( setSearchableInfo(searchManager.getSearchableInfo(
ComponentName(this@GroupActivity, GroupActivity::class.java))) ComponentName(this@GroupActivity, GroupActivity::class.java)))
setIconifiedByDefault(false) // Do not iconify the widget; expand it by default setIconifiedByDefault(false) // Do not iconify the widget; expand it by default
suggestionsAdapter = searchSuggestionAdapter suggestionsAdapter = mSearchSuggestionAdapter
setOnSuggestionListener(object : SearchView.OnSuggestionListener { setOnSuggestionListener(object : SearchView.OnSuggestionListener {
override fun onSuggestionClick(position: Int): Boolean { override fun onSuggestionClick(position: Int): Boolean {
searchSuggestionAdapter?.let { searchAdapter -> mSearchSuggestionAdapter?.let { searchAdapter ->
searchAdapter.getEntryFromPosition(position)?.let { entry -> searchAdapter.getEntryFromPosition(position)?.let { entry ->
onNodeClick(entry) onNodeClick(entry)
} }
@@ -668,8 +668,8 @@ class GroupActivity : LockingActivity(),
private fun performedNextEducation(groupActivityEducation: GroupActivityEducation, private fun performedNextEducation(groupActivityEducation: GroupActivityEducation,
menu: Menu) { menu: Menu) {
// If no node, show education to add new one // If no node, show education to add new one
if (listNodesFragment != null if (mListNodesFragment != null
&& listNodesFragment!!.isEmpty && mListNodesFragment!!.isEmpty
&& addNodeButtonView != null && addNodeButtonView != null
&& addNodeButtonView!!.isEnable && addNodeButtonView!!.isEnable
&& groupActivityEducation.checkAndPerformedAddNodeButtonEducation( && groupActivityEducation.checkAndPerformedAddNodeButtonEducation(
@@ -815,7 +815,7 @@ class GroupActivity : LockingActivity(),
// TODO custom icon // TODO custom icon
updateGroup.icon = icon updateGroup.icon = icon
listNodesFragment?.removeNode(oldGroupToUpdate) mListNodesFragment?.removeNode(oldGroupToUpdate)
// If group updated save it in the database // If group updated save it in the database
Thread(UpdateGroupRunnable(this, Thread(UpdateGroupRunnable(this,
@@ -838,7 +838,7 @@ class GroupActivity : LockingActivity(),
runOnUiThread { runOnUiThread {
if (actionNodeValues.success) { if (actionNodeValues.success) {
if (actionNodeValues.newNode != null) if (actionNodeValues.newNode != null)
listNodesFragment?.addNode(actionNodeValues.newNode) mListNodesFragment?.addNode(actionNodeValues.newNode)
} }
} }
} }
@@ -849,7 +849,7 @@ class GroupActivity : LockingActivity(),
runOnUiThread { runOnUiThread {
if (actionNodeValues.success) { if (actionNodeValues.success) {
if (actionNodeValues.oldNode!= null && actionNodeValues.newNode != null) if (actionNodeValues.oldNode!= null && actionNodeValues.newNode != null)
listNodesFragment?.updateNode(actionNodeValues.oldNode, actionNodeValues.newNode) mListNodesFragment?.updateNode(actionNodeValues.oldNode, actionNodeValues.newNode)
} }
} }
} }
@@ -860,7 +860,7 @@ class GroupActivity : LockingActivity(),
runOnUiThread { runOnUiThread {
if (actionNodeValues.success) { if (actionNodeValues.success) {
if (actionNodeValues.oldNode != null) if (actionNodeValues.oldNode != null)
listNodesFragment?.removeNode(actionNodeValues.oldNode) mListNodesFragment?.removeNode(actionNodeValues.oldNode)
actionNodeValues.oldNode?.let { oldNode -> actionNodeValues.oldNode?.let { oldNode ->
oldNode.parent?.let { parent -> oldNode.parent?.let { parent ->
@@ -872,7 +872,7 @@ class GroupActivity : LockingActivity(),
&& mCurrentGroup != null && mCurrentGroup != null
&& mCurrentGroup!!.parent == null && mCurrentGroup!!.parent == null
&& mCurrentGroup != recycleBin) { && mCurrentGroup != recycleBin) {
listNodesFragment?.addNode(parent) mListNodesFragment?.addNode(parent)
} }
} }
} }
@@ -938,7 +938,7 @@ class GroupActivity : LockingActivity(),
} }
override fun onSortSelected(sortNodeEnum: SortNodeEnum, ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean) { override fun onSortSelected(sortNodeEnum: SortNodeEnum, ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean) {
listNodesFragment?.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom) mListNodesFragment?.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom)
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@@ -972,7 +972,7 @@ class GroupActivity : LockingActivity(),
private fun removeSearchInIntent(intent: Intent) { private fun removeSearchInIntent(intent: Intent) {
if (Intent.ACTION_SEARCH == intent.action) { if (Intent.ACTION_SEARCH == intent.action) {
currentGroupIsASearch = false mCurrentGroupIsASearch = false
intent.action = Intent.ACTION_DEFAULT intent.action = Intent.ACTION_DEFAULT
intent.removeExtra(SearchManager.QUERY) intent.removeExtra(SearchManager.QUERY)
} }
@@ -992,10 +992,10 @@ class GroupActivity : LockingActivity(),
} }
} }
listNodesFragment = supportFragmentManager.findFragmentByTag(LIST_NODES_FRAGMENT_TAG) as ListNodesFragment mListNodesFragment = supportFragmentManager.findFragmentByTag(LIST_NODES_FRAGMENT_TAG) as ListNodesFragment
// to refresh fragment // to refresh fragment
listNodesFragment?.rebuildList() mListNodesFragment?.rebuildList()
mCurrentGroup = listNodesFragment?.mainGroup mCurrentGroup = mListNodesFragment?.mainGroup
removeSearchInIntent(intent) removeSearchInIntent(intent)
assignGroupViewElements() assignGroupViewElements()
} }

View File

@@ -171,7 +171,10 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
override fun getChildGroups(): MutableList<GroupVersioned> { override fun getChildGroups(): MutableList<GroupVersioned> {
val children = ArrayList<GroupVersioned>() val children = ArrayList<GroupVersioned>()
pwGroupV3?:pwGroupV4?.getChildGroups()?.forEach { pwGroupV3?.getChildGroups()?.forEach {
children.add(GroupVersioned(it))
}
pwGroupV4?.getChildGroups()?.forEach {
children.add(GroupVersioned(it)) children.add(GroupVersioned(it))
} }
@@ -181,7 +184,10 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
override fun getChildEntries(): MutableList<EntryVersioned> { override fun getChildEntries(): MutableList<EntryVersioned> {
val children = ArrayList<EntryVersioned>() val children = ArrayList<EntryVersioned>()
pwGroupV3?:pwGroupV4?.getChildEntries()?.forEach { pwGroupV3?.getChildEntries()?.forEach {
children.add(EntryVersioned(it))
}
pwGroupV4?.getChildEntries()?.forEach {
children.add(EntryVersioned(it)) children.add(EntryVersioned(it))
} }
@@ -194,7 +200,6 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
*/ */
fun getChildrenWithoutMetaStream(): List<NodeVersioned> { fun getChildrenWithoutMetaStream(): List<NodeVersioned> {
val children = ArrayList<NodeVersioned>() val children = ArrayList<NodeVersioned>()
children.addAll(getChildGroups()) children.addAll(getChildGroups())
pwGroupV3?.let { pwGroupV3?.let {