[Widgets] Fix pending intents mutability. Hide timetable sync button.

This commit is contained in:
Kuba Szczodrzyński 2023-03-24 11:13:00 +01:00
parent beff1b6460
commit 8177d4aa2d
No known key found for this signature in database
GPG Key ID: 43037AC62A600562
3 changed files with 14 additions and 14 deletions

View File

@ -73,6 +73,12 @@ fun pendingIntentFlag(): Int {
return 0 return 0
} }
fun pendingIntentMutable(): Int {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
return PendingIntent.FLAG_MUTABLE
return 0
}
fun Int?.takeValue() = if (this == -1) null else this fun Int?.takeValue() = if (this == -1) null else this
fun Int?.takePositive() = if (this == -1 || this == 0) null else this fun Int?.takePositive() = if (this == -1 || this == 0) null else this

View File

@ -23,6 +23,7 @@ import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.ext.Bundle import pl.szczodrzynski.edziennik.ext.Bundle
import pl.szczodrzynski.edziennik.ext.getJsonObject import pl.szczodrzynski.edziennik.ext.getJsonObject
import pl.szczodrzynski.edziennik.ext.pendingIntentFlag import pl.szczodrzynski.edziennik.ext.pendingIntentFlag
import pl.szczodrzynski.edziennik.ext.pendingIntentMutable
import pl.szczodrzynski.edziennik.ext.putExtras import pl.szczodrzynski.edziennik.ext.putExtras
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget
@ -50,7 +51,7 @@ class WidgetNotificationsProvider : AppWidgetProvider() {
val syncIntent = SzkolnyReceiver.getIntent(context, Bundle( val syncIntent = SzkolnyReceiver.getIntent(context, Bundle(
"task" to "SyncRequest" "task" to "SyncRequest"
)) ))
val syncPendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, pendingIntentFlag()) val syncPendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, pendingIntentMutable())
views.setOnClickPendingIntent(R.id.widgetNotificationsSync, syncPendingIntent) views.setOnClickPendingIntent(R.id.widgetNotificationsSync, syncPendingIntent)
views.setImageViewBitmap( views.setImageViewBitmap(
@ -71,13 +72,13 @@ class WidgetNotificationsProvider : AppWidgetProvider() {
val itemIntent = Intent(context, MainActivity::class.java) val itemIntent = Intent(context, MainActivity::class.java)
itemIntent.action = Intent.ACTION_MAIN itemIntent.action = Intent.ACTION_MAIN
val itemPendingIntent = PendingIntent.getActivity(context, 0, itemIntent, pendingIntentFlag()) val itemPendingIntent = PendingIntent.getActivity(context, appWidgetId, itemIntent, pendingIntentMutable())
views.setPendingIntentTemplate(R.id.widgetNotificationsListView, itemPendingIntent) views.setPendingIntentTemplate(R.id.widgetNotificationsListView, itemPendingIntent)
val headerIntent = Intent(context, MainActivity::class.java) val headerIntent = Intent(context, MainActivity::class.java)
headerIntent.action = Intent.ACTION_MAIN headerIntent.action = Intent.ACTION_MAIN
headerIntent.putExtras("fragmentId" to NavTarget.NOTIFICATIONS) headerIntent.putExtras("fragmentId" to NavTarget.NOTIFICATIONS)
val headerPendingIntent = PendingIntent.getActivity(context, 0, headerIntent, pendingIntentFlag()) val headerPendingIntent = PendingIntent.getActivity(context, appWidgetId, headerIntent, pendingIntentMutable())
views.setOnClickPendingIntent(R.id.widgetNotificationsHeader, headerPendingIntent) views.setOnClickPendingIntent(R.id.widgetNotificationsHeader, headerPendingIntent)
appWidgetManager.updateAppWidget(appWidgetId, views) appWidgetManager.updateAppWidget(appWidgetId, views)

View File

@ -34,6 +34,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.Lesson.Companion.TYPE_NO_LESSON
import pl.szczodrzynski.edziennik.ext.filterOutArchived import pl.szczodrzynski.edziennik.ext.filterOutArchived
import pl.szczodrzynski.edziennik.ext.getJsonObject import pl.szczodrzynski.edziennik.ext.getJsonObject
import pl.szczodrzynski.edziennik.ext.pendingIntentFlag import pl.szczodrzynski.edziennik.ext.pendingIntentFlag
import pl.szczodrzynski.edziennik.ext.pendingIntentMutable
import pl.szczodrzynski.edziennik.ext.putExtras import pl.szczodrzynski.edziennik.ext.putExtras
import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget
import pl.szczodrzynski.edziennik.ui.widgets.LessonDialogActivity import pl.szczodrzynski.edziennik.ui.widgets.LessonDialogActivity
@ -119,7 +120,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT or pendingIntentFlag()) 0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT or pendingIntentFlag())
views.setOnClickPendingIntent(R.id.widgetTimetableRefresh, refreshPendingIntent) views.setOnClickPendingIntent(R.id.widgetTimetableRefresh, refreshPendingIntent)
views.setOnClickPendingIntent(R.id.widgetTimetableSync, getPendingSelfIntent(context, ACTION_SYNC_DATA)) views.setViewVisibility(R.id.widgetTimetableSync, View.GONE)
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.widgetTimetableRefresh, R.id.widgetTimetableRefresh,
@ -129,14 +130,6 @@ class WidgetTimetableProvider : AppWidgetProvider() {
}.toBitmap() }.toBitmap()
) )
views.setImageViewBitmap(
R.id.widgetTimetableSync,
IconicsDrawable(context, CommunityMaterial.Icon.cmd_download_outline).apply {
colorInt = Color.WHITE
sizeDp = if (config.bigStyle) 28 else 20
}.toBitmap()
)
prepareAppWidget(app, appWidgetId, views, config, bellSyncDiffMillis) prepareAppWidget(app, appWidgetId, views, config, bellSyncDiffMillis)
appWidgetManager.updateAppWidget(appWidgetId, views) appWidgetManager.updateAppWidget(appWidgetId, views)
@ -402,7 +395,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
} }
} }
headerIntent.putExtras("fragmentId" to NavTarget.TIMETABLE) headerIntent.putExtras("fragmentId" to NavTarget.TIMETABLE)
val headerPendingIntent = PendingIntent.getActivity(app, appWidgetId, headerIntent, pendingIntentFlag()) val headerPendingIntent = PendingIntent.getActivity(app, appWidgetId, headerIntent, pendingIntentMutable())
views.setOnClickPendingIntent(R.id.widgetTimetableHeader, headerPendingIntent) views.setOnClickPendingIntent(R.id.widgetTimetableHeader, headerPendingIntent)
timetables!!.put(appWidgetId, models) timetables!!.put(appWidgetId, models)
@ -416,7 +409,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
// create an intent used to display the lesson details dialog // create an intent used to display the lesson details dialog
val itemIntent = Intent(app, LessonDialogActivity::class.java) val itemIntent = Intent(app, LessonDialogActivity::class.java)
itemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK/* or Intent.FLAG_ACTIVITY_CLEAR_TASK*/) itemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK/* or Intent.FLAG_ACTIVITY_CLEAR_TASK*/)
val itemPendingIntent = PendingIntent.getActivity(app, appWidgetId, itemIntent, PendingIntent.FLAG_MUTABLE) val itemPendingIntent = PendingIntent.getActivity(app, appWidgetId, itemIntent, pendingIntentMutable())
views.setPendingIntentTemplate(R.id.widgetTimetableListView, itemPendingIntent) views.setPendingIntentTemplate(R.id.widgetTimetableListView, itemPendingIntent)
if (!unified) if (!unified)