pull/48/head
kunfei 5 years ago
parent fa92c468a6
commit da1a3c1f54
  1. 10
      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. 25
      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
&& ruleContent == source.ruleContent
}
}
data class ExploreKind(
var title: String,
var url: String? = null
)
data class ExploreKind(
var title: String,
var url: String? = null
)
}

@ -30,4 +30,29 @@ data class RssSource(
var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false,
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,21 +117,22 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
recreate()
}
}
}
private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) :
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) :
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> BookshelfFragment()
1 -> ExploreFragment()
2 -> RssFragment()
else -> MyFragment()
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> BookshelfFragment()
1 -> ExploreFragment()
2 -> RssFragment()
else -> MyFragment()
}
}
}
override fun getCount(): Int {
return 4
override fun getCount(): Int {
return 4
}
}
}

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

Loading…
Cancel
Save