mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-16 08:17:23 +02:00
use the Commons config
This commit is contained in:
parent
c6b81f45f2
commit
e7566caee2
@ -1,40 +1,26 @@
|
|||||||
package com.simplemobiletools.notes
|
package com.simplemobiletools.notes
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
|
|
||||||
class Config(context: Context) {
|
|
||||||
private val mPrefs: SharedPreferences
|
|
||||||
|
|
||||||
|
class Config(context: Context) : BaseConfig(context) {
|
||||||
companion object {
|
companion object {
|
||||||
fun newInstance(context: Context) = Config(context)
|
fun newInstance(context: Context) = Config(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
var isFirstRun: Boolean
|
|
||||||
get() = mPrefs.getBoolean(IS_FIRST_RUN, true)
|
|
||||||
set(firstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, firstRun).apply()
|
|
||||||
|
|
||||||
var isDarkTheme: Boolean
|
|
||||||
get() = mPrefs.getBoolean(IS_DARK_THEME, false)
|
|
||||||
set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
|
|
||||||
|
|
||||||
var fontSize: Int
|
var fontSize: Int
|
||||||
get() = mPrefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
|
get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
|
||||||
set(size) = mPrefs.edit().putInt(FONT_SIZE, size).apply()
|
set(size) = prefs.edit().putInt(FONT_SIZE, size).apply()
|
||||||
|
|
||||||
var gravity: Int
|
var gravity: Int
|
||||||
get() = mPrefs.getInt(GRAVITY, GRAVITY_LEFT)
|
get() = prefs.getInt(GRAVITY, GRAVITY_LEFT)
|
||||||
set(size) = mPrefs.edit().putInt(GRAVITY, size).apply()
|
set(size) = prefs.edit().putInt(GRAVITY, size).apply()
|
||||||
|
|
||||||
var currentNoteId: Int
|
var currentNoteId: Int
|
||||||
get() = mPrefs.getInt(CURRENT_NOTE_ID, 1)
|
get() = prefs.getInt(CURRENT_NOTE_ID, 1)
|
||||||
set(id) = mPrefs.edit().putInt(CURRENT_NOTE_ID, id).apply()
|
set(id) = prefs.edit().putInt(CURRENT_NOTE_ID, id).apply()
|
||||||
|
|
||||||
var widgetNoteId: Int
|
var widgetNoteId: Int
|
||||||
get() = mPrefs.getInt(WIDGET_NOTE_ID, 1)
|
get() = prefs.getInt(WIDGET_NOTE_ID, 1)
|
||||||
set(id) = mPrefs.edit().putInt(WIDGET_NOTE_ID, id).apply()
|
set(id) = prefs.edit().putInt(WIDGET_NOTE_ID, id).apply()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.simplemobiletools.notes.activities
|
package com.simplemobiletools.notes.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.TaskStackBuilder
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
@ -16,21 +15,11 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_settings)
|
setContentView(R.layout.activity_settings)
|
||||||
|
|
||||||
setupDarkTheme()
|
|
||||||
setupFontSize()
|
setupFontSize()
|
||||||
setupWidgetNote()
|
setupWidgetNote()
|
||||||
setupGravity()
|
setupGravity()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupDarkTheme() {
|
|
||||||
settings_dark_theme.isChecked = config.isDarkTheme
|
|
||||||
settings_dark_theme_holder.setOnClickListener {
|
|
||||||
settings_dark_theme.toggle()
|
|
||||||
config.isDarkTheme = settings_dark_theme.isChecked
|
|
||||||
restartActivity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupFontSize() {
|
private fun setupFontSize() {
|
||||||
settings_font_size.setSelection(config.fontSize)
|
settings_font_size.setSelection(config.fontSize)
|
||||||
settings_font_size.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
settings_font_size.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
@ -95,8 +84,4 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||||
return adapter
|
return adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restartActivity() {
|
|
||||||
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user