mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix orientation change
This commit is contained in:
@@ -116,8 +116,9 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
|
|
||||||
// Manage group
|
// Manage group
|
||||||
private var mSearchState: SearchState? = null
|
private var mSearchState: SearchState? = null
|
||||||
private var mMainGroupState: GroupState? = null // Group in the tree, not a search
|
private var mMainGroupState: GroupState? = null // Group state, not a search
|
||||||
private var mRootGroup: Group? = null // Root group in the tree
|
private var mRootGroup: Group? = null // Root group in the tree
|
||||||
|
private var mMainGroup: Group? = null // Main group currently in memory
|
||||||
private var mCurrentGroup: Group? = null // Group currently visible (search or main group)
|
private var mCurrentGroup: Group? = null // Group currently visible (search or main group)
|
||||||
private var mPreviousGroupsIds = mutableListOf<GroupState>()
|
private var mPreviousGroupsIds = mutableListOf<GroupState>()
|
||||||
private var mOldGroupToUpdate: Group? = null
|
private var mOldGroupToUpdate: Group? = null
|
||||||
@@ -246,7 +247,7 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
// Open group on breadcrumb click
|
// Open group on breadcrumb click
|
||||||
onItemClickListener = { node, _ ->
|
onItemClickListener = { node, _ ->
|
||||||
// If last item & not a virtual root group
|
// If last item & not a virtual root group
|
||||||
val currentGroup = mCurrentGroup
|
val currentGroup = mMainGroup
|
||||||
if (currentGroup != null && node == currentGroup
|
if (currentGroup != null && node == currentGroup
|
||||||
&& (currentGroup != mDatabase?.rootGroup
|
&& (currentGroup != mDatabase?.rootGroup
|
||||||
|| mDatabase?.rootGroupIsVirtual == false)
|
|| mDatabase?.rootGroupIsVirtual == false)
|
||||||
@@ -263,7 +264,7 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
onLongItemClickListener = { node, position ->
|
onLongItemClickListener = { node, position ->
|
||||||
val currentGroup = mCurrentGroup
|
val currentGroup = mMainGroup
|
||||||
if (currentGroup != null && node == currentGroup
|
if (currentGroup != null && node == currentGroup
|
||||||
&& (currentGroup != mDatabase?.rootGroup
|
&& (currentGroup != mDatabase?.rootGroup
|
||||||
|| mDatabase?.rootGroupIsVirtual == false)
|
|| mDatabase?.rootGroupIsVirtual == false)
|
||||||
@@ -319,20 +320,26 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
GROUP_FRAGMENT_TAG
|
GROUP_FRAGMENT_TAG
|
||||||
).commit()
|
).commit()
|
||||||
|
|
||||||
|
// Observe main group
|
||||||
|
mGroupViewModel.mainGroup.observe(this) {
|
||||||
|
val mainGroup = it.group
|
||||||
|
mMainGroup = mainGroup
|
||||||
|
mRecyclingBinIsCurrentGroup = it.isRecycleBin
|
||||||
|
// Save group state
|
||||||
|
mMainGroupState = GroupState(mainGroup.nodeId, it.showFromPosition)
|
||||||
|
// Update last access time.
|
||||||
|
mainGroup.touch(modified = false, touchParents = false)
|
||||||
|
}
|
||||||
|
|
||||||
// Observe group
|
// Observe group
|
||||||
mGroupViewModel.group.observe(this) {
|
mGroupViewModel.group.observe(this) {
|
||||||
val currentGroup = it.group
|
val currentGroup = it.group
|
||||||
mCurrentGroup = currentGroup
|
mCurrentGroup = currentGroup
|
||||||
if (!currentGroup.isVirtual) {
|
if (currentGroup.isVirtual) {
|
||||||
mRecyclingBinIsCurrentGroup = it.isRecycleBin
|
|
||||||
// Save group state
|
|
||||||
mMainGroupState = GroupState(currentGroup.nodeId, it.showFromPosition)
|
|
||||||
// Update last access time.
|
|
||||||
currentGroup.touch(modified = false, touchParents = false)
|
|
||||||
} else {
|
|
||||||
mSearchState = SearchState(it.searchParameters, it.showFromPosition)
|
mSearchState = SearchState(it.searchParameters, it.showFromPosition)
|
||||||
searchFiltersView?.searchParameters = it.searchParameters
|
searchFiltersView?.searchParameters = it.searchParameters
|
||||||
}
|
}
|
||||||
|
// Main group in activity is managed with another variable to keep value during orientation
|
||||||
|
|
||||||
loadingView?.hideByFading()
|
loadingView?.hideByFading()
|
||||||
}
|
}
|
||||||
@@ -366,7 +373,7 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
|
|
||||||
mGroupEditViewModel.onGroupCreated.observe(this) { groupInfo ->
|
mGroupEditViewModel.onGroupCreated.observe(this) { groupInfo ->
|
||||||
if (groupInfo.title.isNotEmpty()) {
|
if (groupInfo.title.isNotEmpty()) {
|
||||||
mCurrentGroup?.let { currentGroup ->
|
mMainGroup?.let { currentGroup ->
|
||||||
createGroup(currentGroup, groupInfo)
|
createGroup(currentGroup, groupInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,7 +381,7 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
|
|
||||||
mGroupEditViewModel.onGroupUpdated.observe(this) { groupInfo ->
|
mGroupEditViewModel.onGroupUpdated.observe(this) { groupInfo ->
|
||||||
if (groupInfo.title.isNotEmpty()) {
|
if (groupInfo.title.isNotEmpty()) {
|
||||||
mOldGroupToUpdate?.let { oldGroupToUpdate ->
|
mMainGroup?.let { oldGroupToUpdate ->
|
||||||
updateGroup(oldGroupToUpdate, groupInfo)
|
updateGroup(oldGroupToUpdate, groupInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,16 +389,16 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
|
|
||||||
// Add listeners to the add buttons
|
// Add listeners to the add buttons
|
||||||
addNodeButtonView?.setAddGroupClickListener {
|
addNodeButtonView?.setAddGroupClickListener {
|
||||||
mCurrentGroup?.let { currentGroup ->
|
mMainGroup?.let { currentGroup ->
|
||||||
launchDialogForGroupCreation(currentGroup)
|
launchDialogForGroupCreation(currentGroup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addNodeButtonView?.setAddEntryClickListener {
|
addNodeButtonView?.setAddEntryClickListener {
|
||||||
mDatabase?.let { database ->
|
mDatabase?.let { database ->
|
||||||
mCurrentGroup?.let { currentGroup ->
|
mMainGroup?.let { currentGroup ->
|
||||||
EntrySelectionHelper.doSpecialAction(intent,
|
EntrySelectionHelper.doSpecialAction(intent,
|
||||||
{
|
{
|
||||||
mCurrentGroup?.nodeId?.let { currentParentGroupId ->
|
mMainGroup?.nodeId?.let { currentParentGroupId ->
|
||||||
mGroupFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
mGroupFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||||
EntryEditActivity.launchToCreate(
|
EntryEditActivity.launchToCreate(
|
||||||
this@GroupActivity,
|
this@GroupActivity,
|
||||||
@@ -571,7 +578,7 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
ACTION_DATABASE_UPDATE_GROUP_TASK -> {
|
ACTION_DATABASE_UPDATE_GROUP_TASK -> {
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
try {
|
try {
|
||||||
if (mCurrentGroup == newNodes[0] as Group)
|
if (mMainGroup == newNodes[0] as Group)
|
||||||
reloadCurrentGroup()
|
reloadCurrentGroup()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(
|
Log.e(
|
||||||
@@ -977,13 +984,13 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
when (pasteMode) {
|
when (pasteMode) {
|
||||||
GroupFragment.PasteMode.PASTE_FROM_COPY -> {
|
GroupFragment.PasteMode.PASTE_FROM_COPY -> {
|
||||||
// Copy
|
// Copy
|
||||||
mCurrentGroup?.let { newParent ->
|
mMainGroup?.let { newParent ->
|
||||||
copyNodes(nodes, newParent)
|
copyNodes(nodes, newParent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GroupFragment.PasteMode.PASTE_FROM_MOVE -> {
|
GroupFragment.PasteMode.PASTE_FROM_MOVE -> {
|
||||||
// Move
|
// Move
|
||||||
mCurrentGroup?.let { newParent ->
|
mMainGroup?.let { newParent ->
|
||||||
moveNodes(nodes, newParent)
|
moveNodes(nodes, newParent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1176,7 +1183,7 @@ class GroupActivity : DatabaseLockActivity(),
|
|||||||
}
|
}
|
||||||
R.id.menu_empty_recycle_bin -> {
|
R.id.menu_empty_recycle_bin -> {
|
||||||
if (mRecyclingBinEnabled && mRecyclingBinIsCurrentGroup) {
|
if (mRecyclingBinEnabled && mRecyclingBinIsCurrentGroup) {
|
||||||
mCurrentGroup?.getChildren()?.let { listChildren ->
|
mMainGroup?.getChildren()?.let { listChildren ->
|
||||||
// Automatically delete all elements
|
// Automatically delete all elements
|
||||||
deleteNodes(listChildren, true)
|
deleteNodes(listChildren, true)
|
||||||
finishNodeAction()
|
finishNodeAction()
|
||||||
|
|||||||
@@ -259,9 +259,9 @@ class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
|
|||||||
private fun rebuildList() {
|
private fun rebuildList() {
|
||||||
try {
|
try {
|
||||||
// Add elements to the list
|
// Add elements to the list
|
||||||
mCurrentGroup?.let { mainGroup ->
|
mCurrentGroup?.let { currentGroup ->
|
||||||
// Thrown an exception when sort cannot be performed
|
// Thrown an exception when sort cannot be performed
|
||||||
mAdapter?.rebuildList(mainGroup)
|
mAdapter?.rebuildList(currentGroup)
|
||||||
}
|
}
|
||||||
} catch (e:Exception) {
|
} catch (e:Exception) {
|
||||||
Log.e(TAG, "Unable to rebuild the list", e)
|
Log.e(TAG, "Unable to rebuild the list", e)
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ import com.kunzisoft.keepass.database.search.SearchParameters
|
|||||||
|
|
||||||
class GroupViewModel: ViewModel() {
|
class GroupViewModel: ViewModel() {
|
||||||
|
|
||||||
|
val mainGroup : LiveData<SuperGroup> get() = _mainGroup
|
||||||
|
private val _mainGroup = MutableLiveData<SuperGroup>()
|
||||||
|
|
||||||
val group : LiveData<SuperGroup> get() = _group
|
val group : LiveData<SuperGroup> get() = _group
|
||||||
private val _group = MutableLiveData<SuperGroup>()
|
private val _group = MutableLiveData<SuperGroup>()
|
||||||
|
|
||||||
@@ -51,9 +54,10 @@ class GroupViewModel: ViewModel() {
|
|||||||
},
|
},
|
||||||
{ group ->
|
{ group ->
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
_group.value = SuperGroup(group,
|
_mainGroup.value = SuperGroup(group,
|
||||||
database?.recycleBin == group,
|
database?.recycleBin == group,
|
||||||
showFromPosition)
|
showFromPosition)
|
||||||
|
_group.value = _mainGroup.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).execute()
|
).execute()
|
||||||
@@ -62,9 +66,10 @@ class GroupViewModel: ViewModel() {
|
|||||||
fun loadMainGroup(database: Database?,
|
fun loadMainGroup(database: Database?,
|
||||||
group: Group,
|
group: Group,
|
||||||
showFromPosition: Int?) {
|
showFromPosition: Int?) {
|
||||||
_group.value = SuperGroup(group,
|
_mainGroup.value = SuperGroup(group,
|
||||||
database?.recycleBin == group,
|
database?.recycleBin == group,
|
||||||
showFromPosition)
|
showFromPosition)
|
||||||
|
_group.value = _mainGroup.value
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadSearchGroup(database: Database?,
|
fun loadSearchGroup(database: Database?,
|
||||||
|
|||||||
Reference in New Issue
Block a user