Skip to content

Commit b2f65a4

Browse files
committed
allow opening folders from search results
1 parent 1308e1b commit b2f65a4

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
160160

161161
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
162162
val fileDirItem = listItems[position]
163-
holder.bindView(fileDirItem, !fileDirItem.isSectionTitle, !fileDirItem.isSectionTitle) { itemView, layoutPosition ->
163+
holder.bindView(fileDirItem, true, !fileDirItem.isSectionTitle) { itemView, layoutPosition ->
164164
setupView(itemView, fileDirItem)
165165
}
166166
bindViewHolder(holder)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
175175

176176
storedItems = items
177177
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) {
178-
itemClicked(it as FileDirItem)
178+
if ((it as? ListItem)?.isSectionTitle == true) {
179+
openDirectory(it.mPath)
180+
searchClosed()
181+
} else {
182+
itemClicked(it as FileDirItem)
183+
}
179184
}.apply {
180185
setupZoomListener(zoomListener)
181186
items_list.adapter = this
@@ -278,11 +283,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
278283

279284
private fun itemClicked(item: FileDirItem) {
280285
if (item.isDirectory) {
281-
(activity as? MainActivity)?.apply {
282-
skipItemUpdating = isSearchOpen
283-
openedDirectory()
284-
}
285-
openPath(item.path)
286+
openDirectory(item.path)
286287
} else {
287288
val path = item.path
288289
if (isGetContentIntent) {
@@ -299,6 +300,14 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
299300
}
300301
}
301302

303+
private fun openDirectory(path: String) {
304+
(activity as? MainActivity)?.apply {
305+
skipItemUpdating = isSearchOpen
306+
openedDirectory()
307+
}
308+
openPath(path)
309+
}
310+
302311
fun searchQueryChanged(text: String) {
303312
val searchText = text.trim()
304313
lastSearchedText = searchText
@@ -337,7 +346,8 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
337346
files.forEach {
338347
val parent = it.mPath.getParentPath()
339348
if (parent != previousParent && context != null) {
340-
listItems.add(ListItem("", context!!.humanizePath(parent), false, 0, 0, 0, true))
349+
val sectionTitle = ListItem(parent, context!!.humanizePath(parent), false, 0, 0, 0, true)
350+
listItems.add(sectionTitle)
341351
previousParent = parent
342352
}
343353
listItems.add(it)

app/src/main/res/layout/item_section.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
android:id="@+id/item_section"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7+
android:background="?attr/selectableItemBackground"
78
android:paddingStart="@dimen/normal_margin"
89
android:paddingTop="@dimen/activity_margin"
910
android:paddingEnd="@dimen/normal_margin"

0 commit comments

Comments
 (0)