diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index 00b296359..7b56df2aa 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -18,8 +18,8 @@ import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.textColorResource -class RssArticlesAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context, R.layout.item_rss_article) { +class RssArticlesAdapter(context: Context, layoutId: Int, val callBack: CallBack) : + SimpleRecyclerAdapter(context, layoutId) { override fun convert(holder: ItemViewHolder, item: RssArticle, payloads: MutableList) { with(holder.itemView) { 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 f7a1b6bb6..201675028 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 @@ -55,7 +55,7 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration(VerticalDivider(requireContext())) - adapter = RssArticlesAdapter(requireContext(), this) + adapter = RssArticlesAdapter(requireContext(), activityViewModel.layoutId, this) recycler_view.adapter = adapter loadMoreView = LoadMoreView(requireContext()) adapter.addFooterView(loadMoreView) 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..41fad7292 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 @@ -53,6 +53,10 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a viewModel.clearArticles() } } + R.id.menu_switch_layout -> { + viewModel.switchLayout() + upFragments() + } } return super.onCompatOptionsItemSelected(item) } @@ -84,6 +88,10 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { + override fun getItemPosition(`object`: Any): Int { + return POSITION_NONE + } + override fun getPageTitle(position: Int): CharSequence? { return fragments.keys.elementAt(position) } 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 4b1149f2e..e65dd37f4 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 @@ -4,6 +4,7 @@ import android.app.Application import android.content.Intent import androidx.lifecycle.MutableLiveData import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssReadRecord @@ -15,6 +16,11 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) { var rssSource: RssSource? = null val titleLiveData = MutableLiveData() var order = System.currentTimeMillis() + val layoutId + get() = when (rssSource?.articleStyle) { + 1 -> R.layout.item_rss_article_1 + else -> R.layout.item_rss_article + } fun initData(intent: Intent, finally: () -> Unit) { execute { @@ -32,6 +38,19 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) { } } + fun switchLayout() { + rssSource?.let { + if (it.articleStyle < 1) { + it.articleStyle = it.articleStyle + 1 + } else { + it.articleStyle = 0 + } + execute { + App.db.rssSourceDao().update(it) + } + } + } + fun read(rssArticle: RssArticle) { execute { App.db.rssArticleDao().insertRecord(RssReadRecord(rssArticle.link)) diff --git a/app/src/main/res/drawable/bg_img_border.xml b/app/src/main/res/drawable/bg_img_border.xml deleted file mode 100644 index 07783726c..000000000 --- a/app/src/main/res/drawable/bg_img_border.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - \ 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 deleted file mode 100644 index 55eaa7aac..000000000 --- a/app/src/main/res/layout/item_rss_article_2.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - \ No newline at end of file