@@ -15,8 +15,6 @@ package com.owncloud.android.ui.adapter
1515
1616import android.annotation.SuppressLint
1717import android.content.Context
18- import android.os.Handler
19- import android.os.Looper
2018import android.view.LayoutInflater
2119import android.view.View
2220import android.view.ViewGroup
@@ -68,7 +66,6 @@ class GalleryAdapter(
6866
6967 // (section, row) -> unique stable ID for that row
7068 private val rowIdMap = mutableMapOf<Pair <Int , Int >, Long > ()
71- private var nextRowId = 0L
7269
7370 private var cachedAllFiles: List <OCFile >? = null
7471 private var cachedFilesCount: Int = 0
@@ -120,11 +117,12 @@ class GalleryAdapter(
120117 galleryItem.rows.forEachIndexed { rowIndex, row ->
121118 val position = sectionIndex to rowIndex
122119
123- // Create stable ID for this row
124- val rowStableId = row.files.firstOrNull()?.fileId ? : nextRowId++
125- rowIdMap[position] = rowStableId
120+ // since row can contain files two to five use first files id as adapter id
121+ row.files.firstOrNull()?.fileId?.let { firstFileId ->
122+ rowIdMap[position] = firstFileId
123+ }
126124
127- // Map each file to its position
125+ // map all row files
128126 row.files.forEach { file ->
129127 filePositionMap[file.fileId] = position
130128 }
@@ -346,10 +344,8 @@ class GalleryAdapter(
346344 val allFiles = getAllFiles()
347345 allFiles.firstOrNull { it.remotePath == remotePath }?.also { file ->
348346 file.isFavorite = favorite
349- Handler (Looper .getMainLooper()).post {
350- files = allFiles.toGalleryItems()
351- notifyItemChanged(file)
352- }
347+ files = allFiles.toGalleryItems()
348+ notifyItemChanged(file)
353349 }
354350 }
355351
0 commit comments