Add abstract ComposeController

This commit is contained in:
arkon 2022-04-21 22:42:37 -04:00
parent f1e5cccee7
commit eb1cfc4cd4
2 changed files with 49 additions and 39 deletions

View File

@ -0,0 +1,23 @@
package eu.kanade.tachiyomi.ui.base.controller
import android.view.LayoutInflater
import android.view.View
import androidx.compose.runtime.Composable
import eu.kanade.tachiyomi.databinding.ComposeControllerBinding
import nucleus.presenter.Presenter
abstract class ComposeController<P : Presenter<*>> : NucleusController<ComposeControllerBinding, P>() {
override fun createBinding(inflater: LayoutInflater): ComposeControllerBinding =
ComposeControllerBinding.inflate(inflater)
override fun onViewCreated(view: View) {
super.onViewCreated(view)
binding.root.setContent {
ComposeContent()
}
}
@Composable abstract fun ComposeContent()
}

View File

@ -1,16 +1,14 @@
package eu.kanade.tachiyomi.ui.recent.history package eu.kanade.tachiyomi.ui.recent.history
import android.view.LayoutInflater
import android.view.Menu 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 androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.compose.runtime.Composable
import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.presentation.history.HistoryScreen import eu.kanade.presentation.history.HistoryScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ComposeControllerBinding import eu.kanade.tachiyomi.ui.base.controller.ComposeController
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.RootController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.manga.MangaController
@ -21,26 +19,16 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.appcompat.queryTextChanges import reactivecircus.flowbinding.appcompat.queryTextChanges
/** class HistoryController : ComposeController<HistoryPresenter>(), RootController {
* Fragment that shows recently read manga.
*/
class HistoryController :
NucleusController<ComposeControllerBinding, HistoryPresenter>(),
RootController {
private var query = "" private var query = ""
override fun getTitle(): String? = resources?.getString(R.string.label_recent_manga) override fun getTitle() = resources?.getString(R.string.label_recent_manga)
override fun createPresenter(): HistoryPresenter = HistoryPresenter() override fun createPresenter() = HistoryPresenter()
override fun createBinding(inflater: LayoutInflater): ComposeControllerBinding = @Composable
ComposeControllerBinding.inflate(inflater) override fun ComposeContent() {
override fun onViewCreated(view: View) {
super.onViewCreated(view)
binding.root.setContent {
HistoryScreen( HistoryScreen(
composeView = binding.root, composeView = binding.root,
presenter = presenter, presenter = presenter,
@ -61,7 +49,6 @@ class HistoryController :
}, },
) )
} }
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.history, menu) inflater.inflate(R.menu.history, menu)