diff --git a/src/ar/mangalek/build.gradle b/src/ar/mangalek/build.gradle index 8bcb69e30..509f3360e 100644 --- a/src/ar/mangalek/build.gradle +++ b/src/ar/mangalek/build.gradle @@ -3,7 +3,8 @@ ext { extClass = '.Mangalek' themePkg = 'madara' baseUrl = 'https://lekmanga.net' - overrideVersionCode = 5 + overrideVersionCode = 6 + isNsfw = false } apply from: "$rootDir/common.gradle" diff --git a/src/ar/mangalek/src/eu/kanade/tachiyomi/extension/ar/mangalek/Mangalek.kt b/src/ar/mangalek/src/eu/kanade/tachiyomi/extension/ar/mangalek/Mangalek.kt index 2ccb62014..6bb29f7c9 100644 --- a/src/ar/mangalek/src/eu/kanade/tachiyomi/extension/ar/mangalek/Mangalek.kt +++ b/src/ar/mangalek/src/eu/kanade/tachiyomi/extension/ar/mangalek/Mangalek.kt @@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.extension.ar.mangalek import android.app.Application import android.content.SharedPreferences import android.widget.Toast +import androidx.preference.ListPreference import androidx.preference.PreferenceScreen -import eu.kanade.tachiyomi.extension.BuildConfig import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.ConfigurableSource @@ -18,14 +18,25 @@ import okhttp3.Request import okhttp3.Response import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import java.text.ParseException import java.text.SimpleDateFormat import java.util.Locale -private const val mangalekUrl = "https://lekmanga.net" +private const val MIRROR_PREF_KEY = "MIRROR" +private const val MIRROR_PREF_TITLE = "تعديل رابط مانجا ليك" +internal val MIRROR_PREF_ENTRY_VALUES = arrayOf( + "https://lekmanga.net", + "https://lekmanga.org", + "https://like-manga.net", + "https://lekmanga.com", +) +private val MIRROR_PREF_DEFAULT_VALUE = MIRROR_PREF_ENTRY_VALUES[0] +private const val RESTART_TACHIYOMI = ".لتطبيق الإعدادات الجديدة Tachiyomi أعد تشغيل" + class Mangalek : Madara( "مانجا ليك", - mangalekUrl, + MIRROR_PREF_DEFAULT_VALUE, "ar", SimpleDateFormat("MMMM dd, yyyy", Locale("ar")), ), @@ -35,38 +46,50 @@ class Mangalek : override val useLoadMoreRequest = LoadMoreStrategy.Always override val chapterUrlSuffix = "" - private val defaultBaseUrl = mangalekUrl - override val baseUrl by lazy { getPrefBaseUrl() } + override val baseUrl by lazy { + when { + System.getenv("CI") == "true" -> MIRROR_PREF_ENTRY_VALUES.joinToString("#, ") + else -> preferences.getString(MIRROR_PREF_KEY, MIRROR_PREF_DEFAULT_VALUE)!! + } + } private val preferences: SharedPreferences by lazy { Injekt.get().getSharedPreferences("source_$id", 0x0000) } - companion object { - private const val RESTART_TACHIYOMI = ".لتطبيق الإعدادات الجديدة Tachiyomi أعد تشغيل" - private const val BASE_URL_PREF_TITLE = "تعديل الرابط" - private const val BASE_URL_PREF = "overrideBaseUrl_v${BuildConfig.VERSION_CODE}" - private const val BASE_URL_PREF_SUMMARY = ".للاستخدام المؤقت. تحديث التطبيق سيؤدي الى حذف الإعدادات" - } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply { - key = BASE_URL_PREF - title = BASE_URL_PREF_TITLE - summary = BASE_URL_PREF_SUMMARY - this.setDefaultValue(defaultBaseUrl) - dialogTitle = BASE_URL_PREF_TITLE - dialogMessage = "Default: $defaultBaseUrl" + 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(baseUrlPref) + screen.addPreference(mirrorPref) } - private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, defaultBaseUrl)!! + private val formatOne = SimpleDateFormat("MMMM dd, yyyy", Locale("ar")) + private val formatTwo = SimpleDateFormat("yyyy-MM-dd", Locale.US) + + override fun parseChapterDate(date: String?): Long { + date ?: return 0L + + return try { + formatOne.parse(date)!!.time + } catch (_: ParseException) { + try { + formatTwo.parse(date)!!.time + } catch (_: ParseException) { + 0L + } + } + } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = POST(