Refactor ignoring pending task reviews

This commit is contained in:
Jonas Lochmann 2023-02-06 01:00:00 +01:00
parent 29ef411eb3
commit 1468d9d5a0
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
3 changed files with 30 additions and 12 deletions

View file

@ -28,7 +28,6 @@ import io.timelimit.android.ui.model.main.OverviewHandling
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.flow.*
@ -42,7 +41,7 @@ class MainModel(application: Application): AndroidViewModel(application) {
private val logic = DefaultAppLogic.with(application)
private val activityCommandInternal = Channel<ActivityCommand>()
private val authenticationScreenClosed = MutableSharedFlow<Unit>()
private val authenticationScreenClosed = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
private val authenticationModelApi = object: AuthenticationModelApi {
override val authenticatedParentOnly: Flow<AuthenticationModelApi.Parent?> =
@ -58,6 +57,8 @@ class MainModel(application: Application): AndroidViewModel(application) {
}
override suspend fun doParentAuthentication(): AuthenticationModelApi.Parent? {
authenticatedParentOnly.firstOrNull()?.let { return it }
triggerAuthenticationScreen()
authenticationScreenClosed.firstOrNull()

View file

@ -92,13 +92,19 @@ object OverviewHandling {
}
},
skipTaskReview = { task ->
stateLive.update { oldState ->
if (oldState is State.Overview) oldState.copy(
state = oldState.state.copy(
hiddenTaskIds = oldState.state.hiddenTaskIds + task.task.childTask.taskId
)
)
else oldState
scope.launch {
lock.tryWithLock {
if (authentication.doParentAuthentication() != null) {
stateLive.update { oldState ->
if (oldState is State.Overview) oldState.copy(
state = oldState.state.copy(
hiddenTaskIds = oldState.state.hiddenTaskIds + task.task.childTask.taskId
)
)
else oldState
}
}
}
}
}
)

View file

@ -35,6 +35,7 @@ import io.timelimit.android.ui.MainActivity
import io.timelimit.android.ui.model.UpdateStateCommand
import io.timelimit.android.ui.model.main.OverviewHandling
import io.timelimit.android.ui.payment.RequiresPurchaseDialogFragment
import io.timelimit.android.ui.util.DateUtil
import io.timelimit.android.util.TimeTextUtil
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class)
@ -172,14 +173,24 @@ fun OverviewScreen(
style = MaterialTheme.typography.subtitle1
)
screen.taskToReview.task.childTask.lastGrantTimestamp.let { lastGrantTimestamp ->
if (lastGrantTimestamp != 0L) {
Text(
stringResource(
R.string.task_review_last_grant,
DateUtil.formatAbsoluteDate(LocalContext.current, lastGrantTimestamp)
),
style = MaterialTheme.typography.subtitle1
)
}
}
Row {
val auth = activity.getActivityViewModel()
val logic = auth.logic
TextButton(onClick = {
if (activity.getActivityViewModel().isParentAuthenticated()) {
screen.actions.skipTaskReview(screen.taskToReview)
} else activity.showAuthenticationScreen()
screen.actions.skipTaskReview(screen.taskToReview)
}) {
Text(stringResource(R.string.generic_skip))
}