Browse Source

Little cleanup for stub source (#7519)

* Little cleanup for stub source

Fixes instances where name shows up blank for stub sources

* Review Changes

Co-authored-by: Andreas <[email protected]>

Co-authored-by: Andreas <[email protected]>
AntsyLich 2 years ago
parent
commit
902bb35ba7

+ 4 - 1
app/src/main/java/eu/kanade/domain/source/model/SourceData.kt

@@ -4,4 +4,7 @@ data class SourceData(
     val id: Long,
     val lang: String,
     val name: String,
-)
+) {
+
+    val isMissingInfo: Boolean = name.isBlank() || lang.isBlank()
+}

+ 4 - 7
app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt

@@ -108,11 +108,11 @@ class SourceManager(private val context: Context) {
     @Suppress("OverridingDeprecatedMember")
     open inner class StubSource(val sourceData: SourceData) : Source {
 
-        override val name: String = sourceData.name
+        override val id: Long = sourceData.id
 
-        override val lang: String = sourceData.lang
+        override val name: String = sourceData.name.ifBlank { id.toString() }
 
-        override val id: Long = sourceData.id
+        override val lang: String = sourceData.lang
 
         override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
             throw getSourceNotInstalledException()
@@ -139,10 +139,7 @@ class SourceManager(private val context: Context) {
         }
 
         override fun toString(): String {
-            if (name.isNotBlank() && lang.isNotBlank()) {
-                return "$name (${lang.uppercase()})"
-            }
-            return id.toString()
+            return if (sourceData.isMissingInfo.not()) "$name (${lang.uppercase()})" else id.toString()
         }
 
         fun getSourceNotInstalledException(): SourceNotInstalledException {