mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +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})"
|
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
|
* Returns an observable containing a page with a list of manga. Normally it's not needed to
|
||||||
* override this method.
|
* override this method.
|
||||||
|
@ -145,8 +145,7 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ((i, element) in document.select(image_css).withIndex()) {
|
for ((i, element) in document.select(image_css).withIndex()) {
|
||||||
val page = pages.getOrElse(i) { Page(i, "").apply { pages.add(this) } }
|
pages.getOrNull(i)?.imageUrl = element.attr(image_attr).let {
|
||||||
page.imageUrl = element.attr(image_attr).let {
|
|
||||||
getAbsoluteUrl(it, response.request().url())
|
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.Language
|
||||||
import eu.kanade.tachiyomi.data.source.model.MangasPage
|
import eu.kanade.tachiyomi.data.source.model.MangasPage
|
||||||
import eu.kanade.tachiyomi.data.source.model.Page
|
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 eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
@ -26,7 +27,7 @@ import java.text.SimpleDateFormat
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.regex.Pattern
|
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"
|
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()
|
return client.newCall(POST(url, headers, payload)).asObservable()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isLoginRequired() = true
|
|
||||||
|
|
||||||
override fun isAuthenticationSuccessful(response: Response) =
|
override fun isAuthenticationSuccessful(response: Response) =
|
||||||
response.priorResponse() != null && response.priorResponse().code() == 302
|
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.Source
|
||||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.data.source.model.MangasPage
|
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.data.source.online.OnlineSource
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
import eu.kanade.tachiyomi.util.RxPager
|
import eu.kanade.tachiyomi.util.RxPager
|
||||||
@ -299,15 +300,13 @@ class CataloguePresenter : BasePresenter<CatalogueFragment>() {
|
|||||||
* @return true if the source is valid, false otherwise.
|
* @return true if the source is valid, false otherwise.
|
||||||
*/
|
*/
|
||||||
fun isValidSource(source: Source?): Boolean {
|
fun isValidSource(source: Source?): Boolean {
|
||||||
if (source == null || source !is OnlineSource) return false
|
if (source == null) return false
|
||||||
|
|
||||||
return with(source) {
|
if (source is LoginSource) {
|
||||||
if (!isLoginRequired() || isLogged()) {
|
return source.isLogged() ||
|
||||||
true
|
(prefs.sourceUsername(source) != "" && prefs.sourcePassword(source) != "")
|
||||||
} else {
|
|
||||||
prefs.sourceUsername(this) != "" && prefs.sourcePassword(this) != ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +97,6 @@ class PagerReaderFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
with(image_view) {
|
with(image_view) {
|
||||||
setParallelLoadingEnabled(true)
|
|
||||||
setMaxBitmapDimensions(readerActivity.maxBitmapSize)
|
setMaxBitmapDimensions(readerActivity.maxBitmapSize)
|
||||||
setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED)
|
setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED)
|
||||||
setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE)
|
setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE)
|
||||||
|
@ -44,7 +44,6 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
with(view.image_view) {
|
with(view.image_view) {
|
||||||
setParallelLoadingEnabled(true)
|
|
||||||
setMaxBitmapDimensions(readerActivity.maxBitmapSize)
|
setMaxBitmapDimensions(readerActivity.maxBitmapSize)
|
||||||
setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED)
|
setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED)
|
||||||
setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE)
|
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.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.data.source.Source
|
import eu.kanade.tachiyomi.data.source.Source
|
||||||
import eu.kanade.tachiyomi.data.source.getLanguages
|
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.LoginPreference
|
||||||
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
|
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
@ -45,11 +46,9 @@ class SettingsSourcesFragment : SettingsNestedFragment() {
|
|||||||
val enabledSources = settingsActivity.sourceManager.getOnlineSources()
|
val enabledSources = settingsActivity.sourceManager.getOnlineSources()
|
||||||
.filter { it.lang.code in languages }
|
.filter { it.lang.code in languages }
|
||||||
|
|
||||||
for (source in enabledSources) {
|
for (source in enabledSources.filterIsInstance(LoginSource::class.java)) {
|
||||||
if (source.isLoginRequired()) {
|
val pref = createLoginSourceEntry(source)
|
||||||
val pref = createSource(source)
|
sourcesPref.addPreference(pref)
|
||||||
sourcesPref.addPreference(pref)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide category if it doesn't have any child
|
// Hide category if it doesn't have any child
|
||||||
@ -62,7 +61,7 @@ class SettingsSourcesFragment : SettingsNestedFragment() {
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSource(source: Source): Preference {
|
fun createLoginSourceEntry(source: Source): Preference {
|
||||||
return LoginPreference(preferenceManager.context).apply {
|
return LoginPreference(preferenceManager.context).apply {
|
||||||
key = preferences.keys.sourceUsername(source.id)
|
key = preferences.keys.sourceUsername(source.id)
|
||||||
title = source.toString()
|
title = source.toString()
|
||||||
|
@ -4,7 +4,7 @@ import android.os.Bundle
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.source.Source
|
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.ui.setting.SettingsActivity
|
||||||
import eu.kanade.tachiyomi.util.toast
|
import eu.kanade.tachiyomi.util.toast
|
||||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val sourceId = arguments.getInt("key")
|
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) {
|
override fun setCredentialsOnView(view: View) = with(view) {
|
||||||
|
Loading…
Reference in New Issue
Block a user