-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from galihif/improve-notif
Limit daily reminders of take programs
- Loading branch information
Showing
4 changed files
with
54 additions
and
33 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
app/src/main/java/com/giftech/terbit/domain/usecase/GetDailyNotificationListUseCase.kt
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...rc/main/java/com/giftech/terbit/domain/usecase/GetEligibleDailyNotificationListUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.giftech.terbit.domain.usecase | ||
|
||
import com.giftech.terbit.data.repository.ProgramRepository | ||
import com.giftech.terbit.domain.enums.NotificationType | ||
import com.giftech.terbit.domain.enums.ProgramTag | ||
import com.giftech.terbit.domain.model.Notification | ||
import com.giftech.terbit.domain.repository.INotificationRepository | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flatMapLatest | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.mapLatest | ||
import javax.inject.Inject | ||
|
||
class GetEligibleDailyNotificationListUseCase @Inject constructor( | ||
private val notificationRepository: INotificationRepository, | ||
private val programRepository: ProgramRepository, | ||
) { | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
suspend operator fun invoke(): Flow<List<Notification>> { | ||
return programRepository.getAll() | ||
.flatMapLatest { programList -> | ||
notificationRepository.getAll() | ||
.mapLatest { notificationList -> | ||
val preTestProgramList = programList.filter { | ||
it.tag == ProgramTag.PRE_TEST | ||
} | ||
val weeklyProgramList = programList.filter { | ||
it.tag == ProgramTag.WEEKLY_PROGRAM | ||
} | ||
val isPreTestDone = preTestProgramList.all { it.isCompleted } | ||
val isWeeklyProgramDone = weeklyProgramList.all { it.isCompleted } | ||
|
||
notificationList.filter { | ||
when (it.id) { | ||
6000 -> isPreTestDone && !isWeeklyProgramDone | ||
else -> it.type == NotificationType.DAILY_TIPS | ||
} | ||
} | ||
|
||
} | ||
.flowOn(Dispatchers.IO) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters