-
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.
feat [onboarding]: add onboarding functionality (cont.)
- Loading branch information
1 parent
b5eac58
commit 37fef00
Showing
9 changed files
with
182 additions
and
45 deletions.
There are no files selected for viewing
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
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
8 changes: 8 additions & 0 deletions
8
app/src/main/java/io/github/kabirnayeem99/islamqaorg/domain/useCase/DetermineIfFirstTime.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,8 @@ | ||
package io.github.kabirnayeem99.islamqaorg.domain.useCase | ||
|
||
import io.github.kabirnayeem99.islamqaorg.domain.repository.SettingsRepository | ||
import javax.inject.Inject | ||
|
||
class DetermineIfFirstTime @Inject constructor(private val settingsRepository: SettingsRepository) { | ||
suspend operator fun invoke(): Boolean = settingsRepository.determineIfFirstTime() | ||
} |
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/io/github/kabirnayeem99/islamqaorg/domain/useCase/OnboardUser.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,39 @@ | ||
package io.github.kabirnayeem99.islamqaorg.domain.useCase | ||
|
||
import androidx.work.WorkManager | ||
import io.github.kabirnayeem99.islamqaorg.common.base.Resource | ||
import io.github.kabirnayeem99.islamqaorg.data.workers.BackgroundQAListFetcherWorker | ||
import io.github.kabirnayeem99.islamqaorg.domain.entity.Fiqh | ||
import io.github.kabirnayeem99.islamqaorg.domain.repository.QuestionAnswerRepository | ||
import io.github.kabirnayeem99.islamqaorg.domain.repository.SettingsRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.flow | ||
import javax.inject.Inject | ||
|
||
class OnboardUser @Inject constructor( | ||
private val settingsRepo: SettingsRepository, | ||
private val qaRepo: QuestionAnswerRepository, | ||
private val workManager: WorkManager, | ||
) { | ||
suspend operator fun invoke(fiqh: Fiqh): Flow<Resource<Boolean>> { | ||
return flow { | ||
emit(Resource.Loading()) | ||
settingsRepo.savePreferredFiqh(fiqh) | ||
BackgroundQAListFetcherWorker.enqueuePeriodically( | ||
workManager, | ||
qaRepo, | ||
onSuccess = { | ||
settingsRepo.markAsOpened() | ||
emit(Resource.Success(true)) | ||
}, | ||
onFailure = { | ||
emit(Resource.Error<Boolean>("Failed to start fetching resources.")) | ||
}, | ||
) | ||
}.catch { e -> | ||
emit(Resource.Error(e.localizedMessage ?: "Error")) | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.