From 4e60a81b36b3cc2711e19686367f4b99dcb18f83 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 27 Feb 2020 22:43:48 -0500 Subject: [PATCH] Remove unused LoginSource --- .../data/preference/PreferenceKeys.kt | 8 --- .../data/preference/PreferencesHelper.kt | 12 ---- .../tachiyomi/source/online/LoginSource.kt | 14 ---- .../ui/catalogue/CatalogueController.kt | 25 +------ .../tachiyomi/ui/catalogue/SourceHolder.kt | 15 ++-- .../global_search/CatalogueSearchPresenter.kt | 2 - .../extension/ExtensionDetailsController.kt | 11 +-- .../ui/setting/SettingsSourcesController.kt | 20 +----- .../preference/LoginCheckBoxPreference.kt | 57 --------------- .../widget/preference/SourceLoginDialog.kt | 71 ------------------- 10 files changed, 9 insertions(+), 226 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/source/online/LoginSource.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginCheckBoxPreference.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 03f05e2732..26bb85c76b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -131,14 +131,6 @@ object PreferenceKeys { 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 trackPassword(syncId: Int) = "pref_mangasync_password_$syncId" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 38da493c09..97502ce66a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values import eu.kanade.tachiyomi.data.track.TrackService -import eu.kanade.tachiyomi.source.Source import java.io.File import java.text.DateFormat 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 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 trackPassword(sync: TrackService) = prefs.getString(Keys.trackPassword(sync.id), "") diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/LoginSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/LoginSource.kt deleted file mode 100644 index 71ef190053..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/LoginSource.kt +++ /dev/null @@ -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 - - fun isAuthenticationSuccessful(response: Response): Boolean -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt index c3ebcfcd89..2b5ef6dedd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt @@ -19,7 +19,6 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.requestPermissionsSafe 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.latest.LatestUpdatesController import eu.kanade.tachiyomi.ui.setting.SettingsSourcesController -import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog import kotlinx.android.synthetic.main.catalogue_main_controller.recycler import uy.kohesive.injekt.Injekt 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 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.OnLatestClickListener] call function data on latest item click */ class CatalogueController : NucleusController(), - SourceLoginDialog.Listener, FlexibleAdapter.OnItemClickListener, CatalogueAdapter.OnBrowseClickListener, CatalogueAdapter.OnLatestClickListener { @@ -122,32 +118,13 @@ class CatalogueController : NucleusController(), } } - /** - * 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 */ override fun onItemClick(view: View, position: Int): Boolean { val item = adapter?.getItem(position) as? SourceItem ?: return false 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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt index 5d063595b3..46036530b3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.catalogue import android.view.View 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.SlicedHolder import eu.kanade.tachiyomi.util.view.getRound @@ -48,17 +47,11 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) : 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() + source_browse.setText(R.string.browse) + if (source.supportsLatest) { + source_latest.visible() } else { - source_browse.setText(R.string.browse) - if (source.supportsLatest) { - source_latest.visible() - } else { - source_latest.gone() - } + source_latest.gone() } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt index 4043d9ef06..29087ec248 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchPresenter.kt @@ -12,7 +12,6 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage 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.catalogue.browse.BrowseCataloguePresenter import rx.Observable @@ -105,7 +104,6 @@ open class CatalogueSearchPresenter( return sourceManager.getCatalogueSources() .filter { it.lang in languages } - .filterNot { it is LoginSource && !it.isLogged() } .filterNot { it.id.toString() in hiddenCatalogues } .sortedBy { "(${it.lang}) ${it.name}" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt index 8b4ff7a7b1..da84d5b0e4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt @@ -28,12 +28,9 @@ import eu.kanade.tachiyomi.data.preference.EmptyPreferenceDataStore import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore import eu.kanade.tachiyomi.source.ConfigurableSource 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.util.preference.preferenceCategory 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_lang 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) : NucleusController(bundle), PreferenceManager.OnDisplayPreferenceDialogListener, - DialogPreference.TargetFragment, - SourceLoginDialog.Listener { + DialogPreference.TargetFragment { private var lastOpenPreferencePosition: Int? = null @@ -205,11 +201,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) : return preferenceScreen!!.findPreference(key) } - override fun loginDialogClosed(source: LoginSource) { - val lastOpen = lastOpenPreferencePosition ?: return - (preferenceScreen?.getPreference(lastOpen) as? LoginPreference)?.notifyChanged() - } - private companion object { const val PKGNAME_KEY = "pkg_name" const val LASTOPENPREFERENCE_KEY = "last_open_preference" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt index c34b476946..0a7619cda3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt @@ -1,25 +1,22 @@ package eu.kanade.tachiyomi.ui.setting import android.graphics.drawable.Drawable +import androidx.preference.CheckBoxPreference import androidx.preference.PreferenceGroup import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.SourceManager 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.switchPreferenceCategory import eu.kanade.tachiyomi.util.preference.titleRes 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 uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsSourcesController : SettingsController(), - SourceLoginDialog.Listener { +class SettingsSourcesController : SettingsController() { private val onlineSources by lazy { Injekt.get().getOnlineSources() } @@ -78,7 +75,7 @@ class SettingsSourcesController : SettingsController(), val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault() sources.forEach { source -> - val sourcePreference = LoginCheckBoxPreference(group.context, source).apply { + val sourcePreference = CheckBoxPreference(group.context).apply { val id = source.id.toString() title = source.name key = getSourceKey(source.id) @@ -96,23 +93,12 @@ class SettingsSourcesController : SettingsController(), true } - - setOnLoginClickListener { - val dialog = SourceLoginDialog(source) - dialog.targetController = this@SettingsSourcesController - dialog.showDialog(router) - } } group.addPreference(sourcePreference) } } - override fun loginDialogClosed(source: LoginSource) { - val pref = findPreference(getSourceKey(source.id)) as? LoginCheckBoxPreference - pref?.notifyChanged() - } - private fun getSourceKey(sourceId: Long): String { return "source_$sourceId" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginCheckBoxPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginCheckBoxPreference.kt deleted file mode 100644 index d80ffaa86c..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginCheckBoxPreference.kt +++ /dev/null @@ -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() - } -} 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 deleted file mode 100644 index 7bd1cdf132..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt +++ /dev/null @@ -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().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) - } -}