mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[Widgets] Fix pending intents mutability. Hide timetable sync button.
This commit is contained in:
parent
beff1b6460
commit
8177d4aa2d
@ -73,6 +73,12 @@ fun pendingIntentFlag(): Int {
|
||||
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?.takePositive() = if (this == -1 || this == 0) null else this
|
||||
|
||||
|
@ -23,6 +23,7 @@ import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.ext.Bundle
|
||||
import pl.szczodrzynski.edziennik.ext.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.ext.pendingIntentFlag
|
||||
import pl.szczodrzynski.edziennik.ext.pendingIntentMutable
|
||||
import pl.szczodrzynski.edziennik.ext.putExtras
|
||||
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
|
||||
import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget
|
||||
@ -50,7 +51,7 @@ class WidgetNotificationsProvider : AppWidgetProvider() {
|
||||
val syncIntent = SzkolnyReceiver.getIntent(context, Bundle(
|
||||
"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.setImageViewBitmap(
|
||||
@ -71,13 +72,13 @@ class WidgetNotificationsProvider : AppWidgetProvider() {
|
||||
|
||||
val itemIntent = Intent(context, MainActivity::class.java)
|
||||
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)
|
||||
|
||||
val headerIntent = Intent(context, MainActivity::class.java)
|
||||
headerIntent.action = Intent.ACTION_MAIN
|
||||
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)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
|
@ -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.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.ext.pendingIntentFlag
|
||||
import pl.szczodrzynski.edziennik.ext.pendingIntentMutable
|
||||
import pl.szczodrzynski.edziennik.ext.putExtras
|
||||
import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget
|
||||
import pl.szczodrzynski.edziennik.ui.widgets.LessonDialogActivity
|
||||
@ -119,7 +120,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
|
||||
0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT or pendingIntentFlag())
|
||||
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(
|
||||
R.id.widgetTimetableRefresh,
|
||||
@ -129,14 +130,6 @@ class WidgetTimetableProvider : AppWidgetProvider() {
|
||||
}.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)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
@ -402,7 +395,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
||||
timetables!!.put(appWidgetId, models)
|
||||
@ -416,7 +409,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
|
||||
// create an intent used to display the lesson details dialog
|
||||
val itemIntent = Intent(app, LessonDialogActivity::class.java)
|
||||
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)
|
||||
|
||||
if (!unified)
|
||||
|
Loading…
Reference in New Issue
Block a user