mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-16 16:27:23 +02:00
47 lines
1.5 KiB
Kotlin
47 lines
1.5 KiB
Kotlin
package com.simplemobiletools.notes.extensions
|
|
|
|
import android.appwidget.AppWidgetManager
|
|
import android.content.ComponentName
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import com.simplemobiletools.notes.R
|
|
import com.simplemobiletools.notes.helpers.*
|
|
import com.simplemobiletools.notes.models.Note
|
|
import java.io.File
|
|
import java.io.FileNotFoundException
|
|
|
|
fun Context.getTextSize() =
|
|
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)
|
|
else -> resources.getDimension(R.dimen.bigger_text_size)
|
|
}
|
|
|
|
fun Context.updateWidget() {
|
|
val widgetManager = AppWidgetManager.getInstance(this)
|
|
val ids = widgetManager.getAppWidgetIds(ComponentName(this, MyWidgetProvider::class.java))
|
|
|
|
Intent(this, MyWidgetProvider::class.java).apply {
|
|
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
|
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
|
|
sendBroadcast(this)
|
|
}
|
|
}
|
|
|
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
|
|
|
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
|
|
|
|
fun Context.getNoteStoredValue(note: Note): String? {
|
|
return if (note.path.isNotEmpty()) {
|
|
return try {
|
|
File(note.path).readText()
|
|
} catch (e: FileNotFoundException) {
|
|
null
|
|
}
|
|
} else {
|
|
note.value
|
|
}
|
|
}
|