Remove unused LoginSource

This commit is contained in:
arkon 2020-02-27 22:43:48 -05:00
parent 464b4b18a4
commit 4e60a81b36
10 changed files with 9 additions and 226 deletions

View file

@ -131,14 +131,6 @@ object PreferenceKeys {
const val downloadBadge = "display_download_badge" const val downloadBadge = "display_download_badge"
@Deprecated("Use the preferences of the source")
fun sourceUsername(sourceId: Long) = "pref_source_username_$sourceId"
@Deprecated("Use the preferences of the source")
fun sourcePassword(sourceId: Long) = "pref_source_password_$sourceId"
fun sourceSharedPref(sourceId: Long) = "source_$sourceId"
fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId" fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId"
fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId" fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId"

View file

@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.source.Source
import java.io.File import java.io.File
import java.text.DateFormat import java.text.DateFormat
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -132,17 +131,6 @@ class PreferencesHelper(val context: Context) {
fun enabledLanguages() = rxPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language)) fun enabledLanguages() = rxPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language))
fun sourceUsername(source: Source) = prefs.getString(Keys.sourceUsername(source.id), "")
fun sourcePassword(source: Source) = prefs.getString(Keys.sourcePassword(source.id), "")
fun setSourceCredentials(source: Source, username: String, password: String) {
prefs.edit()
.putString(Keys.sourceUsername(source.id), username)
.putString(Keys.sourcePassword(source.id), password)
.apply()
}
fun trackUsername(sync: TrackService) = prefs.getString(Keys.trackUsername(sync.id), "") fun trackUsername(sync: TrackService) = prefs.getString(Keys.trackUsername(sync.id), "")
fun trackPassword(sync: TrackService) = prefs.getString(Keys.trackPassword(sync.id), "") fun trackPassword(sync: TrackService) = prefs.getString(Keys.trackPassword(sync.id), "")

View file

@ -1,14 +0,0 @@
package eu.kanade.tachiyomi.source.online
import eu.kanade.tachiyomi.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
}

View file

@ -19,7 +19,6 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
@ -27,7 +26,6 @@ import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCatalogueController
import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController
import eu.kanade.tachiyomi.ui.catalogue.latest.LatestUpdatesController import eu.kanade.tachiyomi.ui.catalogue.latest.LatestUpdatesController
import eu.kanade.tachiyomi.ui.setting.SettingsSourcesController import eu.kanade.tachiyomi.ui.setting.SettingsSourcesController
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
import kotlinx.android.synthetic.main.catalogue_main_controller.recycler import kotlinx.android.synthetic.main.catalogue_main_controller.recycler
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -35,12 +33,10 @@ import uy.kohesive.injekt.api.get
/** /**
* This controller shows and manages the different catalogues enabled by the user. * This controller shows and manages the different catalogues enabled by the user.
* This controller should only handle UI actions, IO actions should be done by [CataloguePresenter] * This controller should only handle UI actions, IO actions should be done by [CataloguePresenter]
* [SourceLoginDialog.Listener] refreshes the adapter on successful login of catalogues.
* [CatalogueAdapter.OnBrowseClickListener] call function data on browse item click. * [CatalogueAdapter.OnBrowseClickListener] call function data on browse item click.
* [CatalogueAdapter.OnLatestClickListener] call function data on latest item click * [CatalogueAdapter.OnLatestClickListener] call function data on latest item click
*/ */
class CatalogueController : NucleusController<CataloguePresenter>(), class CatalogueController : NucleusController<CataloguePresenter>(),
SourceLoginDialog.Listener,
FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemClickListener,
CatalogueAdapter.OnBrowseClickListener, CatalogueAdapter.OnBrowseClickListener,
CatalogueAdapter.OnLatestClickListener { CatalogueAdapter.OnLatestClickListener {
@ -122,32 +118,13 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
} }
} }
/**
* Called when login dialog is closed, refreshes the adapter.
*
* @param source clicked item containing source information.
*/
override fun loginDialogClosed(source: LoginSource) {
if (source.isLogged()) {
adapter?.clear()
presenter.loadSources()
}
}
/** /**
* Called when item is clicked * Called when item is clicked
*/ */
override fun onItemClick(view: View, position: Int): Boolean { override fun onItemClick(view: View, position: Int): Boolean {
val item = adapter?.getItem(position) as? SourceItem ?: return false val item = adapter?.getItem(position) as? SourceItem ?: return false
val source = item.source val source = item.source
if (source is LoginSource && !source.isLogged()) {
val dialog = SourceLoginDialog(source)
dialog.targetController = this
dialog.showDialog(router)
} else {
// Open the catalogue view.
openCatalogue(source, BrowseCatalogueController(source)) openCatalogue(source, BrowseCatalogueController(source))
}
return false return false
} }

