Skip to content

Commit

Permalink
add widget update on goal change
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Oct 28, 2023
1 parent 174896d commit c9d27d0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class AddRecordMediator @Inject constructor(
suspend fun doAfterAdd(typeId: Long) {
notificationTypeInteractor.checkAndShow(typeId)
notificationGoalTimeInteractor.checkAndReschedule(typeId)
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
widgetInteractor.updateWidgets(
listOf(
WidgetType.STATISTICS_CHART,
WidgetType.RECORD_TYPE,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class RemoveRecordMediator @Inject constructor(
suspend fun doAfterRemove(typeId: Long) {
notificationTypeInteractor.checkAndShow(typeId)
notificationGoalTimeInteractor.checkAndReschedule(typeId)
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
widgetInteractor.updateWidgets(
listOf(
WidgetType.STATISTICS_CHART,
WidgetType.RECORD_TYPE,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ class ChangeRecordViewModel @Inject constructor(
comment = newComment,
tagIds = newCategoryIds
).let {
addRecordMediator.add(it)
if (newTypeId != originalTypeId) {
notificationTypeInteractor.checkAndShow(originalTypeId)
notificationGoalTimeInteractor.checkAndReschedule(originalTypeId)
}
addRecordMediator.add(it)
router.back()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import com.example.util.simpletimetracker.domain.interactor.NotificationGoalTime
import com.example.util.simpletimetracker.domain.interactor.RecordTypeGoalInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor
import com.example.util.simpletimetracker.domain.interactor.WidgetInteractor
import com.example.util.simpletimetracker.domain.model.RecordTypeGoal
import com.example.util.simpletimetracker.domain.model.WidgetType
import com.example.util.simpletimetracker.feature_notification.goalTime.manager.NotificationGoalTimeManager
import com.example.util.simpletimetracker.feature_notification.goalTime.scheduler.NotificationGoalTimeScheduler
import com.example.util.simpletimetracker.feature_notification.goalTime.scheduler.NotificationRangeEndScheduler
Expand All @@ -27,6 +29,7 @@ class NotificationGoalTimeInteractorImpl @Inject constructor(
private val scheduler: NotificationGoalTimeScheduler,
private val rangeEndScheduler: NotificationRangeEndScheduler,
private val notificationGoalParamsInteractor: NotificationGoalParamsInteractor,
private val widgetInteractor: WidgetInteractor,
) : NotificationGoalTimeInteractor {

override suspend fun checkAndReschedule() {
Expand Down Expand Up @@ -134,6 +137,8 @@ class NotificationGoalTimeInteractorImpl @Inject constructor(
range = goalRange,
type = NotificationGoalParamsInteractor.Type.Duration,
)?.let(manager::show)
// TODO update only by typeId, not all widgets.
widgetInteractor.updateWidgets(listOf(WidgetType.RECORD_TYPE))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ class SettingsAdditionalViewModelDelegate @Inject constructor(
delegateScope.launch {
val newValue = prefsInteractor.getStartOfDayShift() * -1
prefsInteractor.setStartOfDayShift(newValue)
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
widgetInteractor.updateWidgets(
listOf(
WidgetType.STATISTICS_CHART,
WidgetType.RECORD_TYPE,
),
)
notificationTypeInteractor.updateNotifications()
notificationGoalTimeInteractor.checkAndReschedule()
updateStartOfDayViewData()
Expand Down Expand Up @@ -193,7 +198,12 @@ class SettingsAdditionalViewModelDelegate @Inject constructor(
val wasPositive = prefsInteractor.getStartOfDayShift() >= 0
val newValue = settingsMapper.toStartOfDayShift(timestamp, wasPositive)
prefsInteractor.setStartOfDayShift(newValue)
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
widgetInteractor.updateWidgets(
listOf(
WidgetType.STATISTICS_CHART,
WidgetType.RECORD_TYPE,
),
)
notificationTypeInteractor.updateNotifications()
notificationGoalTimeInteractor.checkAndReschedule()
updateStartOfDayViewData()
Expand Down

0 comments on commit c9d27d0

Please sign in to comment.