mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 22:59:18 +01:00
LoginSource moved to an interface
This commit is contained in:
parent
46cc078e93
commit
6beff242b0
@ -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<Boolean>
|
||||
|
||||
fun isAuthenticationSuccessful(response: Response): Boolean
|
||||
|
||||
}
|
@ -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<Boolean>
|
||||
= 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.
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<CatalogueFragment>() {
|
||||
* @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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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,12 +46,10 @@ 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)
|
||||
for (source in enabledSources.filterIsInstance(LoginSource::class.java)) {
|
||||
val pref = createLoginSourceEntry(source)
|
||||
sourcesPref.addPreference(pref)
|
||||
}
|
||||
}
|
||||
|
||||
// Hide category if it doesn't have any child
|
||||
sourcesPref.isVisible = sourcesPref.preferenceCount > 0
|
||||
@ -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()
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user