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 7888cb7f9..0e435079f 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -17,8 +17,9 @@ import java.util.* entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, - RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class], - version = 24, + RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class, + SourceSub::class], + version = 25, exportSchema = true ) abstract class AppDatabase : RoomDatabase() { @@ -39,6 +40,7 @@ abstract class AppDatabase : RoomDatabase() { abstract fun readRecordDao(): ReadRecordDao abstract fun httpTTSDao(): HttpTTSDao abstract fun cacheDao(): CacheDao + abstract fun sourceSubDao(): SourceSubDao companion object { @@ -48,19 +50,10 @@ abstract class AppDatabase : RoomDatabase() { Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME) .fallbackToDestructiveMigration() .addMigrations( - migration_10_11, - migration_11_12, - migration_12_13, - migration_13_14, - 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 + migration_10_11, migration_11_12, migration_12_13, migration_13_14, + 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, migration_24_25 ) .allowMainThreadQueries() .addCallback(dbCallback) @@ -210,6 +203,12 @@ abstract class AppDatabase : RoomDatabase() { 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`))") + } + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/SourceSubDao.kt b/app/src/main/java/io/legado/app/data/dao/SourceSubDao.kt new file mode 100644 index 000000000..96baf62de --- /dev/null +++ b/app/src/main/java/io/legado/app/data/dao/SourceSubDao.kt @@ -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 + + @Query("select * from sourceSubs") + fun observeAll(): LiveData> + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(vararg sourceSub: SourceSub) + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/SourceSub.kt b/app/src/main/java/io/legado/app/data/entities/SourceSub.kt new file mode 100644 index 000000000..3c7fa16e0 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/SourceSub.kt @@ -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, +) diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubscription.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubscription.kt index 5506c873f..e4042821d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubscription.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubscription.kt @@ -14,7 +14,8 @@ class SourceSubscription : BaseActivity() { } override fun onActivityCreated(savedInstanceState: Bundle?) { - + initView() + initData() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -29,6 +30,14 @@ class SourceSubscription : BaseActivity() { return super.onCompatOptionsItemSelected(item) } + private fun initView() { + binding.recyclerView + } + + private fun initData() { + + } + private fun editSubscription() { }