pull/36/head
kunfei 5 years ago
parent 358f955071
commit 498cbf99a5
  1. 3
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  2. 6
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  3. 18
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  4. 13
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt

@ -7,6 +7,9 @@ import io.legado.app.data.entities.RssSource
@Dao @Dao
interface RssSourceDao { interface RssSourceDao {
@Query("select * from rssSources where sourceUrl = :key")
fun getByKey(key: String): RssSource?
@get:Query("SELECT * FROM rssSources") @get:Query("SELECT * FROM rssSources")
val all: List<RssSource> val all: List<RssSource>

@ -8,10 +8,10 @@ import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@Entity(tableName = "rssSources") @Entity(tableName = "rssSources")
data class RssSource( data class RssSource(
var sourceName: String, var sourceName: String = "",
@PrimaryKey @PrimaryKey
var sourceUrl: String, var sourceUrl: String = "",
var iconUrl: String, var iconUrl: String = "",
var enabled: Boolean = true, var enabled: Boolean = true,
var ruleGuid: String? = null, var ruleGuid: String? = null,
var ruleTitle: String? = null, var ruleTitle: String? = null,

@ -7,10 +7,12 @@ import android.view.Menu
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.widget.EditText import android.widget.EditText
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.data.entities.RssSource
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
@ -33,6 +35,19 @@ class RssSourceEditActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
viewModel.sourceLiveData.observe(this, Observer {
upRecyclerView(it)
})
if (viewModel.sourceLiveData.value == null) {
val sourceID = intent.getStringExtra("data")
if (sourceID == null) {
upRecyclerView(null)
} else {
sourceID.let { viewModel.setSource(sourceID) }
}
} else {
upRecyclerView(viewModel.sourceLiveData.value)
}
} }
override fun onDestroy() { override fun onDestroy() {
@ -53,6 +68,9 @@ class RssSourceEditActivity :
recycler_view.adapter = adapter recycler_view.adapter = adapter
} }
private fun upRecyclerView(rssSource: RssSource?) {
}
override fun sendText(text: String) { override fun sendText(text: String) {
if (text.isBlank()) return if (text.isBlank()) return

@ -1,9 +1,22 @@
package io.legado.app.ui.rss.source.edit package io.legado.app.ui.rss.source.edit
import android.app.Application import android.app.Application
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssSource
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { class RssSourceEditViewModel(application: Application) : BaseViewModel(application) {
val sourceLiveData: MutableLiveData<RssSource> = MutableLiveData()
fun setSource(key: String) {
execute {
App.db.rssSourceDao().getByKey(key)?.let {
sourceLiveData.postValue(it)
} ?: sourceLiveData.postValue(RssSource())
}
}
} }
Loading…
Cancel
Save