Skip to content

Commit 2f74d97

Browse files
author
alllexey
committed
Fixes, little changes, error logging
1 parent 3a2ab1f commit 2f74d97

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

app/src/main/java/me/alllexey123/itmowidgets/ui/widgets/SingleLessonWidget.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ open class SingleLessonWidget : AppWidgetProvider() {
4545
views.setTextViewText(R.id.location_building, widgetData.building)
4646
views.setTextViewText(R.id.time, widgetData.times)
4747
views.setTextViewText(R.id.more_lessons_text, widgetData.moreLessonsText)
48-
views.setViewVisibility(R.id.teacher_layout, if (widgetData.teacher == null) View.GONE else View.VISIBLE)
48+
views.setViewVisibility(R.id.teacher_layout, if (widgetData.teacher.isNullOrEmpty()) View.GONE else View.VISIBLE)
4949
views.setViewVisibility(R.id.location_layout, if (widgetData.room == null && widgetData.building == null) View.GONE else View.VISIBLE)
50-
views.setViewVisibility(R.id.time_layout, if (widgetData.times == null) View.GONE else View.VISIBLE)
51-
views.setViewVisibility(R.id.more_lessons_layout, if (widgetData.moreLessonsText == null) View.GONE else View.VISIBLE)
50+
views.setViewVisibility(R.id.time_layout, if (widgetData.times.isNullOrEmpty()) View.GONE else View.VISIBLE)
51+
views.setViewVisibility(R.id.more_lessons_layout, if (widgetData.moreLessonsText.isNullOrEmpty()) View.GONE else View.VISIBLE)
5252

5353
val colorId = ScheduleUtils.getWorkTypeColor(widgetData.workTypeId)
5454
views.setInt(

app/src/main/java/me/alllexey123/itmowidgets/ui/widgets/data/LessonWidgetDataManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LessonWidgetDataManager(
3030
listDataResult = getLessonListData(lessons)
3131
nextUpdateAt = getNextUpdateAt(lessons)
3232
} catch (e: Exception) {
33-
e.printStackTrace()
33+
storage.setErrorLog("[${javaClass.name}]: ${e.stackTraceToString()}}")
3434
singleDataResult = SingleLessonWidgetData.Error(getSingleLessonWidgetLayout())
3535

3636
listDataResult = LessonListWidgetData(

app/src/main/java/me/alllexey123/itmowidgets/util/ScheduleUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object ScheduleUtils {
2222
val currTime = DateTimeFormatter.ofPattern("HH:mm").format(timeContext)
2323

2424
for (lesson in lessons) {
25-
if (lesson.timeEnd >= currTime && lesson.timeStart <= currTime) {
25+
if (lesson.timeEnd > currTime && lesson.timeStart <= currTime) {
2626
result = lesson
2727
break
2828
}

app/src/main/java/me/alllexey123/itmowidgets/workers/LessonWidgetUpdateWorker.kt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,34 @@ class LessonWidgetUpdateWorker(
4444
return Result.success()
4545
}
4646

47-
val onlyDataChanged = !storage.getLessonWidgetStyleChanged()
48-
49-
val dataManager = LessonWidgetDataManager(repository, storage)
50-
val widgetsState = dataManager.getLessonWidgetsState()
51-
52-
updateSingleLessonWidgets(
53-
appWidgetManager,
54-
singleWidgetIds,
55-
widgetsState.singleLessonData
56-
)
57-
58-
updateLessonListWidgets(
59-
appWidgetManager,
60-
listWidgetIds,
61-
widgetsState.lessonListWidgetData,
62-
onlyDataChanged
63-
)
47+
try {
48+
val onlyDataChanged = !storage.getLessonWidgetStyleChanged()
6449

65-
storage.setLessonWidgetStyleChanged(false)
50+
val dataManager = LessonWidgetDataManager(repository, storage)
51+
val widgetsState = dataManager.getLessonWidgetsState()
6652

67-
// Small offset to prevent update loops
68-
// nextUpdateAt = nextUpdateAt?.plusSeconds(70)
53+
updateSingleLessonWidgets(
54+
appWidgetManager,
55+
singleWidgetIds,
56+
widgetsState.singleLessonData
57+
)
58+
59+
updateLessonListWidgets(
60+
appWidgetManager,
61+
listWidgetIds,
62+
widgetsState.lessonListWidgetData,
63+
onlyDataChanged
64+
)
65+
66+
storage.setLessonWidgetStyleChanged(false)
67+
68+
scheduleNextUpdate(appContext, widgetsState.nextUpdateAt)
69+
} catch (e: Exception) {
70+
storage.setErrorLog("[${javaClass.name}]: ${e.stackTraceToString()}}")
71+
72+
scheduleNextUpdate(appContext, null)
73+
}
6974

70-
scheduleNextUpdate(appContext, widgetsState.nextUpdateAt)
7175
return Result.success()
7276
}
7377

0 commit comments

Comments
 (0)