From e4e5fbf5495d3c3cf7abbf0ced3c8743bf9b2f72 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 19 May 2020 11:06:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/rss/article/RssArticlesFragment.kt | 7 ++- .../app/ui/rss/article/RssSortViewModel.kt | 4 +- app/src/main/res/drawable/bg_img_border.xml | 13 +++++ .../main/res/layout/item_rss_article_2.xml | 54 +++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/bg_img_border.xml create mode 100644 app/src/main/res/layout/item_rss_article_2.xml diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index 201675028..22a62bb63 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.View import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.App @@ -53,7 +54,11 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme private fun initView() { ATH.applyEdgeEffectColor(recycler_view) - recycler_view.layoutManager = LinearLayoutManager(requireContext()) + recycler_view.layoutManager = if (activityViewModel.isGridLayout) { + GridLayoutManager(requireContext(), 2) + } else { + LinearLayoutManager(requireContext()) + } recycler_view.addItemDecoration(VerticalDivider(requireContext())) adapter = RssArticlesAdapter(requireContext(), activityViewModel.layoutId, this) recycler_view.adapter = adapter diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt index e65dd37f4..135064bce 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt @@ -16,9 +16,11 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) { var rssSource: RssSource? = null val titleLiveData = MutableLiveData() var order = System.currentTimeMillis() + val isGridLayout get() = rssSource?.articleStyle == 2 val layoutId get() = when (rssSource?.articleStyle) { 1 -> R.layout.item_rss_article_1 + 2 -> R.layout.item_rss_article_2 else -> R.layout.item_rss_article } @@ -40,7 +42,7 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) { fun switchLayout() { rssSource?.let { - if (it.articleStyle < 1) { + if (it.articleStyle < 2) { it.articleStyle = it.articleStyle + 1 } else { it.articleStyle = 0 diff --git a/app/src/main/res/drawable/bg_img_border.xml b/app/src/main/res/drawable/bg_img_border.xml new file mode 100644 index 000000000..07783726c --- /dev/null +++ b/app/src/main/res/drawable/bg_img_border.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_rss_article_2.xml b/app/src/main/res/layout/item_rss_article_2.xml new file mode 100644 index 000000000..55eaa7aac --- /dev/null +++ b/app/src/main/res/layout/item_rss_article_2.xml @@ -0,0 +1,54 @@ + + + + + + + + + + \ No newline at end of file