mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-01-29 21:49:16 +01:00
create a config context extension
This commit is contained in:
parent
bf86fdec64
commit
08bf07f7f4
@ -23,6 +23,7 @@ import com.simplemobiletools.notes.adapters.NotesPagerAdapter
|
||||
import com.simplemobiletools.notes.dialogs.NewNoteDialog
|
||||
import com.simplemobiletools.notes.dialogs.OpenNoteDialog
|
||||
import com.simplemobiletools.notes.dialogs.RenameNoteDialog
|
||||
import com.simplemobiletools.notes.extensions.config
|
||||
import com.simplemobiletools.notes.extensions.getTextSize
|
||||
import com.simplemobiletools.notes.helpers.DBHelper
|
||||
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
||||
|
@ -6,6 +6,7 @@ import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.extensions.config
|
||||
import com.simplemobiletools.notes.extensions.updateWidget
|
||||
import com.simplemobiletools.notes.helpers.DBHelper
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
|
@ -2,13 +2,9 @@ package com.simplemobiletools.notes.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.notes.helpers.Config
|
||||
|
||||
open class SimpleActivity : BaseSimpleActivity() {
|
||||
lateinit var config: Config
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
config = Config.newInstance(applicationContext)
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import android.widget.RemoteViews
|
||||
import android.widget.SeekBar
|
||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.extensions.config
|
||||
import com.simplemobiletools.notes.extensions.getTextSize
|
||||
import com.simplemobiletools.notes.helpers.Config
|
||||
import com.simplemobiletools.notes.helpers.MyWidgetProvider
|
||||
import kotlinx.android.synthetic.main.widget_config.*
|
||||
|
||||
@ -47,7 +47,6 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun initVariables() {
|
||||
val config = Config.newInstance(this)
|
||||
mBgColor = config.widgetBgColor
|
||||
if (mBgColor == 1) {
|
||||
mBgColor = Color.BLACK
|
||||
@ -83,7 +82,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun storeWidgetBackground() {
|
||||
Config.newInstance(this).apply {
|
||||
config.apply {
|
||||
widgetBgColor = mBgColor
|
||||
widgetTextColor = mTextColor
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.extensions.config
|
||||
import com.simplemobiletools.notes.helpers.DBHelper
|
||||
import com.simplemobiletools.notes.helpers.Config
|
||||
import kotlinx.android.synthetic.main.dialog_radio_group.view.*
|
||||
|
||||
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> Unit) : RadioGroup.OnCheckedChangeListener {
|
||||
@ -16,7 +16,6 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> U
|
||||
var wasInit = false
|
||||
|
||||
init {
|
||||
val config = Config.newInstance(activity)
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null)
|
||||
val radioGroup = view.dialog_radio_group
|
||||
radioGroup.setOnCheckedChangeListener(this)
|
||||
@ -26,7 +25,7 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> U
|
||||
val radioButton = activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton
|
||||
radioButton.apply {
|
||||
text = it.title
|
||||
isChecked = it.id == config.currentNoteId
|
||||
isChecked = it.id == activity.config.currentNoteId
|
||||
id = it.id
|
||||
}
|
||||
radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
|
@ -5,11 +5,11 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.Gravity
|
||||
import com.simplemobiletools.notes.*
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.helpers.*
|
||||
|
||||
fun Context.getTextSize() =
|
||||
when (Config.newInstance(this).fontSize) {
|
||||
when (config.fontSize) {
|
||||
FONT_SIZE_SMALL -> resources.getDimension(R.dimen.smaller_text_size)
|
||||
FONT_SIZE_LARGE -> resources.getDimension(R.dimen.big_text_size)
|
||||
FONT_SIZE_EXTRA_LARGE -> resources.getDimension(R.dimen.extra_big_text_size)
|
||||
@ -17,7 +17,7 @@ fun Context.getTextSize() =
|
||||
}
|
||||
|
||||
fun Context.getTextGravity() =
|
||||
when (Config.newInstance(this).gravity) {
|
||||
when (config.gravity) {
|
||||
GRAVITY_CENTER -> Gravity.CENTER_HORIZONTAL
|
||||
GRAVITY_RIGHT -> Gravity.RIGHT
|
||||
else -> Gravity.LEFT
|
||||
@ -33,3 +33,5 @@ fun Context.updateWidget() {
|
||||
sendBroadcast(this)
|
||||
}
|
||||
}
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
||||
|
@ -10,10 +10,10 @@ import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import com.simplemobiletools.commons.extensions.value
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.extensions.config
|
||||
import com.simplemobiletools.notes.extensions.getTextGravity
|
||||
import com.simplemobiletools.notes.extensions.getTextSize
|
||||
import com.simplemobiletools.notes.extensions.updateWidget
|
||||
import com.simplemobiletools.notes.helpers.Config
|
||||
import com.simplemobiletools.notes.helpers.DBHelper
|
||||
import com.simplemobiletools.notes.helpers.NOTE_ID
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
@ -52,7 +52,7 @@ class NoteFragment : Fragment() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val config = Config.newInstance(context)
|
||||
val config = context.config
|
||||
view.notes_view.apply {
|
||||
setText(note.value)
|
||||
setColors(config.textColor, config.primaryColor, config.backgroundColor)
|
||||
|
@ -10,6 +10,7 @@ import android.widget.RemoteViews
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.R.layout.widget
|
||||
import com.simplemobiletools.notes.activities.MainActivity
|
||||
import com.simplemobiletools.notes.extensions.config
|
||||
import com.simplemobiletools.notes.extensions.getTextSize
|
||||
|
||||
class MyWidgetProvider : AppWidgetProvider() {
|
||||
@ -22,7 +23,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
initVariables(context)
|
||||
val config = Config.newInstance(context)
|
||||
val config = context.config
|
||||
val widgetBgColor = config.widgetBgColor
|
||||
val widgetTextColor = config.widgetTextColor
|
||||
|
||||
@ -44,7 +45,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
private fun getProperTextView(context: Context): Int {
|
||||
return when (Config.newInstance(context).gravity) {
|
||||
return when (context.config.gravity) {
|
||||
GRAVITY_CENTER -> R.id.notes_view_center
|
||||
GRAVITY_RIGHT -> R.id.notes_view_right
|
||||
else -> R.id.notes_view_left
|
||||
@ -64,7 +65,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews, context: Context) {
|
||||
val note = mDb.getNote(Config.newInstance(context).widgetNoteId)
|
||||
val note = mDb.getNote(context.config.widgetNoteId)
|
||||
for (id in textIds)
|
||||
remoteViews.setTextViewText(id, note?.value ?: "")
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews)
|
||||
|
Loading…
x
Reference in New Issue
Block a user