From 1d35000725433c67ef5da709434391070cdbd460 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 31 Aug 2019 22:52:10 +0800 Subject: [PATCH] up --- .../app/ui/booksource/BookSourceActivity.kt | 5 +- .../app/ui/booksource/BookSourceViewModel.kt | 8 +++ .../app/ui/booksource/GroupManageDialog.kt | 62 +++++++++++++++++-- app/src/main/res/layout/item_group_manage.xml | 8 ++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt index 6cfd7fa7e..eceeb0845 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt @@ -81,7 +81,10 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } } } - + R.id.menu_group_manage -> GroupManageDialog().show( + supportFragmentManager, + "groupManage" + ) } if (item.groupId == R.id.source_group) { search_view.setQuery(item.title, true) diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt index aed90d952..cc9cc3bf9 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt @@ -23,4 +23,12 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun update(vararg bookSource: BookSource) { execute { App.db.bookSourceDao().update(*bookSource) } } + + fun upGroup(oldGroup: String, newGroup: String?) { + + } + + fun delGroup(group: String) { + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt index 738a71338..4a41914dd 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt @@ -1,24 +1,48 @@ package io.legado.app.ui.booksource +import android.annotation.SuppressLint import android.content.Context import android.os.Bundle +import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.EditText import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer +import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.noButton +import io.legado.app.lib.dialogs.yesButton +import io.legado.app.lib.theme.ATH +import io.legado.app.utils.applyTint +import io.legado.app.utils.getViewModelOfActivity +import io.legado.app.utils.requestInputMethod import io.legado.app.utils.splitNotBlank +import kotlinx.android.synthetic.main.dialog_edittext.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* +import kotlinx.android.synthetic.main.item_book_group.view.tv_group +import kotlinx.android.synthetic.main.item_group_manage.view.* +import org.jetbrains.anko.sdk27.listeners.onClick class GroupManageDialog : DialogFragment() { - + private val viewModel = getViewModelOfActivity(BookSourceViewModel::class.java) private lateinit var adapter: GroupAdapter + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt()) + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -34,8 +58,11 @@ class GroupManageDialog : DialogFragment() { private fun initData() { tool_bar.title = getString(R.string.group_manage) - adapter = GroupAdapter(requireContext()) + adapter = GroupAdapter(requireContext(), this) recycler_view.layoutManager = LinearLayoutManager(requireContext()) + recycler_view.addItemDecoration( + DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) + ) recycler_view.adapter = adapter App.db.bookSourceDao().observeGroup().observe(viewLifecycleOwner, Observer { val groups = linkedSetOf() @@ -46,13 +73,38 @@ class GroupManageDialog : DialogFragment() { }) } + @SuppressLint("InflateParams") + private fun editGroup(group: String) { + alert(title = getString(R.string.group_edit)) { + var editText: EditText? = null + customView { + layoutInflater.inflate(R.layout.dialog_edittext, null).apply { + editText = edit_view.apply { + ATH.applyAccentTint(this) + hint = "分组名称" + } + } + } + + yesButton { + viewModel.upGroup(group, editText?.text?.toString()) + } + + noButton() - class GroupAdapter(context: Context) : + }.show().applyTint().requestInputMethod() + } + + class GroupAdapter(context: Context, val dialog: GroupManageDialog) : SimpleRecyclerAdapter(context, R.layout.item_group_manage) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { - + with(holder.itemView) { + tv_group.text = item + tv_edit.onClick { dialog.editGroup(item) } + tv_del.onClick { dialog.viewModel.delGroup(item) } + } } - } + } \ No newline at end of file diff --git a/app/src/main/res/layout/item_group_manage.xml b/app/src/main/res/layout/item_group_manage.xml index de089dbb4..493bf7998 100644 --- a/app/src/main/res/layout/item_group_manage.xml +++ b/app/src/main/res/layout/item_group_manage.xml @@ -1,12 +1,12 @@ @@ -15,6 +15,7 @@ android:id="@+id/tv_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" android:padding="8dp" android:text="@string/edit" /> @@ -22,6 +23,7 @@ android:id="@+id/tv_del" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" android:padding="8dp" android:text="@string/delete" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4cf8c832e..86d6d28ce 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -491,5 +491,6 @@ 文字颜色 选择图片 分组管理 + 编辑分组