Handle more deprecated items

This commit is contained in:
Jobobby04 2021-06-02 00:10:36 -04:00
parent 1e55a3f21a
commit aeaf52cb58
18 changed files with 106 additions and 70 deletions

View File

@ -313,6 +313,7 @@ tasks {
"-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi",
"-Xuse-experimental=kotlinx.serialization.ExperimentalSerializationApi",
"-Xuse-experimental=coil.annotation.ExperimentalCoilApi",
"-Xuse-experimental=kotlin.time.ExperimentalTime",
)
}

View File

@ -56,6 +56,7 @@ import exh.log.XLogTree
import exh.log.xLogD
import exh.log.xLogE
import exh.syDebugVersion
import exh.util.days
import io.realm.Realm
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -70,8 +71,6 @@ import java.security.Security
import java.text.SimpleDateFormat
import java.util.Locale
import javax.net.ssl.SSLContext
import kotlin.time.ExperimentalTime
import kotlin.time.days
open class App : Application(), LifecycleObserver, ImageLoaderFactory {
@ -231,7 +230,6 @@ open class App : Application(), LifecycleObserver, ImageLoaderFactory {
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault())
@OptIn(ExperimentalTime::class)
printers += EnhancedFilePrinter
.Builder(logFolder.absolutePath) {
fileNameGenerator = object : DateFileNameGenerator() {
@ -245,7 +243,7 @@ open class App : Application(), LifecycleObserver, ImageLoaderFactory {
flattener { timeMillis, level, tag, message ->
"${dateFormat.format(timeMillis)} ${LogLevel.getShortLevelName(level)}/$tag: $message"
}
cleanStrategy = FileLastModifiedCleanStrategy(7.days.toLongMilliseconds())
cleanStrategy = FileLastModifiedCleanStrategy(7.days.inWholeMilliseconds)
backupStrategy = NeverBackupStrategy()
}

View File

@ -60,7 +60,7 @@ class SourcePresenter(
// SY -->
val categories = mutableListOf<SourceCategory>()
preferences.sourcesTabCategories().get().sortedByDescending { it.toLowerCase() }.forEach {
preferences.sourcesTabCategories().get().sortedByDescending { it.lowercase() }.forEach {
categories.add(SourceCategory(it))
}
@ -126,7 +126,7 @@ class SourcePresenter(
// SY -->
categories.forEach {
sourceItems = it.sources.sortedBy { sourceItem -> sourceItem.source.name.toLowerCase() } + sourceItems
sourceItems = it.sources.sortedBy { sourceItem -> sourceItem.source.name.lowercase() } + sourceItems
}
// SY <--

View File

@ -8,16 +8,14 @@ import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import exh.log.xLogD
import exh.util.hours
import exh.util.minutes
import java.util.Calendar
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.hours
import kotlin.time.minutes
/**
* Dialog to create a new category for the library.
*/
@OptIn(ExperimentalTime::class)
class BiometricTimesCreateDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
where T : Controller, T : BiometricTimesCreateDialog.Listener {

View File

@ -2,28 +2,24 @@ package eu.kanade.tachiyomi.ui.category.biometric
import android.content.Context
import android.text.format.DateFormat
import exh.util.hours
import exh.util.minutes
import java.util.Date
import java.util.SimpleTimeZone
import kotlin.math.floor
import kotlin.math.roundToInt
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.hours
import kotlin.time.minutes
@ExperimentalTime
data class TimeRange(val startTime: Duration, val endTime: Duration) {
override fun toString(): String {
val startHour = floor(startTime.inHours).roundToInt()
val startMinute = (startTime - floor(startTime.inHours).hours).inMinutes.roundToInt()
val endHour = floor(endTime.inHours).roundToInt()
val endMinute = (endTime - floor(endTime.inHours).hours).inMinutes.roundToInt()
val startHour = startTime.inWholeHours
val startMinute = (startTime - startHour.hours).inWholeMinutes
val endHour = endTime.inWholeHours
val endMinute = (endTime - endHour.hours).inWholeMinutes
return String.format("%02d:%02d - %02d:%02d", startHour, startMinute, endHour, endMinute)
}
fun getFormattedString(context: Context): String {
val startDate = Date(startTime.toLongMilliseconds())
val endDate = Date(endTime.toLongMilliseconds())
val startDate = Date(startTime.inWholeMilliseconds)
val endDate = Date(endTime.inWholeMilliseconds)
val format = DateFormat.getTimeFormat(context)
format.timeZone = SimpleTimeZone(0, "UTC")
@ -31,7 +27,7 @@ data class TimeRange(val startTime: Duration, val endTime: Duration) {
}
fun toPreferenceString(): String {
return "${startTime.inMinutes},${endTime.inMinutes}"
return "${startTime.inWholeMinutes},${endTime.inWholeMinutes}"
}
fun conflictsWith(other: TimeRange): Boolean {

View File

@ -49,6 +49,7 @@ import exh.source.isEhBasedManga
import exh.source.mangaDexSourceIds
import exh.source.nHentaiSourceIds
import exh.ui.LoaderManager
import exh.util.milliseconds
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn
@ -59,8 +60,6 @@ import reactivecircus.flowbinding.viewpager.pageSelections
import rx.Subscription
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.time.ExperimentalTime
import kotlin.time.milliseconds
class LibraryController(
bundle: Bundle? = null,
@ -674,7 +673,6 @@ class LibraryController(
}
// SY -->
@OptIn(ExperimentalTime::class)
override fun onAttach(view: View) {
super.onAttach(view)

View File

@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.databinding.TrackSearchItemBinding
import eu.kanade.tachiyomi.util.view.inflate
import exh.util.capitalize
class TrackSearchAdapter(context: Context) :
ArrayAdapter<TrackSearch>(context, R.layout.track_search_item, mutableListOf<TrackSearch>()) {

View File

@ -82,6 +82,7 @@ import exh.log.xLogE
import exh.source.isEhBasedSource
import exh.util.defaultReaderType
import exh.util.mangaType
import exh.util.seconds
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@ -99,9 +100,6 @@ import timber.log.Timber
import uy.kohesive.injekt.injectLazy
import java.io.File
import kotlin.math.abs
import kotlin.time.ExperimentalTime
import kotlin.time.seconds
/**
* Activity containing the reader of Tachiyomi. This activity is mostly a container of the
* viewers, to which calls from the presenter or UI events are delegated.
@ -236,7 +234,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
}
}
@OptIn(ExperimentalTime::class)
private fun setupAutoscroll(interval: Double) {
autoScrollJob?.cancel()
if (interval == -1.0) return

View File

@ -7,14 +7,13 @@ import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.category.biometric.TimeRange
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
import exh.util.hours
import exh.util.minutes
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import uy.kohesive.injekt.injectLazy
import java.util.Calendar
import java.util.Date
import kotlin.time.ExperimentalTime
import kotlin.time.hours
import kotlin.time.minutes
class SecureActivityDelegate(private val activity: FragmentActivity) {
@ -48,7 +47,6 @@ class SecureActivityDelegate(private val activity: FragmentActivity) {
}
}
@OptIn(ExperimentalTime::class)
private fun isAppLocked(): Boolean {
if (!locked) {
return false

View File

@ -47,9 +47,13 @@ import exh.metadata.metadata.base.getFlatMetadataForManga
import exh.source.isEhBasedManga
import exh.uconfig.WarnConfigureDialogController
import exh.ui.login.EhLoginActivity
import exh.util.days
import exh.util.executeOnIO
import exh.util.floor
import exh.util.hours
import exh.util.milliseconds
import exh.util.minutes
import exh.util.nullIfBlank
import exh.util.seconds
import exh.util.trans
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn
@ -61,12 +65,6 @@ import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.days
import kotlin.time.hours
import kotlin.time.milliseconds
import kotlin.time.minutes
import kotlin.time.seconds
/**
* EH Settings fragment
@ -649,7 +647,6 @@ class SettingsEhController : SettingsController() {
.cancelable(false)
progress.show()
@OptIn(ExperimentalTime::class)
viewScope.launch(Dispatchers.IO) {
val updateInfo = try {
val stats =
@ -669,7 +666,7 @@ class SettingsEhController : SettingsController() {
}.toList()
fun metaInRelativeDuration(duration: Duration): Int {
val durationMs = duration.toLongMilliseconds()
val durationMs = duration.inWholeMilliseconds
return allMeta.asSequence().filter {
System.currentTimeMillis() - it.lastUpdateCheck < durationMs
}.count()
@ -703,7 +700,6 @@ class SettingsEhController : SettingsController() {
}
}
@OptIn(ExperimentalTime::class)
private fun getRelativeTimeFromNow(then: Duration): RelativeTime {
val now = System.currentTimeMillis().milliseconds
var period: Duration = now - then
@ -711,50 +707,50 @@ class SettingsEhController : SettingsController() {
while (period > 0.milliseconds) {
when {
period >= 365.days -> {
(period.inDays / 365).floor().let {
(period.inWholeDays / 365).let {
relativeTime.years = it
period -= (it * 365).days
}
continue
}
period >= 30.days -> {
(period.inDays / 30).floor().let {
(period.inWholeDays / 30).let {
relativeTime.months = it
period -= (it * 30).days
}
}
period >= 7.days -> {
(period.inDays / 7).floor().let {
(period.inWholeDays / 7).let {
relativeTime.weeks = it
period -= (it * 7).days
}
}
period >= 1.days -> {
period.inDays.floor().let {
period.inWholeDays.let {
relativeTime.days = it
period -= it.days
}
}
period >= 1.hours -> {
period.inHours.floor().let {
period.inWholeHours.let {
relativeTime.hours = it
period -= it.hours
}
}
period >= 1.minutes -> {
period.inMinutes.floor().let {
period.inWholeMinutes.let {
relativeTime.minutes = it
period -= it.minutes
}
}
period >= 1.seconds -> {
period.inSeconds.floor().let {
period.inWholeSeconds.let {
relativeTime.seconds = it
period -= it.seconds
}
}
period >= 1.milliseconds -> {
period.inMilliseconds.floor().let {
period.inWholeMilliseconds.let {
relativeTime.milliseconds = it
}
period = 0.milliseconds
@ -765,17 +761,26 @@ class SettingsEhController : SettingsController() {
}
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) }
return relativeTime.years?.let { context.resources.getQuantityString(R.plurals.humanize_year, it.toInt(), it) }
?: relativeTime.months?.let { context.resources.getQuantityString(R.plurals.humanize_month, it.toInt(), it) }
?: relativeTime.weeks?.let { context.resources.getQuantityString(R.plurals.humanize_week, it.toInt(), it) }
?: relativeTime.days?.let { context.resources.getQuantityString(R.plurals.humanize_day, it.toInt(), it) }
?: relativeTime.hours?.let { context.resources.getQuantityString(R.plurals.humanize_hour, it.toInt(), it) }
?: relativeTime.minutes?.let { context.resources.getQuantityString(R.plurals.humanize_minute, it.toInt(), it) }
?: relativeTime.seconds?.let { context.resources.getQuantityString(R.plurals.humanize_second, it.toInt(), 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)
data class RelativeTime(
var years: Long? = null,
var months: Long? = null,
var weeks: Long? = null,
var days: Long? = null,
var hours: Long? = null,
var minutes: Long? = null,
var seconds: Long? = null,
var milliseconds: Long? = null
)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK) {

View File

@ -20,7 +20,7 @@ enum class DebugToggles(val default: Boolean) {
// Pretend that all galleries only have a single version
INCLUDE_ONLY_ROOT_WHEN_LOADING_EXH_VERSIONS(false);
val prefKey = "eh_debug_toggle_${name.toLowerCase(Locale.getDefault())}"
val prefKey = "eh_debug_toggle_${name.lowercase(Locale.US)}"
var enabled: Boolean
get() = prefs.flowPrefs.getBoolean(prefKey, default).get()

View File

@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.util.preference.onClick
import eu.kanade.tachiyomi.util.preference.preference
import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.switchPreference
import exh.util.capitalize
import java.util.Locale
import kotlin.reflect.KVisibility
import kotlin.reflect.full.declaredFunctions

View File

@ -28,7 +28,9 @@ import exh.metadata.metadata.base.getFlatMetadataForManga
import exh.metadata.metadata.base.insertFlatMetadataAsync
import exh.source.isEhBasedManga
import exh.util.cancellable
import exh.util.days
import exh.util.executeOnIO
import exh.util.hours
import exh.util.jobScheduler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -46,9 +48,6 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.util.ArrayList
import kotlin.time.ExperimentalTime
import kotlin.time.days
import kotlin.time.hours
class EHentaiUpdateWorker : JobService() {
private val scope = CoroutineScope(Dispatchers.Default + Job())
@ -289,8 +288,7 @@ class EHentaiUpdateWorker : JobService() {
companion object {
private const val MAX_UPDATE_FAILURES = 5
@OptIn(ExperimentalTime::class)
private val MIN_BACKGROUND_UPDATE_FREQ = 1.days.toLongMilliseconds()
private val MIN_BACKGROUND_UPDATE_FREQ = 1.days.inWholeMilliseconds
private const val JOB_ID_UPDATE_BACKGROUND = 700000
private const val JOB_ID_UPDATE_BACKGROUND_TEST = 700001
@ -356,9 +354,8 @@ class EHentaiUpdateWorker : JobService() {
val acRestriction = "ac" in restrictions
val wifiRestriction = "wifi" in restrictions
@OptIn(ExperimentalTime::class)
val jobInfo = context.periodicBackgroundJobInfo(
duration.hours.toLongMilliseconds(),
duration.hours.inWholeMilliseconds,
acRestriction,
wifiRestriction
)
@ -382,6 +379,5 @@ data class UpdateEntry(val manga: Manga, val meta: EHentaiSearchMetadata, val ro
object EHentaiUpdateWorkerConstants {
const val UPDATES_PER_ITERATION = 50
@OptIn(ExperimentalTime::class)
val GALLERY_AGE_TIME = 365.days.toLongMilliseconds()
val GALLERY_AGE_TIME = 365.days.inWholeMilliseconds
}

View File

@ -15,6 +15,7 @@ import exh.metadata.metadata.MangaDexSearchMetadata
import exh.metadata.metadata.base.RaisedTag
import exh.metadata.metadata.base.getFlatMetadataForManga
import exh.metadata.metadata.base.insertFlatMetadata
import exh.util.capitalize
import exh.util.dropEmpty
import exh.util.executeOnIO
import exh.util.floor

View File

@ -13,6 +13,7 @@ import rx.Observable
import tachiyomi.source.model.ChapterInfo
import tachiyomi.source.model.MangaInfo
@Suppress("OverridingDeprecatedMember", "DEPRECATION")
abstract class DelegatedHttpSource(val delegate: HttpSource) : HttpSource() {
/**
* Returns the request for the popular manga given the page.

View File

@ -12,6 +12,7 @@ import tachiyomi.source.model.ChapterInfo
import tachiyomi.source.model.MangaInfo
import uy.kohesive.injekt.injectLazy
@Suppress("OverridingDeprecatedMember", "DEPRECATION")
class EnhancedHttpSource(
val originalSource: HttpSource,
val enhancedSource: HttpSource

View File

@ -0,0 +1,32 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package exh.util
import kotlin.time.DurationUnit
import kotlin.time.toDuration
val Int.nanoseconds get() = toDuration(DurationUnit.NANOSECONDS)
val Long.nanoseconds get() = toDuration(DurationUnit.NANOSECONDS)
val Double.nanoseconds get() = toDuration(DurationUnit.NANOSECONDS)
val Int.microseconds get() = toDuration(DurationUnit.MICROSECONDS)
val Long.microseconds get() = toDuration(DurationUnit.MICROSECONDS)
val Double.microseconds get() = toDuration(DurationUnit.MICROSECONDS)
val Int.milliseconds get() = toDuration(DurationUnit.MILLISECONDS)
val Long.milliseconds get() = toDuration(DurationUnit.MILLISECONDS)
val Double.milliseconds get() = toDuration(DurationUnit.MILLISECONDS)
val Int.seconds get() = toDuration(DurationUnit.SECONDS)
val Long.seconds get() = toDuration(DurationUnit.SECONDS)
val Double.seconds get() = toDuration(DurationUnit.SECONDS)
val Int.minutes get() = toDuration(DurationUnit.MINUTES)
val Long.minutes get() = toDuration(DurationUnit.MINUTES)
val Double.minutes get() = toDuration(DurationUnit.MINUTES)
val Int.hours get() = toDuration(DurationUnit.HOURS)
val Long.hours get() = toDuration(DurationUnit.HOURS)
val Double.hours get() = toDuration(DurationUnit.HOURS)
val Int.days get() = toDuration(DurationUnit.DAYS)
val Long.days get() = toDuration(DurationUnit.DAYS)
val Double.days get() = toDuration(DurationUnit.DAYS)

View File

@ -0,0 +1,12 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package exh.util
import java.util.Locale
fun String.capitalize(locale: Locale = Locale.getDefault()) =
replaceFirstChar { if (it.isLowerCase()) it.titlecase(locale) else it.toString() }