diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 5c62c01dc..877054299 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -12,7 +12,7 @@ import io.legado.app.data.entities.* @Database( 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, exportSchema = true ) @@ -56,4 +56,5 @@ abstract class AppDatabase : RoomDatabase() { abstract fun searchBookDao(): SearchBookDao abstract fun searchKeywordDao(): SearchKeywordDao abstract fun sourceCookieDao(): SourceCookieDao + abstract fun rssSourceDao(): RssSourceDao } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt new file mode 100644 index 000000000..49532a846 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -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 + + @Query("SELECT * FROM rssSources where enabled = 1") + fun observeEnabled(): DataSource.Factory +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 028740ee0..f18df8b03 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -4,5 +4,6 @@ import androidx.room.Entity @Entity(tableName = "rssSources") data class RssSource( - var sourceName: String + var sourceName: String, + var enabled: Boolean = true ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index bcf752a39..cbce98ce0 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -8,5 +8,6 @@ class RssAdapter { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index d13c1d8e1..e00c9d00e 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -2,19 +2,38 @@ package io.legado.app.ui.main.rss import android.os.Bundle 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.base.BaseFragment +import io.legado.app.data.entities.RssSource import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.ThemeStore import kotlinx.android.synthetic.main.fragment_rss.* class RssFragment : BaseFragment(R.layout.fragment_rss) { + private lateinit var adapter: RssAdapter + private var rssLiveData: LiveData>? = null + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { initRecyclerView() + initData() } private fun initRecyclerView() { 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 { }) } } \ No newline at end of file