create a config extension for getting the Config
This commit is contained in:
parent
612bb269e3
commit
f0d2c8e491
3 changed files with 18 additions and 12 deletions
|
@ -28,7 +28,7 @@ import com.simplemobiletools.draw.BuildConfig
|
|||
import com.simplemobiletools.draw.MyCanvas
|
||||
import com.simplemobiletools.draw.R
|
||||
import com.simplemobiletools.draw.Svg
|
||||
import com.simplemobiletools.draw.helpers.Config
|
||||
import com.simplemobiletools.draw.extensions.config
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
|
@ -56,10 +56,10 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
my_canvas.setListener(this)
|
||||
stroke_width_bar.setOnSeekBarChangeListener(onStrokeWidthBarChangeListener)
|
||||
|
||||
setBackgroundColor(Config.newInstance(this).canvasBackgroundColor)
|
||||
setColor(Config.newInstance(this).brushColor)
|
||||
setBackgroundColor(config.canvasBackgroundColor)
|
||||
setColor(config.brushColor)
|
||||
|
||||
strokeWidth = Config.newInstance(this).brushSize
|
||||
strokeWidth = config.brushSize
|
||||
my_canvas.setStrokeWidth(strokeWidth)
|
||||
stroke_width_bar.progress = strokeWidth.toInt()
|
||||
|
||||
|
@ -69,20 +69,20 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val isStrokeWidthBarEnabled = Config.newInstance(this).showBrushSize
|
||||
val isStrokeWidthBarEnabled = config.showBrushSize
|
||||
stroke_width_bar.beVisibleIf(isStrokeWidthBarEnabled)
|
||||
my_canvas.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
Config.newInstance(this).brushColor = color
|
||||
Config.newInstance(this).brushSize = strokeWidth
|
||||
config.brushColor = color
|
||||
config.brushSize = strokeWidth
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
Config.newInstance(applicationContext).isFirstRun = false
|
||||
config.isFirstRun = false
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
@ -112,7 +112,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
val oldColor = (my_canvas.background as ColorDrawable).color
|
||||
ColorPickerDialog(this, oldColor) {
|
||||
setBackgroundColor(it)
|
||||
Config.newInstance(applicationContext).canvasBackgroundColor = it
|
||||
config.canvasBackgroundColor = it
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package com.simplemobiletools.draw.activities
|
|||
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.draw.helpers.Config
|
||||
import com.simplemobiletools.draw.R
|
||||
import com.simplemobiletools.draw.extensions.config
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
||||
class SettingsActivity : SimpleActivity() {
|
||||
|
@ -27,10 +27,10 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupBrushSize() {
|
||||
settings_show_brush_size.isChecked = Config.newInstance(this).showBrushSize
|
||||
settings_show_brush_size.isChecked = config.showBrushSize
|
||||
settings_show_brush_size_holder.setOnClickListener {
|
||||
settings_show_brush_size.toggle()
|
||||
Config.newInstance(this).showBrushSize = settings_show_brush_size.isChecked
|
||||
config.showBrushSize = settings_show_brush_size.isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package com.simplemobiletools.draw.extensions
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.draw.helpers.Config
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
Loading…
Reference in a new issue