View file

@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.catalogue
import android.view.View import android.view.View
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
import eu.kanade.tachiyomi.util.view.getRound import eu.kanade.tachiyomi.util.view.getRound
@ -48,11 +47,6 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(), false)) image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(), false))
} }
// If source is login, show only login option
if (source is LoginSource && !source.isLogged()) {
source_browse.setText(R.string.login)
source_latest.gone()
} else {
source_browse.setText(R.string.browse) source_browse.setText(R.string.browse)
if (source.supportsLatest) { if (source.supportsLatest) {
source_latest.visible() source_latest.visible()
@ -61,4 +55,3 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
} }
} }
} }
}

View file

@ -12,7 +12,6 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCataloguePresenter import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCataloguePresenter
import rx.Observable import rx.Observable
@ -105,7 +104,6 @@ open class CatalogueSearchPresenter(
return sourceManager.getCatalogueSources() return sourceManager.getCatalogueSources()
.filter { it.lang in languages } .filter { it.lang in languages }
.filterNot { it is LoginSource && !it.isLogged() }
.filterNot { it.id.toString() in hiddenCatalogues } .filterNot { it.id.toString() in hiddenCatalogues }
.sortedBy { "(${it.lang}) ${it.name}" } .sortedBy { "(${it.lang}) ${it.name}" }
} }

View file

@ -28,12 +28,9 @@ import eu.kanade.tachiyomi.data.preference.EmptyPreferenceDataStore
import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore
import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.widget.preference.LoginPreference
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
import kotlinx.android.synthetic.main.extension_detail_controller.extension_icon import kotlinx.android.synthetic.main.extension_detail_controller.extension_icon
import kotlinx.android.synthetic.main.extension_detail_controller.extension_lang import kotlinx.android.synthetic.main.extension_detail_controller.extension_lang
import kotlinx.android.synthetic.main.extension_detail_controller.extension_obsolete import kotlinx.android.synthetic.main.extension_detail_controller.extension_obsolete
@ -48,8 +45,7 @@ import kotlinx.android.synthetic.main.extension_detail_controller.extension_vers
class ExtensionDetailsController(bundle: Bundle? = null) : class ExtensionDetailsController(bundle: Bundle? = null) :
NucleusController<ExtensionDetailsPresenter>(bundle), NucleusController<ExtensionDetailsPresenter>(bundle),
PreferenceManager.OnDisplayPreferenceDialogListener, PreferenceManager.OnDisplayPreferenceDialogListener,
DialogPreference.TargetFragment, DialogPreference.TargetFragment {
SourceLoginDialog.Listener {
private var lastOpenPreferencePosition: Int? = null private var lastOpenPreferencePosition: Int? = null
@ -205,11 +201,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
return preferenceScreen!!.findPreference(key) return preferenceScreen!!.findPreference(key)
} }
override fun loginDialogClosed(source: LoginSource) {
val lastOpen = lastOpenPreferencePosition ?: return
(preferenceScreen?.getPreference(lastOpen) as? LoginPreference)?.notifyChanged()
}
private companion object { private companion object {
const val PKGNAME_KEY = "pkg_name" const val PKGNAME_KEY = "pkg_name"
const val LASTOPENPREFERENCE_KEY = "last_open_preference" const val LASTOPENPREFERENCE_KEY = "last_open_preference"

View file

@ -1,25 +1,22 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import androidx.preference.CheckBoxPreference
import androidx.preference.PreferenceGroup import androidx.preference.PreferenceGroup
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.onChange
import eu.kanade.tachiyomi.util.preference.switchPreferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreferenceCategory
import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.widget.preference.LoginCheckBoxPreference
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
import java.util.TreeMap import java.util.TreeMap
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
class SettingsSourcesController : SettingsController(), class SettingsSourcesController : SettingsController() {
SourceLoginDialog.Listener {
private val onlineSources by lazy { Injekt.get<SourceManager>().getOnlineSources() } private val onlineSources by lazy { Injekt.get<SourceManager>().getOnlineSources() }
@ -78,7 +75,7 @@ class SettingsSourcesController : SettingsController(),
val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault() val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault()
sources.forEach { source -> sources.forEach { source ->
val sourcePreference = LoginCheckBoxPreference(group.context, source).apply { val sourcePreference = CheckBoxPreference(group.context).apply {
val id = source.id.toString() val id = source.id.toString()
title = source.name title = source.name
key = getSourceKey(source.id) key = getSourceKey(source.id)
@ -96,23 +93,12 @@ class SettingsSourcesController : SettingsController(),
true true
} }
setOnLoginClickListener {
val dialog = SourceLoginDialog(source)
dialog.targetController = this@SettingsSourcesController
dialog.showDialog(router)
}
} }
group.addPreference(sourcePreference) group.addPreference(sourcePreference)
} }
} }
override fun loginDialogClosed(source: LoginSource) {
val pref = findPreference(getSourceKey(source.id)) as? LoginCheckBoxPreference
pref?.notifyChanged()
}
private fun getSourceKey(sourceId: Long): String { private fun getSourceKey(sourceId: Long): String {
return "source_$sourceId" return "source_$sourceId"
} }

