From fa1f69ce57c239aaba90e968b7b48c5be9962d9f Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 5 Dec 2020 13:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BA=90=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/AppDatabase.kt | 2 +- .../io/legado/app/data/entities/SourceSub.kt | 4 +- .../ui/rss/subscription/SourceSubActivity.kt | 28 ++++++++-- .../res/layout/dialog_source_sub_edit.xml | 54 +++++++++++++++++++ 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/layout/dialog_source_sub_edit.xml 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 0e435079f..53a28233d 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -206,7 +206,7 @@ abstract class AppDatabase : RoomDatabase() { 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`))") + database.execSQL("CREATE TABLE IF NOT EXISTS `sourceSubs` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `type` INTEGER NOT NULL, PRIMARY KEY(`id`))") } } } 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 index 4c6bd18da..401d9a515 100644 --- a/app/src/main/java/io/legado/app/data/entities/SourceSub.kt +++ b/app/src/main/java/io/legado/app/data/entities/SourceSub.kt @@ -7,8 +7,8 @@ import androidx.room.PrimaryKey data class SourceSub( @PrimaryKey val id: Long = System.currentTimeMillis(), - var name: String, - var url: String, + var name: String = "", + var url: String = "", var type: Int = 0 ) { diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt index 4dac4c939..490d23491 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt @@ -9,6 +9,8 @@ import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.data.entities.SourceSub import io.legado.app.databinding.ActivitySourceSubBinding +import io.legado.app.databinding.DialogSourceSubEditBinding +import io.legado.app.lib.dialogs.alert class SourceSubActivity : BaseActivity() { @@ -31,7 +33,7 @@ class SourceSubActivity : BaseActivity() { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_add -> editSubscription() + R.id.menu_add -> editSubscription(SourceSub()) } return super.onCompatOptionsItemSelected(item) } @@ -49,8 +51,28 @@ class SourceSubActivity : BaseActivity() { } } - private fun editSubscription() { - + private fun editSubscription(sourceSub: SourceSub) { + alert(R.string.source_subscription) { + val alertBinding = DialogSourceSubEditBinding.inflate(layoutInflater).apply { + when (sourceSub.type) { + SourceSub.Type.RssSource.ordinal -> rgType.check(R.id.rb_rss_source) + else -> rgType.check(R.id.rb_book_source) + } + etName.setText(sourceSub.name) + etUrl.setText(sourceSub.url) + } + customView = alertBinding.root + okButton { + when (alertBinding.rgType.checkedRadioButtonId) { + R.id.rb_rss_source -> sourceSub.setType(SourceSub.Type.RssSource) + else -> sourceSub.setType(SourceSub.Type.BookSource) + } + sourceSub.name = alertBinding.etName.text?.toString() ?: "" + sourceSub.url = alertBinding.etUrl.text?.toString() ?: "" + App.db.sourceSubDao().insert(sourceSub) + } + cancelButton() + }.show() } diff --git a/app/src/main/res/layout/dialog_source_sub_edit.xml b/app/src/main/res/layout/dialog_source_sub_edit.xml new file mode 100644 index 000000000..97cd9b7e6 --- /dev/null +++ b/app/src/main/res/layout/dialog_source_sub_edit.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file