From ddb63109376dbc2d4a9c40a0c5d8a449c9228016 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 25 May 2017 21:23:59 +0200 Subject: [PATCH] add a function for updating directory adapter --- .../simplemobiletools/gallery/activities/MainActivity.kt | 7 ++++++- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 7 ++++++- 2 files changed, 12 insertions(+), 2 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 67e00e98a..e3017393e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -343,7 +343,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { itemClicked(it.path) } - directories_grid.adapter = adapter + val currAdapter = directories_grid.adapter + if (currAdapter != null) { + (currAdapter as DirectoryAdapter).updateDirs(mDirs) + } else { + directories_grid.adapter = adapter + } directories_fastscroller.setViews(directories_grid, directories_refresh_layout) } 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 cdaf426c9..2acc9dd99 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.directory_tmb.view.* import java.io.File import java.util.* -class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList, val listener: DirOperationsListener?, val itemClick: (Directory) -> Unit) : +class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, val listener: DirOperationsListener?, val itemClick: (Directory) -> Unit) : RecyclerView.Adapter() { val multiSelector = MultiSelector() @@ -345,6 +345,11 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList) { + dirs = newDirs + notifyDataSetChanged() + } + fun selectItem(pos: Int) { toggleItemSelection(true, pos) }