pull/32/head
kunfei 5 years ago
parent fac2bb44a6
commit b1bbac7b25
  1. 3
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 16
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  4. 1
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  5. 21
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt

@ -12,7 +12,7 @@ import io.legado.app.data.entities.*
@Database( @Database(
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class,
SearchKeyword::class, SourceCookie::class], SearchKeyword::class, SourceCookie::class, RssSourceDao::class],
version = 1, version = 1,
exportSchema = true exportSchema = true
) )
@ -56,4 +56,5 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun searchBookDao(): SearchBookDao abstract fun searchBookDao(): SearchBookDao
abstract fun searchKeywordDao(): SearchKeywordDao abstract fun searchKeywordDao(): SearchKeywordDao
abstract fun sourceCookieDao(): SourceCookieDao abstract fun sourceCookieDao(): SourceCookieDao
abstract fun rssSourceDao(): RssSourceDao
} }

@ -0,0 +1,16 @@
package io.legado.app.data.dao
import androidx.paging.DataSource
import androidx.room.Dao
import androidx.room.Query
import io.legado.app.data.entities.RssSource
@Dao
interface RssSourceDao {
@Query("SELECT * FROM rssSources")
fun observeAll(): DataSource.Factory<Int, RssSource>
@Query("SELECT * FROM rssSources where enabled = 1")
fun observeEnabled(): DataSource.Factory<Int, RssSource>
}

@ -4,5 +4,6 @@ import androidx.room.Entity
@Entity(tableName = "rssSources") @Entity(tableName = "rssSources")
data class RssSource( data class RssSource(
var sourceName: String var sourceName: String,
var enabled: Boolean = true
) )

@ -8,5 +8,6 @@ class RssAdapter {
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
} }
} }

@ -2,19 +2,38 @@ package io.legado.app.ui.main.rss
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.recyclerview.widget.GridLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseFragment import io.legado.app.base.BaseFragment
import io.legado.app.data.entities.RssSource
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore
import kotlinx.android.synthetic.main.fragment_rss.* import kotlinx.android.synthetic.main.fragment_rss.*
class RssFragment : BaseFragment(R.layout.fragment_rss) { class RssFragment : BaseFragment(R.layout.fragment_rss) {
private lateinit var adapter: RssAdapter
private var rssLiveData: LiveData<PagedList<RssSource>>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initData()
} }
private fun initRecyclerView() { private fun initRecyclerView() {
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(recycler_view)
adapter = RssAdapter()
recycler_view.layoutManager = GridLayoutManager(requireContext(), 4)
}
private fun initData() {
rssLiveData?.removeObservers(viewLifecycleOwner)
rssLiveData = LivePagedListBuilder(App.db.rssSourceDao().observeEnabled(), 50).build()
rssLiveData?.observe(viewLifecycleOwner, Observer { })
} }
} }
Loading…
Cancel
Save