@@ -12,6 +12,7 @@ import android.view.View
1212import androidx.lifecycle.lifecycleScope
1313import com.afollestad.sectionedrecyclerview.SectionedViewHolder
1414import com.nextcloud.android.common.ui.theme.utils.ColorRole
15+ import com.nextcloud.common.NextcloudClient
1516import com.nextcloud.model.SearchResultEntryType
1617import com.nextcloud.utils.CalendarEventManager
1718import com.nextcloud.utils.ContactManager
@@ -47,6 +48,7 @@ class UnifiedSearchItemViewHolder(
4748
4849 private val contactManager = ContactManager (context)
4950 private val calendarEventManager = CalendarEventManager (context)
51+ private var cachedClient: NextcloudClient ? = null
5052
5153 fun bind (entry : SearchResultEntry ) {
5254 binding.title.text = entry.title
@@ -61,20 +63,21 @@ class UnifiedSearchItemViewHolder(
6163 val entryType = entry.getType()
6264 viewThemeUtils.platform.colorImageView(binding.thumbnail, ColorRole .PRIMARY )
6365
64- fragment.lifecycleScope.launch(Dispatchers .IO ) {
65- val client =
66- fragment.getTypedActivity(FileActivity ::class .java)?.clientRepository?.getNextcloudClient()
66+ val client = cachedClient
67+ if (client != null ) {
68+ loadThumbnailUrl(client, entry, entryType)
69+ } else {
70+ fragment.lifecycleScope.launch(Dispatchers .IO ) {
71+ val newClient = fragment.getTypedActivity(FileActivity ::class .java)
72+ ?.clientRepository
73+ ?.getNextcloudClient()
6774 ? : return @launch
6875
69- withContext(Dispatchers .Main ) {
70- GlideHelper .loadIntoImageView(
71- context,
72- client,
73- entry.thumbnailUrl,
74- binding.thumbnail,
75- entryType.iconId(),
76- circleCrop = entry.rounded
77- )
76+ cachedClient = newClient
77+
78+ withContext(Dispatchers .Main ) {
79+ loadThumbnailUrl(newClient, entry, entryType)
80+ }
7881 }
7982 }
8083
@@ -92,6 +95,17 @@ class UnifiedSearchItemViewHolder(
9295 }
9396 }
9497
98+ private fun loadThumbnailUrl (client : NextcloudClient , entry : SearchResultEntry , entryType : SearchResultEntryType ) {
99+ GlideHelper .loadIntoImageView(
100+ context,
101+ client,
102+ entry.thumbnailUrl,
103+ binding.thumbnail,
104+ entryType.iconId(),
105+ circleCrop = entry.rounded
106+ )
107+ }
108+
95109 private fun searchEntryOnClick (entry : SearchResultEntry , entryType : SearchResultEntryType ) {
96110 if (supportsOpeningCalendarContactsLocally) {
97111 when (entryType) {
0 commit comments