添加源地址订阅功能

pull/517/head
gedoor 4 years ago
parent f4394a7059
commit c819890a43
  1. 29
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 22
      app/src/main/java/io/legado/app/data/dao/SourceSubDao.kt
  3. 12
      app/src/main/java/io/legado/app/data/entities/SourceSub.kt
  4. 11
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubscription.kt

@ -17,8 +17,9 @@ import java.util.*
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class], RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class,
version = 24, SourceSub::class],
version = 25,
exportSchema = true exportSchema = true
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
@ -39,6 +40,7 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun readRecordDao(): ReadRecordDao abstract fun readRecordDao(): ReadRecordDao
abstract fun httpTTSDao(): HttpTTSDao abstract fun httpTTSDao(): HttpTTSDao
abstract fun cacheDao(): CacheDao abstract fun cacheDao(): CacheDao
abstract fun sourceSubDao(): SourceSubDao
companion object { companion object {
@ -48,19 +50,10 @@ abstract class AppDatabase : RoomDatabase() {
Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME) Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
.fallbackToDestructiveMigration() .fallbackToDestructiveMigration()
.addMigrations( .addMigrations(
migration_10_11, migration_10_11, migration_11_12, migration_12_13, migration_13_14,
migration_11_12, migration_14_15, migration_15_17, migration_17_18, migration_18_19,
migration_12_13, migration_19_20, migration_20_21, migration_21_22, migration_22_23,
migration_13_14, migration_23_24, migration_24_25
migration_14_15,
migration_15_17,
migration_17_18,
migration_18_19,
migration_19_20,
migration_20_21,
migration_21_22,
migration_22_23,
migration_23_24
) )
.allowMainThreadQueries() .allowMainThreadQueries()
.addCallback(dbCallback) .addCallback(dbCallback)
@ -210,6 +203,12 @@ abstract class AppDatabase : RoomDatabase() {
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_caches_key` ON `caches` (`key`)") database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_caches_key` ON `caches` (`key`)")
} }
} }
private val migration_24_25 = object : Migration(24, 25) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `sourceSubs` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, PRIMARY KEY(`id`))")
}
}
} }
} }

@ -0,0 +1,22 @@
package io.legado.app.data.dao
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.legado.app.data.entities.SourceSub
@Dao
interface SourceSubDao {
@get:Query("select * from sourceSubs")
val all: List<SourceSub>
@Query("select * from sourceSubs")
fun observeAll(): LiveData<List<SourceSub>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg sourceSub: SourceSub)
}

@ -0,0 +1,12 @@
package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "sourceSubs")
data class SourceSub(
@PrimaryKey
val id: Long = System.currentTimeMillis(),
val name: String,
val url: String,
)

@ -14,7 +14,8 @@ class SourceSubscription : BaseActivity<ActivitySourceSubBinding>() {
} }
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initData()
} }
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
@ -29,6 +30,14 @@ class SourceSubscription : BaseActivity<ActivitySourceSubBinding>() {
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
private fun initView() {
binding.recyclerView
}
private fun initData() {
}
private fun editSubscription() { private fun editSubscription() {
} }

Loading…
Cancel
Save