Renamed loadConfig() to initConfig()
This commit is contained in:
parent
dbd147977e
commit
63ade32602
1 changed files with 28 additions and 28 deletions
|
@ -74,6 +74,33 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
|||
val PAUSE = ','
|
||||
}
|
||||
|
||||
fun initConfigs() {
|
||||
try {
|
||||
ObjectInputStream(openFileInput(current_config_data)).use {
|
||||
config = it.readObject() as Config
|
||||
}
|
||||
} catch (ex: FileNotFoundException) {
|
||||
val confs = Configurations()
|
||||
|
||||
defaultConfigs.forEach {
|
||||
config = Gson().fromJson(InputStreamReader(resources.openRawResource(it)),
|
||||
Config::class.java)
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
val errors = StringBuilder()
|
||||
if (!validateConfig(config, errors)) {
|
||||
info(">>> ${config.params.name}: " + Html.fromHtml(errors.toString()))
|
||||
}
|
||||
}
|
||||
|
||||
confs.configs.put(config.params.name, config)
|
||||
}
|
||||
|
||||
saveConfigurations(confs)
|
||||
saveConfig(false)
|
||||
}
|
||||
}
|
||||
|
||||
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
fun importConfig(intent: Intent) {
|
||||
val errors = StringBuilder()
|
||||
|
@ -119,7 +146,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
|||
|
||||
val fields = arrayListOf<EditText>()
|
||||
|
||||
loadConfig()
|
||||
initConfigs()
|
||||
|
||||
verticalLayout {
|
||||
padding = dip(20)
|
||||
|
@ -294,33 +321,6 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
|||
}
|
||||
}
|
||||
|
||||
fun loadConfig() {
|
||||
try {
|
||||
ObjectInputStream(openFileInput(current_config_data)).use {
|
||||
config = it.readObject() as Config
|
||||
}
|
||||
} catch (ex: FileNotFoundException) {
|
||||
val confs = Configurations()
|
||||
|
||||
defaultConfigs.forEach {
|
||||
config = Gson().fromJson(InputStreamReader(resources.openRawResource(it)),
|
||||
Config::class.java)
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
val errors = StringBuilder()
|
||||
if (!validateConfig(config, errors)) {
|
||||
info(">>> ${config.params.name}: " + Html.fromHtml(errors.toString()))
|
||||
}
|
||||
}
|
||||
|
||||
confs.configs.put(config.params.name, config)
|
||||
}
|
||||
|
||||
saveConfigurations(confs)
|
||||
saveConfig(false)
|
||||
}
|
||||
}
|
||||
|
||||
fun saveConfigurations(confs: Configurations) {
|
||||
ObjectOutputStream(openFileOutput(configurations_data, Context.MODE_PRIVATE)).use {
|
||||
it.writeObject(confs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue