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 index 96baf62de..5a62b1475 100644 --- a/app/src/main/java/io/legado/app/data/dao/SourceSubDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SourceSubDao.kt @@ -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) + } \ No newline at end of file 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 73cab72ca..77614b077 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 @@ -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(), SourceSubAdapter.Callback { @@ -52,6 +57,17 @@ class SourceSubActivity : BaseActivity(), } } + override fun openSubscription(sourceSub: SourceSub) { + when (sourceSub.type) { + SourceSub.Type.RssSource.ordinal -> { + startActivity("source" to sourceSub.url) + } + else -> { + startActivity("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(), } sourceSub.name = alertBinding.etName.text?.toString() ?: "" sourceSub.url = alertBinding.etUrl.text?.toString() ?: "" - App.db.sourceSubDao().insert(sourceSub) + launch(IO) { + App.db.sourceSubDao().insert(sourceSub) + } } cancelButton() }.show() } override fun delSubscription(sourceSub: SourceSub) { - + launch(IO) { + App.db.sourceSubDao().delete(sourceSub) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt index f08b443e7..e08727b4e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt @@ -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) } diff --git a/app/src/main/res/layout/item_source_sub.xml b/app/src/main/res/layout/item_source_sub.xml index 6e65c171e..1c8cf4852 100644 --- a/app/src/main/res/layout/item_source_sub.xml +++ b/app/src/main/res/layout/item_source_sub.xml @@ -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"