Code optimization.
This commit is contained in:
parent
56ea5a1a36
commit
2c324efaea
4 changed files with 39 additions and 41 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -24,7 +24,7 @@
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -59,11 +59,11 @@ import java.util.*
|
||||||
|
|
||||||
@RuntimePermissions
|
@RuntimePermissions
|
||||||
class MainActivity : AppCompatActivity(), AnkoLogger {
|
class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
lateinit var config: Config
|
private lateinit var config: Config
|
||||||
val aboutConfig: AboutConfig = AboutConfig.getInstance()
|
private val aboutConfig: AboutConfig = AboutConfig.getInstance()
|
||||||
val configurationsData = "configurations.dat"
|
private val configurationsData = "configurations.dat"
|
||||||
val currentConfigData = "config.dat"
|
private val currentConfigData = "config.dat"
|
||||||
val defaultConfigurations = listOf(
|
private val defaultConfigurations = listOf(
|
||||||
R.raw.dks_1802,
|
R.raw.dks_1802,
|
||||||
R.raw.dks_1802_epd,
|
R.raw.dks_1802_epd,
|
||||||
R.raw.dks_1812,
|
R.raw.dks_1812,
|
||||||
|
@ -71,14 +71,14 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
R.raw.linear_ae_100,
|
R.raw.linear_ae_100,
|
||||||
R.raw.linear_ae_500,
|
R.raw.linear_ae_500,
|
||||||
R.raw.dks_1803_1808_1810)
|
R.raw.dks_1803_1808_1810)
|
||||||
val readRequestCode = 42
|
private val readRequestCode = 42
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val PAUSE = ','
|
const val PAUSE = ','
|
||||||
val QUOTE = "'"
|
const val QUOTE = "'"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromHtml(s: String): Spanned {
|
private fun fromHtml(s: String): Spanned {
|
||||||
if (Build.VERSION.SDK_INT >= 24) {
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
return Html.fromHtml(s, Html.FROM_HTML_MODE_LEGACY)
|
return Html.fromHtml(s, Html.FROM_HTML_MODE_LEGACY)
|
||||||
} else {
|
} else {
|
||||||
|
@ -87,7 +87,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initConfigurations() {
|
private fun initConfigurations() {
|
||||||
try {
|
try {
|
||||||
ObjectInputStream(openFileInput(currentConfigData)).use {
|
ObjectInputStream(openFileInput(currentConfigData)).use {
|
||||||
config = it.readObject() as Config
|
config = it.readObject() as Config
|
||||||
|
@ -108,7 +108,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
confs.configs.put(config.params.name, config)
|
confs.configs[config.params.name] = config
|
||||||
}
|
}
|
||||||
|
|
||||||
saveConfigurations(confs)
|
saveConfigurations(confs)
|
||||||
|
@ -318,29 +318,26 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
|
|
||||||
alert.setTitle(R.string.action_config)
|
alert.setTitle(R.string.action_config)
|
||||||
|
|
||||||
alert.setSingleChoiceItems(keys.toTypedArray(), checked,
|
alert.setSingleChoiceItems(keys.toTypedArray(), checked) { dialogInterface, i ->
|
||||||
{ dialogInterface, i ->
|
|
||||||
if (i != checked) {
|
if (i != checked) {
|
||||||
config = confs.getOrElse(keys.elementAt(i), defaultValue = { config })
|
config = confs.getOrElse(keys.elementAt(i), defaultValue = { config })
|
||||||
saveConfig()
|
saveConfig()
|
||||||
this.recreate()
|
this.recreate()
|
||||||
}
|
}
|
||||||
dialogInterface.dismiss()
|
dialogInterface.dismiss()
|
||||||
})
|
}
|
||||||
|
|
||||||
alert.setNegativeButton(android.R.string.cancel,
|
alert.setNegativeButton(android.R.string.cancel) { dialogInterface, _ ->
|
||||||
{ dialogInterface, _ ->
|
|
||||||
dialogInterface.dismiss()
|
dialogInterface.dismiss()
|
||||||
})
|
}
|
||||||
|
|
||||||
alert.setNeutralButton(R.string.dialog_import,
|
alert.setNeutralButton(R.string.dialog_import) { dialogInterface, _ ->
|
||||||
{ dialogInterface, _ ->
|
|
||||||
dialogInterface.dismiss()
|
dialogInterface.dismiss()
|
||||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
intent.type = "application/json"
|
intent.type = "application/json"
|
||||||
startActivityForResult(intent, readRequestCode)
|
startActivityForResult(intent, readRequestCode)
|
||||||
})
|
}
|
||||||
|
|
||||||
alert.show()
|
alert.show()
|
||||||
|
|
||||||
|
@ -357,7 +354,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
onRequestPermissionsResult(requestCode, grantResults)
|
onRequestPermissionsResult(requestCode, grantResults)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadConfigurations(): Configurations {
|
private fun loadConfigurations(): Configurations {
|
||||||
try {
|
try {
|
||||||
ObjectInputStream(openFileInput(configurationsData)).use {
|
ObjectInputStream(openFileInput(configurationsData)).use {
|
||||||
return it.readObject() as Configurations
|
return it.readObject() as Configurations
|
||||||
|
@ -367,15 +364,15 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveConfigurations(confs: Configurations) =
|
private fun saveConfigurations(confs: Configurations) =
|
||||||
ObjectOutputStream(openFileOutput(configurationsData, Context.MODE_PRIVATE)).use {
|
ObjectOutputStream(openFileOutput(configurationsData, Context.MODE_PRIVATE)).use {
|
||||||
it.writeObject(confs)
|
it.writeObject(confs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveConfig(backup: Boolean = true) {
|
private fun saveConfig(backup: Boolean = true) {
|
||||||
if (backup) {
|
if (backup) {
|
||||||
val confs = loadConfigurations()
|
val confs = loadConfigurations()
|
||||||
confs.configs.put(config.params.name, config)
|
confs.configs[config.params.name] = config
|
||||||
saveConfigurations(confs)
|
saveConfigurations(confs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +381,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validateConfig(config: Config, errors: StringBuilder): Boolean {
|
private fun validateConfig(config: Config, errors: StringBuilder): Boolean {
|
||||||
val len = errors.length
|
val len = errors.length
|
||||||
|
|
||||||
with(config) {
|
with(config) {
|
||||||
|
@ -421,6 +418,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
opts.forEachIndexed { i, option ->
|
opts.forEachIndexed { i, option ->
|
||||||
// gson will create a null object on trailing comma
|
// gson will create a null object on trailing comma
|
||||||
// see: https://github.com/google/gson/issues/494
|
// see: https://github.com/google/gson/issues/494
|
||||||
|
@Suppress("SENSELESS_COMPARISON")
|
||||||
if (option == null) {
|
if (option == null) {
|
||||||
errors.append(getString(R.string.validate_syntax_error, "opts[]"))
|
errors.append(getString(R.string.validate_syntax_error, "opts[]"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -600,7 +598,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
|
||||||
return errors.length == len
|
return errors.length == len
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validateFields(fields: ArrayList<Pair<EditText, Int>>): Boolean {
|
private fun validateFields(fields: ArrayList<Pair<EditText, Int>>): Boolean {
|
||||||
var isValid = true
|
var isValid = true
|
||||||
|
|
||||||
fields.forEach {
|
fields.forEach {
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.util.*
|
||||||
|
|
||||||
class StepsActivity : FragmentActivity() {
|
class StepsActivity : FragmentActivity() {
|
||||||
companion object {
|
companion object {
|
||||||
val EXTRA_STEPS = "steps"
|
const val EXTRA_STEPS = "steps"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ class StepsFragment : Fragment() {
|
||||||
private var pageNumber: Int = 0
|
private var pageNumber: Int = 0
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val ARG_PAGE = "page"
|
const val ARG_PAGE = "page"
|
||||||
private val steps = ArrayList<String>()
|
private val steps = ArrayList<String>()
|
||||||
|
|
||||||
fun create(pageNumber: Int, steps: ArrayList<String>): StepsFragment {
|
fun create(pageNumber: Int, steps: ArrayList<String>): StepsFragment {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue