Skip to content

Commit

Permalink
Merge pull request #347 from joeloewi7178/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
joeloewi7178 authored Feb 8, 2024
2 parents 61c8426 + 69af5fd commit 028b957
Show file tree
Hide file tree
Showing 26 changed files with 237 additions and 334 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {

defaultConfig {
applicationId = "com.joeloewi.croissant"
versionCode = 55
versionName = "1.2.6"
versionCode = 56
versionName = "1.2.7"
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import com.joeloewi.croissant.worker.AttendCheckInEventWorker
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -53,22 +50,22 @@ class AlarmReceiver : BroadcastReceiver() {
lateinit var alarmScheduler: AlarmScheduler

override fun onReceive(p0: Context, p1: Intent) {
_processLifecycleScope.launch(_coroutineContext) {
when (p1.action) {
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED, AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED -> {
getAllOneShotAttendanceUseCase().map { attendance ->
async(SupervisorJob() + Dispatchers.IO + CoroutineExceptionHandler { _, _ -> }) {
attendance.runCatching {
alarmScheduler.scheduleCheckInAlarm(
attendance = attendance,
scheduleForTomorrow = false
)
}
when (p1.action) {
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED, AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED -> {
_processLifecycleScope.launch(_coroutineContext) {
getAllOneShotAttendanceUseCase().forEach { attendance ->
attendance.runCatching {
alarmScheduler.scheduleCheckInAlarm(
attendance = attendance,
scheduleForTomorrow = false
)
}
}.awaitAll()
}
}
}

RECEIVE_ATTEND_CHECK_IN_ALARM -> {
RECEIVE_ATTEND_CHECK_IN_ALARM -> {
_processLifecycleScope.launch(_coroutineContext) {
val attendanceId = p1.getLongExtra(ATTENDANCE_ID, Long.MIN_VALUE)
val attendanceWithGames = getOneAttendanceUseCase(attendanceId)
val attendance = attendanceWithGames.attendance
Expand All @@ -87,10 +84,10 @@ class AlarmReceiver : BroadcastReceiver() {
scheduleForTomorrow = true
)
}
}

else -> {
else -> {

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import com.joeloewi.croissant.domain.usecase.ResinStatusWidgetUseCase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -46,20 +43,18 @@ class MigrationHelper : BroadcastReceiver() {
lateinit var workManager: WorkManager

override fun onReceive(p0: Context, p1: Intent) {
_processLifecycleScope.launch(_coroutineContext) {
when (p1.action) {
Intent.ACTION_MY_PACKAGE_REPLACED -> {
when (p1.action) {
Intent.ACTION_MY_PACKAGE_REPLACED -> {
_processLifecycleScope.launch(_coroutineContext) {
//because work manager's job can be deferred, cancel check in event worker
//instead of work manager, use alarm manager
getAllOneShotAttendanceUseCase().map { attendance ->
async(SupervisorJob() + Dispatchers.IO + CoroutineExceptionHandler { _, _ -> }) {
workManager.cancelUniqueWork(attendance.attendCheckInEventWorkerName.toString())
}
}.awaitAll()
getAllOneShotAttendanceUseCase().forEach { attendance ->
workManager.cancelUniqueWork(attendance.attendCheckInEventWorkerName.toString())
}
}

else -> {}
}

else -> {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class TimeZoneChangedReceiver @Inject constructor(
lateinit var notificationGenerator: NotificationGenerator

override fun onReceive(context: Context, intent: Intent) {
_processLifecycleScope.launch(_coroutineContext) {
when (intent.action) {
Intent.ACTION_TIMEZONE_CHANGED -> {
when (intent.action) {
Intent.ACTION_TIMEZONE_CHANGED -> {
_processLifecycleScope.launch(_coroutineContext) {
with(notificationGenerator) {
safeNotify(
UUID.randomUUID().toString(),
Expand All @@ -41,10 +41,10 @@ class TimeZoneChangedReceiver @Inject constructor(
)
}
}
}

else -> {
else -> {

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.Pending
import androidx.compose.material.icons.filled.PlayCircle
import androidx.compose.material3.DismissDirection
import androidx.compose.material3.DismissValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
Expand All @@ -40,10 +37,11 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SwipeToDismiss
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.rememberDismissState
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -225,101 +223,80 @@ fun AttendanceWithGamesItem(
onDeleteAttendance: (Attendance) -> Unit,
onClickAttendance: (Attendance) -> Unit
) {
val dismissState = rememberDismissState()
val swipeToDismissState = rememberSwipeToDismissBoxState()
val context = LocalContext.current
val activity = LocalActivity.current
val coroutineScope = rememberCoroutineScope()

LaunchedEffect(Unit) {
snapshotFlow { dismissState.currentValue }.catch { }.collectLatest {
if (it == DismissValue.DismissedToStart) {
snapshotFlow { swipeToDismissState.currentValue }.catch { }.collectLatest {
if (it == SwipeToDismissBoxValue.EndToStart) {
onDeleteAttendance(item().value.attendance)
}
}
}

SwipeToDismiss(
state = dismissState,
SwipeToDismissBox(
modifier = modifier,
directions = setOf(DismissDirection.EndToStart),
background = {
state = swipeToDismissState,
enableDismissFromStartToEnd = false,
backgroundContent = {
SwipeToDismissBackground(
direction = dismissState.dismissDirection,
targetValue = { dismissState.targetValue }
targetValue = { swipeToDismissState.targetValue }
)
},
dismissContent = {
DismissContent(
elevation = animateDpAsState(
if (dismissState.dismissDirection != null) HalfDp else 0.dp, label = ""
).value,
attendanceWithGames = item,
onClickOneTimeAttend = remember {
{ attendance ->
Firebase.analytics.logEvent("instant_attend_click", bundleOf())
}
) {
DismissContent(
elevation = animateDpAsState(
HalfDp, label = ""
).value,
attendanceWithGames = item,
onClickOneTimeAttend = remember {
{ attendance ->
Firebase.analytics.logEvent("instant_attend_click", bundleOf())

val oneTimeWork = AttendCheckInEventWorker.buildOneTimeWork(
attendanceId = attendance.id
)
val oneTimeWork = AttendCheckInEventWorker.buildOneTimeWork(
attendanceId = attendance.id
)

WorkManager.getInstance(context).beginUniqueWork(
attendance.oneTimeAttendCheckInEventWorkerName.toString(),
ExistingWorkPolicy.APPEND_OR_REPLACE,
oneTimeWork
).enqueue()
WorkManager.getInstance(context).beginUniqueWork(
attendance.oneTimeAttendCheckInEventWorkerName.toString(),
ExistingWorkPolicy.APPEND_OR_REPLACE,
oneTimeWork
).enqueue()

coroutineScope.launch {
requestReview(
activity = activity,
logMessage = "ImmediateAttendance"
)
}
coroutineScope.launch {
requestReview(
activity = activity,
logMessage = "ImmediateAttendance"
)
}
},
onClickAttendance = remember { onClickAttendance }
)
}
)
}
},
onClickAttendance = remember { onClickAttendance }
)
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun SwipeToDismissBackground(
direction: DismissDirection?,
targetValue: () -> DismissValue
targetValue: () -> SwipeToDismissBoxValue
) {
val alignment by remember(direction) {
derivedStateOf {
when (direction) {
DismissDirection.StartToEnd -> Alignment.CenterStart
DismissDirection.EndToStart -> Alignment.CenterEnd
null -> Alignment.TopStart
}
}
}
val icon by remember(direction) {
derivedStateOf {
when (direction) {
DismissDirection.StartToEnd -> Icons.Default.Done
DismissDirection.EndToStart -> Icons.Default.Delete
null -> Icons.Default.Pending
}
}
}
val scale by animateFloatAsState(
if (targetValue() == DismissValue.Default) 0.75f else 1f, label = ""
if (targetValue() == SwipeToDismissBoxValue.Settled) 0.75f else 1f, label = ""
)
val backgroundColor by animateColorAsState(
when (targetValue()) {
DismissValue.DismissedToStart -> MaterialTheme.colorScheme.errorContainer
SwipeToDismissBoxValue.EndToStart -> MaterialTheme.colorScheme.errorContainer
else -> {
MaterialTheme.colorScheme.surfaceColorAtElevation(HalfDp)
}
}, label = ""
)
val iconColor by animateColorAsState(
when (targetValue()) {
DismissValue.DismissedToStart -> MaterialTheme.colorScheme.onErrorContainer
SwipeToDismissBoxValue.EndToStart -> MaterialTheme.colorScheme.onErrorContainer
else -> {
MaterialTheme.colorScheme.onSurface
}
Expand All @@ -331,10 +308,10 @@ private fun SwipeToDismissBackground(
.fillMaxSize()
.background(backgroundColor)
.padding(horizontal = DoubleDp),
contentAlignment = alignment
contentAlignment = Alignment.CenterEnd
) {
Icon(
imageVector = icon,
imageVector = Icons.Default.Delete,
contentDescription = null,
modifier = Modifier.scale(scale),
tint = iconColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Login
import androidx.compose.material.icons.automirrored.filled.Login
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.Card
import androidx.compose.material3.FilledTonalButton
Expand Down Expand Up @@ -77,8 +77,8 @@ fun GetSession(
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Default.Login,
contentDescription = Icons.Default.Login.name
imageVector = Icons.AutoMirrored.Default.Login,
contentDescription = Icons.AutoMirrored.Default.Login.name
)
Text(
text = stringResource(id = R.string.go_to_hoyolab),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.selection.toggleable
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowForward
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.AlertDialog
Expand Down Expand Up @@ -193,8 +193,8 @@ fun SelectGames(
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Default.ArrowForward,
contentDescription = Icons.Default.ArrowForward.name
imageVector = Icons.AutoMirrored.Default.ArrowForward,
contentDescription = Icons.AutoMirrored.Default.ArrowForward.name
)
Text(text = stringResource(id = R.string.next_step))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.OpenInNew
import androidx.compose.material.icons.filled.Public
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -176,8 +176,8 @@ private fun DeveloperInfoContent(
},
trailingContent = {
Icon(
imageVector = Icons.Default.OpenInNew,
contentDescription = Icons.Default.OpenInNew.name
imageVector = Icons.AutoMirrored.Default.OpenInNew,
contentDescription = Icons.AutoMirrored.Default.OpenInNew.name
)
},
overlineContent = {
Expand Down Expand Up @@ -230,8 +230,8 @@ private fun DeveloperInfoContent(
},
trailingContent = {
Icon(
imageVector = Icons.Default.OpenInNew,
contentDescription = Icons.Default.OpenInNew.name
imageVector = Icons.AutoMirrored.Default.OpenInNew,
contentDescription = Icons.AutoMirrored.Default.OpenInNew.name
)
},
overlineContent = {
Expand Down
Loading

0 comments on commit 028b957

Please sign in to comment.