mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-04 08:07:32 +01:00
convert Constants to kotlin
This commit is contained in:
parent
5821d5a811
commit
29d679ece0
@ -1,21 +0,0 @@
|
||||
package com.simplemobiletools.notes;
|
||||
|
||||
public class Constants {
|
||||
public static final String TEXT = "text";
|
||||
|
||||
// shared preferences
|
||||
public static final String PREFS_KEY = "Notes";
|
||||
public static final String IS_FIRST_RUN = "is_first_run";
|
||||
public static final String IS_DARK_THEME = "is_dark_theme";
|
||||
public static final String CURRENT_NOTE_ID = "current_note_id";
|
||||
public static final String WIDGET_NOTE_ID = "widget_note_id";
|
||||
public static final String FONT_SIZE = "font_size";
|
||||
public static final String WIDGET_BG_COLOR = "widget_bg_color";
|
||||
public static final String WIDGET_TEXT_COLOR = "widget_text_color";
|
||||
|
||||
// font sizes
|
||||
public static final int FONT_SIZE_SMALL = 0;
|
||||
public static final int FONT_SIZE_MEDIUM = 1;
|
||||
public static final int FONT_SIZE_LARGE = 2;
|
||||
public static final int FONT_SIZE_EXTRA_LARGE = 3;
|
||||
}
|
@ -11,26 +11,26 @@ class Config(context: Context) {
|
||||
}
|
||||
|
||||
init {
|
||||
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
|
||||
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
var isFirstRun: Boolean
|
||||
get() = mPrefs.getBoolean(Constants.IS_FIRST_RUN, true)
|
||||
set(firstRun) = mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply()
|
||||
get() = mPrefs.getBoolean(IS_FIRST_RUN, true)
|
||||
set(firstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, firstRun).apply()
|
||||
|
||||
var isDarkTheme: Boolean
|
||||
get() = mPrefs.getBoolean(Constants.IS_DARK_THEME, false)
|
||||
set(isDarkTheme) = mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply()
|
||||
get() = mPrefs.getBoolean(IS_DARK_THEME, false)
|
||||
set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
|
||||
|
||||
var fontSize: Int
|
||||
get() = mPrefs.getInt(Constants.FONT_SIZE, Constants.FONT_SIZE_MEDIUM)
|
||||
set(size) = mPrefs.edit().putInt(Constants.FONT_SIZE, size).apply()
|
||||
get() = mPrefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
|
||||
set(size) = mPrefs.edit().putInt(FONT_SIZE, size).apply()
|
||||
|
||||
var currentNoteId: Int
|
||||
get() = mPrefs.getInt(Constants.CURRENT_NOTE_ID, 1)
|
||||
set(id) = mPrefs.edit().putInt(Constants.CURRENT_NOTE_ID, id).apply()
|
||||
get() = mPrefs.getInt(CURRENT_NOTE_ID, 1)
|
||||
set(id) = mPrefs.edit().putInt(CURRENT_NOTE_ID, id).apply()
|
||||
|
||||
var widgetNoteId: Int
|
||||
get() = mPrefs.getInt(Constants.WIDGET_NOTE_ID, 1)
|
||||
set(id) = mPrefs.edit().putInt(Constants.WIDGET_NOTE_ID, id).apply()
|
||||
get() = mPrefs.getInt(WIDGET_NOTE_ID, 1)
|
||||
set(id) = mPrefs.edit().putInt(WIDGET_NOTE_ID, id).apply()
|
||||
}
|
||||
|
19
app/src/main/kotlin/com/simplemobiletools/notes/Constants.kt
Normal file
19
app/src/main/kotlin/com/simplemobiletools/notes/Constants.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package com.simplemobiletools.notes
|
||||
|
||||
val TEXT = "text"
|
||||
|
||||
// shared preferences
|
||||
val PREFS_KEY = "Notes"
|
||||
val IS_FIRST_RUN = "is_first_run"
|
||||
val IS_DARK_THEME = "is_dark_theme"
|
||||
val CURRENT_NOTE_ID = "current_note_id"
|
||||
val WIDGET_NOTE_ID = "widget_note_id"
|
||||
val FONT_SIZE = "font_size"
|
||||
val WIDGET_BG_COLOR = "widget_bg_color"
|
||||
val WIDGET_TEXT_COLOR = "widget_text_color"
|
||||
|
||||
// font sizes
|
||||
val FONT_SIZE_SMALL = 0
|
||||
val FONT_SIZE_MEDIUM = 1
|
||||
val FONT_SIZE_LARGE = 2
|
||||
val FONT_SIZE_EXTRA_LARGE = 3
|
@ -23,8 +23,8 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
initVariables(context)
|
||||
val defaultColor = context.resources.getColor(R.color.dark_grey)
|
||||
val newBgColor = mPrefs.getInt(Constants.WIDGET_BG_COLOR, defaultColor)
|
||||
val newTextColor = mPrefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE)
|
||||
val newBgColor = mPrefs.getInt(WIDGET_BG_COLOR, defaultColor)
|
||||
val newTextColor = mPrefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE)
|
||||
mRemoteViews.apply {
|
||||
setInt(R.id.notes_view, "setBackgroundColor", newBgColor)
|
||||
setInt(R.id.notes_view, "setTextColor", newTextColor)
|
||||
@ -38,7 +38,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
private fun initVariables(context: Context) {
|
||||
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
|
||||
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
mDb = DBHelper.newInstance(context)
|
||||
mRemoteViews = RemoteViews(context.packageName, widget)
|
||||
setupAppOpenIntent(R.id.notes_holder, context)
|
||||
@ -51,7 +51,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews) {
|
||||
val widgetNoteId = mPrefs.getInt(Constants.WIDGET_NOTE_ID, 1)
|
||||
val widgetNoteId = mPrefs.getInt(WIDGET_NOTE_ID, 1)
|
||||
val note = mDb.getNote(widgetNoteId)
|
||||
remoteViews.setTextViewText(R.id.notes_view, if (note != null) note.value else "")
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews)
|
||||
|
@ -14,13 +14,12 @@ object Utils {
|
||||
fun getTextSize(context: Context): Float {
|
||||
val fontSize = Config.newInstance(context).fontSize
|
||||
val res = context.resources
|
||||
var textSize = res.getDimension(R.dimen.medium_text_size)
|
||||
when (fontSize) {
|
||||
Constants.FONT_SIZE_SMALL -> textSize = res.getDimension(R.dimen.small_text_size)
|
||||
Constants.FONT_SIZE_LARGE -> textSize = res.getDimension(R.dimen.large_text_size)
|
||||
Constants.FONT_SIZE_EXTRA_LARGE -> textSize = res.getDimension(R.dimen.extra_large_text_size)
|
||||
return when (fontSize) {
|
||||
FONT_SIZE_SMALL -> res.getDimension(R.dimen.small_text_size)
|
||||
FONT_SIZE_LARGE -> res.getDimension(R.dimen.large_text_size)
|
||||
FONT_SIZE_EXTRA_LARGE -> res.getDimension(R.dimen.extra_large_text_size)
|
||||
else -> res.getDimension(R.dimen.medium_text_size)
|
||||
}
|
||||
return textSize
|
||||
}
|
||||
|
||||
fun updateWidget(context: Context) {
|
||||
|
@ -10,10 +10,7 @@ import android.support.v7.app.AppCompatActivity
|
||||
import android.util.TypedValue
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.SeekBar
|
||||
import com.simplemobiletools.notes.Constants
|
||||
import com.simplemobiletools.notes.MyWidgetProvider
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.Utils
|
||||
import com.simplemobiletools.notes.*
|
||||
import kotlinx.android.synthetic.main.widget_config.*
|
||||
import yuku.ambilwarna.AmbilWarnaDialog
|
||||
|
||||
@ -48,8 +45,8 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun initVariables() {
|
||||
val prefs = getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
|
||||
mBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, 1)
|
||||
val prefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
mBgColor = prefs.getInt(WIDGET_BG_COLOR, 1)
|
||||
if (mBgColor == 1) {
|
||||
mBgColor = Color.BLACK
|
||||
mBgAlpha = .2f
|
||||
@ -64,7 +61,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
||||
}
|
||||
updateBackgroundColor()
|
||||
|
||||
mTextColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, resources.getColor(R.color.colorPrimary))
|
||||
mTextColor = prefs.getInt(WIDGET_TEXT_COLOR, resources.getColor(R.color.colorPrimary))
|
||||
updateTextColor()
|
||||
}
|
||||
|
||||
@ -84,8 +81,8 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun storeWidgetBackground() {
|
||||
getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE).apply {
|
||||
edit().putInt(Constants.WIDGET_BG_COLOR, mBgColor).putInt(Constants.WIDGET_TEXT_COLOR, mTextColor).apply()
|
||||
getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE).apply {
|
||||
edit().putInt(WIDGET_BG_COLOR, mBgColor).putInt(WIDGET_TEXT_COLOR, mTextColor).apply()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,8 @@ import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import com.simplemobiletools.notes.Constants
|
||||
import com.simplemobiletools.notes.PREFS_KEY
|
||||
import com.simplemobiletools.notes.TEXT
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
import java.util.*
|
||||
|
||||
@ -39,8 +40,8 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
}
|
||||
|
||||
private fun insertFirstNote(db: SQLiteDatabase) {
|
||||
val prefs = mContext.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
|
||||
val text = prefs.getString(Constants.TEXT, "")
|
||||
val prefs = mContext.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
val text = prefs.getString(TEXT, "")
|
||||
val note = Note(1, NOTE, text)
|
||||
insertNote(note, db)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user