Skip to content

Commit

Permalink
Some minors renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Jun 13, 2024
1 parent 041cb25 commit 4cf8a20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import kotlin.math.min

class MoveAdapter @Inject constructor() : ListAdapter<Folder, FolderViewHolder>(FolderDiffCallback()) {

private inline val folders: List<Folder> get() = currentList

private var currentFolderId: String? = null

private lateinit var onFolderClicked: (folderId: String) -> Unit
Expand All @@ -55,7 +53,7 @@ class MoveAdapter @Inject constructor() : ListAdapter<Folder, FolderViewHolder>(
return this
}

override fun getItemCount(): Int = runCatchingRealm { folders.size }.getOrDefault(0)
override fun getItemCount(): Int = runCatchingRealm { currentList.size }.getOrDefault(0)

override fun getItemViewType(position: Int): Int = R.layout.item_selectable_folder

Expand All @@ -67,14 +65,14 @@ class MoveAdapter @Inject constructor() : ListAdapter<Folder, FolderViewHolder>(

override fun onBindViewHolder(holder: FolderViewHolder, position: Int, payloads: MutableList<Any>) = runCatchingRealm {
if (payloads.firstOrNull() == Unit) {
(holder.binding as ItemSelectableFolderBinding).root.setSelectedState(currentFolderId == folders[position].id)
(holder.binding as ItemSelectableFolderBinding).root.setSelectedState(currentFolderId == currentList[position].id)
} else {
super.onBindViewHolder(holder, position, payloads)
}
}.getOrDefault(Unit)

override fun onBindViewHolder(holder: FolderViewHolder, position: Int) = with(holder.binding) {
(this as ItemSelectableFolderBinding).root.displayFolder(folders[position])
(this as ItemSelectableFolderBinding).root.displayFolder(currentList[position])
}

private fun SelectableItemView.displayFolder(folder: Folder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class MoveFragment : Fragment() {
}

private fun observeSearchResults() {
moveViewModel.filterResults.observe(viewLifecycleOwner) { (folders, currentFolderId) ->
moveAdapter.setFolders(folders, currentFolderId, isSearching = true)
moveViewModel.filterResults.observe(viewLifecycleOwner) { (filteredFolders, currentFolderId) ->
moveAdapter.setFolders(filteredFolders, currentFolderId, isSearching = true)
}
}

Expand Down

0 comments on commit 4cf8a20

Please sign in to comment.