mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 09:49:25 +02:00
Refactor ignoring pending task reviews
This commit is contained in:
parent
29ef411eb3
commit
1468d9d5a0
3 changed files with 30 additions and 12 deletions
|
@ -28,7 +28,6 @@ import io.timelimit.android.ui.model.main.OverviewHandling
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.channels.ReceiveChannel
|
import kotlinx.coroutines.channels.ReceiveChannel
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
|
@ -42,7 +41,7 @@ class MainModel(application: Application): AndroidViewModel(application) {
|
||||||
|
|
||||||
private val logic = DefaultAppLogic.with(application)
|
private val logic = DefaultAppLogic.with(application)
|
||||||
private val activityCommandInternal = Channel<ActivityCommand>()
|
private val activityCommandInternal = Channel<ActivityCommand>()
|
||||||
private val authenticationScreenClosed = MutableSharedFlow<Unit>()
|
private val authenticationScreenClosed = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
||||||
|
|
||||||
private val authenticationModelApi = object: AuthenticationModelApi {
|
private val authenticationModelApi = object: AuthenticationModelApi {
|
||||||
override val authenticatedParentOnly: Flow<AuthenticationModelApi.Parent?> =
|
override val authenticatedParentOnly: Flow<AuthenticationModelApi.Parent?> =
|
||||||
|
@ -58,6 +57,8 @@ class MainModel(application: Application): AndroidViewModel(application) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun doParentAuthentication(): AuthenticationModelApi.Parent? {
|
override suspend fun doParentAuthentication(): AuthenticationModelApi.Parent? {
|
||||||
|
authenticatedParentOnly.firstOrNull()?.let { return it }
|
||||||
|
|
||||||
triggerAuthenticationScreen()
|
triggerAuthenticationScreen()
|
||||||
|
|
||||||
authenticationScreenClosed.firstOrNull()
|
authenticationScreenClosed.firstOrNull()
|
||||||
|
|
|
@ -92,6 +92,9 @@ object OverviewHandling {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
skipTaskReview = { task ->
|
skipTaskReview = { task ->
|
||||||
|
scope.launch {
|
||||||
|
lock.tryWithLock {
|
||||||
|
if (authentication.doParentAuthentication() != null) {
|
||||||
stateLive.update { oldState ->
|
stateLive.update { oldState ->
|
||||||
if (oldState is State.Overview) oldState.copy(
|
if (oldState is State.Overview) oldState.copy(
|
||||||
state = oldState.state.copy(
|
state = oldState.state.copy(
|
||||||
|
@ -101,6 +104,9 @@ object OverviewHandling {
|
||||||
else oldState
|
else oldState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import io.timelimit.android.ui.MainActivity
|
||||||
import io.timelimit.android.ui.model.UpdateStateCommand
|
import io.timelimit.android.ui.model.UpdateStateCommand
|
||||||
import io.timelimit.android.ui.model.main.OverviewHandling
|
import io.timelimit.android.ui.model.main.OverviewHandling
|
||||||
import io.timelimit.android.ui.payment.RequiresPurchaseDialogFragment
|
import io.timelimit.android.ui.payment.RequiresPurchaseDialogFragment
|
||||||
|
import io.timelimit.android.ui.util.DateUtil
|
||||||
import io.timelimit.android.util.TimeTextUtil
|
import io.timelimit.android.util.TimeTextUtil
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class)
|
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class)
|
||||||
|
@ -172,14 +173,24 @@ fun OverviewScreen(
|
||||||
style = MaterialTheme.typography.subtitle1
|
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 {
|
Row {
|
||||||
val auth = activity.getActivityViewModel()
|
val auth = activity.getActivityViewModel()
|
||||||
val logic = auth.logic
|
val logic = auth.logic
|
||||||
|
|
||||||
TextButton(onClick = {
|
TextButton(onClick = {
|
||||||
if (activity.getActivityViewModel().isParentAuthenticated()) {
|
|
||||||
screen.actions.skipTaskReview(screen.taskToReview)
|
screen.actions.skipTaskReview(screen.taskToReview)
|
||||||
} else activity.showAuthenticationScreen()
|
|
||||||
}) {
|
}) {
|
||||||
Text(stringResource(R.string.generic_skip))
|
Text(stringResource(R.string.generic_skip))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue