|
|
|
@ -5,25 +5,27 @@ import org.koitharu.kotatsu.core.model.findById
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
import org.koitharu.kotatsu.details.data.MangaDetails
|
|
|
|
import org.koitharu.kotatsu.details.data.MangaDetails
|
|
|
|
import org.koitharu.kotatsu.details.data.ReadingTime
|
|
|
|
import org.koitharu.kotatsu.details.data.ReadingTime
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.stats.data.StatsRepository
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Inject
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
|
|
|
|
|
|
|
|
class ReadingTimeUseCase @Inject constructor(
|
|
|
|
class ReadingTimeUseCase @Inject constructor(
|
|
|
|
private val settings: AppSettings,
|
|
|
|
private val settings: AppSettings,
|
|
|
|
|
|
|
|
private val statsRepository: StatsRepository,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
fun invoke(manga: MangaDetails?, branch: String?, history: MangaHistory?): ReadingTime? {
|
|
|
|
suspend fun invoke(manga: MangaDetails?, branch: String?, history: MangaHistory?): ReadingTime? {
|
|
|
|
if (!settings.isReadingTimeEstimationEnabled) {
|
|
|
|
if (!settings.isReadingTimeEstimationEnabled) {
|
|
|
|
return null
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FIXME MAXIMUM HARDCODE!!! To do calculation with user's page read speed and his favourites/history mangas average pages in chapter
|
|
|
|
|
|
|
|
val chapters = manga?.chapters?.get(branch)
|
|
|
|
val chapters = manga?.chapters?.get(branch)
|
|
|
|
if (chapters.isNullOrEmpty()) {
|
|
|
|
if (chapters.isNullOrEmpty()) {
|
|
|
|
return null
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val isOnHistoryBranch = history != null && chapters.findById(history.chapterId) != null
|
|
|
|
val isOnHistoryBranch = history != null && chapters.findById(history.chapterId) != null
|
|
|
|
// Impossible task, I guess. Good luck on this.
|
|
|
|
// Impossible task, I guess. Good luck on this.
|
|
|
|
var averageTimeSec: Int = 20 * 10 * chapters.size // 20 pages, 10 seconds per page
|
|
|
|
var averageTimeSec: Int = 20 /* pages */ * getSecondsPerPage(manga.id) * chapters.size
|
|
|
|
if (isOnHistoryBranch) {
|
|
|
|
if (isOnHistoryBranch) {
|
|
|
|
averageTimeSec = (averageTimeSec * (1f - checkNotNull(history).percent)).roundToInt()
|
|
|
|
averageTimeSec = (averageTimeSec * (1f - checkNotNull(history).percent)).roundToInt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -36,4 +38,16 @@ class ReadingTimeUseCase @Inject constructor(
|
|
|
|
isContinue = isOnHistoryBranch,
|
|
|
|
isContinue = isOnHistoryBranch,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun getSecondsPerPage(mangaId: Long): Int {
|
|
|
|
|
|
|
|
var time = if (settings.isStatsEnabled) {
|
|
|
|
|
|
|
|
TimeUnit.MILLISECONDS.toSeconds(statsRepository.getTimePerPage(mangaId)).toInt()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time == 0) {
|
|
|
|
|
|
|
|
time = 10 // default
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return time
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|