mirror of
https://github.com/PhilKes/NotallyX.git
synced 2025-06-28 12:19:55 +00:00
Merge pull request #579 from PhilKes/fix/lock-widget
Fix showing widget when actually locked
This commit is contained in:
commit
628bd9d564
2 changed files with 9 additions and 6 deletions
|
@ -70,7 +70,7 @@ class NotallyXApplication : Application(), Application.ActivityLifecycleCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (oldTheme != null) {
|
if (oldTheme != null) {
|
||||||
WidgetProvider.updateWidgets(this)
|
WidgetProvider.updateWidgets(this, locked = locked.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.philkes.notallyx.NotallyXApplication
|
||||||
import com.philkes.notallyx.R
|
import com.philkes.notallyx.R
|
||||||
import com.philkes.notallyx.data.NotallyDatabase
|
import com.philkes.notallyx.data.NotallyDatabase
|
||||||
import com.philkes.notallyx.data.dao.BaseNoteDao
|
import com.philkes.notallyx.data.dao.BaseNoteDao
|
||||||
|
@ -42,9 +43,10 @@ class WidgetProvider : AppWidgetProvider() {
|
||||||
super.onReceive(context, intent)
|
super.onReceive(context, intent)
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
ACTION_NOTES_MODIFIED -> {
|
ACTION_NOTES_MODIFIED -> {
|
||||||
|
val app = context.applicationContext as NotallyXApplication
|
||||||
val noteIds = intent.getLongArrayExtra(EXTRA_MODIFIED_NOTES)
|
val noteIds = intent.getLongArrayExtra(EXTRA_MODIFIED_NOTES)
|
||||||
if (noteIds != null) {
|
if (noteIds != null) {
|
||||||
updateWidgets(context, noteIds)
|
updateWidgets(context, noteIds, locked = app.locked.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ACTION_OPEN_NOTE -> openActivity(context, intent, EditNoteActivity::class.java)
|
ACTION_OPEN_NOTE -> openActivity(context, intent, EditNoteActivity::class.java)
|
||||||
|
@ -85,7 +87,8 @@ class WidgetProvider : AppWidgetProvider() {
|
||||||
baseNoteDao.updateChecked(noteId, childrenPositions + position, checked!!)
|
baseNoteDao.updateChecked(noteId, childrenPositions + position, checked!!)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
updateWidgets(context, longArrayOf(noteId))
|
val app = context.applicationContext as NotallyXApplication
|
||||||
|
updateWidgets(context, longArrayOf(noteId), locked = app.locked.value)
|
||||||
pendingResult.finish()
|
pendingResult.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,19 +138,19 @@ class WidgetProvider : AppWidgetProvider() {
|
||||||
appWidgetManager: AppWidgetManager,
|
appWidgetManager: AppWidgetManager,
|
||||||
appWidgetIds: IntArray,
|
appWidgetIds: IntArray,
|
||||||
) {
|
) {
|
||||||
val app = context.applicationContext as Application
|
val app = context.applicationContext as NotallyXApplication
|
||||||
val preferences = NotallyXPreferences.getInstance(app)
|
val preferences = NotallyXPreferences.getInstance(app)
|
||||||
|
|
||||||
appWidgetIds.forEach { id ->
|
appWidgetIds.forEach { id ->
|
||||||
val noteId = preferences.getWidgetData(id)
|
val noteId = preferences.getWidgetData(id)
|
||||||
val noteType = preferences.getWidgetNoteType(id) ?: return
|
val noteType = preferences.getWidgetNoteType(id) ?: return
|
||||||
updateWidget(app, appWidgetManager, id, noteId, noteType)
|
updateWidget(app, appWidgetManager, id, noteId, noteType, locked = app.locked.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun updateWidgets(context: Context, noteIds: LongArray? = null, locked: Boolean = false) {
|
fun updateWidgets(context: Context, noteIds: LongArray? = null, locked: Boolean) {
|
||||||
val app = context.applicationContext as Application
|
val app = context.applicationContext as Application
|
||||||
val preferences = NotallyXPreferences.getInstance(app)
|
val preferences = NotallyXPreferences.getInstance(app)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue