From 6beff242b0a36d28d7624965cab613051043ca51 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 28 May 2016 00:20:59 +0200 Subject: [PATCH] LoginSource moved to an interface --- .../tachiyomi/data/source/online/LoginSource.kt | 15 +++++++++++++++ .../tachiyomi/data/source/online/OnlineSource.kt | 12 ------------ .../data/source/online/YamlOnlineSource.kt | 3 +-- .../data/source/online/english/Batoto.kt | 5 ++--- .../tachiyomi/ui/catalogue/CataloguePresenter.kt | 13 ++++++------- .../ui/reader/viewer/pager/PagerReaderFragment.kt | 1 - .../ui/reader/viewer/webtoon/WebtoonHolder.kt | 1 - .../ui/setting/SettingsSourcesFragment.kt | 11 +++++------ .../widget/preference/SourceLoginDialog.kt | 6 +++--- 9 files changed, 32 insertions(+), 35 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/source/online/LoginSource.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/LoginSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/LoginSource.kt new file mode 100644 index 000000000..0c9917f7c --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/LoginSource.kt @@ -0,0 +1,15 @@ +package eu.kanade.tachiyomi.data.source.online + +import eu.kanade.tachiyomi.data.source.Source +import okhttp3.Response +import rx.Observable + +interface LoginSource : Source { + + fun isLogged(): Boolean + + fun login(username: String, password: String): Observable + + fun isAuthenticationSuccessful(response: Response): Boolean + +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt index 696d9e345..0c8780098 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt @@ -78,18 +78,6 @@ abstract class OnlineSource(context: Context) : Source { */ override fun toString() = "$name (${lang.code})" - // Login source - - open fun isLoginRequired() = false - - open fun isLogged(): Boolean = throw Exception("Not implemented") - - open fun login(username: String, password: String): Observable - = throw Exception("Not implemented") - - open fun isAuthenticationSuccessful(response: Response): Boolean - = throw Exception("Not implemented") - /** * Returns an observable containing a page with a list of manga. Normally it's not needed to * override this method. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt index c8257db51..00fe76bb6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt @@ -145,8 +145,7 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con } for ((i, element) in document.select(image_css).withIndex()) { - val page = pages.getOrElse(i) { Page(i, "").apply { pages.add(this) } } - page.imageUrl = element.attr(image_attr).let { + pages.getOrNull(i)?.imageUrl = element.attr(image_attr).let { getAbsoluteUrl(it, response.request().url()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt index 91c7036e2..ce54abccc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.source.EN import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page +import eu.kanade.tachiyomi.data.source.online.LoginSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import okhttp3.FormBody import okhttp3.Request @@ -26,7 +27,7 @@ import java.text.SimpleDateFormat import java.util.* import java.util.regex.Pattern -class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(context) { +class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(context), LoginSource { override val name = "Batoto" @@ -238,8 +239,6 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex return client.newCall(POST(url, headers, payload)).asObservable() } - override fun isLoginRequired() = true - override fun isAuthenticationSuccessful(response: Response) = response.priorResponse() != null && response.priorResponse().code() == 302 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt index 76d833cbb..7178bae36 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.source.EN import eu.kanade.tachiyomi.data.source.Source import eu.kanade.tachiyomi.data.source.SourceManager import eu.kanade.tachiyomi.data.source.model.MangasPage +import eu.kanade.tachiyomi.data.source.online.LoginSource import eu.kanade.tachiyomi.data.source.online.OnlineSource import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.RxPager @@ -299,15 +300,13 @@ class CataloguePresenter : BasePresenter() { * @return true if the source is valid, false otherwise. */ fun isValidSource(source: Source?): Boolean { - if (source == null || source !is OnlineSource) return false + if (source == null) return false - return with(source) { - if (!isLoginRequired() || isLogged()) { - true - } else { - prefs.sourceUsername(this) != "" && prefs.sourcePassword(this) != "" - } + if (source is LoginSource) { + return source.isLogged() || + (prefs.sourceUsername(source) != "" && prefs.sourcePassword(source) != "") } + return true } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt index 2d3a4a16a..aea00b28c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt @@ -97,7 +97,6 @@ class PagerReaderFragment : BaseFragment() { } with(image_view) { - setParallelLoadingEnabled(true) setMaxBitmapDimensions(readerActivity.maxBitmapSize) setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED) setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt index 1ab3aed22..3df86f398 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt @@ -44,7 +44,6 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) init { with(view.image_view) { - setParallelLoadingEnabled(true) setMaxBitmapDimensions(readerActivity.maxBitmapSize) setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED) setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt index 627269407..1d806c331 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt @@ -9,6 +9,7 @@ import android.view.View import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.source.Source import eu.kanade.tachiyomi.data.source.getLanguages +import eu.kanade.tachiyomi.data.source.online.LoginSource import eu.kanade.tachiyomi.widget.preference.LoginPreference import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog import rx.Subscription @@ -45,11 +46,9 @@ class SettingsSourcesFragment : SettingsNestedFragment() { val enabledSources = settingsActivity.sourceManager.getOnlineSources() .filter { it.lang.code in languages } - for (source in enabledSources) { - if (source.isLoginRequired()) { - val pref = createSource(source) - sourcesPref.addPreference(pref) - } + for (source in enabledSources.filterIsInstance(LoginSource::class.java)) { + val pref = createLoginSourceEntry(source) + sourcesPref.addPreference(pref) } // Hide category if it doesn't have any child @@ -62,7 +61,7 @@ class SettingsSourcesFragment : SettingsNestedFragment() { super.onDestroyView() } - fun createSource(source: Source): Preference { + fun createLoginSourceEntry(source: Source): Preference { return LoginPreference(preferenceManager.context).apply { key = preferences.keys.sourceUsername(source.id) title = source.toString() diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt index dd39dfab0..76d315da1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt @@ -4,7 +4,7 @@ import android.os.Bundle import android.view.View import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.source.Source -import eu.kanade.tachiyomi.data.source.online.OnlineSource +import eu.kanade.tachiyomi.data.source.online.LoginSource import eu.kanade.tachiyomi.ui.setting.SettingsActivity import eu.kanade.tachiyomi.util.toast import kotlinx.android.synthetic.main.pref_account_login.view.* @@ -24,13 +24,13 @@ class SourceLoginDialog : LoginDialogPreference() { } } - lateinit var source: OnlineSource + lateinit var source: LoginSource override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val sourceId = arguments.getInt("key") - source = (activity as SettingsActivity).sourceManager.get(sourceId) as OnlineSource + source = (activity as SettingsActivity).sourceManager.get(sourceId) as LoginSource } override fun setCredentialsOnView(view: View) = with(view) {