Refactor databinding fields to parent abstract classes
This commit is contained in:
parent
31b94fd3ff
commit
6a532b836d
@ -4,6 +4,7 @@ import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
@ -11,10 +12,12 @@ import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
abstract class BaseActivity : AppCompatActivity() {
|
||||
abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
lateinit var binding: VB
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
private val secureActivityDelegate = SecureActivityDelegate(this)
|
||||
|
||||
|
@ -1,16 +1,19 @@
|
||||
package eu.kanade.tachiyomi.ui.base.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
import nucleus.view.NucleusAppCompatActivity
|
||||
|
||||
abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>() {
|
||||
abstract class BaseRxActivity<VB : ViewBinding, P : BasePresenter<*>> : NucleusAppCompatActivity<P>() {
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
private val secureActivityDelegate = SecureActivityDelegate(this)
|
||||
|
||||
lateinit var binding: VB
|
||||
|
||||
init {
|
||||
@Suppress("LeakingThis")
|
||||
LocaleHelper.updateConfiguration(this)
|
||||
|
@ -6,6 +6,7 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.bluelinelabs.conductor.Controller
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.ControllerChangeType
|
||||
@ -14,9 +15,11 @@ import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.clearFindViewByIdCache
|
||||
import timber.log.Timber
|
||||
|
||||
abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateController(bundle),
|
||||
abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) : RestoreViewOnCreateController(bundle),
|
||||
LayoutContainer {
|
||||
|
||||
lateinit var binding: VB
|
||||
|
||||
init {
|
||||
addLifecycleListener(object : LifecycleListener() {
|
||||
override fun postCreateView(controller: Controller, view: View) {
|
||||
@ -72,7 +75,7 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr
|
||||
fun setTitle() {
|
||||
var parentController = parentController
|
||||
while (parentController != null) {
|
||||
if (parentController is BaseController && parentController.getTitle() != null) {
|
||||
if (parentController is BaseController<*> && parentController.getTitle() != null) {
|
||||
return
|
||||
}
|
||||
parentController = parentController.parentController
|
||||
|
@ -1,14 +1,16 @@
|
||||
package eu.kanade.tachiyomi.ui.base.controller
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.NucleusConductorDelegate
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.NucleusConductorLifecycleListener
|
||||
import nucleus.factory.PresenterFactory
|
||||
import nucleus.presenter.Presenter
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
abstract class NucleusController<P : Presenter<*>>(val bundle: Bundle? = null) : RxController(bundle),
|
||||
PresenterFactory<P> {
|
||||
abstract class NucleusController<VB : ViewBinding, P : Presenter<*>>(val bundle: Bundle? = null) :
|
||||
RxController<VB>(bundle),
|
||||
PresenterFactory<P> {
|
||||
|
||||
private val delegate = NucleusConductorDelegate(this)
|
||||
|
||||
|
@ -3,11 +3,12 @@ package eu.kanade.tachiyomi.ui.base.controller
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.subscriptions.CompositeSubscription
|
||||
|
||||
abstract class RxController(bundle: Bundle? = null) : BaseController(bundle) {
|
||||
abstract class RxController<VB : ViewBinding>(bundle: Bundle? = null) : BaseController<VB>(bundle) {
|
||||
|
||||
var untilDetachSubscriptions = CompositeSubscription()
|
||||
private set
|
||||
|
@ -25,7 +25,7 @@ import reactivecircus.flowbinding.android.view.clicks
|
||||
/**
|
||||
* Controller to manage the categories for the users' library.
|
||||
*/
|
||||
class CategoryController : NucleusController<CategoryPresenter>(),
|
||||
class CategoryController : NucleusController<CategoriesControllerBinding, CategoryPresenter>(),
|
||||
ActionMode.Callback,
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
@ -49,8 +49,6 @@ class CategoryController : NucleusController<CategoryPresenter>(),
|
||||
*/
|
||||
private var undoHelper: UndoHelper? = null
|
||||
|
||||
private lateinit var binding: CategoriesControllerBinding
|
||||
|
||||
/**
|
||||
* Creates the presenter for this controller. Not to be manually called.
|
||||
*/
|
||||
|
@ -23,7 +23,7 @@ import rx.android.schedulers.AndroidSchedulers
|
||||
* Controller that shows the currently active downloads.
|
||||
* Uses R.layout.fragment_download_queue.
|
||||
*/
|
||||
class DownloadController : NucleusController<DownloadPresenter>(),
|
||||
class DownloadController : NucleusController<DownloadControllerBinding, DownloadPresenter>(),
|
||||
DownloadAdapter.DownloadItemListener {
|
||||
|
||||
/**
|
||||
@ -41,8 +41,6 @@ class DownloadController : NucleusController<DownloadPresenter>(),
|
||||
*/
|
||||
private var isRunning: Boolean = false
|
||||
|
||||
private lateinit var binding: DownloadControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import uy.kohesive.injekt.api.get
|
||||
/**
|
||||
* Controller to manage the catalogues available in the app.
|
||||
*/
|
||||
open class ExtensionController : NucleusController<ExtensionPresenter>(),
|
||||
open class ExtensionController : NucleusController<ExtensionControllerBinding, ExtensionPresenter>(),
|
||||
ExtensionAdapter.OnButtonClickListener,
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
@ -49,8 +49,6 @@ open class ExtensionController : NucleusController<ExtensionPresenter>(),
|
||||
|
||||
private var query = ""
|
||||
|
||||
private lateinit var binding: ExtensionControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
class ExtensionDetailsController(bundle: Bundle? = null) :
|
||||
NucleusController<ExtensionDetailsPresenter>(bundle),
|
||||
NucleusController<ExtensionDetailControllerBinding, ExtensionDetailsPresenter>(bundle),
|
||||
PreferenceManager.OnDisplayPreferenceDialogListener,
|
||||
DialogPreference.TargetFragment {
|
||||
|
||||
@ -46,8 +46,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
||||
|
||||
private var preferenceScreen: PreferenceScreen? = null
|
||||
|
||||
private lateinit var binding: ExtensionDetailControllerBinding
|
||||
|
||||
constructor(pkgName: String) : this(Bundle().apply {
|
||||
putString(PKGNAME_KEY, pkgName)
|
||||
})
|
||||
|
@ -51,7 +51,7 @@ import uy.kohesive.injekt.api.get
|
||||
class LibraryController(
|
||||
bundle: Bundle? = null,
|
||||
private val preferences: PreferencesHelper = Injekt.get()
|
||||
) : NucleusController<LibraryPresenter>(bundle),
|
||||
) : NucleusController<LibraryControllerBinding, LibraryPresenter>(bundle),
|
||||
RootController,
|
||||
TabbedController,
|
||||
ActionMode.Callback,
|
||||
@ -126,8 +126,6 @@ class LibraryController(
|
||||
|
||||
private var tabsVisibilitySubscription: Subscription? = null
|
||||
|
||||
private lateinit var binding: LibraryControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
retainViewMode = RetainViewMode.RETAIN_DETACH
|
||||
|
@ -38,7 +38,7 @@ import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
class MainActivity : BaseActivity<MainActivityBinding>() {
|
||||
|
||||
private lateinit var router: Router
|
||||
|
||||
@ -55,8 +55,6 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
private var isHandlingShortcut: Boolean = false
|
||||
|
||||
private lateinit var binding: MainActivityBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
@ -33,7 +33,7 @@ import rx.Subscription
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class MangaController : RxController, TabbedController {
|
||||
class MangaController : RxController<MangaControllerBinding>, TabbedController {
|
||||
|
||||
constructor(manga: Manga?, fromSource: Boolean = false) : super(Bundle().apply {
|
||||
putLong(MANGA_EXTRA, manga?.id ?: 0)
|
||||
@ -63,8 +63,6 @@ class MangaController : RxController, TabbedController {
|
||||
|
||||
val mangaFavoriteRelay: PublishRelay<Boolean> = PublishRelay.create()
|
||||
|
||||
private lateinit var binding: MangaControllerBinding
|
||||
|
||||
private val trackingIconRelay: BehaviorRelay<Boolean> = BehaviorRelay.create()
|
||||
|
||||
private var trackingIconSubscription: Subscription? = null
|
||||
|
@ -40,7 +40,7 @@ import reactivecircus.flowbinding.android.view.clicks
|
||||
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
||||
import timber.log.Timber
|
||||
|
||||
class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
class ChaptersController : NucleusController<ChaptersControllerBinding, ChaptersPresenter>(),
|
||||
ActionMode.Callback,
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
@ -64,8 +64,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
|
||||
private var lastClickPosition = -1
|
||||
|
||||
private lateinit var binding: ChaptersControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
setOptionsMenuHidden(true)
|
||||
|
@ -71,13 +71,11 @@ import uy.kohesive.injekt.injectLazy
|
||||
* UI related actions should be called from here.
|
||||
*/
|
||||
class MangaInfoController(private val fromSource: Boolean = false) :
|
||||
NucleusController<MangaInfoPresenter>(),
|
||||
NucleusController<MangaInfoControllerBinding, MangaInfoPresenter>(),
|
||||
ChangeMangaCategoriesDialog.Listener {
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
private lateinit var binding: MangaInfoControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
setOptionsMenuHidden(true)
|
||||
|
@ -17,7 +17,7 @@ import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
||||
import timber.log.Timber
|
||||
|
||||
class TrackController : NucleusController<TrackPresenter>(),
|
||||
class TrackController : NucleusController<TrackControllerBinding, TrackPresenter>(),
|
||||
TrackAdapter.OnClickListener,
|
||||
SetTrackStatusDialog.Listener,
|
||||
SetTrackChaptersDialog.Listener,
|
||||
@ -25,8 +25,6 @@ class TrackController : NucleusController<TrackPresenter>(),
|
||||
|
||||
private var adapter: TrackAdapter? = null
|
||||
|
||||
private lateinit var binding: TrackControllerBinding
|
||||
|
||||
init {
|
||||
// There's no menu, but this avoids a bug when coming from the catalogue, where the menu
|
||||
// disappears if the searchview is expanded
|
||||
|
@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.databinding.MigrationControllerBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
|
||||
class MigrationController : NucleusController<MigrationPresenter>(),
|
||||
class MigrationController : NucleusController<MigrationControllerBinding, MigrationPresenter>(),
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
SourceAdapter.OnSelectClickListener {
|
||||
|
||||
@ -23,8 +23,6 @@ class MigrationController : NucleusController<MigrationPresenter>(),
|
||||
setTitle()
|
||||
}
|
||||
|
||||
private lateinit var binding: MigrationControllerBinding
|
||||
|
||||
override fun createPresenter(): MigrationPresenter {
|
||||
return MigrationPresenter()
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ import uy.kohesive.injekt.injectLazy
|
||||
* viewers, to which calls from the presenter or UI events are delegated.
|
||||
*/
|
||||
@RequiresPresenter(ReaderPresenter::class)
|
||||
class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>() {
|
||||
|
||||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
|
||||
@ -102,8 +102,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
@Suppress("DEPRECATION")
|
||||
private var progressDialog: ProgressDialog? = null
|
||||
|
||||
private lateinit var binding: ReaderActivityBinding
|
||||
|
||||
companion object {
|
||||
@Suppress("unused")
|
||||
const val LEFT_TO_RIGHT = 1
|
||||
|
@ -22,7 +22,7 @@ import eu.kanade.tachiyomi.util.system.toast
|
||||
* Uses [R.layout.history_controller].
|
||||
* UI related actions should be called from here.
|
||||
*/
|
||||
class HistoryController : NucleusController<HistoryPresenter>(),
|
||||
class HistoryController : NucleusController<HistoryControllerBinding, HistoryPresenter>(),
|
||||
RootController,
|
||||
NoToolbarElevationController,
|
||||
FlexibleAdapter.OnUpdateListener,
|
||||
@ -37,8 +37,6 @@ class HistoryController : NucleusController<HistoryPresenter>(),
|
||||
var adapter: HistoryAdapter? = null
|
||||
private set
|
||||
|
||||
private lateinit var binding: HistoryControllerBinding
|
||||
|
||||
override fun getTitle(): String? {
|
||||
return resources?.getString(R.string.label_recent_manga)
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import timber.log.Timber
|
||||
* Uses [R.layout.updates_controller].
|
||||
* UI related actions should be called from here.
|
||||
*/
|
||||
class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||
class UpdatesController : NucleusController<UpdatesControllerBinding, UpdatesPresenter>(),
|
||||
RootController,
|
||||
NoToolbarElevationController,
|
||||
ActionMode.Callback,
|
||||
@ -59,8 +59,6 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||
var adapter: UpdatesAdapter? = null
|
||||
private set
|
||||
|
||||
private lateinit var binding: UpdatesControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ abstract class SettingsController : PreferenceController() {
|
||||
fun setTitle() {
|
||||
var parentController = parentController
|
||||
while (parentController != null) {
|
||||
if (parentController is BaseController && parentController.getTitle() != null) {
|
||||
if (parentController is BaseController<*> && parentController.getTitle() != null) {
|
||||
return
|
||||
}
|
||||
parentController = parentController.parentController
|
||||
|
@ -44,7 +44,7 @@ import uy.kohesive.injekt.api.get
|
||||
* [SourceAdapter.OnBrowseClickListener] call function data on browse item click.
|
||||
* [SourceAdapter.OnLatestClickListener] call function data on latest item click
|
||||
*/
|
||||
class SourceController : NucleusController<SourcePresenter>(),
|
||||
class SourceController : NucleusController<SourceMainControllerBinding, SourcePresenter>(),
|
||||
RootController,
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
@ -58,8 +58,6 @@ class SourceController : NucleusController<SourcePresenter>(),
|
||||
*/
|
||||
private var adapter: SourceAdapter? = null
|
||||
|
||||
private lateinit var binding: SourceMainControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ import uy.kohesive.injekt.injectLazy
|
||||
* Controller to manage the catalogues available in the app.
|
||||
*/
|
||||
open class BrowseSourceController(bundle: Bundle) :
|
||||
NucleusController<BrowseSourcePresenter>(bundle),
|
||||
NucleusController<SourceControllerBinding, BrowseSourcePresenter>(bundle),
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
FlexibleAdapter.EndlessScrollListener,
|
||||
@ -95,8 +95,6 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
*/
|
||||
private var progressItem: ProgressItem? = null
|
||||
|
||||
private lateinit var binding: SourceControllerBinding
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import reactivecircus.flowbinding.appcompat.queryTextEvents
|
||||
open class GlobalSearchController(
|
||||
protected val initialQuery: String? = null,
|
||||
protected val extensionFilter: String? = null
|
||||
) : NucleusController<GlobalSearchPresenter>(),
|
||||
) : NucleusController<GlobalSearchControllerBinding, GlobalSearchPresenter>(),
|
||||
GlobalSearchCardAdapter.OnMangaClickListener {
|
||||
|
||||
/**
|
||||
@ -38,11 +38,6 @@ open class GlobalSearchController(
|
||||
*/
|
||||
protected var adapter: GlobalSearchAdapter? = null
|
||||
|
||||
private lateinit var binding: GlobalSearchControllerBinding
|
||||
|
||||
/**
|
||||
* Called when controller is initialized.
|
||||
*/
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
@ -59,11 +54,6 @@ open class GlobalSearchController(
|
||||
return binding.root
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title of controller.
|
||||
*
|
||||
* @return title.
|
||||
*/
|
||||
override fun getTitle(): String? {
|
||||
return presenter.query
|
||||
}
|
||||
|
@ -23,14 +23,12 @@ import eu.kanade.tachiyomi.util.view.invisible
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class WebViewActivity : BaseActivity() {
|
||||
class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
||||
|
||||
private val sourceManager by injectLazy<SourceManager>()
|
||||
|
||||
private var bundle: Bundle? = null
|
||||
|
||||
private lateinit var binding: WebviewActivityBinding
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
Loading…
Reference in New Issue
Block a user