mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-23 01:01:15 +01:00
Refactor Base Controller inflate method
This commit is contained in:
parent
31c3e9cc9b
commit
50728932c8
@ -50,10 +50,11 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :
|
||||
get() = view
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
|
||||
return inflateView(inflater, container)
|
||||
binding = createBinding(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
abstract fun inflateView(inflater: LayoutInflater, container: ViewGroup): View
|
||||
abstract fun createBinding(inflater: LayoutInflater): VB
|
||||
|
||||
open fun onViewCreated(view: View) { }
|
||||
|
||||
|
@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.category
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
@ -51,15 +50,7 @@ class CategoryController(bundle: Bundle? = null) :
|
||||
return resources?.getString(R.string.edit_categories)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of this controller.
|
||||
*
|
||||
* @param inflater The layout inflater to create the view from XML.
|
||||
* @param container The parent view for this one.
|
||||
*/
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.categories_controller, container, false)
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = CategoriesControllerBinding.inflate(inflater)
|
||||
|
||||
/**
|
||||
* Called after view inflation. Used to initialize the view.
|
||||
|
@ -13,7 +13,6 @@ import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.preference.DialogPreference
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.EditTextPreferenceDialogController
|
||||
@ -77,11 +76,8 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
||||
}
|
||||
)
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
val themedInflater = inflater.cloneInContext(getPreferenceThemeContext())
|
||||
|
||||
return themedInflater.inflate(R.layout.extension_detail_controller, container, false)
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) =
|
||||
ExtensionDetailControllerBinding.inflate(inflater.cloneInContext(getPreferenceThemeContext()))
|
||||
|
||||
override fun createPresenter(): ExtensionDetailsPresenter {
|
||||
return ExtensionDetailsPresenter(args.getString(PKGNAME_KEY)!!)
|
||||
|
@ -383,6 +383,8 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater) = LibraryListControllerBinding.inflate(inflater)
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
if (!::presenter.isInitialized) presenter = LibraryPresenter(this)
|
||||
@ -726,11 +728,6 @@ class LibraryController(
|
||||
return adapter.headerItems.firstOrNull() as? LibraryHeaderItem
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
binding = LibraryListControllerBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun anchorView(): View {
|
||||
return if (binding.categoryHopperFrame.isVisible()) {
|
||||
binding.categoryHopperFrame
|
||||
|
@ -183,10 +183,7 @@ class MangaDetailsController :
|
||||
return null
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
binding = MangaDetailsControllerBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = MangaDetailsControllerBinding.inflate(inflater)
|
||||
|
||||
//region UI Methods
|
||||
override fun onViewCreated(view: View) {
|
||||
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.migration
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -41,10 +40,7 @@ class MigrationController :
|
||||
return MigrationPresenter()
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.migration_controller, container, false)
|
||||
}
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater) = MigrationControllerBinding.inflate(inflater)
|
||||
fun searchController(manga: Manga): SearchController {
|
||||
val controller = SearchController(manga)
|
||||
controller.targetController = this
|
||||
|
@ -49,10 +49,7 @@ class PreMigrationController(bundle: Bundle? = null) :
|
||||
|
||||
override fun getTitle() = view?.context?.getString(R.string.select_sources)
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.pre_migration_controller, container, false)
|
||||
}
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater) = PreMigrationControllerBinding.inflate(inflater)
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
liftAppbarWith(recycler)
|
||||
|
@ -8,7 +8,6 @@ import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@ -88,10 +87,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
||||
private var selectedPosition: Int? = null
|
||||
private var manaulMigrations = 0
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.migration_list_controller, container, false)
|
||||
}
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater) = MigrationListControllerBinding.inflate(inflater)
|
||||
override fun getTitle(): String? {
|
||||
return resources?.getString(R.string.migration) + " (${adapter?.items?.count {
|
||||
it.manga.migrationStatus != MigrationStatus.RUNNUNG
|
||||
|
@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@ -60,9 +59,7 @@ class RecentChaptersController(bundle: Bundle? = null) :
|
||||
return resources?.getString(R.string.recent_updates)
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.recent_chapters_controller, container, false)
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = RecentChaptersControllerBinding.inflate(inflater)
|
||||
|
||||
/**
|
||||
* Called when view is created
|
||||
|
@ -7,7 +7,6 @@ import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
@ -66,9 +65,7 @@ class RecentlyReadController(bundle: Bundle? = null) :
|
||||
return resources?.getString(R.string.history)
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.recently_read_controller, container, false)
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = RecentlyReadControllerBinding.inflate(inflater)
|
||||
|
||||
/**
|
||||
* Called when view is created
|
||||
|
@ -91,10 +91,7 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
} else resources?.getString(R.string.recents)
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
binding = RecentsControllerBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = RecentsControllerBinding.inflate(inflater)
|
||||
|
||||
/**
|
||||
* Called when view is created
|
||||
|
@ -6,7 +6,6 @@ import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -35,16 +34,7 @@ class SettingsSearchController :
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate the view with [R.layout.settings_search_controller].
|
||||
*
|
||||
* @param inflater used to load the layout xml.
|
||||
* @param container containing parent views.
|
||||
* @return inflated view
|
||||
*/
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.settings_search_controller, container, false)
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = SettingsSearchControllerBinding.inflate(inflater)
|
||||
|
||||
override fun getTitle(): String {
|
||||
return presenter.query
|
||||
|
@ -113,17 +113,7 @@ class BrowseController :
|
||||
return SourcePresenter()
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate the view with [R.layout.browse_controller].
|
||||
*
|
||||
* @param inflater used to load the layout xml.
|
||||
* @param container containing parent views.
|
||||
* @return inflated view.
|
||||
*/
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
binding = BrowseControllerBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = BrowseControllerBinding.inflate(inflater)
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
|
@ -130,9 +130,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
return BrowseSourcePresenter(args.getLong(SOURCE_ID_KEY))
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.browse_source_controller, container, false)
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = BrowseSourceControllerBinding.inflate(inflater)
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
|
@ -6,7 +6,6 @@ import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -46,16 +45,7 @@ open class GlobalSearchController(
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate the view with [R.layout.source_global_search_controller].
|
||||
*
|
||||
* @param inflater used to load the layout xml.
|
||||
* @param container containing parent views.
|
||||
* @return inflated view
|
||||
*/
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): android.view.View {
|
||||
return inflater.inflate(R.layout.source_global_search_controller, container, false)
|
||||
}
|
||||
override fun createBinding(inflater: LayoutInflater) = SourceGlobalSearchControllerBinding.inflate(inflater)
|
||||
|
||||
/**
|
||||
* Set the title of controller.
|
||||
|
Loading…
x
Reference in New Issue
Block a user