添加源地址订阅功能

pull/517/head
gedoor 4 years ago
parent e7a2ab958d
commit bea16e8667
  1. 8
      app/src/main/java/io/legado/app/data/dao/SourceSubDao.kt
  2. 22
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt
  3. 7
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt
  4. 1
      app/src/main/res/layout/item_source_sub.xml

@ -1,10 +1,7 @@
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 androidx.room.*
import io.legado.app.data.entities.SourceSub
@Dao
@ -19,4 +16,7 @@ interface SourceSubDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg sourceSub: SourceSub)
@Delete
fun delete(vararg sourceSub: SourceSub)
}

@ -11,6 +11,11 @@ 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
import io.legado.app.ui.association.ImportBookSourceActivity
import io.legado.app.ui.association.ImportRssSourceActivity
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity
class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>(),
SourceSubAdapter.Callback {
@ -52,6 +57,17 @@ class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>(),
}
}
override fun openSubscription(sourceSub: SourceSub) {
when (sourceSub.type) {
SourceSub.Type.RssSource.ordinal -> {
startActivity<ImportRssSourceActivity>("source" to sourceSub.url)
}
else -> {
startActivity<ImportBookSourceActivity>("source" to sourceSub.url)
}
}
}
override fun editSubscription(sourceSub: SourceSub) {
alert(R.string.source_subscription) {
val alertBinding = DialogSourceSubEditBinding.inflate(layoutInflater).apply {
@ -70,13 +86,17 @@ class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>(),
}
sourceSub.name = alertBinding.etName.text?.toString() ?: ""
sourceSub.url = alertBinding.etUrl.text?.toString() ?: ""
launch(IO) {
App.db.sourceSubDao().insert(sourceSub)
}
}
cancelButton()
}.show()
}
override fun delSubscription(sourceSub: SourceSub) {
launch(IO) {
App.db.sourceSubDao().delete(sourceSub)
}
}
}

@ -24,9 +24,15 @@ class SourceSubAdapter(context: Context, val callBack: Callback) :
}
override fun registerListener(holder: ItemViewHolder, binding: ItemSourceSubBinding) {
binding.root.onClick {
callBack.openSubscription(getItem(holder.layoutPosition)!!)
}
binding.ivEdit.onClick {
callBack.editSubscription(getItem(holder.layoutPosition)!!)
}
binding.ivMenuMore.onClick {
}
}
override fun getViewBinding(parent: ViewGroup): ItemSourceSubBinding {
@ -34,6 +40,7 @@ class SourceSubAdapter(context: Context, val callBack: Callback) :
}
interface Callback {
fun openSubscription(sourceSub: SourceSub)
fun editSubscription(sourceSub: SourceSub)
fun delSubscription(sourceSub: SourceSub)
}

@ -37,6 +37,7 @@
android:textSize="12sp"
android:textColor="@color/secondaryText"
android:ellipsize="middle"
android:singleLine="true"
app:layout_constraintTop_toBottomOf="@+id/tv_name"
app:layout_constraintLeft_toRightOf="@+id/tv_type"
app:layout_constraintRight_toLeftOf="@+id/iv_edit"

Loading…
Cancel
Save