diff --git a/lib-multisrc/grouple/build.gradle.kts b/lib-multisrc/grouple/build.gradle.kts index a4171c782..1258098ad 100644 --- a/lib-multisrc/grouple/build.gradle.kts +++ b/lib-multisrc/grouple/build.gradle.kts @@ -2,4 +2,4 @@ plugins { id("lib-multisrc") } -baseVersionCode = 23 +baseVersionCode = 24 diff --git a/src/ru/allhentai/src/eu/kanade/tachiyomi/extension/ru/allhentai/AllHentai.kt b/src/ru/allhentai/src/eu/kanade/tachiyomi/extension/ru/allhentai/AllHentai.kt index 678f0eb78..bfd73028e 100644 --- a/src/ru/allhentai/src/eu/kanade/tachiyomi/extension/ru/allhentai/AllHentai.kt +++ b/src/ru/allhentai/src/eu/kanade/tachiyomi/extension/ru/allhentai/AllHentai.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.extension.ru.allhentai import android.app.Application -import android.content.SharedPreferences import android.widget.Toast import androidx.preference.EditTextPreference import eu.kanade.tachiyomi.multisrc.grouple.GroupLe @@ -16,12 +15,10 @@ class AllHentai : GroupLe("AllHentai", "https://z.ahen.me", "ru") { override val id: Long = 1809051393403180443 - private val preferences: SharedPreferences by lazy { + private val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) - } - private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!! - override val baseUrl: String = domain + override val baseUrl by lazy { getPrefBaseUrl() } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = super.searchMangaRequest(page, query, filters).url.newBuilder() @@ -269,26 +266,34 @@ class AllHentai : GroupLe("AllHentai", "https://z.ahen.me", "ru") { override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { super.setupPreferenceScreen(screen) EditTextPreference(screen.context).apply { - key = DOMAIN_TITLE - this.title = DOMAIN_TITLE - summary = domain - this.setDefaultValue(DOMAIN_DEFAULT) + key = DOMAIN_PREF + title = DOMAIN_TITLE + setDefaultValue(super.baseUrl) dialogTitle = DOMAIN_TITLE - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(DOMAIN_TITLE, newValue as String).commit() - Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } + dialogMessage = "Default URL:\n\t${super.baseUrl}" + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() + true } }.let(screen::addPreference) } + private fun getPrefBaseUrl(): String = preferences.getString(DOMAIN_PREF, super.baseUrl)!! + + init { + preferences.getString(DEFAULT_DOMAIN_PREF, null).let { defaultBaseUrl -> + if (defaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(DOMAIN_PREF, super.baseUrl) + .putString(DEFAULT_DOMAIN_PREF, super.baseUrl) + .apply() + } + } + } + companion object { + private const val DOMAIN_PREF = "Домен" + private const val DEFAULT_DOMAIN_PREF = "pref_default_domain" private const val DOMAIN_TITLE = "Домен" - private const val DOMAIN_DEFAULT = "https://z.ahen.me" } } diff --git a/src/ru/mintmanga/build.gradle b/src/ru/mintmanga/build.gradle index 7f9ce0e4e..9e8b43494 100644 --- a/src/ru/mintmanga/build.gradle +++ b/src/ru/mintmanga/build.gradle @@ -2,7 +2,7 @@ ext { extName = 'MintManga' extClass = '.MintManga' themePkg = 'grouple' - baseUrl = 'https://mintmanga.com' + baseUrl = 'https://1.mintmanga.com' overrideVersionCode = 46 isNsfw = true } diff --git a/src/ru/mintmanga/src/eu/kanade/tachiyomi/extension/ru/mintmanga/MintManga.kt b/src/ru/mintmanga/src/eu/kanade/tachiyomi/extension/ru/mintmanga/MintManga.kt index 3d440a165..4eacc1d2b 100644 --- a/src/ru/mintmanga/src/eu/kanade/tachiyomi/extension/ru/mintmanga/MintManga.kt +++ b/src/ru/mintmanga/src/eu/kanade/tachiyomi/extension/ru/mintmanga/MintManga.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.extension.ru.mintmanga import android.app.Application -import android.content.SharedPreferences import android.widget.Toast import androidx.preference.EditTextPreference import eu.kanade.tachiyomi.multisrc.grouple.GroupLe @@ -12,16 +11,15 @@ import okhttp3.Request import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class MintManga : GroupLe("MintManga", "https://mintmanga.com", "ru") { +class MintManga : GroupLe("MintManga", "https://1.mintmanga.com", "ru") { override val id: Long = 6 - private val preferences: SharedPreferences by lazy { + private val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) - } - private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!! - override val baseUrl: String = domain + override val baseUrl by lazy { getPrefBaseUrl() } + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = super.searchMangaRequest(page, query, filters).url.newBuilder() (if (filters.isEmpty()) getFilterList().reversed() else filters.reversed()).forEach { filter -> @@ -174,26 +172,34 @@ class MintManga : GroupLe("MintManga", "https://mintmanga.com", "ru") { override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { super.setupPreferenceScreen(screen) EditTextPreference(screen.context).apply { - key = DOMAIN_TITLE - this.title = DOMAIN_TITLE - summary = domain - this.setDefaultValue(DOMAIN_DEFAULT) + key = DOMAIN_PREF + title = DOMAIN_TITLE + setDefaultValue(super.baseUrl) dialogTitle = DOMAIN_TITLE - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(DOMAIN_TITLE, newValue as String).commit() - Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } + dialogMessage = "Default URL:\n\t${super.baseUrl}" + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() + true } }.let(screen::addPreference) } + private fun getPrefBaseUrl(): String = preferences.getString(DOMAIN_PREF, super.baseUrl)!! + + init { + preferences.getString(DEFAULT_DOMAIN_PREF, null).let { defaultBaseUrl -> + if (defaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(DOMAIN_PREF, super.baseUrl) + .putString(DEFAULT_DOMAIN_PREF, super.baseUrl) + .apply() + } + } + } + companion object { + private const val DOMAIN_PREF = "Домен" + private const val DEFAULT_DOMAIN_PREF = "pref_default_domain" private const val DOMAIN_TITLE = "Домен" - private const val DOMAIN_DEFAULT = "https://mintmanga.com" } } diff --git a/src/ru/readmanga/src/eu/kanade/tachiyomi/extension/ru/readmanga/ReadManga.kt b/src/ru/readmanga/src/eu/kanade/tachiyomi/extension/ru/readmanga/ReadManga.kt index a9c90e9df..5a2710973 100644 --- a/src/ru/readmanga/src/eu/kanade/tachiyomi/extension/ru/readmanga/ReadManga.kt +++ b/src/ru/readmanga/src/eu/kanade/tachiyomi/extension/ru/readmanga/ReadManga.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.extension.ru.readmanga import android.app.Application -import android.content.SharedPreferences import android.widget.Toast import androidx.preference.EditTextPreference import eu.kanade.tachiyomi.multisrc.grouple.GroupLe @@ -16,12 +15,11 @@ class ReadManga : GroupLe("ReadManga", "https://1.readmanga.io", "ru") { override val id: Long = 5 - private val preferences: SharedPreferences by lazy { + private val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) - } - private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!! - override val baseUrl: String = domain + override val baseUrl by lazy { getPrefBaseUrl() } + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = super.searchMangaRequest(page, query, filters).url.newBuilder() (if (filters.isEmpty()) getFilterList().reversed() else filters.reversed()).forEach { filter -> @@ -171,25 +169,34 @@ class ReadManga : GroupLe("ReadManga", "https://1.readmanga.io", "ru") { override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { super.setupPreferenceScreen(screen) EditTextPreference(screen.context).apply { - key = DOMAIN_TITLE - this.title = DOMAIN_TITLE - summary = domain - this.setDefaultValue(DOMAIN_DEFAULT) + key = DOMAIN_PREF + title = DOMAIN_TITLE + setDefaultValue(super.baseUrl) dialogTitle = DOMAIN_TITLE - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(DOMAIN_TITLE, newValue as String).commit() - Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } + dialogMessage = "Default URL:\n\t${super.baseUrl}" + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() + true } }.let(screen::addPreference) } + + private fun getPrefBaseUrl(): String = preferences.getString(DOMAIN_PREF, super.baseUrl)!! + + init { + preferences.getString(DEFAULT_DOMAIN_PREF, null).let { defaultBaseUrl -> + if (defaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(DOMAIN_PREF, super.baseUrl) + .putString(DEFAULT_DOMAIN_PREF, super.baseUrl) + .apply() + } + } + } + companion object { + private const val DOMAIN_PREF = "Домен" + private const val DEFAULT_DOMAIN_PREF = "pref_default_domain" private const val DOMAIN_TITLE = "Домен" - private const val DOMAIN_DEFAULT = "https://1.readmanga.io" } } diff --git a/src/ru/rumix/src/eu/kanade/tachiyomi/extension/ru/rumix/RuMIX.kt b/src/ru/rumix/src/eu/kanade/tachiyomi/extension/ru/rumix/RuMIX.kt index 5f42397bb..4be9606a1 100644 --- a/src/ru/rumix/src/eu/kanade/tachiyomi/extension/ru/rumix/RuMIX.kt +++ b/src/ru/rumix/src/eu/kanade/tachiyomi/extension/ru/rumix/RuMIX.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.extension.ru.rumix import android.app.Application -import android.content.SharedPreferences import android.widget.Toast import androidx.preference.EditTextPreference import eu.kanade.tachiyomi.multisrc.grouple.GroupLe @@ -14,12 +13,10 @@ import uy.kohesive.injekt.api.get class RuMIX : GroupLe("RuMIX", "https://rumix.me", "ru") { - private val preferences: SharedPreferences by lazy { + private val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) - } - private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!! - override val baseUrl: String = domain + override val baseUrl by lazy { getPrefBaseUrl() } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = super.searchMangaRequest(page, query, filters).url.newBuilder() @@ -54,26 +51,34 @@ class RuMIX : GroupLe("RuMIX", "https://rumix.me", "ru") { override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { super.setupPreferenceScreen(screen) EditTextPreference(screen.context).apply { - key = DOMAIN_TITLE - this.title = DOMAIN_TITLE - summary = domain - this.setDefaultValue(DOMAIN_DEFAULT) + key = DOMAIN_PREF + title = DOMAIN_TITLE + setDefaultValue(super.baseUrl) dialogTitle = DOMAIN_TITLE - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(DOMAIN_TITLE, newValue as String).commit() - Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } + dialogMessage = "Default URL:\n\t${super.baseUrl}" + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() + true } }.let(screen::addPreference) } + private fun getPrefBaseUrl(): String = preferences.getString(DOMAIN_PREF, super.baseUrl)!! + + init { + preferences.getString(DEFAULT_DOMAIN_PREF, null).let { defaultBaseUrl -> + if (defaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(DOMAIN_PREF, super.baseUrl) + .putString(DEFAULT_DOMAIN_PREF, super.baseUrl) + .apply() + } + } + } + companion object { + private const val DOMAIN_PREF = "Домен" + private const val DEFAULT_DOMAIN_PREF = "pref_default_domain" private const val DOMAIN_TITLE = "Домен" - private const val DOMAIN_DEFAULT = "https://rumix.me" } } diff --git a/src/ru/seimanga/build.gradle b/src/ru/seimanga/build.gradle new file mode 100644 index 000000000..86b919ad5 --- /dev/null +++ b/src/ru/seimanga/build.gradle @@ -0,0 +1,10 @@ +ext { + extName = 'SeiManga' + extClass = '.SeiManga' + themePkg = 'grouple' + baseUrl = 'https://1.seimanga.me' + overrideVersionCode = 0 + isNsfw = true +} + +apply from: "$rootDir/common.gradle" diff --git a/src/ru/seimanga/res/mipmap-hdpi/ic_launcher.png b/src/ru/seimanga/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..f60c9215d Binary files /dev/null and b/src/ru/seimanga/res/mipmap-hdpi/ic_launcher.png differ diff --git a/src/ru/seimanga/res/mipmap-mdpi/ic_launcher.png b/src/ru/seimanga/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..8169cd415 Binary files /dev/null and b/src/ru/seimanga/res/mipmap-mdpi/ic_launcher.png differ diff --git a/src/ru/seimanga/res/mipmap-xhdpi/ic_launcher.png b/src/ru/seimanga/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..cb64ea625 Binary files /dev/null and b/src/ru/seimanga/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/src/ru/seimanga/res/mipmap-xxhdpi/ic_launcher.png b/src/ru/seimanga/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..edbfa9bb2 Binary files /dev/null and b/src/ru/seimanga/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/src/ru/seimanga/res/mipmap-xxxhdpi/ic_launcher.png b/src/ru/seimanga/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..a427e7304 Binary files /dev/null and b/src/ru/seimanga/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/src/ru/seimanga/src/eu/kanade/tachiyomi/extension/ru/seimanga/SeiManga.kt b/src/ru/seimanga/src/eu/kanade/tachiyomi/extension/ru/seimanga/SeiManga.kt new file mode 100644 index 000000000..97d1b76c1 --- /dev/null +++ b/src/ru/seimanga/src/eu/kanade/tachiyomi/extension/ru/seimanga/SeiManga.kt @@ -0,0 +1,203 @@ +package eu.kanade.tachiyomi.extension.ru.seimanga + +import android.app.Application +import android.widget.Toast +import androidx.preference.EditTextPreference +import eu.kanade.tachiyomi.multisrc.grouple.GroupLe +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.model.Filter +import eu.kanade.tachiyomi.source.model.FilterList +import okhttp3.Request +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get + +class SeiManga : GroupLe("SeiManga", "https://1.seimanga.me", "ru") { + + private val preferences = + Injekt.get().getSharedPreferences("source_$id", 0x0000) + + override val baseUrl by lazy { getPrefBaseUrl() } + + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val url = super.searchMangaRequest(page, query, filters).url.newBuilder() + (if (filters.isEmpty()) getFilterList().reversed() else filters.reversed()).forEach { filter -> + when (filter) { + is GenreList -> filter.state.forEach { genre -> + if (genre.state != Filter.TriState.STATE_IGNORE) { + url.addQueryParameter(genre.id, arrayOf("=", "=in", "=ex")[genre.state]) + } + } + is Category -> filter.state.forEach { category -> + if (category.state != Filter.TriState.STATE_IGNORE) { + url.addQueryParameter(category.id, arrayOf("=", "=in", "=ex")[category.state]) + } + } + is AgeList -> filter.state.forEach { age -> + if (age.state != Filter.TriState.STATE_IGNORE) { + url.addQueryParameter(age.id, arrayOf("=", "=in", "=ex")[age.state]) + } + } + is More -> filter.state.forEach { more -> + if (more.state != Filter.TriState.STATE_IGNORE) { + url.addQueryParameter(more.id, arrayOf("=", "=in", "=ex")[more.state]) + } + } + is FilList -> filter.state.forEach { fils -> + if (fils.state != Filter.TriState.STATE_IGNORE) { + url.addQueryParameter(fils.id, arrayOf("=", "=in", "=ex")[fils.state]) + } + } + is OrderBy -> { + if (url.toString().contains("&") && filter.state < 6) { + url.addQueryParameter("sortType", arrayOf("RATING", "POPULARITY", "YEAR", "NAME", "DATE_CREATE", "DATE_UPDATE")[filter.state]) + } else { + val ord = arrayOf("rate", "popularity", "year", "name", "created", "updated", "votes")[filter.state] + return GET("$baseUrl/list?sortType=$ord&offset=${70 * (page - 1)}", headers) + } + } + else -> {} + } + } + return if (url.toString().contains("&")) { + GET(url.toString().replace("=%3D", "="), headers) + } else { + popularMangaRequest(page) + } + } + + private class OrderBy : Filter.Select( + "Сортировка", + arrayOf("По популярности", "Популярно сейчас", "По году", "По имени", "Новинки", "По дате обновления", "По рейтингу"), + ) + + private class Genre(name: String, val id: String) : Filter.TriState(name) + + private class GenreList(genres: List) : Filter.Group("Жанры", genres) + private class Category(categories: List) : Filter.Group("Категории", categories) + private class AgeList(ages: List) : Filter.Group("Возрастная рекомендация", ages) + private class More(moren: List) : Filter.Group("Прочее", moren) + private class FilList(fils: List) : Filter.Group("Фильтры", fils) + + override fun getFilterList() = FilterList( + OrderBy(), + Category(getCategoryList()), + GenreList(getGenreList()), + AgeList(getAgeList()), + More(getMore()), + FilList(getFilList()), + ) + private fun getFilList() = listOf( + Genre("Высокий рейтинг", "s_high_rate"), + Genre("Сингл", "s_single"), + Genre("Для взрослых", "s_mature"), + Genre("Завершенная", "s_completed"), + Genre("Переведено", "s_translated"), + Genre("Заброшен перевод", "s_abandoned_popular"), + Genre("Длинная", "s_many_chapters"), + Genre("Ожидает загрузки", "s_wait_upload"), + Genre("Белые жанры", "s_not_pessimized"), + ) + private fun getMore() = listOf( + Genre("Анонс", "el_6641"), + Genre("В цвете", "el_4614"), + Genre("Веб", "el_1355"), + Genre("Выпуск приостановлен", "el_5232"), + Genre("Не Яой", "el_1874"), + Genre("Сборник", "el_1348"), + ) + + private fun getAgeList() = listOf( + Genre("R(16+)", "el_3968"), + Genre("NC-17(18+)", "el_3969"), + Genre("R18+(18+)", "el_3990"), + ) + + private fun getCategoryList() = listOf( + Genre("OEL-манга", "el_6637"), + Genre("Додзинси", "el_1332"), + Genre("Арт", "el_2220"), + Genre("Ёнкома", "el_2741"), + Genre("Комикс", "el_1903"), + Genre("Манга", "el_6421"), + Genre("Манхва", "el_1873"), + Genre("Маньхуа", "el_1875"), + Genre("Ранобэ", "el_5688"), + ) + + private fun getGenreList() = listOf( + Genre("боевик", "el_1346"), + Genre("боевые искусства", "el_1334"), + Genre("гарем", "el_1333"), + Genre("гендерная интрига", "el_1347"), + Genre("героическое фэнтези", "el_1337"), + Genre("детектив", "el_1343"), + Genre("дзёсэй", "el_1349"), + Genre("драма", "el_1310"), + Genre("игра", "el_5229"), + Genre("исэкай", "el_6420"), + Genre("история", "el_1311"), + Genre("киберпанк", "el_1351"), + Genre("комедия", "el_1328"), + Genre("меха", "el_1318"), + Genre("научная фантастика", "el_1325"), + Genre("омегаверс", "el_5676"), + Genre("повседневность", "el_1327"), + Genre("постапокалиптика", "el_1342"), + Genre("приключения", "el_1322"), + Genre("психология", "el_1335"), + Genre("романтика", "el_1313"), + Genre("самурайский боевик", "el_1316"), + Genre("сверхъестественное", "el_1350"), + Genre("сёдзё", "el_1314"), + Genre("сёдзё-ай", "el_1320"), + Genre("сёнэн", "el_1326"), + Genre("сёнэн-ай", "el_1330"), + Genre("спорт", "el_1321"), + Genre("сэйнэн", "el_1329"), + Genre("сянься", "el_6631"), + Genre("трагедия", "el_1344"), + Genre("триллер", "el_1341"), + Genre("ужасы", "el_1317"), + Genre("уся", "el_6632"), + Genre("фэнтези", "el_1323"), + Genre("школа", "el_1319"), + Genre("эротика", "el_1340"), + Genre("этти", "el_1354"), + Genre("юри", "el_1315"), + Genre("яой", "el_1336"), + ) + + override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { + super.setupPreferenceScreen(screen) + EditTextPreference(screen.context).apply { + key = DOMAIN_PREF + title = DOMAIN_TITLE + setDefaultValue(super.baseUrl) + dialogTitle = DOMAIN_TITLE + dialogMessage = "Default URL:\n\t${super.baseUrl}" + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() + true + } + }.let(screen::addPreference) + } + + private fun getPrefBaseUrl(): String = preferences.getString(DOMAIN_PREF, super.baseUrl)!! + + init { + preferences.getString(DEFAULT_DOMAIN_PREF, null).let { defaultBaseUrl -> + if (defaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(DOMAIN_PREF, super.baseUrl) + .putString(DEFAULT_DOMAIN_PREF, super.baseUrl) + .apply() + } + } + } + + companion object { + private const val DOMAIN_PREF = "pref_domain" + private const val DEFAULT_DOMAIN_PREF = "pref_default_domain" + private const val DOMAIN_TITLE = "Домен" + } +} diff --git a/src/ru/selfmanga/src/eu/kanade/tachiyomi/extension/ru/selfmanga/SelfManga.kt b/src/ru/selfmanga/src/eu/kanade/tachiyomi/extension/ru/selfmanga/SelfManga.kt index c108b5293..29c43f2da 100644 --- a/src/ru/selfmanga/src/eu/kanade/tachiyomi/extension/ru/selfmanga/SelfManga.kt +++ b/src/ru/selfmanga/src/eu/kanade/tachiyomi/extension/ru/selfmanga/SelfManga.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.extension.ru.selfmanga import android.app.Application -import android.content.SharedPreferences import android.widget.Toast import androidx.preference.EditTextPreference import eu.kanade.tachiyomi.multisrc.grouple.GroupLe @@ -16,12 +15,10 @@ class SelfManga : GroupLe("SelfManga", "https://selfmanga.live", "ru") { override val id: Long = 5227602742162454547 - private val preferences: SharedPreferences by lazy { + private val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) - } - private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!! - override val baseUrl: String = domain + override val baseUrl by lazy { getPrefBaseUrl() } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = super.searchMangaRequest(page, query, filters).url.newBuilder() @@ -118,25 +115,34 @@ class SelfManga : GroupLe("SelfManga", "https://selfmanga.live", "ru") { override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { super.setupPreferenceScreen(screen) EditTextPreference(screen.context).apply { - key = DOMAIN_TITLE - this.title = DOMAIN_TITLE - summary = domain - this.setDefaultValue(DOMAIN_DEFAULT) + key = DOMAIN_PREF + title = DOMAIN_TITLE + setDefaultValue(super.baseUrl) dialogTitle = DOMAIN_TITLE - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(DOMAIN_TITLE, newValue as String).commit() - Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } + dialogMessage = "Default URL:\n\t${super.baseUrl}" + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show() + true } }.let(screen::addPreference) } + + private fun getPrefBaseUrl(): String = preferences.getString(DOMAIN_PREF, super.baseUrl)!! + + init { + preferences.getString(DEFAULT_DOMAIN_PREF, null).let { defaultBaseUrl -> + if (defaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(DOMAIN_PREF, super.baseUrl) + .putString(DEFAULT_DOMAIN_PREF, super.baseUrl) + .apply() + } + } + } + companion object { + private const val DOMAIN_PREF = "Домен" + private const val DEFAULT_DOMAIN_PREF = "pref_default_domain" private const val DOMAIN_TITLE = "Домен" - private const val DOMAIN_DEFAULT = "https://selfmanga.live" } }