Drop humanize and guava(an older version still gets compiled in), use custom humanize solution for E-Hentai updater stats
This commit is contained in:
parent
fe798e40cb
commit
528f6c7f65
@ -322,9 +322,6 @@ dependencies {
|
|||||||
releaseImplementation "com.ms-square:debugoverlay-no-op:$debug_overlay_version"
|
releaseImplementation "com.ms-square:debugoverlay-no-op:$debug_overlay_version"
|
||||||
testImplementation "com.ms-square:debugoverlay-no-op:$debug_overlay_version"
|
testImplementation "com.ms-square:debugoverlay-no-op:$debug_overlay_version"
|
||||||
|
|
||||||
// Humanize (EH) used for E-Hentai updater statistics
|
|
||||||
implementation 'com.github.mfornos:humanize-slim:1.2.2'
|
|
||||||
|
|
||||||
// RatingBar (SY)
|
// RatingBar (SY)
|
||||||
implementation 'me.zhanghai.android.materialratingbar:library:1.4.0'
|
implementation 'me.zhanghai.android.materialratingbar:library:1.4.0'
|
||||||
|
|
||||||
@ -332,8 +329,6 @@ dependencies {
|
|||||||
implementation 'com.squareup.moshi:moshi:1.11.0'
|
implementation 'com.squareup.moshi:moshi:1.11.0'
|
||||||
|
|
||||||
implementation 'androidx.gridlayout:gridlayout:1.0.0'
|
implementation 'androidx.gridlayout:gridlayout:1.0.0'
|
||||||
|
|
||||||
implementation 'com.google.guava:guava:29.0-android'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.setting
|
package eu.kanade.tachiyomi.ui.setting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -45,6 +46,7 @@ import exh.metadata.metadata.base.getFlatMetadataForManga
|
|||||||
import exh.uconfig.WarnConfigureDialogController
|
import exh.uconfig.WarnConfigureDialogController
|
||||||
import exh.ui.login.LoginController
|
import exh.ui.login.LoginController
|
||||||
import exh.util.await
|
import exh.util.await
|
||||||
|
import exh.util.floor
|
||||||
import exh.util.nullIfBlank
|
import exh.util.nullIfBlank
|
||||||
import exh.util.trans
|
import exh.util.trans
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -57,11 +59,13 @@ import kotlinx.coroutines.withContext
|
|||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
import kotlin.time.days
|
import kotlin.time.days
|
||||||
import kotlin.time.hours
|
import kotlin.time.hours
|
||||||
|
import kotlin.time.milliseconds
|
||||||
|
import kotlin.time.minutes
|
||||||
|
import kotlin.time.seconds
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EH Settings fragment
|
* EH Settings fragment
|
||||||
@ -626,6 +630,7 @@ class SettingsEhController : SettingsController() {
|
|||||||
.cancelable(false)
|
.cancelable(false)
|
||||||
progress.show()
|
progress.show()
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTime::class)
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
val updateInfo = try {
|
val updateInfo = try {
|
||||||
val stats =
|
val stats =
|
||||||
@ -634,7 +639,7 @@ class SettingsEhController : SettingsController() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val statsText = if (stats != null) {
|
val statsText = if (stats != null) {
|
||||||
context.getString(R.string.gallery_updater_stats_text, Humanize.naturalTime(Date(stats.startTime)), stats.updateCount, stats.possibleUpdates)
|
context.getString(R.string.gallery_updater_stats_text, getRelativeTimeString(getRelativeTimeFromNow(stats.startTime.milliseconds), context), stats.updateCount, stats.possibleUpdates)
|
||||||
} else context.getString(R.string.gallery_updater_not_ran_yet)
|
} else context.getString(R.string.gallery_updater_not_ran_yet)
|
||||||
|
|
||||||
val allMeta = db.getFavoriteMangaWithMetadata().await().filter {
|
val allMeta = db.getFavoriteMangaWithMetadata().await().filter {
|
||||||
@ -644,7 +649,6 @@ class SettingsEhController : SettingsController() {
|
|||||||
?.raise<EHentaiSearchMetadata>()
|
?.raise<EHentaiSearchMetadata>()
|
||||||
}.toList()
|
}.toList()
|
||||||
|
|
||||||
@OptIn(ExperimentalTime::class)
|
|
||||||
fun metaInRelativeDuration(duration: Duration): Int {
|
fun metaInRelativeDuration(duration: Duration): Int {
|
||||||
val durationMs = duration.toLongMilliseconds()
|
val durationMs = duration.toLongMilliseconds()
|
||||||
return allMeta.asSequence().filter {
|
return allMeta.asSequence().filter {
|
||||||
@ -652,7 +656,6 @@ class SettingsEhController : SettingsController() {
|
|||||||
}.count()
|
}.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalTime::class)
|
|
||||||
statsText + "\n\n" + context.getString(
|
statsText + "\n\n" + context.getString(
|
||||||
R.string.gallery_updater_stats_time,
|
R.string.gallery_updater_stats_time,
|
||||||
metaInRelativeDuration(1.hours),
|
metaInRelativeDuration(1.hours),
|
||||||
@ -680,4 +683,78 @@ class SettingsEhController : SettingsController() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTime::class)
|
||||||
|
private fun getRelativeTimeFromNow(then: Duration): RelativeTime {
|
||||||
|
val now = System.currentTimeMillis().milliseconds
|
||||||
|
var period: Duration = now - then
|
||||||
|
val relativeTime = RelativeTime()
|
||||||
|
while (period > 0.milliseconds) {
|
||||||
|
when {
|
||||||
|
period >= 365.days -> {
|
||||||
|
(period.inDays / 365).floor().let {
|
||||||
|
relativeTime.years = it
|
||||||
|
period -= (it * 365).days
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
period >= 30.days -> {
|
||||||
|
(period.inDays / 30).floor().let {
|
||||||
|
relativeTime.months = it
|
||||||
|
period -= (it * 30).days
|
||||||
|
}
|
||||||
|
}
|
||||||
|
period >= 7.days -> {
|
||||||
|
(period.inDays / 7).floor().let {
|
||||||
|
relativeTime.weeks = it
|
||||||
|
period -= (it * 7).days
|
||||||
|
}
|
||||||
|
}
|
||||||
|
period >= 1.days -> {
|
||||||
|
period.inDays.floor().let {
|
||||||
|
relativeTime.days = it
|
||||||
|
period -= it.days
|
||||||
|
}
|
||||||
|
}
|
||||||
|
period >= 1.hours -> {
|
||||||
|
period.inHours.floor().let {
|
||||||
|
relativeTime.hours = it
|
||||||
|
period -= it.hours
|
||||||
|
}
|
||||||
|
}
|
||||||
|
period >= 1.minutes -> {
|
||||||
|
period.inMinutes.floor().let {
|
||||||
|
relativeTime.minutes = it
|
||||||
|
period -= it.minutes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
period >= 1.seconds -> {
|
||||||
|
period.inSeconds.floor().let {
|
||||||
|
relativeTime.seconds = it
|
||||||
|
period -= it.seconds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
period >= 1.milliseconds -> {
|
||||||
|
period.inMilliseconds.floor().let {
|
||||||
|
relativeTime.milliseconds = it
|
||||||
|
}
|
||||||
|
period = 0.milliseconds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return relativeTime
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getRelativeTimeString(relativeTime: RelativeTime, context: Context): String {
|
||||||
|
return relativeTime.years?.let { context.resources.getQuantityString(R.plurals.humanize_year, it, it) }
|
||||||
|
?: relativeTime.months?.let { context.resources.getQuantityString(R.plurals.humanize_month, it, it) }
|
||||||
|
?: relativeTime.weeks?.let { context.resources.getQuantityString(R.plurals.humanize_week, it, it) }
|
||||||
|
?: relativeTime.days?.let { context.resources.getQuantityString(R.plurals.humanize_day, it, it) }
|
||||||
|
?: relativeTime.hours?.let { context.resources.getQuantityString(R.plurals.humanize_hour, it, it) }
|
||||||
|
?: relativeTime.minutes?.let { context.resources.getQuantityString(R.plurals.humanize_minute, it, it) }
|
||||||
|
?: relativeTime.seconds?.let { context.resources.getQuantityString(R.plurals.humanize_second, it, it) }
|
||||||
|
?: context.getString(R.string.humanize_fallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class RelativeTime(var years: Int? = null, var months: Int? = null, var weeks: Int? = null, var days: Int? = null, var hours: Int? = null, var minutes: Int? = null, var seconds: Int? = null, var milliseconds: Int? = null)
|
||||||
}
|
}
|
||||||
|
@ -606,4 +606,35 @@
|
|||||||
For more information and to view the source code:\n%s
|
For more information and to view the source code:\n%s
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<!-- Humanize time -->
|
||||||
|
<plurals name="humanize_year">
|
||||||
|
<item quantity="one">%1$d year ago</item>
|
||||||
|
<item quantity="other">%1$d years ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="humanize_month">
|
||||||
|
<item quantity="one">%1$d month ago</item>
|
||||||
|
<item quantity="other">%1$d months ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="humanize_week">
|
||||||
|
<item quantity="one">%1$d week ago</item>
|
||||||
|
<item quantity="other">%1$d weeks ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="humanize_day">
|
||||||
|
<item quantity="one">%1$d day ago</item>
|
||||||
|
<item quantity="other">%1$d days ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="humanize_hour">
|
||||||
|
<item quantity="one">%1$d hour ago</item>
|
||||||
|
<item quantity="other">%1$d hours ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="humanize_minute">
|
||||||
|
<item quantity="one">%1$d minute ago</item>
|
||||||
|
<item quantity="other">%1$d minutes ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="humanize_second">
|
||||||
|
<item quantity="one">%1$d second ago</item>
|
||||||
|
<item quantity="other">%1$d second ago</item>
|
||||||
|
</plurals>
|
||||||
|
<string name="humanize_fallback">moments ago</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user