(cherry picked from commit fd7c993b0bfb897ea0770c91e4594367ae9c2316) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt
17 lines
729 B
Kotlin
17 lines
729 B
Kotlin
package eu.kanade.presentation.util
|
|
|
|
import android.content.Context
|
|
import eu.kanade.tachiyomi.R
|
|
import kotlin.time.Duration
|
|
|
|
fun Duration.toDurationString(context: Context, fallback: String): String {
|
|
return toComponents { days, hours, minutes, seconds, _ ->
|
|
buildList(4) {
|
|
if (days != 0L) add(context.getString(R.string.day_short, days))
|
|
if (hours != 0) add(context.getString(R.string.hour_short, hours))
|
|
if (minutes != 0 && (days == 0L || hours == 0)) add(context.getString(R.string.minute_short, minutes))
|
|
if (seconds != 0 && days == 0L && hours == 0) add(context.getString(R.string.seconds_short, seconds))
|
|
}.joinToString(" ").ifBlank { fallback }
|
|
}
|
|
}
|