From 7933563e95c8054278090b0f4ad27bbea5f63256 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Sep 2019 21:02:55 +0800 Subject: [PATCH] up --- .../java/io/legado/app/ui/main/MainActivity.kt | 4 ++-- .../{FindBookAdapter.kt => ExploreAdapter.kt} | 12 +++++++++++- ...{FindBookFragment.kt => ExploreFragment.kt} | 18 +++++++++++++----- .../app/ui/main/explore/ExploreViewModel.kt | 18 ++++++++++++++++++ app/src/main/res/values/strings.xml | 2 +- 5 files changed, 45 insertions(+), 9 deletions(-) rename app/src/main/java/io/legado/app/ui/main/explore/{FindBookAdapter.kt => ExploreAdapter.kt} (84%) rename app/src/main/java/io/legado/app/ui/main/explore/{FindBookFragment.kt => ExploreFragment.kt} (76%) create mode 100644 app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 6fc769e01..eea51eb6e 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -15,7 +15,7 @@ import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.theme.ATH import io.legado.app.ui.main.bookshelf.BookshelfFragment -import io.legado.app.ui.main.explore.FindBookFragment +import io.legado.app.ui.main.explore.ExploreFragment import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.rss.RssFragment import io.legado.app.utils.getPrefInt @@ -83,7 +83,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun getItem(position: Int): Fragment { return when (position) { 0 -> BookshelfFragment() - 1 -> FindBookFragment() + 1 -> ExploreFragment() 2 -> RssFragment() else -> MyFragment() } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt similarity index 84% rename from app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt rename to app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index a7f786bfe..369bafdcf 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -10,6 +10,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.ACache import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_find_book.view.* @@ -19,7 +20,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick -class FindBookAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : +class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_find_book) { var exIndex = 0 @@ -40,9 +41,17 @@ class FindBookAdapter(context: Context, private val scope: CoroutineScope, val c ll_title.onLongClick { val popupMenu = PopupMenu(context, ll_title) popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit) + popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top) + popupMenu.menu.add(Menu.NONE, R.id.menu_refresh, Menu.NONE, R.string.refresh) popupMenu.setOnMenuItemClickListener { when (it.itemId) { R.id.menu_edit -> callBack.editSource(item.bookSourceUrl) + R.id.menu_top -> { + } + R.id.menu_refresh -> { + ACache.get(context, "explore").remove(item.bookSourceUrl) + notifyItemChanged(holder.layoutPosition) + } } true } @@ -91,5 +100,6 @@ class FindBookAdapter(context: Context, private val scope: CoroutineScope, val c fun scrollTo(pos: Int) fun openExplore(sourceUrl: String, title: String, exploreUrl: String) fun editSource(sourceUrl: String) + fun toTop(source: BookSource) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/FindBookFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt similarity index 76% rename from app/src/main/java/io/legado/app/ui/main/explore/FindBookFragment.kt rename to app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 66ed92289..5c7d78e72 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/FindBookFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -7,18 +7,22 @@ import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R -import io.legado.app.base.BaseFragment +import io.legado.app.base.VMBaseFragment +import io.legado.app.data.entities.BookSource import io.legado.app.lib.theme.ATH import io.legado.app.ui.explore.ExploreShowActivity import io.legado.app.ui.sourceedit.SourceEditActivity +import io.legado.app.utils.getViewModel import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_find_book.* import kotlinx.android.synthetic.main.view_title_bar.* -class FindBookFragment : BaseFragment(R.layout.fragment_find_book), - FindBookAdapter.CallBack { +class ExploreFragment : VMBaseFragment(R.layout.fragment_find_book), + ExploreAdapter.CallBack { + override val viewModel: ExploreViewModel + get() = getViewModel(ExploreViewModel::class.java) - private lateinit var adapter: FindBookAdapter + private lateinit var adapter: ExploreAdapter private lateinit var linearLayoutManager: LinearLayoutManager override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -35,7 +39,7 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book), ATH.applyEdgeEffectColor(rv_find) linearLayoutManager = LinearLayoutManager(context) rv_find.layoutManager = linearLayoutManager - adapter = FindBookAdapter(requireContext(), this, this) + adapter = ExploreAdapter(requireContext(), this, this) rv_find.adapter = adapter } @@ -60,4 +64,8 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book), override fun editSource(sourceUrl: String) { startActivity(Pair("data", sourceUrl)) } + + override fun toTop(source: BookSource) { + viewModel.topSource(source) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt new file mode 100644 index 000000000..a3716b592 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt @@ -0,0 +1,18 @@ +package io.legado.app.ui.main.explore + +import android.app.Application +import io.legado.app.App +import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.BookSource + +class ExploreViewModel(application: Application) : BaseViewModel(application) { + + fun topSource(bookSource: BookSource) { + execute { + val minXh = App.db.bookSourceDao().minOrder + bookSource.customOrder = minXh - 1 + App.db.bookSourceDao().insert(bookSource) + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 076c34dbc..2c849417a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -119,7 +119,7 @@ 正在朗读 点击打开阅读界面 返回 - 重新加载 + 刷新 开始 停止 暂停