From 1abf01c4a030b089e6300cb284cc93f7ed323a22 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 5 Mar 2023 16:16:19 +0100 Subject: [PATCH] Convert source modules to Kotlin Multiplatform (#9172) Use KMP in source modules Use KMP in source-api Expect LocalSource --- .../java/eu/kanade/tachiyomi/AppModule.kt | 6 +-- gradle.properties | 2 + source-api/build.gradle.kts | 34 +++++++++------ .../tachiyomi/source/PreferenceScreen.kt | 3 ++ .../eu/kanade/tachiyomi/util/RxExtension.kt | 6 +++ .../{main => commonMain}/AndroidManifest.xml | 0 .../tachiyomi/source/CatalogueSource.kt | 0 .../tachiyomi/source/ConfigurableSource.kt | 2 - .../tachiyomi/source/PreferenceScreen.kt | 3 ++ .../eu/kanade/tachiyomi/source/Source.kt | 2 +- .../kanade/tachiyomi/source/SourceFactory.kt | 0 .../tachiyomi/source/UnmeteredSource.kt | 0 .../kanade/tachiyomi/source/model/Filter.kt | 0 .../tachiyomi/source/model/FilterList.kt | 0 .../tachiyomi/source/model/MangasPage.kt | 0 .../eu/kanade/tachiyomi/source/model/Page.kt | 0 .../kanade/tachiyomi/source/model/SChapter.kt | 0 .../tachiyomi/source/model/SChapterImpl.kt | 0 .../kanade/tachiyomi/source/model/SManga.kt | 0 .../tachiyomi/source/model/SMangaImpl.kt | 0 .../tachiyomi/source/model/UpdateStrategy.kt | 0 .../tachiyomi/source/online/HttpSource.kt | 0 .../source/online/HttpSourceFetcher.kt | 0 .../source/online/ParsedHttpSource.kt | 0 .../kanade/tachiyomi/util/JsoupExtensions.kt | 0 .../eu/kanade/tachiyomi/util/RxExtension.kt | 5 +++ source-local/build.gradle.kts | 42 +++++++++++-------- .../{main => androidMain}/AndroidManifest.xml | 0 .../tachiyomi/source/local/LocalSource.kt | 2 +- .../tachiyomi/source/local/filter/OrderBy.kt | 0 .../source/local/image/LocalCoverManager.kt} | 11 +++-- .../source/local/io/LocalSourceFileSystem.kt} | 12 +++--- .../source/local/metadata/EpubFile.kt | 0 .../tachiyomi/source/local/LocalSource.kt | 6 +++ .../source/local/image/LocalCoverManager.kt | 2 +- .../tachiyomi/source/local/io/Archive.kt | 0 .../tachiyomi/source/local/io/Format.kt | 0 .../source/local/io/LocalSourceFileSystem.kt | 2 +- 38 files changed, 91 insertions(+), 49 deletions(-) create mode 100644 source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt create mode 100644 source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt rename source-api/src/{main => commonMain}/AndroidManifest.xml (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/CatalogueSource.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/ConfigurableSource.kt (75%) create mode 100644 source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/Source.kt (98%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/SourceFactory.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/UnmeteredSource.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/Filter.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/FilterList.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/MangasPage.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/Page.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/SChapter.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/SChapterImpl.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/SManga.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/SMangaImpl.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/online/HttpSource.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/online/HttpSourceFetcher.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt (100%) rename source-api/src/{main/java => commonMain/kotlin}/eu/kanade/tachiyomi/util/JsoupExtensions.kt (100%) create mode 100644 source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt rename source-local/src/{main => androidMain}/AndroidManifest.xml (100%) rename source-local/src/{main/java => androidMain/kotlin}/tachiyomi/source/local/LocalSource.kt (99%) rename source-local/src/{main/java => androidMain/kotlin}/tachiyomi/source/local/filter/OrderBy.kt (100%) rename source-local/src/{main/java/tachiyomi/source/local/image/AndroidLocalCoverManager.kt => androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt} (90%) rename source-local/src/{main/java/tachiyomi/source/local/io/AndroidLocalSourceFileSystem.kt => androidMain/kotlin/tachiyomi/source/local/io/LocalSourceFileSystem.kt} (77%) rename source-local/src/{main/java => androidMain/kotlin}/tachiyomi/source/local/metadata/EpubFile.kt (100%) create mode 100644 source-local/src/commonMain/kotlin/tachiyomi/source/local/LocalSource.kt rename source-local/src/{main/java => commonMain/kotlin}/tachiyomi/source/local/image/LocalCoverManager.kt (87%) rename source-local/src/{main/java => commonMain/kotlin}/tachiyomi/source/local/io/Archive.kt (100%) rename source-local/src/{main/java => commonMain/kotlin}/tachiyomi/source/local/io/Format.kt (100%) rename source-local/src/{main/java => commonMain/kotlin}/tachiyomi/source/local/io/LocalSourceFileSystem.kt (87%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index f4cee8862..2bddb66ca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -48,9 +48,7 @@ import tachiyomi.data.Mangas import tachiyomi.data.dateAdapter import tachiyomi.data.listOfStringsAdapter import tachiyomi.data.updateStrategyAdapter -import tachiyomi.source.local.image.AndroidLocalCoverManager import tachiyomi.source.local.image.LocalCoverManager -import tachiyomi.source.local.io.AndroidLocalSourceFileSystem import tachiyomi.source.local.io.LocalSourceFileSystem import uy.kohesive.injekt.api.InjektModule import uy.kohesive.injekt.api.InjektRegistrar @@ -137,8 +135,8 @@ class AppModule(val app: Application) : InjektModule { addSingletonFactory { ImageSaver(app) } - addSingletonFactory { AndroidLocalSourceFileSystem(app) } - addSingletonFactory { AndroidLocalCoverManager(app, get()) } + addSingletonFactory { LocalSourceFileSystem(app) } + addSingletonFactory { LocalCoverManager(app, get()) } // Asynchronously init expensive components for a faster cold start ContextCompat.getMainExecutor(app).execute { diff --git a/gradle.properties b/gradle.properties index 87c9723c7..5eaad3635 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,3 +22,5 @@ org.gradle.caching=true # AndroidX support android.useAndroidX=true + +kotlin.mpp.androidSourceSetLayoutVersion=2 \ No newline at end of file diff --git a/source-api/build.gradle.kts b/source-api/build.gradle.kts index 86dc1aab5..285873f7e 100644 --- a/source-api/build.gradle.kts +++ b/source-api/build.gradle.kts @@ -1,7 +1,27 @@ plugins { - id("com.android.library") - kotlin("android") + kotlin("multiplatform") kotlin("plugin.serialization") + id("com.android.library") +} + +kotlin { + android() + sourceSets { + val commonMain by getting { + dependencies { + api(kotlinx.serialization.json) + api(libs.injekt.core) + api(libs.rxjava) + api(libs.jsoup) + } + } + val androidMain by getting { + dependencies { + implementation(project(":core")) + api(libs.preferencektx) + } + } + } } android { @@ -11,13 +31,3 @@ android { consumerProguardFile("consumer-proguard.pro") } } - -dependencies { - implementation(project(":core")) - - api(kotlinx.serialization.json) - api(libs.injekt.core) - api(libs.rxjava) - api(libs.preferencektx) - api(libs.jsoup) -} diff --git a/source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt b/source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt new file mode 100644 index 000000000..58a247ce3 --- /dev/null +++ b/source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt @@ -0,0 +1,3 @@ +package eu.kanade.tachiyomi.source + +actual typealias PreferenceScreen = androidx.preference.PreferenceScreen diff --git a/source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt b/source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt new file mode 100644 index 000000000..6938bb406 --- /dev/null +++ b/source-api/src/androidMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt @@ -0,0 +1,6 @@ +package eu.kanade.tachiyomi.util + +import rx.Observable +import tachiyomi.core.util.lang.awaitSingle + +actual suspend fun Observable.awaitSingle(): T = awaitSingle() diff --git a/source-api/src/main/AndroidManifest.xml b/source-api/src/commonMain/AndroidManifest.xml similarity index 100% rename from source-api/src/main/AndroidManifest.xml rename to source-api/src/commonMain/AndroidManifest.xml diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/CatalogueSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/CatalogueSource.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/ConfigurableSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt similarity index 75% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/ConfigurableSource.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt index 4f5154fe5..d42885f80 100644 --- a/source-api/src/main/java/eu/kanade/tachiyomi/source/ConfigurableSource.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt @@ -1,7 +1,5 @@ package eu.kanade.tachiyomi.source -import androidx.preference.PreferenceScreen - interface ConfigurableSource : Source { fun setupPreferenceScreen(screen: PreferenceScreen) diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt new file mode 100644 index 000000000..860591e29 --- /dev/null +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/PreferenceScreen.kt @@ -0,0 +1,3 @@ +package eu.kanade.tachiyomi.source + +expect class PreferenceScreen diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/Source.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt similarity index 98% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/Source.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt index 62c6f5e9b..9364d95ec 100644 --- a/source-api/src/main/java/eu/kanade/tachiyomi/source/Source.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt @@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.source import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga +import eu.kanade.tachiyomi.util.awaitSingle import rx.Observable -import tachiyomi.core.util.lang.awaitSingle /** * A basic interface for creating a source. It could be an online source, a local source, etc... diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/SourceFactory.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/SourceFactory.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/SourceFactory.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/SourceFactory.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/UnmeteredSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/UnmeteredSource.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/UnmeteredSource.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/UnmeteredSource.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/Filter.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Filter.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/Filter.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Filter.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/FilterList.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/FilterList.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/FilterList.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/FilterList.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/MangasPage.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/MangasPage.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/MangasPage.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/MangasPage.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Page.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Page.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SChapter.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SChapter.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/SChapterImpl.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SChapterImpl.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/SChapterImpl.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SChapterImpl.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SManga.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SManga.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/SMangaImpl.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SMangaImpl.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/SMangaImpl.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/SMangaImpl.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSourceFetcher.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSourceFetcher.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSourceFetcher.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSourceFetcher.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/util/JsoupExtensions.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/util/JsoupExtensions.kt similarity index 100% rename from source-api/src/main/java/eu/kanade/tachiyomi/util/JsoupExtensions.kt rename to source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/util/JsoupExtensions.kt diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt new file mode 100644 index 000000000..5b8420d41 --- /dev/null +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/util/RxExtension.kt @@ -0,0 +1,5 @@ +package eu.kanade.tachiyomi.util + +import rx.Observable + +expect suspend fun Observable.awaitSingle(): T diff --git a/source-local/build.gradle.kts b/source-local/build.gradle.kts index 96a974721..0f6ad1fc2 100644 --- a/source-local/build.gradle.kts +++ b/source-local/build.gradle.kts @@ -1,29 +1,37 @@ plugins { + kotlin("multiplatform") id("com.android.library") - kotlin("android") +} + +kotlin { + android() + sourceSets { + val commonMain by getting { + dependencies { + implementation(project(":source-api")) + implementation(libs.unifile) + implementation(libs.junrar) + } + } + val androidMain by getting { + dependencies { + implementation(project(":core")) + implementation(project(":core-metadata")) + + // Move ChapterRecognition to separate module? + implementation(project(":domain")) + + implementation(kotlinx.bundles.serialization) + } + } + } } android { namespace = "tachiyomi.source.local" defaultConfig { - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") } } - -dependencies { - - implementation(project(":source-api")) - implementation(project(":core")) - implementation(project(":core-metadata")) - - // Move ChapterRecognition to separate module? - implementation(project(":domain")) - - implementation(kotlinx.bundles.serialization) - - implementation(libs.unifile) - implementation(libs.junrar) -} diff --git a/source-local/src/main/AndroidManifest.xml b/source-local/src/androidMain/AndroidManifest.xml similarity index 100% rename from source-local/src/main/AndroidManifest.xml rename to source-local/src/androidMain/AndroidManifest.xml diff --git a/source-local/src/main/java/tachiyomi/source/local/LocalSource.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt similarity index 99% rename from source-local/src/main/java/tachiyomi/source/local/LocalSource.kt rename to source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt index b95c66daf..f527083d7 100644 --- a/source-local/src/main/java/tachiyomi/source/local/LocalSource.kt +++ b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt @@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit import java.util.zip.ZipFile import com.github.junrar.Archive as JunrarArchive -class LocalSource( +actual class LocalSource( private val context: Context, private val fileSystem: LocalSourceFileSystem, private val coverManager: LocalCoverManager, diff --git a/source-local/src/main/java/tachiyomi/source/local/filter/OrderBy.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/filter/OrderBy.kt similarity index 100% rename from source-local/src/main/java/tachiyomi/source/local/filter/OrderBy.kt rename to source-local/src/androidMain/kotlin/tachiyomi/source/local/filter/OrderBy.kt diff --git a/source-local/src/main/java/tachiyomi/source/local/image/AndroidLocalCoverManager.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt similarity index 90% rename from source-local/src/main/java/tachiyomi/source/local/image/AndroidLocalCoverManager.kt rename to source-local/src/androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt index b1161010e..e5aaf5dd7 100644 --- a/source-local/src/main/java/tachiyomi/source/local/image/AndroidLocalCoverManager.kt +++ b/source-local/src/androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt @@ -11,12 +11,12 @@ import java.io.InputStream private const val DEFAULT_COVER_NAME = "cover.jpg" -class AndroidLocalCoverManager( +actual class LocalCoverManager( private val context: Context, private val fileSystem: LocalSourceFileSystem, -) : LocalCoverManager { +) { - override fun find(mangaUrl: String): File? { + actual fun find(mangaUrl: String): File? { return fileSystem.getFilesInMangaDirectory(mangaUrl) // Get all file whose names start with 'cover' .filter { it.isFile && it.nameWithoutExtension.equals("cover", ignoreCase = true) } @@ -26,7 +26,10 @@ class AndroidLocalCoverManager( } } - override fun update(manga: SManga, inputStream: InputStream): File? { + actual fun update( + manga: SManga, + inputStream: InputStream, + ): File? { val directory = fileSystem.getMangaDirectory(manga.url) if (directory == null) { inputStream.close() diff --git a/source-local/src/main/java/tachiyomi/source/local/io/AndroidLocalSourceFileSystem.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/io/LocalSourceFileSystem.kt similarity index 77% rename from source-local/src/main/java/tachiyomi/source/local/io/AndroidLocalSourceFileSystem.kt rename to source-local/src/androidMain/kotlin/tachiyomi/source/local/io/LocalSourceFileSystem.kt index fa100a0b5..a986b5a17 100644 --- a/source-local/src/main/java/tachiyomi/source/local/io/AndroidLocalSourceFileSystem.kt +++ b/source-local/src/androidMain/kotlin/tachiyomi/source/local/io/LocalSourceFileSystem.kt @@ -5,31 +5,31 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil import tachiyomi.source.local.R import java.io.File -class AndroidLocalSourceFileSystem( +actual class LocalSourceFileSystem( private val context: Context, -) : LocalSourceFileSystem { +) { private val baseFolderLocation = "${context.getString(R.string.app_name)}${File.separator}local" - override fun getBaseDirectories(): Sequence { + actual fun getBaseDirectories(): Sequence { return DiskUtil.getExternalStorages(context) .map { File(it.absolutePath, baseFolderLocation) } .asSequence() } - override fun getFilesInBaseDirectories(): Sequence { + actual fun getFilesInBaseDirectories(): Sequence { return getBaseDirectories() // Get all the files inside all baseDir .flatMap { it.listFiles().orEmpty().toList() } } - override fun getMangaDirectory(name: String): File? { + actual fun getMangaDirectory(name: String): File? { return getFilesInBaseDirectories() // Get the first mangaDir or null .firstOrNull { it.isDirectory && it.name == name } } - override fun getFilesInMangaDirectory(name: String): Sequence { + actual fun getFilesInMangaDirectory(name: String): Sequence { return getFilesInBaseDirectories() // Filter out ones that are not related to the manga and is not a directory .filter { it.isDirectory && it.name == name } diff --git a/source-local/src/main/java/tachiyomi/source/local/metadata/EpubFile.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/metadata/EpubFile.kt similarity index 100% rename from source-local/src/main/java/tachiyomi/source/local/metadata/EpubFile.kt rename to source-local/src/androidMain/kotlin/tachiyomi/source/local/metadata/EpubFile.kt diff --git a/source-local/src/commonMain/kotlin/tachiyomi/source/local/LocalSource.kt b/source-local/src/commonMain/kotlin/tachiyomi/source/local/LocalSource.kt new file mode 100644 index 000000000..d592f1c96 --- /dev/null +++ b/source-local/src/commonMain/kotlin/tachiyomi/source/local/LocalSource.kt @@ -0,0 +1,6 @@ +package tachiyomi.source.local + +import eu.kanade.tachiyomi.source.CatalogueSource +import eu.kanade.tachiyomi.source.UnmeteredSource + +expect class LocalSource : CatalogueSource, UnmeteredSource diff --git a/source-local/src/main/java/tachiyomi/source/local/image/LocalCoverManager.kt b/source-local/src/commonMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt similarity index 87% rename from source-local/src/main/java/tachiyomi/source/local/image/LocalCoverManager.kt rename to source-local/src/commonMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt index c8ce8c545..fd31299c2 100644 --- a/source-local/src/main/java/tachiyomi/source/local/image/LocalCoverManager.kt +++ b/source-local/src/commonMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt @@ -4,7 +4,7 @@ import eu.kanade.tachiyomi.source.model.SManga import java.io.File import java.io.InputStream -interface LocalCoverManager { +expect class LocalCoverManager { fun find(mangaUrl: String): File? diff --git a/source-local/src/main/java/tachiyomi/source/local/io/Archive.kt b/source-local/src/commonMain/kotlin/tachiyomi/source/local/io/Archive.kt similarity index 100% rename from source-local/src/main/java/tachiyomi/source/local/io/Archive.kt rename to source-local/src/commonMain/kotlin/tachiyomi/source/local/io/Archive.kt diff --git a/source-local/src/main/java/tachiyomi/source/local/io/Format.kt b/source-local/src/commonMain/kotlin/tachiyomi/source/local/io/Format.kt similarity index 100% rename from source-local/src/main/java/tachiyomi/source/local/io/Format.kt rename to source-local/src/commonMain/kotlin/tachiyomi/source/local/io/Format.kt diff --git a/source-local/src/main/java/tachiyomi/source/local/io/LocalSourceFileSystem.kt b/source-local/src/commonMain/kotlin/tachiyomi/source/local/io/LocalSourceFileSystem.kt similarity index 87% rename from source-local/src/main/java/tachiyomi/source/local/io/LocalSourceFileSystem.kt rename to source-local/src/commonMain/kotlin/tachiyomi/source/local/io/LocalSourceFileSystem.kt index f6c5e6d39..0440df26e 100644 --- a/source-local/src/main/java/tachiyomi/source/local/io/LocalSourceFileSystem.kt +++ b/source-local/src/commonMain/kotlin/tachiyomi/source/local/io/LocalSourceFileSystem.kt @@ -2,7 +2,7 @@ package tachiyomi.source.local.io import java.io.File -interface LocalSourceFileSystem { +expect class LocalSourceFileSystem { fun getBaseDirectories(): Sequence