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