optimize some things at the directory and media adapter
This commit is contained in:
parent
4c9cef04f4
commit
7beff9a692
|
@ -61,11 +61,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
override fun getItemCount() = dirs.size
|
override fun getItemCount() = dirs.size
|
||||||
|
|
||||||
override fun prepareActionMode(menu: Menu) {
|
override fun prepareActionMode(menu: Menu) {
|
||||||
if (getSelectedPaths().isEmpty()) {
|
val selectedPaths = getSelectedPaths()
|
||||||
|
if (selectedPaths.isEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectedPaths = getSelectedPaths()
|
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.cab_rename).isVisible = isOneItemSelected() && !selectedPaths.contains(FAVORITES) && !selectedPaths.contains(RECYCLE_BIN)
|
findItem(R.id.cab_rename).isVisible = isOneItemSelected() && !selectedPaths.contains(FAVORITES) && !selectedPaths.contains(RECYCLE_BIN)
|
||||||
findItem(R.id.cab_change_cover_image).isVisible = isOneItemSelected()
|
findItem(R.id.cab_change_cover_image).isVisible = isOneItemSelected()
|
||||||
|
@ -73,8 +73,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
findItem(R.id.cab_empty_recycle_bin).isVisible = isOneItemSelected() && selectedPaths.first() == RECYCLE_BIN
|
findItem(R.id.cab_empty_recycle_bin).isVisible = isOneItemSelected() && selectedPaths.first() == RECYCLE_BIN
|
||||||
findItem(R.id.cab_empty_disable_recycle_bin).isVisible = isOneItemSelected() && selectedPaths.first() == RECYCLE_BIN
|
findItem(R.id.cab_empty_disable_recycle_bin).isVisible = isOneItemSelected() && selectedPaths.first() == RECYCLE_BIN
|
||||||
|
|
||||||
checkHideBtnVisibility(this)
|
checkHideBtnVisibility(this, selectedPaths)
|
||||||
checkPinBtnVisibility(this)
|
checkPinBtnVisibility(this, selectedPaths)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +117,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkHideBtnVisibility(menu: Menu) {
|
private fun checkHideBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
||||||
var hiddenCnt = 0
|
var hiddenCnt = 0
|
||||||
var unhiddenCnt = 0
|
var unhiddenCnt = 0
|
||||||
getSelectedPaths().forEach {
|
selectedPaths.forEach {
|
||||||
if (File(it).doesThisOrParentHaveNoMedia()) {
|
if (File(it).doesThisOrParentHaveNoMedia()) {
|
||||||
hiddenCnt++
|
hiddenCnt++
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,11 +132,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0
|
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkPinBtnVisibility(menu: Menu) {
|
private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
||||||
val pinnedFolders = config.pinnedFolders
|
val pinnedFolders = config.pinnedFolders
|
||||||
var pinnedCnt = 0
|
var pinnedCnt = 0
|
||||||
var unpinnedCnt = 0
|
var unpinnedCnt = 0
|
||||||
getSelectedPaths().forEach {
|
selectedPaths.forEach {
|
||||||
if (pinnedFolders.contains(it)) {
|
if (pinnedFolders.contains(it)) {
|
||||||
pinnedCnt++
|
pinnedCnt++
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -103,14 +103,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun prepareActionMode(menu: Menu) {
|
override fun prepareActionMode(menu: Menu) {
|
||||||
|
val selectedItems = getSelectedItems()
|
||||||
|
if (selectedItems.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val selectedPaths = selectedItems.map { it.path } as ArrayList<String>
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.cab_rename).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.getIsInRecycleBin() == false
|
findItem(R.id.cab_rename).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.getIsInRecycleBin() == false
|
||||||
findItem(R.id.cab_open_with).isVisible = isOneItemSelected()
|
findItem(R.id.cab_open_with).isVisible = isOneItemSelected()
|
||||||
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.size > 0
|
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.size > 0
|
||||||
findItem(R.id.cab_restore_recycle_bin_files).isVisible = getSelectedPaths().all { it.startsWith(activity.filesDir.absolutePath) }
|
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.filesDir.absolutePath) }
|
||||||
|
|
||||||
checkHideBtnVisibility(this)
|
checkHideBtnVisibility(this, selectedItems)
|
||||||
checkFavoriteBtnVisibility(this)
|
checkFavoriteBtnVisibility(this, selectedItems)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +158,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
super.onViewRecycled(holder)
|
super.onViewRecycled(holder)
|
||||||
if (!activity.isDestroyed) {
|
if (!activity.isDestroyed) {
|
||||||
val itemView = holder.itemView
|
val itemView = holder.itemView
|
||||||
visibleItemPaths.remove(itemView?.photo_name?.tag)
|
visibleItemPaths.remove(itemView.photo_name?.tag)
|
||||||
val tmb = itemView?.medium_thumbnail
|
val tmb = itemView.medium_thumbnail
|
||||||
if (tmb != null) {
|
if (tmb != null) {
|
||||||
Glide.with(activity).clear(tmb)
|
Glide.with(activity).clear(tmb)
|
||||||
}
|
}
|
||||||
|
@ -162,10 +168,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
|
|
||||||
fun isASectionTitle(position: Int) = media.getOrNull(position) is ThumbnailSection
|
fun isASectionTitle(position: Int) = media.getOrNull(position) is ThumbnailSection
|
||||||
|
|
||||||
private fun checkHideBtnVisibility(menu: Menu) {
|
private fun checkHideBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {
|
||||||
var hiddenCnt = 0
|
var hiddenCnt = 0
|
||||||
var unhiddenCnt = 0
|
var unhiddenCnt = 0
|
||||||
getSelectedItems().forEach {
|
selectedItems.forEach {
|
||||||
if (it.isHidden()) {
|
if (it.isHidden()) {
|
||||||
hiddenCnt++
|
hiddenCnt++
|
||||||
} else {
|
} else {
|
||||||
|
@ -173,15 +179,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val isInRecycleBin = getSelectedItems().firstOrNull()?.getIsInRecycleBin() == true
|
val isInRecycleBin = selectedItems.firstOrNull()?.getIsInRecycleBin() == true
|
||||||
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 && !isInRecycleBin
|
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 && !isInRecycleBin
|
||||||
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin
|
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkFavoriteBtnVisibility(menu: Menu) {
|
private fun checkFavoriteBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {
|
||||||
var favoriteCnt = 0
|
var favoriteCnt = 0
|
||||||
var nonFavoriteCnt = 0
|
var nonFavoriteCnt = 0
|
||||||
getSelectedItems().forEach {
|
selectedItems.forEach {
|
||||||
if (it.isFavorite) {
|
if (it.isFavorite) {
|
||||||
favoriteCnt++
|
favoriteCnt++
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue