Skip to content

Commit

Permalink
add more case when goal notifications need to be rechecked
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 26, 2023
1 parent fb9331c commit 9c4848d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package com.example.util.simpletimetracker.domain.interactor

import com.example.util.simpletimetracker.domain.model.WidgetType
import com.example.util.simpletimetracker.domain.resolver.BackupRepo
import com.example.util.simpletimetracker.domain.resolver.ResultCode
import javax.inject.Inject

class BackupInteractor @Inject constructor(
private val backupRepo: BackupRepo
private val backupRepo: BackupRepo,
private val runningRecordInteractor: RunningRecordInteractor,
private val widgetInteractor: WidgetInteractor,
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
) {

suspend fun saveBackupFile(uriString: String): ResultCode {
return backupRepo.saveBackupFile(uriString)
}

suspend fun restoreBackupFile(uriString: String): ResultCode {
return backupRepo.restoreBackupFile(uriString)
val resultCode = backupRepo.restoreBackupFile(uriString)

val runningRecords = runningRecordInteractor.getAll()
notificationGoalTimeInteractor.checkAndReschedule(runningRecords.map { it.id })
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
widgetInteractor.updateWidgets(listOf(WidgetType.RECORD_TYPE))

return resultCode
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package com.example.util.simpletimetracker.domain.interactor

import com.example.util.simpletimetracker.domain.model.Range
import com.example.util.simpletimetracker.domain.model.WidgetType
import com.example.util.simpletimetracker.domain.resolver.CsvRepo
import com.example.util.simpletimetracker.domain.resolver.ResultCode
import javax.inject.Inject

class CsvExportInteractor @Inject constructor(
private val csvRepo: CsvRepo,
private val runningRecordInteractor: RunningRecordInteractor,
private val widgetInteractor: WidgetInteractor,
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
) {

suspend fun saveCsvFile(uriString: String, range: Range?): ResultCode {
return csvRepo.saveCsvFile(uriString = uriString, range = range)
}

suspend fun importCsvFile(uriString: String): ResultCode {
return csvRepo.importCsvFile(uriString)
val resultCode = csvRepo.importCsvFile(uriString)

val runningRecords = runningRecordInteractor.getAll()
notificationGoalTimeInteractor.checkAndReschedule(runningRecords.map { it.id })
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
widgetInteractor.updateWidgets(listOf(WidgetType.RECORD_TYPE))

return resultCode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,4 @@ class RecordTypeCategoryInteractor @Inject constructor(
suspend fun removeTypes(categoryId: Long, typeIds: List<Long>) {
recordTypeCategoryRepo.removeTypes(categoryId, typeIds)
}

suspend fun removeAllByType(typeId: Long) {
recordTypeCategoryRepo.removeAllByType(typeId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import com.example.util.simpletimetracker.domain.interactor.NotificationGoalTime
import com.example.util.simpletimetracker.domain.interactor.NotificationTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor
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_archive.R
import com.example.util.simpletimetracker.feature_archive.interactor.ArchiveViewDataInteractor
import com.example.util.simpletimetracker.feature_archive.viewData.ArchiveViewData
Expand All @@ -33,6 +37,8 @@ class ArchiveViewModel @Inject constructor(
private val recordTypeInteractor: RecordTypeInteractor,
private val recordTagInteractor: RecordTagInteractor,
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
private val widgetInteractor: WidgetInteractor,
private val runningRecordInteractor: RunningRecordInteractor,
) : ViewModel() {

val viewData: LiveData<ArchiveViewData> by lazy {
Expand Down Expand Up @@ -104,7 +110,10 @@ class ArchiveViewModel @Inject constructor(
val message = when (params) {
is ArchiveDialogParams.Activity -> {
recordTypeInteractor.remove(params.id)
notificationGoalTimeInteractor.checkAndReschedule(listOf(params.id))
val runningRecordIds = runningRecordInteractor.getAll().map { it.id }
notificationGoalTimeInteractor.cancel(RecordTypeGoal.IdData.Type(params.id))
notificationGoalTimeInteractor.checkAndReschedule(runningRecordIds + params.id)
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
resourceRepo.getString(R.string.archive_activity_deleted)
}
is ArchiveDialogParams.RecordTag -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class ChangeCategoryViewModel @Inject constructor(
if (categoryId != 0L) {
categoryInteractor.remove(categoryId)
notificationGoalTimeInteractor.cancel(RecordTypeGoal.IdData.Category(categoryId))
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
showMessage(R.string.change_category_removed)
(keyboardVisibility as MutableLiveData).value = false
router.back()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import javax.inject.Inject

/**
* Type goal can be changed:
* - change / remove running record
* - change / remove record
* - change / remove type goal
* - add / change / remove running record
* - add / change / remove record
* - add / change / remove type goal
* - remove type
*
* Category goal can be changed:
* - change / remove running record
* - change / remove record
* - change / remove category goal
* - add / change / remove running record
* - add / change / remove record
* - add / change / remove category goal
* - remove category
* - change type categories
* - change category activities
* - remove category
*/
class NotificationGoalTimeInteractorImpl @Inject constructor(
private val recordTypeGoalInteractor: RecordTypeGoalInteractor,
Expand Down

0 comments on commit 9c4848d

Please sign in to comment.