From 2967ffe0dc1851043b74dc81c29a384c10ee8cfe Mon Sep 17 00:00:00 2001 From: mohamedotaku Date: Mon, 1 Apr 2024 11:29:40 +0000 Subject: [PATCH] Add Mirror link for Dilar "ar" (#2187) * Add Mirror link for Dilar "ar" * Update Dilar.kt * Update Dilar.kt * Update Dilar.kt * override cdnUrl * Update build.gradle.kts * MirrorPref() * MirrorPref() * Update Dilar.kt * remove lazy --------- Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> --- .../tachiyomi/multisrc/gmanga/Gmanga.kt | 2 +- src/ar/dilar/build.gradle | 2 +- .../tachiyomi/extension/ar/dilar/Dilar.kt | 48 ++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lib-multisrc/gmanga/src/eu/kanade/tachiyomi/multisrc/gmanga/Gmanga.kt b/lib-multisrc/gmanga/src/eu/kanade/tachiyomi/multisrc/gmanga/Gmanga.kt index 77370ff80..8ed63ebd6 100644 --- a/lib-multisrc/gmanga/src/eu/kanade/tachiyomi/multisrc/gmanga/Gmanga.kt +++ b/lib-multisrc/gmanga/src/eu/kanade/tachiyomi/multisrc/gmanga/Gmanga.kt @@ -28,7 +28,7 @@ abstract class Gmanga( override val name: String, override val baseUrl: String, final override val lang: String, - protected val cdnUrl: String = baseUrl, + protected open val cdnUrl: String = baseUrl, ) : HttpSource() { override val supportsLatest = true diff --git a/src/ar/dilar/build.gradle b/src/ar/dilar/build.gradle index 8d9d35146..f36dbcd8e 100644 --- a/src/ar/dilar/build.gradle +++ b/src/ar/dilar/build.gradle @@ -2,7 +2,7 @@ ext { extName = 'Dilar' extClass = '.Dilar' themePkg = 'gmanga' - overrideVersionCode = 0 + overrideVersionCode = 1 } apply from: "$rootDir/common.gradle" diff --git a/src/ar/dilar/src/eu/kanade/tachiyomi/extension/ar/dilar/Dilar.kt b/src/ar/dilar/src/eu/kanade/tachiyomi/extension/ar/dilar/Dilar.kt index fe013a50d..3d170b58e 100644 --- a/src/ar/dilar/src/eu/kanade/tachiyomi/extension/ar/dilar/Dilar.kt +++ b/src/ar/dilar/src/eu/kanade/tachiyomi/extension/ar/dilar/Dilar.kt @@ -1,15 +1,30 @@ package eu.kanade.tachiyomi.extension.ar.dilar +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.ListPreference +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.gmanga.Gmanga import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import okhttp3.Request import okhttp3.Response +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get -class Dilar : Gmanga( +private const val MIRROR_PREF_KEY = "MIRROR" +private const val MIRROR_PREF_TITLE = "Dilar : Mirror Urls" +private val MIRROR_PREF_ENTRY_VALUES = arrayOf("https://dilar.tube", "https://golden.rest") +private val MIRROR_PREF_DEFAULT_VALUE = MIRROR_PREF_ENTRY_VALUES[0] +private const val RESTART_TACHIYOMI = ".لتطبيق الإعدادات الجديدة Tachiyomi أعد تشغيل" + +class Dilar : + ConfigurableSource, Gmanga( "Dilar", - "https://dilar.tube", + MIRROR_PREF_DEFAULT_VALUE, "ar", ) { override fun chaptersRequest(manga: SManga): Request { @@ -23,4 +38,33 @@ class Dilar : Gmanga( return releases.map { it.toSChapter() } } + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val mirrorPref = ListPreference(screen.context).apply { + key = MIRROR_PREF_KEY + title = MIRROR_PREF_TITLE + entries = MIRROR_PREF_ENTRY_VALUES + entryValues = MIRROR_PREF_ENTRY_VALUES + setDefaultValue(MIRROR_PREF_DEFAULT_VALUE) + summary = "%s" + + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show() + true + } + } + screen.addPreference(mirrorPref) + } + + private fun mirrorPref() = when { + System.getenv("CI") == "true" -> MIRROR_PREF_ENTRY_VALUES.joinToString("#, ") + else -> preferences.getString(MIRROR_PREF_KEY, MIRROR_PREF_DEFAULT_VALUE)!! + } + + override val baseUrl = mirrorPref() + + private val preferences: SharedPreferences = + Injekt.get().getSharedPreferences("source_$id", 0x0000) + + override val cdnUrl = baseUrl }