App was a little slow with livedata.
This commit is contained in:
parent
4901e7174c
commit
3b6891c84a
@ -107,7 +107,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
private var lastFetchDone: Boolean = false
|
||||
private var hiddenTags: List<String> = emptyList()
|
||||
|
||||
|
||||
private lateinit var tabNewBadge: TextBadgeItem
|
||||
private lateinit var tabArchiveBadge: TextBadgeItem
|
||||
private lateinit var tabStarredBadge: TextBadgeItem
|
||||
@ -128,7 +127,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
private var badgeAll: Int = -1
|
||||
private var badgeFavs: Int = -1
|
||||
|
||||
|
||||
private lateinit var tagsBadge: Map<Long, Int>
|
||||
|
||||
private lateinit var db: AppDatabase
|
||||
@ -521,7 +519,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val filteredHiddenTags: List<Tag> = maybeTags.filter { hiddenTags.contains(it.tag) }
|
||||
val filteredHiddenTags: List<Tag> =
|
||||
maybeTags.filter { hiddenTags.contains(it.tag) }
|
||||
tagsBadge = filteredHiddenTags.map {
|
||||
val gd = GradientDrawable()
|
||||
val color = try {
|
||||
@ -664,7 +663,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
if (maybeDrawerData.sources != null) {
|
||||
thread {
|
||||
val sourceEntities = maybeDrawerData.sources.map { it.toEntity(this@HomeActivity) }
|
||||
val sourceEntities =
|
||||
maybeDrawerData.sources.map { it.toEntity(this@HomeActivity) }
|
||||
db.drawerDataDao().insertAllSources(*sourceEntities.toTypedArray())
|
||||
}
|
||||
}
|
||||
@ -730,20 +730,13 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
)
|
||||
)
|
||||
|
||||
db.drawerDataDao().tags().observeForever { tags ->
|
||||
db.drawerDataDao().sources().observeForever { sources ->
|
||||
var drawerData = DrawerData(null, null)
|
||||
if (tags != null) {
|
||||
drawerData = drawerData.copy(tags = tags.map { it.toView() })
|
||||
}
|
||||
if (sources != null) {
|
||||
drawerData = drawerData.copy(sources = sources.map { it.toView() })
|
||||
}
|
||||
thread {
|
||||
var drawerData = DrawerData(db.drawerDataDao().tags().map { it.toView() },
|
||||
db.drawerDataDao().sources().map { it.toView() })
|
||||
handleDrawerData(drawerData, loadedFromCache = true)
|
||||
drawerApiCalls(drawerData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun reloadLayoutManager() {
|
||||
val currentManager = recyclerView.layoutManager
|
||||
|
@ -12,10 +12,10 @@ import apps.amine.bou.readerforselfoss.persistence.entities.TagEntity
|
||||
@Dao
|
||||
interface DrawerDataDao {
|
||||
@Query("SELECT * FROM tags")
|
||||
fun tags(): LiveData<List<TagEntity>>
|
||||
fun tags(): List<TagEntity>
|
||||
|
||||
@Query("SELECT * FROM sources")
|
||||
fun sources(): LiveData<List<SourceEntity>>
|
||||
fun sources(): List<SourceEntity>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertAllTags(vararg tags: TagEntity)
|
||||
|
Loading…
Reference in New Issue
Block a user