Use Liste of Mirrors Urls for Mangalek "ar" (#2059)
* Use Liste of Mirrors Urls for Mangalek "ar" * Update Mangalek.kt * override baseUrl * Update Mangalek.kt * add isNsfw Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com> * date format --------- Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com>
This commit is contained in:
parent
7217df6180
commit
7bb2113b37
|
@ -3,7 +3,8 @@ ext {
|
||||||
extClass = '.Mangalek'
|
extClass = '.Mangalek'
|
||||||
themePkg = 'madara'
|
themePkg = 'madara'
|
||||||
baseUrl = 'https://lekmanga.net'
|
baseUrl = 'https://lekmanga.net'
|
||||||
overrideVersionCode = 5
|
overrideVersionCode = 6
|
||||||
|
isNsfw = false
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.extension.ar.mangalek
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.extension.BuildConfig
|
|
||||||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||||
import eu.kanade.tachiyomi.network.POST
|
import eu.kanade.tachiyomi.network.POST
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
|
@ -18,14 +18,25 @@ import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import java.text.ParseException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
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 :
|
class Mangalek :
|
||||||
Madara(
|
Madara(
|
||||||
"مانجا ليك",
|
"مانجا ليك",
|
||||||
mangalekUrl,
|
MIRROR_PREF_DEFAULT_VALUE,
|
||||||
"ar",
|
"ar",
|
||||||
SimpleDateFormat("MMMM dd, yyyy", Locale("ar")),
|
SimpleDateFormat("MMMM dd, yyyy", Locale("ar")),
|
||||||
),
|
),
|
||||||
|
@ -35,38 +46,50 @@ class Mangalek :
|
||||||
override val useLoadMoreRequest = LoadMoreStrategy.Always
|
override val useLoadMoreRequest = LoadMoreStrategy.Always
|
||||||
override val chapterUrlSuffix = ""
|
override val chapterUrlSuffix = ""
|
||||||
|
|
||||||
private val defaultBaseUrl = mangalekUrl
|
override val baseUrl by lazy {
|
||||||
override val baseUrl by lazy { getPrefBaseUrl() }
|
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 {
|
private val preferences: SharedPreferences by lazy {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().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) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply {
|
val mirrorPref = ListPreference(screen.context).apply {
|
||||||
key = BASE_URL_PREF
|
key = MIRROR_PREF_KEY
|
||||||
title = BASE_URL_PREF_TITLE
|
title = MIRROR_PREF_TITLE
|
||||||
summary = BASE_URL_PREF_SUMMARY
|
entries = MIRROR_PREF_ENTRY_VALUES
|
||||||
this.setDefaultValue(defaultBaseUrl)
|
entryValues = MIRROR_PREF_ENTRY_VALUES
|
||||||
dialogTitle = BASE_URL_PREF_TITLE
|
setDefaultValue(MIRROR_PREF_DEFAULT_VALUE)
|
||||||
dialogMessage = "Default: $defaultBaseUrl"
|
summary = "%s"
|
||||||
|
|
||||||
setOnPreferenceChangeListener { _, _ ->
|
setOnPreferenceChangeListener { _, _ ->
|
||||||
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
|
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
|
||||||
true
|
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 =
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request =
|
||||||
POST(
|
POST(
|
||||||
|
|
Loading…
Reference in New Issue