Refactor Base Controller inflate method

This commit is contained in:
Jays2Kings 2021-03-29 18:21:57 -04:00
parent 31c3e9cc9b
commit 50728932c8
15 changed files with 19 additions and 89 deletions

View File

@ -50,10 +50,11 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :
get() = view get() = view
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): 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) { } open fun onViewCreated(view: View) { }

View File

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.category
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
@ -51,15 +50,7 @@ class CategoryController(bundle: Bundle? = null) :
return resources?.getString(R.string.edit_categories) return resources?.getString(R.string.edit_categories)
} }
/** override fun createBinding(inflater: LayoutInflater) = CategoriesControllerBinding.inflate(inflater)
* 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)
}
/** /**
* Called after view inflation. Used to initialize the view. * Called after view inflation. Used to initialize the view.

View File

@ -13,7 +13,6 @@ import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.preference.DialogPreference import androidx.preference.DialogPreference
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.EditTextPreferenceDialogController import androidx.preference.EditTextPreferenceDialogController
@ -77,11 +76,8 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
} }
) )
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) =
val themedInflater = inflater.cloneInContext(getPreferenceThemeContext()) ExtensionDetailControllerBinding.inflate(inflater.cloneInContext(getPreferenceThemeContext()))
return themedInflater.inflate(R.layout.extension_detail_controller, container, false)
}
override fun createPresenter(): ExtensionDetailsPresenter { override fun createPresenter(): ExtensionDetailsPresenter {
return ExtensionDetailsPresenter(args.getString(PKGNAME_KEY)!!) return ExtensionDetailsPresenter(args.getString(PKGNAME_KEY)!!)

View File

@ -383,6 +383,8 @@ class LibraryController(
} }
} }
override fun createBinding(inflater: LayoutInflater) = LibraryListControllerBinding.inflate(inflater)
override fun onViewCreated(view: View) { override fun onViewCreated(view: View) {
super.onViewCreated(view) super.onViewCreated(view)
if (!::presenter.isInitialized) presenter = LibraryPresenter(this) if (!::presenter.isInitialized) presenter = LibraryPresenter(this)
@ -726,11 +728,6 @@ class LibraryController(
return adapter.headerItems.firstOrNull() as? LibraryHeaderItem 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 { private fun anchorView(): View {
return if (binding.categoryHopperFrame.isVisible()) { return if (binding.categoryHopperFrame.isVisible()) {
binding.categoryHopperFrame binding.categoryHopperFrame

View File

@ -183,10 +183,7 @@ class MangaDetailsController :
return null return null
} }
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = MangaDetailsControllerBinding.inflate(inflater)
binding = MangaDetailsControllerBinding.inflate(inflater)
return binding.root
}
//region UI Methods //region UI Methods
override fun onViewCreated(view: View) { override fun onViewCreated(view: View) {

View File

@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.migration
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -41,10 +40,7 @@ class MigrationController :
return MigrationPresenter() return MigrationPresenter()
} }
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = MigrationControllerBinding.inflate(inflater)
return inflater.inflate(R.layout.migration_controller, container, false)
}
fun searchController(manga: Manga): SearchController { fun searchController(manga: Manga): SearchController {
val controller = SearchController(manga) val controller = SearchController(manga)
controller.targetController = this controller.targetController = this

View File

@ -49,10 +49,7 @@ class PreMigrationController(bundle: Bundle? = null) :
override fun getTitle() = view?.context?.getString(R.string.select_sources) override fun getTitle() = view?.context?.getString(R.string.select_sources)
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = PreMigrationControllerBinding.inflate(inflater)
return inflater.inflate(R.layout.pre_migration_controller, container, false)
}
override fun onViewCreated(view: View) { override fun onViewCreated(view: View) {
super.onViewCreated(view) super.onViewCreated(view)
liftAppbarWith(recycler) liftAppbarWith(recycler)

View File

@ -8,7 +8,6 @@ import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -88,10 +87,7 @@ class MigrationListController(bundle: Bundle? = null) :
private var selectedPosition: Int? = null private var selectedPosition: Int? = null
private var manaulMigrations = 0 private var manaulMigrations = 0
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = MigrationListControllerBinding.inflate(inflater)
return inflater.inflate(R.layout.migration_list_controller, container, false)
}
override fun getTitle(): String? { override fun getTitle(): String? {
return resources?.getString(R.string.migration) + " (${adapter?.items?.count { return resources?.getString(R.string.migration) + " (${adapter?.items?.count {
it.manga.migrationStatus != MigrationStatus.RUNNUNG it.manga.migrationStatus != MigrationStatus.RUNNUNG

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -60,9 +59,7 @@ class RecentChaptersController(bundle: Bundle? = null) :
return resources?.getString(R.string.recent_updates) return resources?.getString(R.string.recent_updates)
} }
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = RecentChaptersControllerBinding.inflate(inflater)
return inflater.inflate(R.layout.recent_chapters_controller, container, false)
}
/** /**
* Called when view is created * Called when view is created

View File

@ -7,7 +7,6 @@ import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
@ -66,9 +65,7 @@ class RecentlyReadController(bundle: Bundle? = null) :
return resources?.getString(R.string.history) return resources?.getString(R.string.history)
} }
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = RecentlyReadControllerBinding.inflate(inflater)
return inflater.inflate(R.layout.recently_read_controller, container, false)
}
/** /**
* Called when view is created * Called when view is created

View File

@ -91,10 +91,7 @@ class RecentsController(bundle: Bundle? = null) :
} else resources?.getString(R.string.recents) } else resources?.getString(R.string.recents)
} }
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = RecentsControllerBinding.inflate(inflater)
binding = RecentsControllerBinding.inflate(inflater)
return binding.root
}
/** /**
* Called when view is created * Called when view is created

View File

@ -6,7 +6,6 @@ import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -35,16 +34,7 @@ class SettingsSearchController :
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
/** override fun createBinding(inflater: LayoutInflater) = SettingsSearchControllerBinding.inflate(inflater)
* 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 getTitle(): String { override fun getTitle(): String {
return presenter.query return presenter.query

View File

@ -113,17 +113,7 @@ class BrowseController :
return SourcePresenter() return SourcePresenter()
} }
/** override fun createBinding(inflater: LayoutInflater) = BrowseControllerBinding.inflate(inflater)
* 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 onViewCreated(view: View) { override fun onViewCreated(view: View) {
super.onViewCreated(view) super.onViewCreated(view)

View File

@ -130,9 +130,7 @@ open class BrowseSourceController(bundle: Bundle) :
return BrowseSourcePresenter(args.getLong(SOURCE_ID_KEY)) return BrowseSourcePresenter(args.getLong(SOURCE_ID_KEY))
} }
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { override fun createBinding(inflater: LayoutInflater) = BrowseSourceControllerBinding.inflate(inflater)
return inflater.inflate(R.layout.browse_source_controller, container, false)
}
override fun onViewCreated(view: View) { override fun onViewCreated(view: View) {
super.onViewCreated(view) super.onViewCreated(view)

View File

@ -6,7 +6,6 @@ import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -46,16 +45,7 @@ open class GlobalSearchController(
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
/** override fun createBinding(inflater: LayoutInflater) = SourceGlobalSearchControllerBinding.inflate(inflater)
* 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)
}
/** /**
* Set the title of controller. * Set the title of controller.