Skip to content

Commit c9ec160

Browse files
committed
fix: App adapter refreshing on create
Signed-off-by: LooKeR <iamlooker@proton.me>
1 parent af02fd1 commit c9ec160

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

app/src/main/kotlin/com/looker/droidify/database/CursorOwner.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import com.looker.droidify.datastore.SettingsRepository
99
import com.looker.droidify.datastore.model.SortOrder
1010
import com.looker.droidify.model.ProductItem
1111
import dagger.hilt.android.AndroidEntryPoint
12-
import kotlinx.coroutines.runBlocking
1312
import javax.inject.Inject
13+
import kotlinx.coroutines.runBlocking
1414

1515
@AndroidEntryPoint
1616
class CursorOwner : Fragment(), LoaderManager.LoaderCallbacks<Cursor> {
@@ -21,28 +21,28 @@ class CursorOwner : Fragment(), LoaderManager.LoaderCallbacks<Cursor> {
2121
sealed interface Request {
2222
val id: Int
2323

24-
class Available(
24+
data class Available(
2525
val searchQuery: String,
2626
val section: ProductItem.Section,
2727
val order: SortOrder,
2828
override val id: Int = 1,
2929
) : Request
3030

31-
class Installed(
31+
data class Installed(
3232
val searchQuery: String,
3333
val section: ProductItem.Section,
3434
val order: SortOrder,
3535
override val id: Int = 2,
3636
) : Request
3737

38-
class Updates(
38+
data class Updates(
3939
val searchQuery: String,
4040
val section: ProductItem.Section,
4141
val order: SortOrder,
4242
override val id: Int = 3,
4343
) : Request
4444

45-
object Repositories : Request {
45+
data object Repositories : Request {
4646
override val id = 4
4747
}
4848
}

app/src/main/kotlin/com/looker/droidify/ui/appList/AppListAdapter.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,11 @@ class AppListAdapter(
9191
}
9292
}
9393

94-
private val repositories: HashMap<Long, Repository> = HashMap()
95-
96-
fun updateRepos(repos: List<Repository>) {
97-
repos.forEach {
98-
repositories[it.id] = it
94+
var repositories: Map<Long, Repository> = emptyMap()
95+
set(value) {
96+
field = value
97+
notifyDataSetChanged()
9998
}
100-
notifyDataSetChanged()
101-
}
10299

103100
var emptyText: String = ""
104101
@SuppressLint("NotifyDataSetChanged")
@@ -161,7 +158,7 @@ class AppListAdapter(
161158
holder.name.text = productItem.name
162159
holder.summary.text = productItem.summary
163160
holder.summary.isVisible = productItem.summary.isNotEmpty()
164-
&& productItem.name != productItem.summary
161+
&& productItem.name != productItem.summary
165162
val repository = repositories[productItem.repositoryId]
166163
if (repository != null) {
167164
val iconUrl = productItem.icon(view = holder.icon, repository = repository)

app/src/main/kotlin/com/looker/droidify/ui/appList/AppListFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ class AppListFragment() : Fragment(), CursorOwner.Callback {
144144
updateRequest()
145145

146146
viewLifecycleOwner.lifecycleScope.launch {
147-
repeatOnLifecycle(Lifecycle.State.RESUMED) {
147+
repeatOnLifecycle(Lifecycle.State.STARTED) {
148148
launch {
149149
viewModel.reposStream.collect { repos ->
150-
appListAdapter.updateRepos(repos)
150+
appListAdapter.repositories = repos.associateBy { it.id }
151151
}
152152
}
153153
launch {

0 commit comments

Comments
 (0)