Skip to content

Commit

Permalink
Merge pull request #58 from inucat/bugfix/widget-npe
Browse files Browse the repository at this point in the history
Fix exception on widget
  • Loading branch information
private-yusuke authored Oct 21, 2024
2 parents b498cf3 + f0cdd16 commit d4b4f22
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface ScheduleDataStore {
),
)

suspend fun getSchedule(date: Date): Timetable
suspend fun getSchedule(date: Date): Timetable?
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SharedPreferencesScheduleDataStore @Inject constructor(
}
}

override suspend fun getSchedule(date: Date): Timetable = withContext(Dispatchers.IO) {
override suspend fun getSchedule(date: Date): Timetable? = withContext(Dispatchers.IO) {
val d = simpleDateFormat.format(date)
if (!pref.contains(d)) update(arrayOf(date))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class V3LargeWidgetProvider @Inject constructor() : AppWidgetProvider() {
val (current) = WidgetUpdater.getShouldShowCurrentDate()

try {
val schedule = scheduleDataStore.getSchedule(current.time)
val schedule = scheduleDataStore.getSchedule(current.time) ?: return@runBlocking

appWidgetIds.forEach { appWidgetId ->
val views = RemoteViews(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class V3MediumWidgetProvider @Inject constructor() : AppWidgetProvider() {
Log.d("V3MediumWidgetProvider", "OnUpdate received")
val (current) = WidgetUpdater.getShouldShowCurrentDate()
try {
val schedule = scheduleDataStore.getSchedule(current.time)
val schedule = scheduleDataStore.getSchedule(current.time) ?: return@runBlocking

appWidgetIds.forEach { appWidgetId ->
val views = RemoteViews(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class V3SmallWidgetProvider @Inject constructor() : AppWidgetProvider() {
val (current, period) = WidgetUpdater.getShouldShowCurrentDate()

try {
val schedule = scheduleDataStore.getSchedule(current.time)
val schedule = scheduleDataStore.getSchedule(current.time) ?: return@runBlocking

appWidgetIds.forEach { appWidgetId ->
val views = RemoteViews(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ScheduleNotifier : BroadcastReceiver() {
if (get(Calendar.HOUR_OF_DAY) > 18) add(Calendar.DATE, 1)
}

val schedule = scheduleDataStore.getSchedule(targetDate.time)
val schedule = scheduleDataStore.getSchedule(targetDate.time) ?: return@runBlocking

val substitute = schedule.events.find { it.changeTo != null }?.changeTo
if (substitute != null) {
Expand Down

0 comments on commit d4b4f22

Please sign in to comment.