From f4effb2ca7c0b035c5e53a48f6ec73c7d0db8b54 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Wed, 6 May 2020 17:40:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=86=E5=88=ABrss?= =?UTF-8?q?=E5=88=86=E7=BB=84=E4=B8=AD=E7=9A=84=E9=A2=91=E9=81=93=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=9C=A8=E8=8F=9C=E5=8D=95=E4=B8=AD=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=88=87=E6=8D=A2=E9=A2=91=E9=81=93=EF=BC=88=E4=B8=8E?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84sortUrls=E4=B8=8D=E5=86=B2=E7=AA=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/rss/article/RssSortActivity.kt | 42 ++++++++++++++++++- app/src/main/res/menu/rss_articles.xml | 4 ++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index 2d45bcd70..4acd423d1 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.SubMenu import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter @@ -17,6 +18,7 @@ import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_rss_artivles.* import org.jetbrains.anko.startActivityForResult +import java.util.LinkedHashMap class RssSortActivity : VMBaseActivity(R.layout.activity_rss_artivles) { @@ -25,6 +27,8 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a private val editSource = 12319 private val fragments = linkedMapOf() private lateinit var adapter: TabFragmentPageAdapter + private val channels = LinkedHashMap() + private var groupMenu: Menu? = null override fun onActivityCreated(savedInstanceState: Bundle?) { adapter = TabFragmentPageAdapter(supportFragmentManager) @@ -34,6 +38,7 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a title_bar.title = it }) viewModel.initData(intent) { + upChannelMenu() upFragments() } } @@ -43,6 +48,12 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + groupMenu = menu + upChannelMenu() + return super.onPrepareOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let { @@ -54,15 +65,44 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a } } } + if (item.groupId == R.id.source_channel) { + var key = item.title.toString(); + var i = fragments.keys.indexOf(key) + if (i >= 0) + view_pager.currentItem = i + } return super.onCompatOptionsItemSelected(item) } + private fun upChannelMenu() { + // 加入频道列表 + groupMenu?.removeGroup(R.id.source_channel) + var sourceChannel = viewModel.rssSource?.sourceGroup + channels.clear() + sourceChannel?.split("\n\n")?.forEach { c -> + val d = c.split("::") + if (d.size > 1) { + channels[d[0]] = d[1] + var item = groupMenu?.add(R.id.source_channel, Menu.NONE, Menu.NONE, d[0]) + item?.isCheckable = true + var keys = fragments.keys + item?.isChecked = keys.indexOf(d[0]) == view_pager.currentItem + } + } + } + private fun upFragments() { fragments.clear() viewModel.rssSource?.sortUrls()?.forEach { fragments[it.key] = RssArticlesFragment.create(it.key, it.value) } - if (fragments.size == 1) { + var sortUrlsSize = fragments.size + if (sortUrlsSize <= 1) { + channels?.forEach { + fragments[it.key] = RssArticlesFragment.create(it.key, it.value) + } + } + if (sortUrlsSize == 1) { tab_layout.gone() } else { tab_layout.visible() diff --git a/app/src/main/res/menu/rss_articles.xml b/app/src/main/res/menu/rss_articles.xml index 03d187bcd..831b908a5 100644 --- a/app/src/main/res/menu/rss_articles.xml +++ b/app/src/main/res/menu/rss_articles.xml @@ -12,4 +12,8 @@ android:title="@string/clear" app:showAsAction="never" /> + + + + \ No newline at end of file