From e54166f70762091825d8e7f3b8bccf4b1b1c9ba6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 16 Nov 2021 20:33:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/local/rule/TxtTocRuleActivity.kt | 39 +++++++++++++++++-- .../ui/book/local/rule/TxtTocRuleAdapter.kt | 13 ++++++- .../ui/book/local/rule/TxtTocRuleViewModel.kt | 18 ++++++++- build.gradle | 2 +- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt index c34fb8076..151753cb3 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt @@ -3,22 +3,53 @@ package io.legado.app.ui.book.local.rule import android.os.Bundle import androidx.activity.viewModels import io.legado.app.base.VMBaseActivity +import io.legado.app.data.entities.TxtTocRule import io.legado.app.databinding.ActivityTxtTocRuleBinding import io.legado.app.utils.viewbindingdelegate.viewBinding -class TxtTocRuleActivity : VMBaseActivity() { +class TxtTocRuleActivity : VMBaseActivity(), + TxtTocRuleAdapter.Callback { override val viewModel: TxtTocRuleViewModel by viewModels() override val binding: ActivityTxtTocRuleBinding by viewBinding(ActivityTxtTocRuleBinding::inflate) private val adapter: TxtTocRuleAdapter by lazy { - TxtTocRuleAdapter(this) + TxtTocRuleAdapter(this, this) } override fun onActivityCreated(savedInstanceState: Bundle?) { - TODO("Not yet implemented") + initView() } - private fun initView() { + private fun initView() = binding.run { + recyclerView.adapter = adapter + + } + + override fun del(source: TxtTocRule) { + viewModel.del(source) + } + + override fun edit(source: TxtTocRule) { + + } + + override fun update(vararg source: TxtTocRule) { + + } + + override fun toTop(source: TxtTocRule) { + + } + + override fun toBottom(source: TxtTocRule) { + + } + + override fun upOrder() { + + } + + override fun upCountView() { } diff --git a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleAdapter.kt index 412857dc8..5b18f3566 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleAdapter.kt @@ -7,7 +7,7 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.TxtTocRule import io.legado.app.databinding.ItemTxtTocRuleBinding -class TxtTocRuleAdapter(context: Context) : +class TxtTocRuleAdapter(context: Context, private val callback: Callback) : RecyclerAdapter(context) { private val selected = linkedSetOf() @@ -35,6 +35,7 @@ class TxtTocRuleAdapter(context: Context) : } else { selected.remove(it) } + callback.upCountView() } } } @@ -50,4 +51,14 @@ class TxtTocRuleAdapter(context: Context) : } } + interface Callback { + fun del(source: TxtTocRule) + fun edit(source: TxtTocRule) + fun update(vararg source: TxtTocRule) + fun toTop(source: TxtTocRule) + fun toBottom(source: TxtTocRule) + fun upOrder() + fun upCountView() + } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleViewModel.kt index 204f1c59c..b3b6f8dad 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleViewModel.kt @@ -2,5 +2,21 @@ package io.legado.app.ui.book.local.rule import android.app.Application import io.legado.app.base.BaseViewModel +import io.legado.app.data.appDb +import io.legado.app.data.entities.TxtTocRule -class TxtTocRuleViewModel(app: Application) : BaseViewModel(app) \ No newline at end of file +class TxtTocRuleViewModel(app: Application) : BaseViewModel(app) { + + fun del(txtTocRule: TxtTocRule) { + execute { + appDb.txtTocRuleDao.delete(txtTocRule) + } + } + + fun update(txtTocRule: TxtTocRule) { + execute { + appDb.txtTocRuleDao.update(txtTocRule) + } + } + +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 45afa777f..1f3ac687d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.5.31' + ext.kotlin_version = '1.6.0' repositories { google() mavenCentral()