pull/306/head
gedoor 5 years ago
parent a60c9824ac
commit b7ac1f4be3
  1. 4
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  3. 6
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt
  4. 4
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt
  5. 3
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt
  6. 2
      app/src/main/res/values-zh-rHK/strings.xml
  7. 2
      app/src/main/res/values-zh-rTW/strings.xml
  8. 2
      app/src/main/res/values-zh/strings.xml
  9. 2
      app/src/main/res/values/strings.xml

@ -78,7 +78,7 @@ class ImportBookSourceActivity : VMBaseActivity<ImportBookSourceViewModel>(
} }
else -> { else -> {
rotate_loading.hide() rotate_loading.hide()
toast("格式不对") toast(R.string.wrong_format)
finish() finish()
} }
} }
@ -86,7 +86,7 @@ class ImportBookSourceActivity : VMBaseActivity<ImportBookSourceViewModel>(
} }
private fun errorDialog(msg: String) { private fun errorDialog(msg: String) {
alert("导入出错", msg) { alert(getString(R.string.error), msg) {
okButton { } okButton { }
}.show().applyTint().setOnDismissListener { }.show().applyTint().setOnDismissListener {
finish() finish()

@ -6,14 +6,13 @@ import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.App import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.OldRule
import io.legado.app.help.storage.Restore import io.legado.app.help.storage.Restore
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
@ -42,12 +41,11 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
if (content != null) { if (content != null) {
importSource(content) importSource(content)
} else { } else {
withContext(Dispatchers.Main) { errorLiveData.postValue(context.getString(R.string.error_read_file))
errorLiveData.postValue("打开文件出错")
}
} }
}.onError { }.onError {
errorLiveData.postValue(it.localizedMessage ?: "打开文件出错") it.printStackTrace()
errorLiveData.postValue(context.getString(R.string.error_read_file))
} }
} }
@ -80,7 +78,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
text1.isAbsUrl() -> { text1.isAbsUrl() -> {
importSourceUrl(text1) importSourceUrl(text1)
} }
else -> throw Exception("格式不对") else -> throw Exception(context.getString(R.string.wrong_format))
} }
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
@ -93,7 +91,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
private fun importSourceUrl(url: String) { private fun importSourceUrl(url: String) {
HttpHelper.simpleGet(url, "UTF-8").let { body -> HttpHelper.simpleGet(url, "UTF-8").let { body ->
if (body == null) { if (body == null) {
throw Exception("访问网站失败") throw Exception(context.getString(R.string.error_get_data))
} }
val items: List<Map<String, Any>> = Restore.jsonPath.parse(body).read("$") val items: List<Map<String, Any>> = Restore.jsonPath.parse(body).read("$")
for (item in items) { for (item in items) {

@ -4,6 +4,7 @@ import android.app.Application
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
@ -36,10 +37,11 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) {
if (content != null) { if (content != null) {
import(content) import(content)
} else { } else {
errorLiveData.postValue("打开文件出错") errorLiveData.postValue(context.getString(R.string.error_read_file))
} }
}.onError { }.onError {
errorLiveData.postValue(it.localizedMessage ?: "打开文件出错") it.printStackTrace()
errorLiveData.postValue(context.getString(R.string.error_read_file))
} }
} }

@ -78,7 +78,7 @@ class ImportRssSourceActivity : VMBaseActivity<ImportRssSourceViewModel>(
} }
else -> { else -> {
rotate_loading.hide() rotate_loading.hide()
toast("格式不对") toast(R.string.wrong_format)
finish() finish()
} }
} }
@ -86,7 +86,7 @@ class ImportRssSourceActivity : VMBaseActivity<ImportRssSourceViewModel>(
} }
private fun errorDialog(msg: String) { private fun errorDialog(msg: String) {
alert("导入出错", msg) { alert(getString(R.string.error), msg) {
okButton { } okButton { }
}.show().applyTint().setOnDismissListener { }.show().applyTint().setOnDismissListener {
finish() finish()

@ -6,6 +6,7 @@ import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.App import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
@ -76,7 +77,7 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
text1.isAbsUrl() -> { text1.isAbsUrl() -> {
importSourceUrl(text1) importSourceUrl(text1)
} }
else -> throw Exception("格式不对") else -> throw Exception(context.getString(R.string.wrong_format))
} }
}.onError { }.onError {
errorLiveData.postValue("ImportError:${it.localizedMessage}") errorLiveData.postValue("ImportError:${it.localizedMessage}")

@ -739,4 +739,6 @@
<string name="night_bottom_bar_too_light">夜间底栏不能太亮</string> <string name="night_bottom_bar_too_light">夜间底栏不能太亮</string>
<string name="accent_background_diff">强调色不能和背景颜色相似</string> <string name="accent_background_diff">强调色不能和背景颜色相似</string>
<string name="accent_text_diff">强调色不能和文字颜色相似</string> <string name="accent_text_diff">强调色不能和文字颜色相似</string>
<string name="wrong_format">格式不对</string>
<string name="error">错误</string>
</resources> </resources>

@ -739,5 +739,7 @@
<string name="night_bottom_bar_too_light">夜间底栏不能太亮</string> <string name="night_bottom_bar_too_light">夜间底栏不能太亮</string>
<string name="accent_background_diff">强调色不能和背景颜色相似</string> <string name="accent_background_diff">强调色不能和背景颜色相似</string>
<string name="accent_text_diff">强调色不能和文字颜色相似</string> <string name="accent_text_diff">强调色不能和文字颜色相似</string>
<string name="wrong_format">格式不对</string>
<string name="error">错误</string>
</resources> </resources>

@ -739,4 +739,6 @@
<string name="night_bottom_bar_too_light">夜间底栏不能太亮</string> <string name="night_bottom_bar_too_light">夜间底栏不能太亮</string>
<string name="accent_background_diff">强调色不能和背景颜色相似</string> <string name="accent_background_diff">强调色不能和背景颜色相似</string>
<string name="accent_text_diff">强调色不能和文字颜色相似</string> <string name="accent_text_diff">强调色不能和文字颜色相似</string>
<string name="wrong_format">格式不对</string>
<string name="error">错误</string>
</resources> </resources>

@ -740,5 +740,7 @@
<string name="night_bottom_bar_too_light">夜间底栏不能太亮</string> <string name="night_bottom_bar_too_light">夜间底栏不能太亮</string>
<string name="accent_background_diff">强调色不能和背景颜色相似</string> <string name="accent_background_diff">强调色不能和背景颜色相似</string>
<string name="accent_text_diff">强调色不能和文字颜色相似</string> <string name="accent_text_diff">强调色不能和文字颜色相似</string>
<string name="wrong_format">格式不对</string>
<string name="error">错误</string>
</resources> </resources>
Loading…
Cancel
Save