mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix number of entries and refactor GroupFragment
This commit is contained in:
@@ -44,7 +44,7 @@ import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.*
|
||||
import com.kunzisoft.keepass.activities.dialogs.NodesFragment
|
||||
import com.kunzisoft.keepass.activities.fragments.GroupFragment
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.SpecialMode
|
||||
import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
|
||||
@@ -77,9 +77,10 @@ import org.joda.time.DateTime
|
||||
class GroupActivity : DatabaseLockActivity(),
|
||||
DatePickerDialog.OnDateSetListener,
|
||||
TimePickerDialog.OnTimeSetListener,
|
||||
NodesFragment.NodeClickListener,
|
||||
NodesFragment.NodesActionMenuListener,
|
||||
NodesFragment.OnScrollListener,
|
||||
GroupFragment.NodeClickListener,
|
||||
GroupFragment.NodesActionMenuListener,
|
||||
GroupFragment.OnScrollListener,
|
||||
GroupFragment.GroupRefreshedListener,
|
||||
SortDialogFragment.SortSelectionListener {
|
||||
|
||||
// Views
|
||||
@@ -104,7 +105,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
|
||||
private var mBreadcrumbAdapter: BreadcrumbAdapter? = null
|
||||
|
||||
private var mNodesFragment: NodesFragment? = null
|
||||
private var mGroupFragment: GroupFragment? = null
|
||||
private var mRecyclingBinEnabled = false
|
||||
private var mRecyclingBinIsCurrentGroup = false
|
||||
private var mRequestStartupSearch = true
|
||||
@@ -173,7 +174,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
finishNodeAction()
|
||||
launchDialogToShowGroupInfo(currentGroup)
|
||||
} else {
|
||||
if (mNodesFragment?.nodeActionSelectionMode == true) {
|
||||
if (mGroupFragment?.nodeActionSelectionMode == true) {
|
||||
finishNodeAction()
|
||||
}
|
||||
mDatabase?.let { database ->
|
||||
@@ -226,15 +227,15 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
}
|
||||
|
||||
// Initialize the fragment with the list
|
||||
mNodesFragment =
|
||||
supportFragmentManager.findFragmentByTag(GROUP_FRAGMENT_TAG) as NodesFragment?
|
||||
if (mNodesFragment == null)
|
||||
mNodesFragment = NodesFragment()
|
||||
mGroupFragment =
|
||||
supportFragmentManager.findFragmentByTag(GROUP_FRAGMENT_TAG) as GroupFragment?
|
||||
if (mGroupFragment == null)
|
||||
mGroupFragment = GroupFragment()
|
||||
|
||||
// Attach fragment to content view
|
||||
supportFragmentManager.beginTransaction().replace(
|
||||
R.id.nodes_list_fragment_container,
|
||||
mNodesFragment!!,
|
||||
mGroupFragment!!,
|
||||
GROUP_FRAGMENT_TAG
|
||||
).commit()
|
||||
|
||||
@@ -261,7 +262,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
EntrySelectionHelper.doSpecialAction(intent,
|
||||
{
|
||||
mCurrentGroup?.nodeId?.let { currentParentGroupId ->
|
||||
mNodesFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||
mGroupFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||
EntryEditActivity.launchToCreate(
|
||||
this@GroupActivity,
|
||||
database,
|
||||
@@ -552,6 +553,12 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun onGroupRefreshed() {
|
||||
mCurrentGroup?.let { currentGroup ->
|
||||
assignGroupViewElements(currentGroup)
|
||||
}
|
||||
}
|
||||
|
||||
private fun assignGroupViewElements(group: Group?) {
|
||||
// Assign title
|
||||
if (group?.isVirtual == true) {
|
||||
@@ -635,7 +642,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
val entryVersioned = node as Entry
|
||||
EntrySelectionHelper.doSpecialAction(intent,
|
||||
{
|
||||
mNodesFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||
mGroupFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||
EntryActivity.launch(
|
||||
this@GroupActivity,
|
||||
database,
|
||||
@@ -796,7 +803,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
): Boolean {
|
||||
if (nodes.isNotEmpty()) {
|
||||
if (actionNodeMode == null || toolbarAction?.getSupportActionModeCallback() == null) {
|
||||
mNodesFragment?.actionNodesCallback(
|
||||
mGroupFragment?.actionNodesCallback(
|
||||
database,
|
||||
nodes,
|
||||
this
|
||||
@@ -835,7 +842,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
launchDialogForGroupUpdate(node as Group)
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
mNodesFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||
mGroupFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||
EntryEditActivity.launchToUpdate(
|
||||
this@GroupActivity,
|
||||
database,
|
||||
@@ -890,17 +897,17 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
|
||||
override fun onPasteMenuClick(
|
||||
database: Database,
|
||||
pasteMode: NodesFragment.PasteMode?,
|
||||
pasteMode: GroupFragment.PasteMode?,
|
||||
nodes: List<Node>
|
||||
): Boolean {
|
||||
when (pasteMode) {
|
||||
NodesFragment.PasteMode.PASTE_FROM_COPY -> {
|
||||
GroupFragment.PasteMode.PASTE_FROM_COPY -> {
|
||||
// Copy
|
||||
mCurrentGroup?.let { newParent ->
|
||||
copyNodes(nodes, newParent)
|
||||
}
|
||||
}
|
||||
NodesFragment.PasteMode.PASTE_FROM_MOVE -> {
|
||||
GroupFragment.PasteMode.PASTE_FROM_MOVE -> {
|
||||
// Move
|
||||
mCurrentGroup?.let { newParent ->
|
||||
moveNodes(nodes, newParent)
|
||||
@@ -1101,7 +1108,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
sortNodeEnum: SortNodeEnum,
|
||||
sortNodeParameters: SortNodeEnum.SortNodeParameters
|
||||
) {
|
||||
mNodesFragment?.onSortSelected(sortNodeEnum, sortNodeParameters)
|
||||
mGroupFragment?.onSortSelected(sortNodeEnum, sortNodeParameters)
|
||||
}
|
||||
|
||||
override fun startActivity(intent: Intent) {
|
||||
@@ -1140,7 +1147,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (mNodesFragment?.nodeActionSelectionMode == true) {
|
||||
if (mGroupFragment?.nodeActionSelectionMode == true) {
|
||||
finishNodeAction()
|
||||
} else {
|
||||
// Normal way when we are not in root
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.activities.dialogs
|
||||
package com.kunzisoft.keepass.activities.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
@@ -30,7 +30,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.EntryEditActivity
|
||||
import com.kunzisoft.keepass.activities.fragments.DatabaseFragment
|
||||
import com.kunzisoft.keepass.activities.dialogs.SortDialogFragment
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.SpecialMode
|
||||
import com.kunzisoft.keepass.adapters.NodesAdapter
|
||||
@@ -44,10 +44,11 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
import com.kunzisoft.keepass.viewmodels.GroupViewModel
|
||||
import java.util.*
|
||||
|
||||
class NodesFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListener {
|
||||
class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListener {
|
||||
|
||||
private var nodeClickListener: NodeClickListener? = null
|
||||
private var onScrollListener: OnScrollListener? = null
|
||||
private var groupRefreshed: GroupRefreshedListener? = null
|
||||
|
||||
private var mNodesRecyclerView: RecyclerView? = null
|
||||
private var mLayoutManager: LinearLayoutManager? = null
|
||||
@@ -100,6 +101,8 @@ class NodesFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
|
||||
// TODO Change to ViewModel
|
||||
try {
|
||||
nodeClickListener = context as NodeClickListener
|
||||
} catch (e: ClassCastException) {
|
||||
@@ -117,11 +120,20 @@ class NodesFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
|
||||
TAG, context.toString()
|
||||
+ " must implement " + RecyclerView.OnScrollListener::class.java.name)
|
||||
}
|
||||
|
||||
try {
|
||||
groupRefreshed = context as GroupRefreshedListener
|
||||
} catch (e: ClassCastException) {
|
||||
// The activity doesn't implement the interface, throw exception
|
||||
throw ClassCastException(context.toString()
|
||||
+ " must implement " + GroupRefreshedListener::class.java.name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetach() {
|
||||
nodeClickListener = null
|
||||
onScrollListener = null
|
||||
groupRefreshed = null
|
||||
super.onDetach()
|
||||
}
|
||||
|
||||
@@ -259,6 +271,8 @@ class NodesFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
|
||||
} else {
|
||||
notFoundView?.visibility = View.GONE
|
||||
}
|
||||
|
||||
groupRefreshed?.onGroupRefreshed()
|
||||
}
|
||||
|
||||
override fun onSortSelected(sortNodeEnum: SortNodeEnum,
|
||||
@@ -291,15 +305,17 @@ class NodesFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
|
||||
val sortDialogFragment: SortDialogFragment =
|
||||
if (mRecycleBinEnable) {
|
||||
SortDialogFragment.getInstance(
|
||||
PreferencesUtil.getListSort(context),
|
||||
PreferencesUtil.getAscendingSort(context),
|
||||
PreferencesUtil.getGroupsBeforeSort(context),
|
||||
PreferencesUtil.getRecycleBinBottomSort(context))
|
||||
PreferencesUtil.getListSort(context),
|
||||
PreferencesUtil.getAscendingSort(context),
|
||||
PreferencesUtil.getGroupsBeforeSort(context),
|
||||
PreferencesUtil.getRecycleBinBottomSort(context)
|
||||
)
|
||||
} else {
|
||||
SortDialogFragment.getInstance(
|
||||
PreferencesUtil.getListSort(context),
|
||||
PreferencesUtil.getAscendingSort(context),
|
||||
PreferencesUtil.getGroupsBeforeSort(context))
|
||||
PreferencesUtil.getListSort(context),
|
||||
PreferencesUtil.getAscendingSort(context),
|
||||
PreferencesUtil.getGroupsBeforeSort(context)
|
||||
)
|
||||
}
|
||||
|
||||
sortDialogFragment.show(childFragmentManager, "sortDialog")
|
||||
@@ -446,7 +462,11 @@ class NodesFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
|
||||
fun onScrolled(dy: Int)
|
||||
}
|
||||
|
||||
interface GroupRefreshedListener {
|
||||
fun onGroupRefreshed()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = NodesFragment::class.java.name
|
||||
private val TAG = GroupFragment::class.java.name
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user