Skip to content

Commit

Permalink
Added error notifications
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora <[email protected]>
  • Loading branch information
ArnyminerZ committed Apr 1, 2024
1 parent a77733b commit 16cf9cc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/src/main/java/at/bitfire/icsdroid/ProcessEventsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import at.bitfire.icsdroid.ui.views.EditCalendarActivity
import java.io.InputStream
import java.io.InputStreamReader
import java.time.Duration
import at.bitfire.icsdroid.ui.views.CalendarListActivity
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.PropertyList
import net.fortuna.ical4j.model.component.VAlarm
Expand Down Expand Up @@ -60,6 +61,7 @@ class ProcessEventsTask(
} catch (e: Exception) {
Log.e(Constants.TAG, "Couldn't sync calendar", e)
subscriptionsDao.updateStatusError(subscription.id, e.localizedMessage ?: e.toString())
notifyError(e)
}
Log.i(Constants.TAG, "iCalendar file completely processed")
}
Expand Down Expand Up @@ -262,4 +264,25 @@ class ProcessEventsTask(
Log.i(Constants.TAG, "$deleted events deleted")
}

private fun notifyError(exception: Exception) {
val notificationManager = NotificationUtils.createChannels(context)
val notification = NotificationCompat.Builder(context, NotificationUtils.CHANNEL_SYNC)
.setSmallIcon(R.drawable.ic_sync_problem_white)
.setCategory(NotificationCompat.CATEGORY_ERROR)
.setGroup(context.getString(R.string.app_name))
.setContentTitle(context.getString(R.string.sync_error_title))
.setContentText(exception.localizedMessage ?: exception.message)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setOnlyAlertOnce(true)
.setContentIntent(
PendingIntent.getActivity(
context,
0,
Intent(context, CalendarListActivity::class.java),
PendingIntent.FLAG_IMMUTABLE
)
)
notificationManager.notify(subscription.id.toInt(), notification.build())
}
}

0 comments on commit 16cf9cc

Please sign in to comment.