forked from starfish23/mangafeed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract source api from app module (#8014)
* Extract source api from app module * Extract source online api from app module
- Loading branch information
Showing
53 changed files
with
219 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package eu.kanade.tachiyomi.source | ||
|
||
import android.graphics.drawable.Drawable | ||
import eu.kanade.domain.source.model.SourceData | ||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper | ||
import eu.kanade.tachiyomi.extension.ExtensionManager | ||
import uy.kohesive.injekt.Injekt | ||
import uy.kohesive.injekt.api.get | ||
|
||
fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this) | ||
|
||
fun Source.getPreferenceKey(): String = "source_$id" | ||
|
||
fun Source.toSourceData(): SourceData = SourceData(id = id, lang = lang, name = name) | ||
|
||
fun Source.getNameForMangaInfo(): String { | ||
val preferences = Injekt.get<PreferencesHelper>() | ||
val enabledLanguages = preferences.enabledLanguages().get() | ||
.filterNot { it in listOf("all", "other") } | ||
val hasOneActiveLanguages = enabledLanguages.size == 1 | ||
val isInEnabledLanguages = lang in enabledLanguages | ||
return when { | ||
// For edge cases where user disables a source they got manga of in their library. | ||
hasOneActiveLanguages && !isInEnabledLanguages -> toString() | ||
// Hide the language tag when only one language is used. | ||
hasOneActiveLanguages && isInEnabledLanguages -> name | ||
else -> toString() | ||
} | ||
} | ||
|
||
fun Source.isLocalOrStub(): Boolean = id == LocalSource.ID || this is SourceManager.StubSource |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package eu.kanade.tachiyomi.source.model | ||
|
||
import data.Chapters | ||
|
||
fun SChapter.copyFrom(other: Chapters) { | ||
name = other.name | ||
url = other.url | ||
date_upload = other.date_upload | ||
chapter_number = other.chapter_number | ||
scanlator = other.scanlator | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/eu/kanade/tachiyomi/source/model/SMangaExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package eu.kanade.tachiyomi.source.model | ||
|
||
import data.Mangas | ||
|
||
fun SManga.copyFrom(other: Mangas) { | ||
if (other.author != null) { | ||
author = other.author | ||
} | ||
|
||
if (other.artist != null) { | ||
artist = other.artist | ||
} | ||
|
||
if (other.description != null) { | ||
description = other.description | ||
} | ||
|
||
if (other.genre != null) { | ||
genre = other.genre.joinToString(separator = ", ") | ||
} | ||
|
||
if (other.thumbnail_url != null) { | ||
thumbnail_url = other.thumbnail_url | ||
} | ||
|
||
status = other.status.toInt() | ||
|
||
if (!initialized) { | ||
initialized = other.initialized | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtilExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package eu.kanade.tachiyomi.util.system | ||
|
||
import android.os.Build | ||
import com.google.android.material.color.DynamicColors | ||
|
||
val DeviceUtil.isDynamicColorAvailable by lazy { | ||
DynamicColors.isDynamicColorAvailable() || (DeviceUtil.isSamsung && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
kotlin("plugin.serialization") | ||
} | ||
|
||
android { | ||
namespace = "eu.kanade.tachiyomi.core" | ||
compileSdk = AndroidConfig.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = AndroidConfig.minSdk | ||
targetSdk = AndroidConfig.targetSdk | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":i18n")) | ||
|
||
api(libs.logcat) | ||
|
||
api(libs.rxjava) | ||
|
||
api(libs.okhttp.core) | ||
api(libs.okhttp.logging) | ||
api(libs.okhttp.dnsoverhttps) | ||
api(libs.okio) | ||
|
||
api(kotlinx.coroutines.core) | ||
api(kotlinx.serialization.json) | ||
|
||
api(libs.injekt.core) | ||
|
||
api(libs.preferencektx) | ||
|
||
implementation(androidx.corektx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
core/src/main/java/eu/kanade/tachiyomi/util/system/ToastExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package eu.kanade.tachiyomi.util.system | ||
|
||
import android.content.Context | ||
import android.widget.Toast | ||
import androidx.annotation.StringRes | ||
|
||
/** | ||
* Display a toast in this context. | ||
* | ||
* @param resource the text resource. | ||
* @param duration the duration of the toast. Defaults to short. | ||
*/ | ||
fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast { | ||
return toast(getString(resource), duration, block) | ||
} | ||
|
||
/** | ||
* Display a toast in this context. | ||
* | ||
* @param text the text to display. | ||
* @param duration the duration of the toast. Defaults to short. | ||
*/ | ||
fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast { | ||
return Toast.makeText(applicationContext, text.orEmpty(), duration).also { | ||
block(it) | ||
it.show() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Oops, something went wrong.