GC manga updates

This commit is contained in:
Koitharu
2023-08-09 13:17:13 +03:00
parent a07117087a
commit 4b9f4f9af2
3 changed files with 26 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import org.koitharu.kotatsu.core.db.MangaDatabase
import org.koitharu.kotatsu.core.db.entity.MangaEntity
import org.koitharu.kotatsu.core.db.entity.toManga
@@ -33,6 +34,8 @@ class TrackingRepository @Inject constructor(
private val db: MangaDatabase,
) {
private var isGcCalled = false
suspend fun getNewChaptersCount(mangaId: Long): Int {
return db.tracksDao.findNewChapters(mangaId) ?: 0
}
@@ -43,12 +46,14 @@ class TrackingRepository @Inject constructor(
fun observeUpdatedMangaCount(): Flow<Int> {
return db.tracksDao.observeNewChapters().map { list -> list.count { it > 0 } }
.onStart { gcIfNotCalled() }
}
fun observeUpdatedManga(): Flow<List<Manga>> {
return db.tracksDao.observeUpdatedManga()
.mapItems { it.toManga() }
.distinctUntilChanged()
.onStart { gcIfNotCalled() }
}
suspend fun getTracks(mangaList: Collection<Manga>): List<MangaTracking> {
@@ -94,6 +99,8 @@ class TrackingRepository @Inject constructor(
val countersMap = counters.toMutableMap()
entities.map { x -> x.toTrackingLogItem(countersMap) }
}
}.onStart {
gcIfNotCalled()
}
}
@@ -216,5 +223,12 @@ class TrackingRepository @Inject constructor(
)
}
private suspend fun gcIfNotCalled() {
if (!isGcCalled) {
gc()
isGcCalled = true
}
}
private fun Collection<MangaEntity>.toMangaList() = map { it.toManga(emptySet()) }
}

View File

@@ -8,6 +8,7 @@ import android.view.View
import androidx.core.view.MenuProvider
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.ui.dialog.CheckBoxAlertDialog
import org.koitharu.kotatsu.tracker.ui.updates.UpdatesActivity
class FeedMenuProvider(
private val snackbarHost: View,
@@ -40,6 +41,11 @@ class FeedMenuProvider(
true
}
R.id.action_updated -> {
context.startActivity(UpdatesActivity.newIntent(context))
true
}
else -> false
}
}

View File

@@ -3,6 +3,12 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_updated"
android:orderInCategory="50"
android:title="@string/updated"
app:showAsAction="never" />
<item
android:id="@+id/action_update"
android:orderInCategory="50"