Updated on 2026-08-14
This commit is contained in:
parent
c2953cf149
commit
a63cfada65
4 changed files with 21 additions and 8 deletions
|
|
@ -65,6 +65,16 @@ class PersonalizationJson {
|
|||
val builder = GsonBuilder().setPrettyPrinting()
|
||||
return builder.create()
|
||||
}
|
||||
|
||||
fun clarifyJson(json: String): String {
|
||||
val unsupportedQuotes = mutableListOf("“", "”", "«", "»")
|
||||
var clearedJson = json
|
||||
unsupportedQuotes.forEach {
|
||||
if (clearedJson.contains(it)) clearedJson = clearedJson.replace(it, "\"")
|
||||
}
|
||||
// 160 is 00A0 symbol (No-Break Space)
|
||||
return clearedJson.replace(160.toChar().toString(), "").trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
val tvJsonImport = parent.findViewById<EditText>(R.id.et_json_import)
|
||||
val btnImportJson = parent.findViewById<Button>(R.id.btn_import_json)
|
||||
btnImportJson.setOnClickListener {
|
||||
presetManager.importJsonConfig(tvJsonImport.text.toString().trim())
|
||||
presetManager.importJsonConfig(tvJsonImport.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -255,8 +255,7 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_ok)) { dialog, which ->
|
||||
val tvName = dlgController.view?.findViewById<EditText>(R.id.et_item) ?: return@setButton
|
||||
val name = tvName.text.toString()
|
||||
if (name.isEmpty()) showSnackbar(R.string.error_nothing_to_import)
|
||||
else presetManager.importJsonConfig(name)
|
||||
presetManager.importJsonConfig(name)
|
||||
}
|
||||
dlgController.onShowCallback = {
|
||||
dlgController.view?.findViewById<TextView>(R.id.et_item)?.let {
|
||||
|
|
|
|||
|
|
@ -48,14 +48,17 @@ class PersonalizationPresetManager(
|
|||
}
|
||||
|
||||
fun importJsonConfig(jsonString: String) {
|
||||
if (jsonString.isEmpty()) return
|
||||
if (jsonString.isEmpty()) {
|
||||
view.showSnackbar(R.string.error_nothing_to_import)
|
||||
return
|
||||
}
|
||||
|
||||
val jsonDto = try {
|
||||
PersonalizationJson.getJsonConverter().fromJson(jsonString, PersonalizationJson::class.java)
|
||||
val preparedJson = PersonalizationJson.clarifyJson(jsonString)
|
||||
PersonalizationJson.getJsonConverter().fromJson(preparedJson, PersonalizationJson::class.java)
|
||||
} catch (ex: Exception) {
|
||||
val message = "Can't convert imported string to Json object"
|
||||
view.showSnackbar(message)
|
||||
Log.e(this, "$message. $ex")
|
||||
view.showSnackbar(R.string.error_cant_convert_json)
|
||||
Log.e(this, ex)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<string name="hint_paste">Paste</string>
|
||||
|
||||
<string name="error_nothing_to_import">Nothing to import</string>
|
||||
<string name="error_cant_convert_json">Can\'t convert imported string to Json object</string>
|
||||
<string name="error_not_saved">Not saved</string>
|
||||
|
||||
<string name="personalize">Personalize</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue