فهرست منبع

Minor cleanup

arkon 2 سال پیش
والد
کامیت
811931ccc0
19فایلهای تغییر یافته به همراه120 افزوده شده و 146 حذف شده
  1. 11 0
      app/src/main/java/eu/kanade/core/util/CollectionUtils.kt
  2. 1 1
      app/src/main/java/eu/kanade/data/DatabaseAdapter.kt
  3. 6 16
      app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt
  4. 11 0
      app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt
  5. 0 14
      app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/OAuth.kt
  6. 0 10
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Avatar.kt
  7. 52 0
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiModels.kt
  8. 0 16
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Collection.kt
  9. 0 17
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/OAuth.kt
  10. 0 10
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Status.kt
  11. 0 14
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/User.kt
  12. 12 0
      app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt
  13. 0 15
      app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/OAuth.kt
  14. 12 0
      app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListModels.kt
  15. 0 15
      app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/OAuth.kt
  16. 0 16
      app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/OAuth.kt
  17. 13 0
      app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriModels.kt
  18. 1 1
      app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt
  19. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt

+ 11 - 0
app/src/main/java/eu/kanade/core/util/ListUtils.kt → app/src/main/java/eu/kanade/core/util/CollectionUtils.kt

@@ -1,5 +1,7 @@
 package eu.kanade.core.util
 
+import java.util.concurrent.ConcurrentHashMap
+
 fun <T : R, R : Any> List<T>.insertSeparators(
     generator: (T?, T?) -> R?,
 ): List<R> {
@@ -14,3 +16,12 @@ fun <T : R, R : Any> List<T>.insertSeparators(
     }
     return newList
 }
+
+/**
+ * Returns a new map containing only the key entries of [transform] that are not null.
+ */
+inline fun <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): ConcurrentHashMap<R, V> {
+    val mutableMap = ConcurrentHashMap<R, V>()
+    forEach { element -> transform(element)?.let { mutableMap[it] = element.value } }
+    return mutableMap
+}

+ 1 - 1
app/src/main/java/eu/kanade/data/DatabaseAdapter.kt

@@ -13,7 +13,7 @@ private const val listOfStringsSeparator = ", "
 val listOfStringsAdapter = object : ColumnAdapter<List<String>, String> {
     override fun decode(databaseValue: String) =
         if (databaseValue.isEmpty()) {
-            listOf()
+            emptyList()
         } else {
             databaseValue.split(listOfStringsSeparator)
         }

+ 6 - 16
app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt

@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.download
 import android.content.Context
 import androidx.core.net.toUri
 import com.hippo.unifile.UniFile
+import eu.kanade.core.util.mapNotNullKeys
 import eu.kanade.domain.download.service.DownloadPreferences
 import eu.kanade.domain.manga.model.Manga
 import eu.kanade.tachiyomi.data.database.models.Chapter
@@ -68,9 +69,7 @@ class DownloadCache(
         downloadPreferences.downloadsDirectory().changes()
             .onEach {
                 rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
-
-                // Invalidate cache
-                lastRenew = 0L
+                invalidateCache()
             }
             .launchIn(scope)
     }
@@ -225,6 +224,10 @@ class DownloadCache(
         notifyChanges()
     }
 
+    fun invalidateCache() {
+        lastRenew = 0L
+    }
+
     /**
      * Returns the downloads directory from the user's preferences.
      */
@@ -233,10 +236,6 @@ class DownloadCache(
         return UniFile.fromUri(context, dir.toUri())
     }
 
-    fun invalidateCache() {
-        lastRenew = 0L
-    }
-
     /**
      * Renews the downloads cache.
      */
@@ -315,15 +314,6 @@ class DownloadCache(
             _changes.send(Unit)
         }
     }
