订阅源瀑布流 #121 (@Luoyacheng)
This commit is contained in:
@@ -136,10 +136,8 @@ class RssFragment() : VMBaseFragment<RssViewModel>(R.layout.fragment_rss),
|
|||||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||||
val query = searchView.text.toString()
|
val query = searchView.text.toString()
|
||||||
upRssFlowJob(query)
|
upRssFlowJob(query)
|
||||||
searchBar.hint = if (query.isEmpty()) {
|
searchBar.hint = query.ifEmpty {
|
||||||
getString(R.string.search_rss_source)
|
getString(R.string.search_rss_source)
|
||||||
} else {
|
|
||||||
query
|
|
||||||
}
|
}
|
||||||
searchView.hide()
|
searchView.hide()
|
||||||
return@setOnEditorActionListener true
|
return@setOnEditorActionListener true
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package io.legato.kazusa.ui.rss.article
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.bumptech.glide.load.DataSource
|
||||||
|
import com.bumptech.glide.load.engine.GlideException
|
||||||
|
import com.bumptech.glide.request.RequestListener
|
||||||
|
import com.bumptech.glide.request.RequestOptions
|
||||||
|
import com.bumptech.glide.request.target.Target
|
||||||
|
import io.legato.kazusa.R
|
||||||
|
import io.legato.kazusa.base.adapter.ItemViewHolder
|
||||||
|
import io.legato.kazusa.data.entities.RssArticle
|
||||||
|
import io.legato.kazusa.databinding.ItemRssArticle3Binding
|
||||||
|
import io.legato.kazusa.help.glide.ImageLoader
|
||||||
|
import io.legato.kazusa.help.glide.OkHttpModelLoader
|
||||||
|
import io.legato.kazusa.utils.gone
|
||||||
|
import io.legato.kazusa.utils.themeColor
|
||||||
|
import io.legato.kazusa.utils.visible
|
||||||
|
|
||||||
|
class RssArticlesAdapter3(context: Context, callBack: CallBack) :
|
||||||
|
BaseRssArticlesAdapter<ItemRssArticle3Binding>(context, callBack) {
|
||||||
|
|
||||||
|
override fun getViewBinding(parent: ViewGroup): ItemRssArticle3Binding {
|
||||||
|
return ItemRssArticle3Binding.inflate(inflater, parent, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
override fun convert(
|
||||||
|
holder: ItemViewHolder,
|
||||||
|
binding: ItemRssArticle3Binding,
|
||||||
|
item: RssArticle,
|
||||||
|
payloads: MutableList<Any>
|
||||||
|
) {
|
||||||
|
binding.run {
|
||||||
|
tvTitle.text = item.title
|
||||||
|
tvPubDate.text = item.pubDate
|
||||||
|
|
||||||
|
val imageUrl = item.image
|
||||||
|
if (imageUrl.isNullOrBlank() && !callBack.isGridLayout) {
|
||||||
|
imageView.gone()
|
||||||
|
} else {
|
||||||
|
imageView.visible()
|
||||||
|
imageView.adjustViewBounds = true
|
||||||
|
val options = RequestOptions()
|
||||||
|
.set(OkHttpModelLoader.sourceOriginOption, item.origin)
|
||||||
|
|
||||||
|
ImageLoader.load(context, imageUrl)
|
||||||
|
.apply(options)
|
||||||
|
.listener(object : RequestListener<Drawable> {
|
||||||
|
override fun onLoadFailed(
|
||||||
|
e: GlideException?,
|
||||||
|
model: Any?,
|
||||||
|
target: Target<Drawable>?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
imageView.gone()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResourceReady(
|
||||||
|
resource: Drawable,
|
||||||
|
model: Any,
|
||||||
|
target: Target<Drawable>?,
|
||||||
|
dataSource: DataSource?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.into(imageView)
|
||||||
|
}
|
||||||
|
|
||||||
|
tvTitle.setTextColor(
|
||||||
|
if (item.read)
|
||||||
|
context.themeColor(com.google.android.material.R.attr.colorOnSurfaceVariant)
|
||||||
|
else
|
||||||
|
context.themeColor(com.google.android.material.R.attr.colorOnSurface)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticle3Binding) {
|
||||||
|
holder.itemView.setOnClickListener {
|
||||||
|
getItem(holder.layoutPosition)?.let {
|
||||||
|
callBack.readRss(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import androidx.lifecycle.repeatOnLifecycle
|
|||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||||
import io.legato.kazusa.R
|
import io.legato.kazusa.R
|
||||||
import io.legato.kazusa.base.VMBaseFragment
|
import io.legato.kazusa.base.VMBaseFragment
|
||||||
import io.legato.kazusa.constant.AppLog
|
import io.legato.kazusa.constant.AppLog
|
||||||
@@ -50,6 +51,7 @@ class RssArticlesFragment() : VMBaseFragment<RssArticlesViewModel>(R.layout.frag
|
|||||||
when (activityViewModel.rssSource?.articleStyle) {
|
when (activityViewModel.rssSource?.articleStyle) {
|
||||||
1 -> RssArticlesAdapter1(requireContext(), this@RssArticlesFragment)
|
1 -> RssArticlesAdapter1(requireContext(), this@RssArticlesFragment)
|
||||||
2 -> RssArticlesAdapter2(requireContext(), this@RssArticlesFragment)
|
2 -> RssArticlesAdapter2(requireContext(), this@RssArticlesFragment)
|
||||||
|
3 -> RssArticlesAdapter3(requireContext(), this@RssArticlesFragment)
|
||||||
else -> RssArticlesAdapter(requireContext(), this@RssArticlesFragment)
|
else -> RssArticlesAdapter(requireContext(), this@RssArticlesFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,13 +77,15 @@ class RssArticlesFragment() : VMBaseFragment<RssArticlesViewModel>(R.layout.frag
|
|||||||
scrollToBottom(true)
|
scrollToBottom(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recyclerView.layoutManager = if (activityViewModel.isGridLayout) {
|
val layoutManager = if (activityViewModel.isWaterLayout) {
|
||||||
recyclerView.setPadding(8, 0, 8, 0)
|
recyclerView.itemAnimator = null
|
||||||
|
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
|
||||||
|
} else if (activityViewModel.isGridLayout) {
|
||||||
GridLayoutManager(requireContext(), 2)
|
GridLayoutManager(requireContext(), 2)
|
||||||
} else {
|
} else {
|
||||||
recyclerView.addItemDecoration(VerticalDivider(requireContext()))
|
|
||||||
LinearLayoutManager(requireContext())
|
LinearLayoutManager(requireContext())
|
||||||
}
|
}
|
||||||
|
recyclerView.layoutManager = layoutManager
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
adapter.addFooterView {
|
adapter.addFooterView {
|
||||||
ViewLoadMoreBinding.bind(loadMoreView)
|
ViewLoadMoreBinding.bind(loadMoreView)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
val titleLiveData = MutableLiveData<String>()
|
val titleLiveData = MutableLiveData<String>()
|
||||||
var order = System.currentTimeMillis()
|
var order = System.currentTimeMillis()
|
||||||
val isGridLayout get() = rssSource?.articleStyle == 2
|
val isGridLayout get() = rssSource?.articleStyle == 2
|
||||||
|
val isWaterLayout get() = rssSource?.articleStyle == 3
|
||||||
|
|
||||||
fun initData(intent: Intent, finally: () -> Unit) {
|
fun initData(intent: Intent, finally: () -> Unit) {
|
||||||
execute {
|
execute {
|
||||||
@@ -36,7 +37,7 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
|
|
||||||
fun switchLayout() {
|
fun switchLayout() {
|
||||||
rssSource?.let {
|
rssSource?.let {
|
||||||
if (it.articleStyle < 2) {
|
if (it.articleStyle < 3) {
|
||||||
it.articleStyle += 1
|
it.articleStyle += 1
|
||||||
} else {
|
} else {
|
||||||
it.articleStyle = 0
|
it.articleStyle = 0
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/bg_item_focused_on_tv"
|
app:strokeWidth="0dp"
|
||||||
|
app:cardBackgroundColor="@android:color/transparent"
|
||||||
|
android:layout_margin="4dp">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
android:foreground="?android:attr/selectableItemBackground"
|
||||||
android:padding="16dp"
|
android:padding="12dp"
|
||||||
android:scrollbars="none">
|
android:scrollbars="none">
|
||||||
|
|
||||||
<io.legato.kazusa.ui.widget.image.FilletImageView
|
<io.legato.kazusa.ui.widget.image.FilletImageView
|
||||||
@@ -25,16 +32,18 @@
|
|||||||
android:id="@+id/tv_name"
|
android:id="@+id/tv_name"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="8dp"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="top|center_horizontal"
|
android:gravity="top|center_horizontal"
|
||||||
android:lines="2"
|
android:lines="2"
|
||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
android:textSize="14sp"
|
android:textSize="12sp"
|
||||||
|
android:textStyle="bold"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/iv_icon"
|
app:layout_constraintTop_toBottomOf="@+id/iv_icon"
|
||||||
tools:text="RSS" />
|
tools:text="RSS" />
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_margin="8dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="100dp"
|
app:strokeWidth="0dp"
|
||||||
android:padding="16dp">
|
app:cardBackgroundColor="?attr/colorSurfaceContainer">
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:padding="8dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_title"
|
android:id="@+id/tv_title"
|
||||||
@@ -47,3 +53,4 @@
|
|||||||
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:strokeWidth="0dp"
|
||||||
|
app:cardBackgroundColor="?attr/colorSurfaceContainer">
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:padding="8dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp"
|
|
||||||
android:background="?attr/selectableItemBackground">
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
@@ -47,3 +53,4 @@
|
|||||||
tools:ignore="SmallSp" />
|
tools:ignore="SmallSp" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
@@ -1,16 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:strokeWidth="0dp"
|
||||||
|
android:background="?attr/selectableItemBackground">
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground">
|
android:background="?attr/colorSurfaceContainer">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image_view"
|
android:id="@+id/image_view"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="272dp"
|
android:layout_height="240dp"
|
||||||
android:contentDescription="@string/loading"
|
android:contentDescription="@string/loading"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
@@ -49,3 +55,4 @@
|
|||||||
tools:ignore="SmallSp" />
|
tools:ignore="SmallSp" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.google.android.material.card.MaterialCardView 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:layout_margin="8dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:strokeWidth="0dp"
|
||||||
|
app:cardBackgroundColor="?attr/colorSurfaceContainer">
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:padding="8dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
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="3"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:text="@string/app_name"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
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:text="@string/app_name"
|
||||||
|
android:textSize="11sp"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
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>
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
Reference in New Issue
Block a user