feat: 优化

pull/219/head
kunfei 5 years ago
parent 38c48ee8ff
commit 9ed7c87d45
  1. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  3. 8
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt
  4. 19
      app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt
  5. 13
      app/src/main/res/drawable/bg_img_border.xml
  6. 54
      app/src/main/res/layout/item_rss_article_2.xml

@ -18,8 +18,8 @@ import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.textColorResource
class RssArticlesAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssArticle>(context, R.layout.item_rss_article) {
class RssArticlesAdapter(context: Context, layoutId: Int, val callBack: CallBack) :
SimpleRecyclerAdapter<RssArticle>(context, layoutId) {
override fun convert(holder: ItemViewHolder, item: RssArticle, payloads: MutableList<Any>) {
with(holder.itemView) {

@ -55,7 +55,7 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(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)

@ -53,6 +53,10 @@ class RssSortActivity : VMBaseActivity<RssSortViewModel>(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<RssSortViewModel>(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)
}

@ -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<String>()
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))

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/background" />
<stroke
android:width="1dp"
android:color="@color/bg_divider_line" />
<corners android:radius="1dp" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>

@ -1,54 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="4dp"
android:paddingTop="8dp"
android:paddingBottom="6dp"
android:paddingRight="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_view"
android:layout_width="0dp"
android:layout_height="272dp"
android:contentDescription="@string/loading"
android:visibility="visible"
android:scaleType="centerCrop"
android:background="@drawable/bg_img_border"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:text="@string/app_name"
android:textColor="@color/tv_text_default"
android:textSize="13sp"
android:paddingTop="10dp"
app:layout_constraintTop_toBottomOf="@+id/image_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/tv_pub_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textSize="11sp"
android:maxLines="1"
android:paddingTop="8dp"
android:paddingBottom="2dp"
app:layout_constraintTop_toBottomOf="@+id/tv_title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="SmallSp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save