订阅源瀑布流 #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) {
|
||||
val query = searchView.text.toString()
|
||||
upRssFlowJob(query)
|
||||
searchBar.hint = if (query.isEmpty()) {
|
||||
searchBar.hint = query.ifEmpty {
|
||||
getString(R.string.search_rss_source)
|
||||
} else {
|
||||
query
|
||||
}
|
||||
searchView.hide()
|
||||
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.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.base.VMBaseFragment
|
||||
import io.legato.kazusa.constant.AppLog
|
||||
@@ -50,6 +51,7 @@ class RssArticlesFragment() : VMBaseFragment<RssArticlesViewModel>(R.layout.frag
|
||||
when (activityViewModel.rssSource?.articleStyle) {
|
||||
1 -> RssArticlesAdapter1(requireContext(), this@RssArticlesFragment)
|
||||
2 -> RssArticlesAdapter2(requireContext(), this@RssArticlesFragment)
|
||||
3 -> RssArticlesAdapter3(requireContext(), this@RssArticlesFragment)
|
||||
else -> RssArticlesAdapter(requireContext(), this@RssArticlesFragment)
|
||||
}
|
||||
}
|
||||
@@ -75,13 +77,15 @@ class RssArticlesFragment() : VMBaseFragment<RssArticlesViewModel>(R.layout.frag
|
||||
scrollToBottom(true)
|
||||
}
|
||||
}
|
||||
recyclerView.layoutManager = if (activityViewModel.isGridLayout) {
|
||||
recyclerView.setPadding(8, 0, 8, 0)
|
||||
val layoutManager = if (activityViewModel.isWaterLayout) {
|
||||
recyclerView.itemAnimator = null
|
||||
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
|
||||
} else if (activityViewModel.isGridLayout) {
|
||||
GridLayoutManager(requireContext(), 2)
|
||||
} else {
|
||||
recyclerView.addItemDecoration(VerticalDivider(requireContext()))
|
||||
LinearLayoutManager(requireContext())
|
||||
}
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.adapter = adapter
|
||||
adapter.addFooterView {
|
||||
ViewLoadMoreBinding.bind(loadMoreView)
|
||||
|
||||
@@ -17,6 +17,7 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
|
||||
val titleLiveData = MutableLiveData<String>()
|
||||
var order = System.currentTimeMillis()
|
||||
val isGridLayout get() = rssSource?.articleStyle == 2
|
||||
val isWaterLayout get() = rssSource?.articleStyle == 3
|
||||
|
||||
fun initData(intent: Intent, finally: () -> Unit) {
|
||||
execute {
|
||||
@@ -36,7 +37,7 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
fun switchLayout() {
|
||||
rssSource?.let {
|
||||
if (it.articleStyle < 2) {
|
||||
if (it.articleStyle < 3) {
|
||||
it.articleStyle += 1
|
||||
} else {
|
||||
it.articleStyle = 0
|
||||
|
||||
Reference in New Issue
Block a user