diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRecordMediator.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRecordMediator.kt index f9fa59e5..b2deb4ba 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRecordMediator.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRecordMediator.kt @@ -6,8 +6,9 @@ import javax.inject.Inject class AddRecordMediator @Inject constructor( private val recordInteractor: RecordInteractor, - private val widgetInteractor: WidgetInteractor, + private val notificationTypeInteractor: NotificationTypeInteractor, private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor, + private val widgetInteractor: WidgetInteractor, ) { suspend fun add( @@ -18,6 +19,7 @@ class AddRecordMediator @Inject constructor( } suspend fun doAfterAdd(typeId: Long) { + notificationTypeInteractor.checkAndShow(typeId) notificationGoalTimeInteractor.checkAndReschedule(typeId) widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART)) } diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RemoveRecordMediator.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RemoveRecordMediator.kt index 3a6215cf..c7b3f4f1 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RemoveRecordMediator.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RemoveRecordMediator.kt @@ -5,6 +5,7 @@ import javax.inject.Inject class RemoveRecordMediator @Inject constructor( private val recordInteractor: RecordInteractor, + private val notificationTypeInteractor: NotificationTypeInteractor, private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor, private val widgetInteractor: WidgetInteractor, ) { @@ -14,7 +15,8 @@ class RemoveRecordMediator @Inject constructor( doAfterRemove(typeId) } - private suspend fun doAfterRemove(typeId: Long) { + suspend fun doAfterRemove(typeId: Long) { + notificationTypeInteractor.checkAndShow(typeId) notificationGoalTimeInteractor.checkAndReschedule(typeId) widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART)) } diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordViewModel.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordViewModel.kt index a955797e..bdf27124 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordViewModel.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordViewModel.kt @@ -11,6 +11,7 @@ import com.example.util.simpletimetracker.domain.extension.orZero import com.example.util.simpletimetracker.domain.interactor.AddRecordMediator import com.example.util.simpletimetracker.domain.interactor.AddRunningRecordMediator import com.example.util.simpletimetracker.domain.interactor.NotificationGoalTimeInteractor +import com.example.util.simpletimetracker.domain.interactor.NotificationTypeInteractor import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor import com.example.util.simpletimetracker.domain.interactor.RecordInteractor import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor @@ -49,6 +50,7 @@ class ChangeRecordViewModel @Inject constructor( private val addRunningRecordMediator: AddRunningRecordMediator, private val removeRunningRecordMediator: RemoveRunningRecordMediator, private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor, + private val notificationTypeInteractor: NotificationTypeInteractor, private val timeMapper: TimeMapper, ) : ChangeRecordBaseViewModel( router, @@ -102,7 +104,10 @@ class ChangeRecordViewModel @Inject constructor( comment = newComment, tagIds = newCategoryIds ).let { - notificationGoalTimeInteractor.checkAndReschedule(originalTypeId) + if (newTypeId != originalTypeId) { + notificationTypeInteractor.checkAndShow(originalTypeId) + notificationGoalTimeInteractor.checkAndReschedule(originalTypeId) + } addRecordMediator.add(it) router.back() } diff --git a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt index dd19abc6..663d3554 100644 --- a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt +++ b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt @@ -5,6 +5,7 @@ import com.example.util.simpletimetracker.domain.interactor.AddRecordMediator import com.example.util.simpletimetracker.domain.interactor.NotificationGoalTimeInteractor import com.example.util.simpletimetracker.domain.interactor.RecordInteractor import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor +import com.example.util.simpletimetracker.domain.interactor.RemoveRecordMediator import com.example.util.simpletimetracker.domain.model.RecordsFilter import com.example.util.simpletimetracker.feature_base_adapter.category.CategoryViewData import com.example.util.simpletimetracker.feature_data_edit.model.DataEditAddTagsState @@ -17,6 +18,7 @@ import javax.inject.Inject class DateEditChangeInteractor @Inject constructor( private val recordInteractor: RecordInteractor, private val addRecordMediator: AddRecordMediator, + private val removeRecordMediator: RemoveRecordMediator, private val recordFilterInteractor: RecordFilterInteractor, private val recordTagInteractor: RecordTagInteractor, private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor, @@ -56,6 +58,7 @@ class DateEditChangeInteractor @Inject constructor( records.forEach { record -> if (deleteRecord) { + oldTypeIds.add(record.typeId) recordInteractor.remove(record.id) return@forEach } @@ -86,6 +89,11 @@ class DateEditChangeInteractor @Inject constructor( } } + if (deleteRecord) { + oldTypeIds.forEach { typeId -> + removeRecordMediator.doAfterRemove(typeId) + } + } // Check goal time and statistics widget consistency. if (newTypeId != null) { oldTypeIds.forEach { typeId -> diff --git a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/interactor/NotificationTypeInteractorImpl.kt b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/interactor/NotificationTypeInteractorImpl.kt index 4cbe8e9a..84acb6e6 100644 --- a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/interactor/NotificationTypeInteractorImpl.kt +++ b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/interactor/NotificationTypeInteractorImpl.kt @@ -1,11 +1,12 @@ package com.example.util.simpletimetracker.feature_notification.recordType.interactor -import com.example.util.simpletimetracker.domain.interactor.NotificationTypeInteractor +import com.example.util.simpletimetracker.core.interactor.GetCurrentRecordsDurationInteractor import com.example.util.simpletimetracker.core.mapper.ColorMapper import com.example.util.simpletimetracker.core.mapper.IconMapper import com.example.util.simpletimetracker.core.mapper.TimeMapper import com.example.util.simpletimetracker.core.repo.ResourceRepo import com.example.util.simpletimetracker.domain.extension.getFullName +import com.example.util.simpletimetracker.domain.interactor.NotificationTypeInteractor import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor @@ -24,6 +25,7 @@ class NotificationTypeInteractorImpl @Inject constructor( private val recordTypeInteractor: RecordTypeInteractor, private val runningRecordInteractor: RunningRecordInteractor, private val recordTagInteractor: RecordTagInteractor, + private val getCurrentRecordsDurationInteractor: GetCurrentRecordsDurationInteractor, private val prefsInteractor: PrefsInteractor, private val iconMapper: IconMapper, private val colorMapper: ColorMapper, @@ -69,8 +71,9 @@ class NotificationTypeInteractorImpl @Inject constructor( show( recordType = recordType, - runningRecord = runningRecord, - recordTags = recordTags.filter { it.id in runningRecord?.tagIds.orEmpty() }, + runningRecord = runningRecord ?: return, + recordTags = recordTags.filter { it.id in runningRecord.tagIds }, + dailyCurrent = getCurrentRecordsDurationInteractor.getDailyCurrent(runningRecord), isDarkTheme = isDarkTheme, useMilitaryTime = useMilitaryTime, showSeconds = showSeconds, @@ -114,6 +117,7 @@ class NotificationTypeInteractorImpl @Inject constructor( recordType = recordTypes[runningRecord.id], runningRecord = runningRecord, recordTags = recordTags.filter { it.id in runningRecord.tagIds }, + dailyCurrent = getCurrentRecordsDurationInteractor.getDailyCurrent(runningRecord), isDarkTheme = isDarkTheme, useMilitaryTime = useMilitaryTime, showSeconds = showSeconds, @@ -130,16 +134,15 @@ class NotificationTypeInteractorImpl @Inject constructor( private fun show( recordType: RecordType?, - runningRecord: RunningRecord?, + runningRecord: RunningRecord, recordTags: List, + dailyCurrent: GetCurrentRecordsDurationInteractor.Result, isDarkTheme: Boolean, useMilitaryTime: Boolean, showSeconds: Boolean, controls: NotificationTypeParams.Controls, ) { - if (recordType == null || runningRecord == null) { - return - } + if (recordType == null) return NotificationTypeParams( id = recordType.id, @@ -153,6 +156,9 @@ class NotificationTypeInteractorImpl @Inject constructor( showSeconds = showSeconds, ).let { resourceRepo.getString(R.string.notification_time_started, it) }, startedTimeStamp = runningRecord.timeStarted, + totalDuration = dailyCurrent.let { + if (it.durationDiffersFromCurrent) it.duration else null + }, goalTime = recordType.goalTime .takeIf { it > 0 } ?.let(timeMapper::formatDuration) diff --git a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeManager.kt b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeManager.kt index 299a5390..3de85ddc 100644 --- a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeManager.kt +++ b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeManager.kt @@ -125,10 +125,21 @@ class NotificationTypeManager @Inject constructor( setTextViewText(R.id.tvNotificationText, params.text) setTextViewText(R.id.tvNotificationTimeStarted, params.timeStarted) - setTextViewText(R.id.tvNotificationGoalTime, params.goalTime) setImageViewBitmap(R.id.ivNotificationIcon, getIconBitmap(params.icon, params.color)) + val base = SystemClock.elapsedRealtime() - (System.currentTimeMillis() - params.startedTimeStamp) setChronometer(R.id.timerNotification, base, null, true) + + if (params.totalDuration != null) { + val baseTotal = SystemClock.elapsedRealtime() - params.totalDuration + setChronometer(R.id.timerNotificationTotal, baseTotal, "(%s)", true) + setViewVisibility(R.id.timerNotificationTotal, View.VISIBLE) + } else { + setViewVisibility(R.id.timerNotificationTotal, View.GONE) + } + + // TODO show only closest goal time, count down to it? + setTextViewText(R.id.tvNotificationGoalTime, params.goalTime) } } diff --git a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeParams.kt b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeParams.kt index df49b9a1..dca2dc3b 100644 --- a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeParams.kt +++ b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/manager/NotificationTypeParams.kt @@ -9,6 +9,7 @@ data class NotificationTypeParams( val text: String, val timeStarted: String, val startedTimeStamp: Long, + val totalDuration: Long?, val goalTime: String, val stopButton: String, val controls: Controls, diff --git a/features/feature_notification/src/main/res/layout/notification_record_layout.xml b/features/feature_notification/src/main/res/layout/notification_record_layout.xml index 418ef241..e0e6e424 100644 --- a/features/feature_notification/src/main/res/layout/notification_record_layout.xml +++ b/features/feature_notification/src/main/res/layout/notification_record_layout.xml @@ -4,70 +4,95 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + - - - + - + + + + + + + + + + + + + + + + + - +