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,46 +19,35 @@ 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() {
HistoryScreen(
override fun onViewCreated(view: View) { composeView = binding.root,
super.onViewCreated(view) presenter = presenter,
onClickItem = { history ->
binding.root.setContent { router.pushController(MangaController(history).withFadeTransaction())
HistoryScreen( },
composeView = binding.root, onClickResume = { history ->
presenter = presenter, presenter.getNextChapterForManga(history.mangaId, history.chapterId)
onClickItem = { history -> },
router.pushController(MangaController(history).withFadeTransaction()) onClickDelete = { history, all ->
}, if (all) {
onClickResume = { history -> // Reset last read of chapter to 0L
presenter.getNextChapterForManga(history.mangaId, history.chapterId) presenter.removeAllFromHistory(history.mangaId)
}, } else {
onClickDelete = { history, all -> // Remove all chapters belonging to manga from library
if (all) { presenter.removeFromHistory(history)
// Reset last read of chapter to 0L }
presenter.removeAllFromHistory(history.mangaId) },
} else { )
// Remove all chapters belonging to manga from library
presenter.removeFromHistory(history)
}
},
)
}
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {