pull/48/head
kunfei 5 years ago
parent fa92c468a6
commit da1a3c1f54
  1. 2
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 27
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  3. 3
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  4. 44
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt

@ -191,9 +191,9 @@ data class BookSource(
&& ruleToc == source.ruleToc && ruleToc == source.ruleToc
&& ruleContent == source.ruleContent && ruleContent == source.ruleContent
} }
}
data class ExploreKind( data class ExploreKind(
var title: String, var title: String,
var url: String? = null var url: String? = null
) )
}

@ -30,4 +30,29 @@ data class RssSource(
var enableJs: Boolean = false, var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false, var loadWithBaseUrl: Boolean = false,
var customOrder: Int = 0 var customOrder: Int = 0
) : Parcelable ) : Parcelable {
fun equal(source: RssSource?): Boolean {
if (source == null) {
return false
} else {
return sourceUrl == source.sourceUrl
&& sourceName == source.sourceName
&& sourceIcon == source.sourceIcon
&& enabled == source.enabled
&& sourceGroup == source.sourceGroup
&& ruleArticles == source.ruleArticles
&& ruleNextPage == source.ruleNextPage
&& ruleTitle == source.ruleTitle
&& rulePubDate == source.rulePubDate
&& ruleCategories == source.ruleCategories
&& ruleDescription == source.ruleDescription
&& ruleLink == source.ruleLink
&& ruleContent == source.ruleContent
&& enableJs == source.enableJs
&& loadWithBaseUrl == source.loadWithBaseUrl
&& customOrder == source.customOrder
}
}
}

@ -117,7 +117,6 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
recreate() recreate()
} }
} }
}
private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) :
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
@ -135,3 +134,5 @@ private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) :
return 4 return 4
} }
} }
}

@ -18,10 +18,14 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.EditEntity
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity
import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_rss_source_edit.* import kotlinx.android.synthetic.main.activity_rss_source_edit.*
import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.displayMetrics
@ -50,6 +54,24 @@ class RssSourceEditActivity :
} }
} }
override fun finish() {
val source = getRssSource()
if (!source.equal(viewModel.rssSource)) {
alert(R.string.exit_no_save) {
yesButton {
if (checkSource(source)) {
viewModel.save(source) {
super.finish()
}
}
}
noButton { }
}.show().applyTint()
} else {
super.finish()
}
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
mSoftKeyboardTool?.dismiss() mSoftKeyboardTool?.dismiss()
@ -63,17 +85,19 @@ class RssSourceEditActivity :
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_save -> { R.id.menu_save -> {
getRssSource()?.let { val source = getRssSource()
viewModel.save(it) { if (checkSource(source)) {
viewModel.save(source) {
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)
finish() finish()
} }
} }
} }
R.id.menu_debug_source -> { R.id.menu_debug_source -> {
getRssSource()?.let { val source = getRssSource()
viewModel.save(it) { if (checkSource(source)) {
startActivity<RssSourceDebugActivity>(Pair("key", it.sourceUrl)) viewModel.save(source) {
startActivity<RssSourceDebugActivity>(Pair("key", source.sourceUrl))
} }
} }
} }
@ -134,7 +158,7 @@ class RssSourceEditActivity :
adapter.editEntities = sourceEntities adapter.editEntities = sourceEntities
} }
private fun getRssSource(): RssSource? { private fun getRssSource(): RssSource {
val source = viewModel.rssSource?.copy() ?: RssSource() val source = viewModel.rssSource?.copy() ?: RssSource()
source.enabled = cb_is_enable.isChecked source.enabled = cb_is_enable.isChecked
source.enableJs = cb_enable_js.isChecked source.enableJs = cb_enable_js.isChecked
@ -156,11 +180,15 @@ class RssSourceEditActivity :
"ruleContent" -> source.ruleContent = it.value "ruleContent" -> source.ruleContent = it.value
} }
} }
return source
}
private fun checkSource(source: RssSource): Boolean {
if (source.sourceName.isBlank() || source.sourceName.isBlank()) { if (source.sourceName.isBlank() || source.sourceName.isBlank()) {
toast("名称或url不能为空") toast("名称或url不能为空")
return null return false
} }
return source return true
} }
override fun sendText(text: String) { override fun sendText(text: String) {

Loading…
Cancel
Save