Implement simple stats screen (#8068)

* Implement simple stats screen

* Review Changes

* Some other changes

* Remove unused

* Small changes

* Review Changes 2 + Cleanup

* Review Changes 3

* Cleanup leftovers

* Optimize imports
This commit is contained in:
AntsyLich
2022-11-27 02:50:26 +06:00
committed by GitHub
parent e14909fff4
commit 3d7591feca
26 changed files with 695 additions and 14 deletions

View File

@@ -107,6 +107,19 @@ class DownloadCache(
return false
}
/**
* Returns the amount of downloaded chapters.
*/
fun getTotalDownloadCount(): Int {
renewCache()
return rootDownloadsDir.sourceDirs.values.sumOf { sourceDir ->
sourceDir.mangaDirs.values.sumOf { mangaDir ->
mangaDir.chapterDirs.size
}
}
}
/**
* Returns the amount of downloaded chapters for a manga.
*

View File

@@ -205,6 +205,13 @@ class DownloadManager(
.firstOrNull { it.chapter.id == chapter.id && it.chapter.manga_id == chapter.mangaId }
}
/**
* Returns the amount of downloaded chapters.
*/
fun getDownloadCount(): Int {
return cache.getTotalDownloadCount()
}
/**
* Returns the amount of downloaded chapters for a manga.
*

View File

@@ -24,6 +24,7 @@ import okhttp3.OkHttpClient
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import eu.kanade.domain.track.model.Track as DomainTrack
abstract class TrackService(val id: Long) {
@@ -59,6 +60,11 @@ abstract class TrackService(val id: Long) {
abstract fun getScoreList(): List<String>
// TODO: Store all scores as 10 point in the future maybe?
open fun get10PointScore(track: DomainTrack): Float {
return track.score
}
open fun indexToScore(index: Int): Float {
return index.toFloat()
}

View File

@@ -11,6 +11,7 @@ import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy
import eu.kanade.domain.track.model.Track as DomainTrack
class Anilist(private val context: Context, id: Long) : TrackService(id) {
@@ -94,6 +95,11 @@ class Anilist(private val context: Context, id: Long) : TrackService(id) {
}
}
override fun get10PointScore(track: DomainTrack): Float {
// Score is stored in 100 point format
return track.score / 10f
}
override fun indexToScore(index: Int): Float {
return when (scorePreference.get()) {
// 10 point