diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index c868af234..44e55b0fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -19,7 +19,8 @@ import timber.log.Timber abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateController(bundle) { - lateinit var binding: VB + protected lateinit var binding: VB + private set lateinit var viewScope: CoroutineScope @@ -51,11 +52,12 @@ abstract class BaseController(bundle: Bundle? = null) : ) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View { - return inflateView(inflater, container) - } + abstract fun createBinding(inflater: LayoutInflater): VB - abstract fun inflateView(inflater: LayoutInflater, container: ViewGroup): View + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View { + binding = createBinding(inflater) + return binding.root + } open fun onViewCreated(view: View) {} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt index 98ac3e765..3107fe5a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.browse import android.os.Bundle import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import androidx.core.os.bundleOf import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler @@ -50,10 +49,7 @@ class BrowseController : return resources!!.getString(R.string.browse) } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = PagerControllerBinding.inflate(inflater) - return binding.root - } + override fun createBinding(inflater: LayoutInflater) = PagerControllerBinding.inflate(inflater) override fun onViewCreated(view: View) { super.onViewCreated(view) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt index 8adc75cdc..5b3f43bcf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt @@ -5,7 +5,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 com.bluelinelabs.conductor.ControllerChangeHandler @@ -57,18 +56,16 @@ open class ExtensionController : return ExtensionPresenter() } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = ExtensionControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = ExtensionControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.recycler.applyInsetter { type(navigationBars = true) { padding() } } - return binding.root - } - - override fun onViewCreated(view: View) { - super.onViewCreated(view) binding.swipeRefresh.isRefreshing = true binding.swipeRefresh.refreshes() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt index 52882285b..69762a591 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt @@ -12,7 +12,6 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper import androidx.core.os.bundleOf import androidx.preference.Preference @@ -65,15 +64,9 @@ class ExtensionDetailsController(bundle: Bundle? = null) : setHasOptionsMenu(true) } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { + override fun createBinding(inflater: LayoutInflater): ExtensionDetailControllerBinding { val themedInflater = inflater.cloneInContext(getPreferenceThemeContext()) - binding = ExtensionDetailControllerBinding.inflate(themedInflater) - binding.extensionPrefsRecycler.applyInsetter { - type(navigationBars = true) { - padding() - } - } - return binding.root + return ExtensionDetailControllerBinding.inflate(themedInflater) } override fun createPresenter(): ExtensionDetailsPresenter { @@ -88,6 +81,12 @@ class ExtensionDetailsController(bundle: Bundle? = null) : override fun onViewCreated(view: View) { super.onViewCreated(view) + binding.extensionPrefsRecycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } + val extension = presenter.extension ?: return val context = view.context diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt index b98f21161..bb85a9721 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesController.kt @@ -6,7 +6,6 @@ import android.os.Bundle import android.util.TypedValue import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper import androidx.core.os.bundleOf import androidx.preference.DialogPreference @@ -45,10 +44,9 @@ class SourcePreferencesController(bundle: Bundle? = null) : bundleOf(SOURCE_ID to sourceId) ) - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { + override fun createBinding(inflater: LayoutInflater): SourcePreferencesControllerBinding { val themedInflater = inflater.cloneInContext(getPreferenceThemeContext()) - binding = SourcePreferencesControllerBinding.inflate(themedInflater) - return binding.root + return SourcePreferencesControllerBinding.inflate(themedInflater) } override fun createPresenter(): SourcePreferencesPresenter { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt index a7fb20844..20b4445b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.browse.migration.manga import android.os.Bundle import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import androidx.core.os.bundleOf import androidx.recyclerview.widget.LinearLayoutManager import dev.chrisbanes.insetter.applyInsetter @@ -45,18 +44,16 @@ class MigrationMangaController : return MigrationMangaPresenter(sourceId) } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = MigrationMangaControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = MigrationMangaControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.recycler.applyInsetter { type(navigationBars = true) { padding() } } - return binding.root - } - - override fun onViewCreated(view: View) { - super.onViewCreated(view) adapter = MigrationMangaAdapter(this) binding.recycler.layoutManager = LinearLayoutManager(view.context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt index 557c7db71..d70a370fc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt @@ -5,7 +5,6 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter @@ -30,18 +29,16 @@ class MigrationSourcesController : return MigrationSourcesPresenter() } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = MigrationSourcesControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = MigrationSourcesControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.recycler.applyInsetter { type(navigationBars = true) { padding() } } - return binding.root - } - - override fun onViewCreated(view: View) { - super.onViewCreated(view) adapter = SourceAdapter(this) binding.recycler.layoutManager = LinearLayoutManager(view.context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index f0a2dc17d..58043ef7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -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 androidx.recyclerview.widget.LinearLayoutManager import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItems @@ -67,25 +66,16 @@ class SourceController : return SourcePresenter() } - /** - * Initiate the view with [R.layout.source_main_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 = SourceMainControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = SourceMainControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.recycler.applyInsetter { type(navigationBars = true) { padding() } } - return binding.root - } - - override fun onViewCreated(view: View) { - super.onViewCreated(view) adapter = SourceAdapter(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index 764c59d70..1d6269415 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -124,10 +124,7 @@ open class BrowseSourceController(bundle: Bundle) : return BrowseSourcePresenter(args.getLong(SOURCE_ID_KEY), args.getString(SEARCH_QUERY_KEY)) } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = SourceControllerBinding.inflate(inflater) - return binding.root - } + override fun createBinding(inflater: LayoutInflater) = SourceControllerBinding.inflate(inflater) override fun onViewCreated(view: View) { super.onViewCreated(view) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt index b6dc40a14..ad5b1a729 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt @@ -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.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager @@ -50,22 +49,7 @@ open class GlobalSearchController( setHasOptionsMenu(true) } - /** - * Initiate the view with [R.layout.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): View { - binding = GlobalSearchControllerBinding.inflate(inflater) - binding.recycler.applyInsetter { - type(navigationBars = true) { - padding() - } - } - return binding.root - } + override fun createBinding(inflater: LayoutInflater) = GlobalSearchControllerBinding.inflate(inflater) override fun getTitle(): String? { return presenter.query @@ -142,6 +126,12 @@ open class GlobalSearchController( override fun onViewCreated(view: View) { super.onViewCreated(view) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } + adapter = GlobalSearchAdapter(this) // Create recycler and set adapter. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt index af189e574..4b2a17745 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt @@ -4,7 +4,6 @@ import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.view.View -import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.recyclerview.widget.LinearLayoutManager @@ -68,21 +67,7 @@ class CategoryController : return resources?.getString(R.string.action_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 { - binding = CategoriesControllerBinding.inflate(inflater) - binding.recycler.applyInsetter { - type(navigationBars = true) { - padding() - } - } - return binding.root - } + override fun createBinding(inflater: LayoutInflater) = CategoriesControllerBinding.inflate(inflater) /** * Called after view inflation. Used to initialize the view. @@ -92,6 +77,12 @@ class CategoryController : override fun onViewCreated(view: View) { super.onViewCreated(view) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } + adapter = CategoryAdapter(this@CategoryController) binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.setHasFixedSize(true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index 72cacd907..e2699ccf6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -5,7 +5,6 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.view.ViewGroup import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -55,15 +54,7 @@ class DownloadController : setHasOptionsMenu(true) } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = DownloadControllerBinding.inflate(inflater) - binding.recycler.applyInsetter { - type(navigationBars = true) { - padding() - } - } - return binding.root - } + override fun createBinding(inflater: LayoutInflater) = DownloadControllerBinding.inflate(inflater) override fun createPresenter(): DownloadPresenter { return DownloadPresenter() @@ -76,6 +67,12 @@ class DownloadController : override fun onViewCreated(view: View) { super.onViewCreated(view) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } + // Check if download queue is empty and update information accordingly. setInformationView() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index d6f73899e..18023a235 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -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.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.core.graphics.drawable.DrawableCompat @@ -164,18 +163,16 @@ class LibraryController( return LibraryPresenter() } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = LibraryControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = LibraryControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.actionToolbar.applyInsetter { type(navigationBars = true) { margin(bottom = true) } } - return binding.root - } - - override fun onViewCreated(view: View) { - super.onViewCreated(view) adapter = LibraryAdapter(this) binding.libraryPager.adapter = adapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index d4512d7c6..88c07cc80 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -11,7 +11,6 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.core.graphics.blue @@ -199,8 +198,11 @@ class MangaController : ) } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = MangaControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = MangaControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.recycler.applyInsetter { type(navigationBars = true) { padding() @@ -211,11 +213,6 @@ class MangaController : margin(bottom = true) } } - return binding.root - } - - override fun onViewCreated(view: View) { - super.onViewCreated(view) if (manga == null || source == null) return diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt index 57e2ad3ab..c04d6045f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt @@ -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 com.afollestad.materialdialogs.MaterialDialog @@ -72,18 +71,16 @@ class HistoryController : return HistoryPresenter() } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = HistoryControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = HistoryControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) + binding.recycler.applyInsetter { type(navigationBars = true) { padding() } } - return binding.root - } - - override fun onViewCreated(view: View) { - super.onViewCreated(view) // Initialize adapter binding.recycler.layoutManager = LinearLayoutManager(view.context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 4dca1f14a..6b427d0a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -5,7 +5,6 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.recyclerview.widget.LinearLayoutManager @@ -71,8 +70,10 @@ class UpdatesController : return UpdatesPresenter() } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - binding = UpdatesControllerBinding.inflate(inflater) + override fun createBinding(inflater: LayoutInflater) = UpdatesControllerBinding.inflate(inflater) + + override fun onViewCreated(view: View) { + super.onViewCreated(view) binding.recycler.applyInsetter { type(navigationBars = true) { padding() @@ -83,11 +84,7 @@ class UpdatesController : margin(bottom = true) } } - return binding.root - } - override fun onViewCreated(view: View) { - super.onViewCreated(view) view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS) // Init RecyclerView and adapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchController.kt index 2f8517fc5..5dc4e1d05 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchController.kt @@ -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 @@ -33,17 +32,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 { - binding = SettingsSearchControllerBinding.inflate(inflater) - return binding.root - } + override fun createBinding(inflater: LayoutInflater) = SettingsSearchControllerBinding.inflate(inflater) override fun getTitle(): String? { return presenter.query