diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt index ffdb223e9..7caa96d6b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/HiddenFoldersActivity.kt @@ -7,6 +7,8 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.adapters.ManageHiddenFoldersAdapter +import com.simplemobiletools.gallery.extensions.addNoMedia import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getNoMediaFolders import kotlinx.android.synthetic.main.activity_manage_folders.* @@ -25,6 +27,10 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { beVisibleIf(folders.isEmpty()) setTextColor(config.textColor) } + + val adapter = ManageHiddenFoldersAdapter(this, folders, this, manage_folders_list) {} + adapter.setupDragListener(true) + manage_folders_list.adapter = adapter } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -46,7 +52,11 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { private fun addFolder() { FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { - + Thread { + addNoMedia(it) { + updateFolders() + } + }.start() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt new file mode 100644 index 000000000..4126a5c21 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt @@ -0,0 +1,94 @@ +package com.simplemobiletools.gallery.adapters + +import android.view.Menu +import android.view.View +import android.view.ViewGroup +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter +import com.simplemobiletools.commons.extensions.isPathOnSD +import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener +import com.simplemobiletools.commons.views.MyRecyclerView +import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.removeNoMedia +import kotlinx.android.synthetic.main.item_manage_folder.view.* +import java.io.File +import java.util.* + +class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList, val listener: RefreshRecyclerViewListener?, + recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { + + private val config = activity.config + + override fun getActionMenuId() = R.menu.cab_hidden_folders + + override fun prepareActionMode(menu: Menu) {} + + override fun prepareItemSelection(view: View) {} + + override fun markItemSelection(select: Boolean, view: View?) { + view?.manage_folder_holder?.isSelected = select + } + + override fun actionItemPressed(id: Int) { + when (id) { + R.id.cab_unhide -> tryUnhideFolders() + } + } + + override fun getSelectableItemCount() = folders.size + + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int) = createViewHolder(R.layout.item_manage_folder, parent) + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val folder = folders[position] + val view = holder.bindView(folder) { itemView, layoutPosition -> + setupView(itemView, folder) + } + bindViewHolder(holder, position, view) + } + + override fun getItemCount() = folders.size + + private fun setupView(view: View, folder: String) { + view.apply { + manage_folder_title.apply { + text = folder + setTextColor(config.textColor) + } + } + } + + private fun tryUnhideFolders() { + val removeFolders = ArrayList(selectedPositions.size) + + val sdCardPaths = ArrayList() + selectedPositions.forEach { + if (activity.isPathOnSD(folders[it])) { + sdCardPaths.add(folders[it]) + } + } + + if (sdCardPaths.isNotEmpty()) { + activity.handleSAFDialog(File(sdCardPaths.first())) { + unhideFolders(removeFolders) + } + } else { + unhideFolders(removeFolders) + } + } + + private fun unhideFolders(removeFolders: ArrayList) { + selectedPositions.sortedDescending().forEach { + val folder = folders[it] + removeFolders.add(folder) + activity.removeNoMedia(folder) + } + + folders.removeAll(removeFolders) + removeSelectedItems() + if (folders.isEmpty()) { + listener?.refreshItems() + } + } +} diff --git a/app/src/main/res/menu/cab_hidden_folders.xml b/app/src/main/res/menu/cab_hidden_folders.xml new file mode 100644 index 000000000..3bc48d529 --- /dev/null +++ b/app/src/main/res/menu/cab_hidden_folders.xml @@ -0,0 +1,9 @@ + + + +