-
-    /**
-     * Returns a new map containing only the key entries of [transform] that are not null.
-     */
-    private inline fun <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): ConcurrentHashMap<R, V> {
-        val mutableMap = ConcurrentHashMap<R, V>()
-        forEach { element -> transform(element)?.let { mutableMap[it] = element.value } }
-        return mutableMap
-    }
 }
 
 /**

+ 11 - 0
app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt

@@ -4,6 +4,7 @@ import eu.kanade.domain.track.service.TrackPreferences
 import eu.kanade.tachiyomi.data.database.models.Track
 import eu.kanade.tachiyomi.data.track.TrackManager
 import eu.kanade.tachiyomi.data.track.model.TrackSearch
+import kotlinx.serialization.Serializable
 import uy.kohesive.injekt.injectLazy
 import java.text.SimpleDateFormat
 import java.util.Locale
@@ -72,6 +73,16 @@ data class ALUserManga(
     }
 }
 
+@Serializable
+data class OAuth(
+    val access_token: String,
+    val token_type: String,
+    val expires: Long,
+    val expires_in: Long,
+)
+
+fun OAuth.isExpired() = System.currentTimeMillis() > expires
+
 fun Track.toAnilistStatus() = when (status) {
     Anilist.READING -> "CURRENT"
     Anilist.COMPLETED -> "COMPLETED"

+ 0 - 14
app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/OAuth.kt

@@ -1,14 +0,0 @@
-package eu.kanade.tachiyomi.data.track.anilist
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class OAuth(
-    val access_token: String,
-    val token_type: String,
-    val expires: Long,
-    val expires_in: Long,
-) {
-
-    fun isExpired() = System.currentTimeMillis() > expires
-}

+ 0 - 10
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Avatar.kt

@@ -1,10 +0,0 @@
-package eu.kanade.tachiyomi.data.track.bangumi
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class Avatar(
-    val large: String? = "",
-    val medium: String? = "",
-    val small: String? = "",
-)

+ 52 - 0
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiModels.kt

@@ -1,6 +1,58 @@
 package eu.kanade.tachiyomi.data.track.bangumi
 
 import eu.kanade.tachiyomi.data.database.models.Track
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class Avatar(
+    val large: String? = "",
+    val medium: String? = "",
+    val small: String? = "",
+)
+
+@Serializable
+data class Collection(
+    val `private`: Int? = 0,
+    val comment: String? = "",
+    val ep_status: Int? = 0,
+    val lasttouch: Int? = 0,
+    val rating: Float? = 0f,
+    val status: Status? = Status(),
+    val tag: List<String?>? = emptyList(),
+    val user: User? = User(),
+    val vol_status: Int? = 0,
+)
+
+@Serializable
+data class Status(
+    val id: Int? = 0,
+    val name: String? = "",
+    val type: String? = "",
+)
+
+@Serializable
+data class User(
+    val avatar: Avatar? = Avatar(),
+    val id: Int? = 0,
+    val nickname: String? = "",
+    val sign: String? = "",
+    val url: String? = "",
+    val usergroup: Int? = 0,
+    val username: String? = "",
+)
+
+@Serializable
+data class OAuth(
+    val access_token: String,
+    val token_type: String,
+    val created_at: Long = System.currentTimeMillis() / 1000,
+    val expires_in: Long,
+    val refresh_token: String?,
+    val user_id: Long?,
+)
+
+// Access token refresh before expired
+fun OAuth.isExpired() = (System.currentTimeMillis() / 1000) > (created_at + expires_in - 3600)
 
 fun Track.toBangumiStatus() = when (status) {
     Bangumi.READING -> "do"

+ 0 - 16
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Collection.kt

@@ -1,16 +0,0 @@
-package eu.kanade.tachiyomi.data.track.bangumi
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class Collection(
-    val `private`: Int? = 0,
-    val comment: String? = "",
-    val ep_status: Int? = 0,
-    val lasttouch: Int? = 0,
-    val rating: Float? = 0f,
-    val status: Status? = Status(),
-    val tag: List<String?>? = listOf(),
-    val user: User? = User(),
-    val vol_status: Int? = 0,
-)

+ 0 - 17
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/OAuth.kt

@@ -1,17 +0,0 @@
-package eu.kanade.tachiyomi.data.track.bangumi
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class OAuth(
-    val access_token: String,
-    val token_type: String,
-    val created_at: Long = System.currentTimeMillis() / 1000,
-    val expires_in: Long,
-    val refresh_token: String?,
-    val user_id: Long?,
-) {
-
-    // Access token refresh before expired
-    fun isExpired() = (System.currentTimeMillis() / 1000) > (created_at + expires_in - 3600)
-}

+ 0 - 10
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Status.kt

@@ -1,10 +0,0 @@
-package eu.kanade.tachiyomi.data.track.bangumi
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class Status(
-    val id: Int? = 0,
-    val name: String? = "",
-    val type: String? = "",
-)

+ 0 - 14
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/User.kt

@@ -1,14 +0,0 @@
-package eu.kanade.tachiyomi.data.track.bangumi
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class User(
-    val avatar: Avatar? = Avatar(),
-    val id: Int? = 0,
-    val nickname: String? = "",
-    val sign: String? = "",
-    val url: String? = "",
-    val usergroup: Int? = 0,
-    val username: String? = "",
-)

+ 12 - 0
app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt

@@ -4,6 +4,7 @@ import androidx.annotation.CallSuper
 import eu.kanade.tachiyomi.data.database.models.Track
 import eu.kanade.tachiyomi.data.track.TrackManager
 import eu.kanade.tachiyomi.data.track.model.TrackSearch
+import kotlinx.serialization.Serializable
 import kotlinx.serialization.json.JsonObject
 import kotlinx.serialization.json.contentOrNull
 import kotlinx.serialization.json.int
@@ -93,6 +94,17 @@ class KitsuLibManga(obj: JsonObject, manga: JsonObject) {
     }
 }
 
+@Serializable
+data class OAuth(
+    val access_token: String,
+    val token_type: String,
+    val created_at: Long,
+    val expires_in: Long,
+    val refresh_token: String?,
+)
+
+fun OAuth.isExpired() = (System.currentTimeMillis() / 1000) > (created_at + expires_in - 3600)
+
 fun Track.toKitsuStatus() = when (status) {
     Kitsu.READING -> "current"
     Kitsu.COMPLETED -> "completed"

+ 0 - 15
app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/OAuth.kt

@@ -1,15 +0,0 @@
-package eu.kanade.tachiyomi.data.track.kitsu
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class OAuth(
-    val access_token: String,
-    val token_type: String,
-    val created_at: Long,
-    val expires_in: Long,
-    val refresh_token: String?,
-) {
-
-    fun isExpired() = (System.currentTimeMillis() / 1000) > (created_at + expires_in - 3600)
-}

+ 12 - 0
app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListModels.kt

@@ -1,6 +1,18 @@
 package eu.kanade.tachiyomi.data.track.myanimelist
 
 import eu.kanade.tachiyomi.data.database.models.Track
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class OAuth(
+    val refresh_token: String,
+    val access_token: String,
+    val token_type: String,
+    val created_at: Long = System.currentTimeMillis(),
+    val expires_in: Long,
+)
+
+fun OAuth.isExpired() = System.currentTimeMillis() > created_at + (expires_in * 1000)
 
 fun Track.toMyAnimeListStatus() = when (status) {
     MyAnimeList.READING -> "reading"

+ 0 - 15
app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/OAuth.kt

@@ -1,15 +0,0 @@
-package eu.kanade.tachiyomi.data.track.myanimelist
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class OAuth(
-    val refresh_token: String,
-    val access_token: String,
-    val token_type: String,
-    val created_at: Long = System.currentTimeMillis(),
-    val expires_in: Long,
-) {
-
-    fun isExpired() = System.currentTimeMillis() > created_at + (expires_in * 1000)
-}

+ 0 - 16
app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/OAuth.kt

@@ -1,16 +0,0 @@
-package eu.kanade.tachiyomi.data.track.shikimori
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class OAuth(
-    val access_token: String,
-    val token_type: String,
-    val created_at: Long,
-    val expires_in: Long,
-    val refresh_token: String?,
-) {
-
-    // Access token lives 1 day
-    fun isExpired() = (System.currentTimeMillis() / 1000) > (created_at + expires_in - 3600)
-}

+ 13 - 0
app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriModels.kt

@@ -1,6 +1,19 @@
 package eu.kanade.tachiyomi.data.track.shikimori
 
 import eu.kanade.tachiyomi.data.database.models.Track
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class OAuth(
+    val access_token: String,
+    val token_type: String,
+    val created_at: Long,
+    val expires_in: Long,
+    val refresh_token: String?,
+)
+
+// Access token lives 1 day
+fun OAuth.isExpired() = (System.currentTimeMillis() / 1000) > (created_at + expires_in - 3600)
 
 fun Track.toShikimoriStatus() = when (status) {
     Shikimori.READING -> "watching"

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt

@@ -73,7 +73,7 @@ class ExtensionManager(
     private val _availableExtensionsFlow = MutableStateFlow(emptyList<Extension.Available>())
     val availableExtensionsFlow = _availableExtensionsFlow.asStateFlow()
 
-    private var availableExtensionsSourcesData: Map<Long, SourceData> = mapOf()
+    private var availableExtensionsSourcesData: Map<Long, SourceData> = emptyMap()
 
     private fun setupAvailableExtensionsSourcesDataMap(extensions: List<Extension.Available>) {
         if (extensions.isEmpty()) return

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt

@@ -475,7 +475,7 @@ class DownloadController :
                         ?.filterIsInstance<DownloadItem>()
                         ?.map(DownloadItem::download)
                         ?.partition { item.download.manga.id == it.manga.id }
-                        ?: Pair(listOf(), listOf())
+                        ?: Pair(emptyList(), emptyList())
                     presenter.reorder(selectedSeries + otherSeries)
                 }
                 R.id.cancel_download -> {