pull/84/head
kunfei 5 years ago
parent cd4f3fe161
commit 83c2be867d
  1. 44
      app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt
  2. 64
      app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt
  3. 16
      app/src/main/res/layout/activity_rss_favorites.xml

@ -1,16 +1,58 @@
package io.legado.app.ui.rss.favorites package io.legado.app.ui.rss.favorites
import android.os.Bundle import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.data.entities.RssStar
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.rss.read.ReadRssActivity
import kotlinx.android.synthetic.main.view_refresh_recycler.*
import org.jetbrains.anko.startActivity
class RssFavoritesActivity : BaseActivity(R.layout.activity_rss_favorites) { class RssFavoritesActivity : BaseActivity(R.layout.activity_rss_favorites),
RssFavoritesAdapter.CallBack {
private var liveData: LiveData<List<RssStar>>? = null
private lateinit var adapter: RssFavoritesAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initData()
}
private fun initView() {
ATH.applyEdgeEffectColor(recycler_view)
recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.addItemDecoration(
DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply {
ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let {
this.setDrawable(it)
}
})
adapter = RssFavoritesAdapter(this, this)
recycler_view.adapter = adapter
} }
private fun initData() {
liveData?.removeObservers(this)
liveData = App.db.rssStarDao().liveAll()
liveData?.observe(this, Observer {
adapter.setItems(it)
})
}
override fun readRss(rssStar: RssStar) {
startActivity<ReadRssActivity>(
Pair("title", rssStar.title),
Pair("origin", rssStar.origin),
Pair("link", rssStar.link)
)
}
} }

@ -0,0 +1,64 @@
package io.legado.app.ui.rss.favorites
import android.content.Context
import android.graphics.drawable.Drawable
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.RssStar
import io.legado.app.help.ImageLoader
import io.legado.app.utils.gone
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_rss_article.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class RssFavoritesAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssStar>(context, R.layout.item_rss_article) {
override fun convert(holder: ItemViewHolder, item: RssStar, payloads: MutableList<Any>) {
with(holder.itemView) {
tv_title.text = item.title
tv_pub_date.text = item.pubDate
onClick {
callBack.readRss(item)
}
if (item.image.isNullOrBlank()) {
image_view.gone()
} else {
ImageLoader.load(context, item.image)
.addListener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
image_view.gone()
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
image_view.visible()
return false
}
})
.into(image_view)
}
}
}
interface CallBack {
fun readRss(rssStar: RssStar)
}
}

@ -1,6 +1,7 @@
<?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" <androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
@ -12,18 +13,13 @@
app:title="@string/favorites" app:title="@string/favorites"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout <io.legado.app.ui.widget.recycler.RefreshRecyclerView
android:id="@+id/content_view" android:id="@+id/refresh_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_bar"> app:layout_constraintTop_toBottomOf="@id/title_bar"
app:layout_constraintVertical_bias="0.0"
<io.legado.app.ui.widget.recycler.RefreshRecyclerView tools:layout_editor_absoluteX="0dp" />
android:id="@+id/refresh_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save