pull/84/head
parent
cd4f3fe161
commit
83c2be867d
@ -1,16 +1,58 @@ |
||||
package io.legado.app.ui.rss.favorites |
||||
|
||||
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.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?) { |
||||
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) |
||||
} |
||||
} |
Loading…
Reference in new issue