mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 15:02:05 +02:00
show proper file note text on widgets
This commit is contained in:
parent
2ad38bf411
commit
df353031ae
@ -66,6 +66,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
|
||||
config.fontSize = it
|
||||
settings_font_size.text = getFontSizeText()
|
||||
updateWidget()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import android.content.Intent
|
||||
import android.view.Gravity
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.helpers.*
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
import java.io.File
|
||||
|
||||
fun Context.getTextSize() =
|
||||
when (config.fontSize) {
|
||||
@ -35,3 +37,11 @@ fun Context.updateWidget() {
|
||||
}
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
||||
|
||||
fun Context.getNoteStoredValue(note: Note): String {
|
||||
return if (note.path.isNotEmpty()) {
|
||||
File(note.path).readText()
|
||||
} else {
|
||||
note.value
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,7 @@ import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.activities.MainActivity
|
||||
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.extensions.*
|
||||
import com.simplemobiletools.notes.helpers.DBHelper
|
||||
import com.simplemobiletools.notes.helpers.NOTE_ID
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
@ -68,8 +65,11 @@ class NoteFragment : Fragment() {
|
||||
if (note.path.isNotEmpty() && !File(note.path).exists())
|
||||
return
|
||||
|
||||
if (context == null || activity == null)
|
||||
return
|
||||
|
||||
val newText = getCurrentNoteViewText()
|
||||
val oldText = getNoteStoredValue()
|
||||
val oldText = context.getNoteStoredValue(note)
|
||||
if (newText != oldText) {
|
||||
note.value = newText
|
||||
saveNoteValue(note)
|
||||
@ -94,20 +94,12 @@ class NoteFragment : Fragment() {
|
||||
|
||||
fun getCurrentNoteViewText() = view.notes_view.text.toString()
|
||||
|
||||
private fun getNoteStoredValue(): String {
|
||||
return if (note.path.isNotEmpty()) {
|
||||
File(note.path).readText()
|
||||
} else {
|
||||
note.value
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val config = context.config
|
||||
view.notes_view.apply {
|
||||
setText(getNoteStoredValue())
|
||||
setText(context.getNoteStoredValue(note))
|
||||
setColors(config.textColor, config.primaryColor, config.backgroundColor)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getTextSize())
|
||||
gravity = context.getTextGravity()
|
||||
|
@ -11,6 +11,7 @@ import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.R.layout.widget
|
||||
import com.simplemobiletools.notes.activities.SplashActivity
|
||||
import com.simplemobiletools.notes.extensions.config
|
||||
import com.simplemobiletools.notes.extensions.getNoteStoredValue
|
||||
import com.simplemobiletools.notes.extensions.getTextSize
|
||||
|
||||
class MyWidgetProvider : AppWidgetProvider() {
|
||||
@ -66,8 +67,10 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
|
||||
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews, context: Context) {
|
||||
val note = mDb.getNote(context.config.widgetNoteId)
|
||||
for (id in textIds)
|
||||
remoteViews.setTextViewText(id, note?.value ?: "")
|
||||
for (id in textIds) {
|
||||
if (note != null)
|
||||
remoteViews.setTextViewText(id, context.getNoteStoredValue(note))
|
||||
}
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews)
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@
|
||||
android:layout_toStartOf="@+id/settings_gravity"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:text="@string/note_font_size"/>
|
||||
android:text="@string/gravity"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_gravity"
|
||||
|
Loading…
x
Reference in New Issue
Block a user