From bb9ea7eda130442685e13df72df42d4d440a7f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Mon, 2 Sep 2019 12:38:09 +0200 Subject: [PATCH] Fix spaming NoCurentStudentException (#476) --- .../modules/luckynumberwidget/LuckyNumberWidgetProvider.kt | 5 ++++- .../ui/modules/timetablewidget/TimetableWidgetFactory.kt | 2 -- .../ui/modules/timetablewidget/TimetableWidgetProvider.kt | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt index 76bebe92e..895fe5714 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt @@ -23,6 +23,7 @@ import dagger.android.AndroidInjection import io.github.wulkanowy.R import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.LuckyNumber +import io.github.wulkanowy.data.exceptions.NoCurrentStudentException import io.github.wulkanowy.data.repositories.luckynumber.LuckyNumberRepository import io.github.wulkanowy.data.repositories.semester.SemesterRepository import io.github.wulkanowy.data.repositories.student.StudentRepository @@ -114,7 +115,9 @@ class LuckyNumberWidgetProvider : BroadcastReceiver() { .subscribeOn(schedulers.backgroundThread) .blockingGet() } catch (e: Exception) { - Timber.e(e, "An error has occurred in lucky number provider") + if (e.cause !is NoCurrentStudentException) { + Timber.e(e, "An error has occurred in lucky number provider") + } null } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt index 4b47a08b4..a0a519e21 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt @@ -60,8 +60,6 @@ class TimetableWidgetFactory( .filter { true } .flatMap { studentRepository.getSavedStudents().toMaybe() } .flatMap { - if (studentId == 0L) throw IllegalArgumentException("Student id is 0") - it.singleOrNull { student -> student.id == studentId } .let { student -> if (student != null) Maybe.just(student) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt index 2fe59ea89..dadbe0503 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt @@ -1,5 +1,6 @@ package io.github.wulkanowy.ui.modules.timetablewidget +import android.annotation.SuppressLint import android.app.PendingIntent import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.appwidget.AppWidgetManager @@ -17,6 +18,7 @@ import dagger.android.AndroidInjection import io.github.wulkanowy.R import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.Student +import io.github.wulkanowy.data.exceptions.NoCurrentStudentException import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.services.widgets.TimetableWidgetService import io.github.wulkanowy.ui.modules.main.MainActivity @@ -110,6 +112,7 @@ class TimetableWidgetProvider : BroadcastReceiver() { } } + @SuppressLint("DefaultLocale") private fun updateWidget(context: Context, appWidgetId: Int, date: LocalDate, student: Student?) { RemoteViews(context.packageName, R.layout.widget_timetable).apply { setEmptyView(R.id.timetableWidgetList, R.id.timetableWidgetEmpty) @@ -173,7 +176,9 @@ class TimetableWidgetProvider : BroadcastReceiver() { .subscribeOn(schedulers.backgroundThread) .blockingGet() } catch (e: Exception) { - Timber.e(e, "An error has occurred in timetable widget provider") + if (e.cause !is NoCurrentStudentException) { + Timber.e(e, "An error has occurred in timetable widget provider") + } null } }