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