From a842d4daf71f85af9f1457a67f2babe02c5cf0d2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 17 Nov 2016 12:02:04 +0100 Subject: [PATCH] implement folder un/hiding --- .../gallery/activities/MainActivity.kt | 89 +------------------ .../gallery/adapters/DirectoryAdapter.kt | 31 ++++++- 2 files changed, 30 insertions(+), 90 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 1b5abb642..2c925266b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -351,75 +351,17 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get } } - /*override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long, checked: Boolean) { - if (checked) { - mSelectedItemsCnt++ - } else { - mSelectedItemsCnt-- - } - - if (mSelectedItemsCnt > 0) { - mode.title = mSelectedItemsCnt.toString() - } - - mode.invalidate() - } - - override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - val inflater = mode.menuInflater - inflater.inflate(R.menu.cab_directories, menu) - mActionMode = mode - return true - } - - override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { - menu.findItem(R.id.cab_edit).isVisible = mSelectedItemsCnt == 1 - - var hiddenCnt = 0 - var unhiddenCnt = 0 - val items = directories_grid.checkedItemPositions - val cnt = items.size() - for (i in 0..cnt - 1) { - if (items.valueAt(i)) { - val id = items.keyAt(i) - if (mConfig.getIsFolderHidden(mDirs[id].path)) - hiddenCnt++ - else - unhiddenCnt++ - } - } - - menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 - menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 - - return true - } - - override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { + /*override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { return when (item.itemId) { R.id.cab_properties -> { showProperties() true } - R.id.cab_edit -> { - editDirectory() - true - } R.id.cab_delete -> { prepareForDeleting() mode.finish() true } - R.id.cab_hide -> { - hideFolders() - mode.finish() - true - } - R.id.cab_unhide -> { - unhideFolders() - mode.finish() - true - } R.id.cab_copy_move -> { displayCopyDialog() true @@ -428,10 +370,6 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get } } - override fun onDestroyActionMode(mode: ActionMode) { - mSelectedItemsCnt = 0 - } - override fun onTouch(v: View, event: MotionEvent): Boolean { if (mIsSnackbarShown) { deleteDirs() @@ -440,31 +378,6 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get return false }*/ - private fun hideFolders() { - mConfig.addHiddenDirectories(selectedPaths) - getDirectories() - } - - private fun unhideFolders() { - mConfig.removeHiddenDirectories(selectedPaths) - getDirectories() - } - - private val selectedPaths: Set - get() { - return HashSet() - /*val items = directories_grid.checkedItemPositions - val selectedPaths = HashSet() - val cnt = items.size() - for (i in 0..cnt - 1) { - if (items.valueAt(i)) { - val id = items.keyAt(i) - selectedPaths.add(mDirs[id].path) - } - } - return selectedPaths*/ - } - override fun onRefresh() { getDirectories() directories_holder.isRefreshing = false diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 04a91b40a..d2b638d33 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -45,7 +45,15 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList { - editDirectory() + editDir() + true + } + R.id.cab_hide -> { + hideDirs() + true + } + R.id.cab_unhide -> { + unhideDir() true } else -> false @@ -85,7 +93,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList { + val positions = multiSelector.selectedPositions + val paths = HashSet() + positions.forEach { paths.add(dirs[it].path) } + return paths + } + override fun onBindViewHolder(holder: ViewHolder, position: Int) { views.add(holder.bindView(activity, multiSelectorMode, multiSelector, dirs[position])) }