2022-01-29 11:29:15 +00:00
|
|
|
package eu.kanade.tachiyomi.extension.ar.empirewebtoon
|
|
|
|
|
2022-08-15 16:53:58 +00:00
|
|
|
import android.app.Application
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.widget.Toast
|
|
|
|
import androidx.preference.PreferenceScreen
|
|
|
|
import eu.kanade.tachiyomi.AppInfo
|
2022-01-29 11:29:15 +00:00
|
|
|
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
2022-08-15 16:53:58 +00:00
|
|
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
|
import uy.kohesive.injekt.api.get
|
2022-01-29 11:29:15 +00:00
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
import java.util.Locale
|
|
|
|
|
2022-08-15 16:53:58 +00:00
|
|
|
class EmpireWebtoon : ConfigurableSource, Madara("Empire Webtoon", "https://webtoonempire.com", "ar", SimpleDateFormat("yyyy MMMMM dd", Locale("ar"))) {
|
|
|
|
|
|
|
|
private val defaultBaseUrl = "https://webtoonempire.com"
|
|
|
|
|
|
|
|
override val baseUrl by lazy { getPrefBaseUrl() }
|
|
|
|
|
|
|
|
private val preferences: SharedPreferences by lazy {
|
|
|
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
private const val RESTART_TACHIYOMI = "Restart Tachiyomi to apply new setting."
|
|
|
|
private const val BASE_URL_PREF_TITLE = "Override BaseUrl"
|
|
|
|
private val BASE_URL_PREF = "overrideBaseUrl_v${AppInfo.getVersionName()}"
|
|
|
|
private const val BASE_URL_PREF_SUMMARY = "For temporary uses. Updating the extension will erase this setting."
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
|
|
|
val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply {
|
|
|
|
key = BASE_URL_PREF_TITLE
|
|
|
|
title = BASE_URL_PREF_TITLE
|
|
|
|
summary = BASE_URL_PREF_SUMMARY
|
|
|
|
this.setDefaultValue(defaultBaseUrl)
|
|
|
|
dialogTitle = BASE_URL_PREF_TITLE
|
|
|
|
|
|
|
|
setOnPreferenceChangeListener { _, newValue ->
|
|
|
|
try {
|
|
|
|
val res = preferences.edit().putString(BASE_URL_PREF, newValue as String).commit()
|
|
|
|
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
|
|
|
|
res
|
|
|
|
} catch (e: Exception) {
|
|
|
|
e.printStackTrace()
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
screen.addPreference(baseUrlPref)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, defaultBaseUrl)!!
|
|
|
|
}
|