add a function for updating directory adapter

This commit is contained in:
tibbi 2017-05-25 21:23:59 +02:00
parent faf1e19a87
commit ddb6310937
2 changed files with 12 additions and 2 deletions

View file

@ -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)
}

View file

@ -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<Directory>, val listener: DirOperationsListener?, val itemClick: (Directory) -> Unit) :
class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Directory>, val listener: DirOperationsListener?, val itemClick: (Directory) -> Unit) :
RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() {
val multiSelector = MultiSelector()
@ -345,6 +345,11 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
override fun getItemCount() = dirs.size
fun updateDirs(newDirs: ArrayList<Directory>) {
dirs = newDirs
notifyDataSetChanged()
}
fun selectItem(pos: Int) {
toggleItemSelection(true, pos)
}