添加源地址订阅功能

pull/517/head
gedoor 4 years ago
parent 7c9b461347
commit fa1f69ce57
  1. 2
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 4
      app/src/main/java/io/legado/app/data/entities/SourceSub.kt
  3. 28
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt
  4. 54
      app/src/main/res/layout/dialog_source_sub_edit.xml

@ -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`))")
}
}
}

@ -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
) {

@ -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<ActivitySourceSubBinding>() {
@ -31,7 +33,7 @@ class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>() {
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<ActivitySourceSubBinding>() {
}
}
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()
}

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<RadioGroup
android:id="@+id/rg_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<io.legado.app.lib.theme.view.ATERadioButton
android:id="@+id/rb_book_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/book_source" />
<io.legado.app.lib.theme.view.ATERadioButton
android:id="@+id/rb_rss_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rss_source" />
</RadioGroup>
<io.legado.app.ui.widget.text.TextInputLayout
android:id="@+id/til_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name">
<io.legado.app.ui.widget.text.EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</io.legado.app.ui.widget.text.TextInputLayout>
<io.legado.app.ui.widget.text.TextInputLayout
android:id="@+id/til_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Url"
tools:ignore="HardcodedText">
<io.legado.app.ui.widget.text.EditText
android:id="@+id/et_url"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</io.legado.app.ui.widget.text.TextInputLayout>
</LinearLayout>
Loading…
Cancel
Save