add search bar to folder picker at copy destination

This commit is contained in:
fatih ergin 2023-06-20 00:15:10 +03:00
parent e9ad0227ee
commit d7b29aa3f0
3 changed files with 110 additions and 3 deletions

View file

@ -1,6 +1,11 @@
package com.simplemobiletools.gallery.pro.dialogs package com.simplemobiletools.gallery.pro.dialogs
import android.graphics.Color
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.ImageView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -9,6 +14,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.commons.views.MySearchMenu
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.adapters.DirectoryAdapter import com.simplemobiletools.gallery.pro.adapters.DirectoryAdapter
import com.simplemobiletools.gallery.pro.extensions.* import com.simplemobiletools.gallery.pro.extensions.*
@ -32,6 +38,10 @@ class PickDirectoryDialog(
private var isGridViewType = activity.config.viewTypeFolders == VIEW_TYPE_GRID private var isGridViewType = activity.config.viewTypeFolders == VIEW_TYPE_GRID
private var showHidden = activity.config.shouldShowHidden private var showHidden = activity.config.shouldShowHidden
private var currentPathPrefix = "" private var currentPathPrefix = ""
private val config = view.context.config
private val searchView = view.folder_search_view
private val searchEditText = view.findViewById<EditText>(R.id.top_toolbar_search)
private val searchViewAppBarLayout = view.findViewById<View>(R.id.top_app_bar_layout)
init { init {
(view.directories_grid.layoutManager as MyGridLayoutManager).apply { (view.directories_grid.layoutManager as MyGridLayoutManager).apply {
@ -41,6 +51,8 @@ class PickDirectoryDialog(
view.directories_fastscroller.updateColors(activity.getProperPrimaryColor()) view.directories_fastscroller.updateColors(activity.getProperPrimaryColor())
configureSearchView()
val builder = activity.getAlertDialogBuilder() val builder = activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
@ -72,6 +84,75 @@ class PickDirectoryDialog(
fetchDirectories(false) fetchDirectories(false)
} }
private fun configureSearchView() = with(searchView) {
updateHintText(context.getString(R.string.search_folders))
searchEditText.imeOptions = EditorInfo.IME_ACTION_DONE
toggleHideOnScroll(!config.scrollHorizontally)
setupMenu()
setSearchViewListeners()
updateSearchViewUi()
}
private fun MySearchMenu.updateSearchViewUi() {
getToolbar().beInvisible()
updateColors()
setBackgroundColor(Color.TRANSPARENT)
searchViewAppBarLayout.setBackgroundColor(Color.TRANSPARENT)
}
private fun MySearchMenu.setSearchViewListeners() {
onSearchOpenListener = {
updateSearchViewLeftIcon(R.drawable.ic_cross_vector)
}
onSearchClosedListener = {
searchEditText.clearFocus()
activity.hideKeyboard(searchEditText)
updateSearchViewLeftIcon(R.drawable.ic_search_vector)
}
onSearchTextChangedListener = { text ->
filterFolderListBySearchQuery(text)
}
}
private fun updateSearchViewLeftIcon(iconResId: Int) = with(view.findViewById<ImageView>(R.id.top_toolbar_search_icon)) {
post {
setImageResource(iconResId)
}
}
private fun filterFolderListBySearchQuery(query: String) {
val adapter = view.directories_grid.adapter as? DirectoryAdapter
var dirsToShow = allDirectories
if (query.isNotEmpty()) {
dirsToShow = dirsToShow.filter { it.name.contains(query, true) }.sortedBy { !it.name.startsWith(query, true) }
.toMutableList() as ArrayList
}
checkPlaceholderVisibility(dirsToShow)
val filteredFolderListUpdated = adapter?.dirs != dirsToShow
if (filteredFolderListUpdated) {
adapter?.updateDirs(dirsToShow)
view.directories_grid.apply {
post {
scrollToPosition(0)
}
}
}
}
private fun checkPlaceholderVisibility(dirs: ArrayList<Directory>) = with(view) {
directories_empty_placeholder.beVisibleIf(dirs.isEmpty())
if (folder_search_view.isSearchOpen) {
directories_empty_placeholder.text = context.getString(R.string.no_items_found)
}
directories_fastscroller.beVisibleIf(directories_empty_placeholder.isGone())
}
private fun fetchDirectories(forceShowHiddenAndExcluded: Boolean) { private fun fetchDirectories(forceShowHiddenAndExcluded: Boolean) {
activity.getCachedDirectories(forceShowHidden = forceShowHiddenAndExcluded, forceShowExcluded = forceShowHiddenAndExcluded) { activity.getCachedDirectories(forceShowHidden = forceShowHiddenAndExcluded, forceShowExcluded = forceShowHiddenAndExcluded) {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
@ -143,7 +224,9 @@ class PickDirectoryDialog(
} }
private fun backPressed() { private fun backPressed() {
if (activity.config.groupDirectSubfolders) { if (searchView.isSearchOpen) {
searchView.closeSearch()
} else if (activity.config.groupDirectSubfolders) {
if (currentPathPrefix.isEmpty()) { if (currentPathPrefix.isEmpty()) {
dialog?.dismiss() dialog?.dismiss()
} else { } else {

View file

@ -9,12 +9,35 @@
android:id="@+id/directories_grid_holder" android:id="@+id/directories_grid_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="@dimen/activity_margin"> android:minHeight="@dimen/directory_picker_dialog_min_height"
android:paddingTop="@dimen/medium_margin">
<com.simplemobiletools.commons.views.MySearchMenu
android:id="@+id/folder_search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/medium_margin" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/directories_empty_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/folder_search_view"
android:alpha="0.8"
android:gravity="center_horizontal"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/no_media_with_filters"
android:textSize="@dimen/bigger_text_size"
android:textStyle="italic"
android:visibility="gone" />
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller <com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
android:id="@+id/directories_fastscroller" android:id="@+id/directories_fastscroller"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:layout_below="@+id/directories_empty_placeholder">
<com.simplemobiletools.commons.views.MyRecyclerView <com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/directories_grid" android:id="@+id/directories_grid"

View file

@ -26,4 +26,5 @@
<dimen name="full_brush_size">40dp</dimen> <dimen name="full_brush_size">40dp</dimen>
<dimen name="lock_padding">30dp</dimen> <dimen name="lock_padding">30dp</dimen>
<dimen name="sample_thumbnail_size">180dp</dimen> <dimen name="sample_thumbnail_size">180dp</dimen>
<dimen name="directory_picker_dialog_min_height">180dp</dimen>
</resources> </resources>