View file

@ -1,57 +0,0 @@
package eu.kanade.tachiyomi.widget.preference
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import androidx.preference.CheckBoxPreference
import androidx.preference.PreferenceViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.setVectorCompat
import kotlinx.android.synthetic.main.pref_item_source.view.login
import kotlinx.android.synthetic.main.pref_item_source.view.login_frame
class LoginCheckBoxPreference @JvmOverloads constructor(
context: Context,
val source: HttpSource,
attrs: AttributeSet? = null
) : CheckBoxPreference(context, attrs) {
init {
layoutResource = R.layout.pref_item_source
}
private var onLoginClick: () -> Unit = {}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val loginFrame = holder.itemView.login_frame
if (source is LoginSource) {
val tint = if (source.isLogged())
Color.argb(255, 76, 175, 80)
else
context.getResourceColor(android.R.attr.textColorSecondary)
holder.itemView.login.setVectorCompat(R.drawable.ic_account_circle_black_24dp, tint)
loginFrame.visibility = View.VISIBLE
loginFrame.setOnClickListener {
onLoginClick()
}
} else {
loginFrame.visibility = View.GONE
}
}
fun setOnLoginClickListener(block: () -> Unit) {
onLoginClick = block
}
// Make method public
public override fun notifyChanged() {
super.notifyChanged()
}
}

View file

@ -1,71 +0,0 @@
package eu.kanade.tachiyomi.widget.preference
import android.os.Bundle
import android.view.View
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.android.synthetic.main.pref_account_login.view.dialog_title
import kotlinx.android.synthetic.main.pref_account_login.view.login
import kotlinx.android.synthetic.main.pref_account_login.view.password
import kotlinx.android.synthetic.main.pref_account_login.view.username
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class SourceLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle) {
private val source = Injekt.get<SourceManager>().get(args.getLong("key")) as LoginSource
constructor(source: Source) : this(Bundle().apply { putLong("key", source.id) })
override fun setCredentialsOnView(view: View) = with(view) {
dialog_title.text = context.getString(R.string.login_title, source.toString())
username.setText(preferences.sourceUsername(source))
password.setText(preferences.sourcePassword(source))
}
override fun checkLogin() {
requestSubscription?.unsubscribe()
v?.apply {
if (username.text.isEmpty() || password.text.isEmpty())
return
login.progress = 1
requestSubscription = source.login(username.text.toString(), password.text.toString())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ logged ->
if (logged) {
preferences.setSourceCredentials(source,
username.text.toString(),
password.text.toString())
dialog?.dismiss()
context.toast(R.string.login_success)
} else {
preferences.setSourceCredentials(source, "", "")
login.progress = -1
}
}, { error ->
login.progress = -1
login.setText(R.string.unknown_error)
error.message?.let { context.toast(it) }
})
}
}
override fun onDialogClosed() {
super.onDialogClosed()
(targetController as? Listener)?.loginDialogClosed(source)
}
interface Listener {
fun loginDialogClosed(source: LoginSource)
}
}