Skip to content

Commit

Permalink
general code tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
ahudson20 committed Apr 27, 2024
1 parent 80bd001 commit 7f601ca
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 45 deletions.
18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ android {

dependencies {
implementation "androidx.navigation:navigation-compose:$nav_version"
implementation "androidx.core:core-ktx:1.12.0"
implementation "androidx.compose.ui:ui:1.6.5"
implementation "androidx.compose.ui:ui-tooling-preview:1.6.5"
implementation "androidx.core:core-ktx:1.13.0"
implementation "androidx.compose.ui:ui:1.6.6"
implementation "androidx.compose.ui:ui-tooling-preview:1.6.6"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"
implementation "androidx.activity:activity-compose:1.8.2"
implementation "androidx.activity:activity-compose:1.9.0"

// Material
implementation "com.google.android.material:material:1.11.0"
implementation "androidx.compose.material3:material3:1.2.1"
implementation "androidx.compose.material:material-icons-extended:1.6.5"
implementation "androidx.compose.material:material:1.6.5"
implementation "androidx.compose.material:material-icons-extended:1.6.6"
implementation "androidx.compose.material:material:1.6.6"

// Timepicker Material3
implementation "com.marosseleng.android:compose-material3-datetime-pickers:$time_picker_version"
Expand Down Expand Up @@ -103,9 +103,9 @@ dependencies {
testImplementation "org.mockito.kotlin:mockito-kotlin:5.2.1"
androidTestImplementation "androidx.test.ext:junit:1.1.5"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.6.5"
debugImplementation "androidx.compose.ui:ui-tooling:1.6.5"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.6.5"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.6.6"
debugImplementation "androidx.compose.ui:ui-tooling:1.6.6"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.6.6"

implementation "javax.inject:javax.inject:1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MainActivity :
super.onCreate(savedInstanceState)

installSplashScreen().setKeepOnScreenCondition {
viewModel.alarmState.value is AlarmState.Loading && !viewModel.isReady.value
viewModel.alarmState.value is AlarmState.Loading && !viewModel.preferencesUiState.value.isReady
}

setContent {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/app/whakaara/logic/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class MainViewModel @Inject constructor(
val alarmState: StateFlow<AlarmState> = _alarmState.asStateFlow()

// preferences
private val _isReady = MutableStateFlow(false)
val isReady = _isReady.asStateFlow()
private val _preferencesState = MutableStateFlow(PreferencesState())
val preferencesUiState: StateFlow<PreferencesState> = _preferencesState.asStateFlow()

Expand All @@ -62,8 +60,7 @@ class MainViewModel @Inject constructor(
//region preferences
private fun getPreferences() = viewModelScope.launch {
preferencesRepository.getPreferencesFlow().flowOn(ioDispatcher).collect { preferences ->
_preferencesState.value = PreferencesState(preferences = preferences)
_isReady.value = true
_preferencesState.value = PreferencesState(preferences = preferences, isReady = true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class StopwatchManagerWrapper @Inject constructor(
stopwatchNotificationBuilder.apply {
clearActions()
setUsesChronometer(false)
setSubText(app.applicationContext.getString(R.string.notification_sub_text_pasused))
setSubText(app.applicationContext.getString(R.string.notification_sub_text_paused))
setWhen(System.currentTimeMillis())
addAction(0, app.applicationContext.getString(R.string.notification_timer_play_action_label), playReceiverPendingIntent)
addAction(0, app.applicationContext.getString(R.string.notification_timer_stop_action_label), stopReceiverPendingIntent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class TimerManagerWrapper @Inject constructor(
setUsesChronometer(false)
setChronometerCountDown(false)
setContentTitle(app.applicationContext.getString(R.string.timer_notification_title_paused))
setSubText(app.applicationContext.getString(R.string.notification_sub_text_pasused))
setSubText(app.applicationContext.getString(R.string.notification_sub_text_paused))
addAction(0, app.applicationContext.getString(R.string.notification_timer_play_action_label), playTimerReceiverPendingIntent)
addAction(0, app.applicationContext.getString(R.string.notification_timer_stop_action_label), stopTimerReceiverPendingIntent)
}.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Qualifier

@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class ApplicationScope

@InstallIn(SingletonComponent::class)
@Module
object CoroutinesScopesModule {

@Provides
@ApplicationScope
fun providesCoroutineScope(
@DefaultDispatcher defaultDispatcher: CoroutineDispatcher
): CoroutineScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class NotificationModule {
setSmallIcon(R.drawable.outline_timer_24)
setCategory(CATEGORY_ALARM)
setAutoCancel(true)
setContentTitle("Upcoming alarm")
setSubText("Time to alarm")
setContentTitle(context.getString(R.string.upcoming_alarm_notification_content_title))
setSubText(context.getString(R.string.upcoming_alarm_notification_sub_text))
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
setUsesChronometer(true)
setChronometerCountDown(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import androidx.glance.appwidget.GlanceAppWidgetReceiver
import androidx.glance.appwidget.state.updateAppWidgetState
import androidx.glance.state.PreferencesGlanceStateDefinition
import com.app.whakaara.data.alarm.AlarmRepository
import com.app.whakaara.module.IoDispatcher
import com.app.whakaara.widget.AppWidget
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -26,6 +27,10 @@ class AppWidgetReceiver : GlanceAppWidgetReceiver() {
@Inject
lateinit var alarmRepository: AlarmRepository

@Inject
@IoDispatcher
lateinit var iODispatcher: CoroutineDispatcher

override fun onUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
Expand All @@ -47,7 +52,7 @@ class AppWidgetReceiver : GlanceAppWidgetReceiver() {
// https://issuetracker.google.com/issues/257513022
// goAsync is still the best way to run suspend functions from broadcast receivers
// but it throws exception when initially creating the widget. Works fine once widget created + updated.
GlobalScope.launch(Dispatchers.IO) {
GlobalScope.launch(iODispatcher) {
val alarms = alarmRepository.getAllAlarms()
val serializedList = Gson().toJson(alarms)
val glanceIds = GlanceAppWidgetManager(context).getGlanceIds(glanceAppWidget.javaClass)
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/app/whakaara/receiver/TimerReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package com.app.whakaara.receiver
import android.content.Context
import android.content.Intent
import com.app.whakaara.logic.TimerManagerWrapper
import com.app.whakaara.module.MainDispatcher
import com.app.whakaara.utils.constants.NotificationUtilsConstants.TIMER_RECEIVER_ACTION_PAUSE
import com.app.whakaara.utils.constants.NotificationUtilsConstants.TIMER_RECEIVER_ACTION_START
import com.app.whakaara.utils.constants.NotificationUtilsConstants.TIMER_RECEIVER_ACTION_STOP
import com.app.whakaara.utils.constants.NotificationUtilsConstants.TIMER_RECEIVER_CURRENT_TIME_EXTRA
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineDispatcher
import java.util.Calendar
import javax.inject.Inject

Expand All @@ -17,6 +18,11 @@ class TimerReceiver : HiltBroadcastReceiver() {

@Inject
lateinit var timerManagerWrapper: TimerManagerWrapper

@Inject
@MainDispatcher
lateinit var mainDispatcher: CoroutineDispatcher

override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
val actionsList = listOf(TIMER_RECEIVER_ACTION_PAUSE, TIMER_RECEIVER_ACTION_STOP, TIMER_RECEIVER_ACTION_START)
Expand All @@ -25,7 +31,7 @@ class TimerReceiver : HiltBroadcastReceiver() {
val currentTime = intent.getLongExtra(TIMER_RECEIVER_CURRENT_TIME_EXTRA, 0L)

goAsync(
coroutineContext = Dispatchers.Main
coroutineContext = mainDispatcher
) {
when (intent.action) {
TIMER_RECEIVER_ACTION_START -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.app.whakaara.state
import com.app.whakaara.data.preferences.Preferences

data class PreferencesState(
val isReady: Boolean = false,
val preferences: Preferences = Preferences()
)
7 changes: 3 additions & 4 deletions app/src/main/java/com/app/whakaara/ui/card/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.AutoDelete
import androidx.compose.material.icons.outlined.Repeat
Expand All @@ -39,8 +38,8 @@ import com.app.whakaara.R
import com.app.whakaara.data.alarm.Alarm
import com.app.whakaara.ui.bottomsheet.details.BottomSheetDetailsContent
import com.app.whakaara.ui.theme.FontScalePreviews
import com.app.whakaara.ui.theme.Shapes
import com.app.whakaara.ui.theme.Spacings.space10
import com.app.whakaara.ui.theme.Spacings.space100
import com.app.whakaara.ui.theme.Spacings.space20
import com.app.whakaara.ui.theme.Spacings.space28
import com.app.whakaara.ui.theme.Spacings.space80
Expand Down Expand Up @@ -100,11 +99,11 @@ fun Card(
}

ElevatedCard(
shape = RoundedCornerShape(space100),
shape = Shapes.extraLarge,
modifier = modifier
.fillMaxWidth()
.height(space80)
.clip(RoundedCornerShape(space100))
.clip(Shapes.extraLarge)
.clickable {
scope.launch { sheetState.expand() }
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/app/whakaara/ui/card/SwipeToDismiss.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -26,7 +25,7 @@ import androidx.compose.ui.draw.scale
import androidx.compose.ui.res.stringResource
import com.app.whakaara.R
import com.app.whakaara.ui.theme.FontScalePreviews
import com.app.whakaara.ui.theme.Spacings
import com.app.whakaara.ui.theme.Shapes
import com.app.whakaara.ui.theme.Spacings.space20
import com.app.whakaara.ui.theme.ThemePreviews
import com.app.whakaara.ui.theme.WhakaaraTheme
Expand Down Expand Up @@ -56,7 +55,7 @@ fun DismissBackground(

Box(
modifier
.clip(shape = RoundedCornerShape(Spacings.space100))
.clip(shape = Shapes.extraLarge)
.fillMaxSize()
.background(color),
contentAlignment = Alignment.CenterEnd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -31,6 +30,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.app.whakaara.state.Lap
import com.app.whakaara.ui.theme.FontScalePreviews
import com.app.whakaara.ui.theme.Shapes
import com.app.whakaara.ui.theme.Spacings.space40
import com.app.whakaara.ui.theme.Spacings.spaceMedium
import com.app.whakaara.ui.theme.Spacings.spaceNone
Expand Down Expand Up @@ -75,7 +75,7 @@ private fun LapCell(index: Int, lap: Lap) {
.fillMaxWidth()
.padding(start = space40, end = space40)
) {
Card(shape = RoundedCornerShape(spaceMedium)) {
Card(shape = Shapes.small) {
Box(
modifier = Modifier.padding(all = spaceMedium)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Pause
import androidx.compose.material.icons.filled.PlayArrow
Expand All @@ -30,6 +29,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.app.whakaara.R
import com.app.whakaara.ui.theme.BooleanPreviewProvider
import com.app.whakaara.ui.theme.Shapes
import com.app.whakaara.ui.theme.WhakaaraTheme

@Composable
Expand All @@ -49,7 +49,7 @@ fun FloatingActionButtonRow(
modifier = Modifier
.weight(1f)
.fillMaxWidth()
.clip(shape = RoundedCornerShape(50)),
.clip(shape = Shapes.large),
horizontalArrangement = Arrangement.End
) {
AnimatedVisibility(
Expand Down Expand Up @@ -87,7 +87,7 @@ fun FloatingActionButtonRow(
modifier = Modifier
.weight(1f)
.fillMaxWidth()
.clip(shape = RoundedCornerShape(50)),
.clip(shape = Shapes.large),
horizontalArrangement = Arrangement.Start
) {
AnimatedVisibility(isPlaying) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarHostState
Expand All @@ -36,6 +35,7 @@ import com.airbnb.lottie.compose.rememberLottieComposition
import com.app.whakaara.R
import com.app.whakaara.ui.floatingactionbutton.rememberPermissionStateSafe
import com.app.whakaara.ui.theme.FontScalePreviews
import com.app.whakaara.ui.theme.Shapes
import com.app.whakaara.ui.theme.Spacings.space20
import com.app.whakaara.ui.theme.Spacings.space200
import com.app.whakaara.ui.theme.Spacings.spaceMedium
Expand Down Expand Up @@ -70,7 +70,7 @@ fun NotificationsOnboarding(
modifier = Modifier
.size(space200)
.align(Alignment.Center)
.clip(RoundedCornerShape(25.dp))
.clip(Shapes.medium)
.background(color = lightBlueAnimation),
isCompleted = notificationPermissionState.status.isGranted
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -23,6 +22,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.app.whakaara.R
import com.app.whakaara.ui.theme.FontScalePreviews
import com.app.whakaara.ui.theme.Shapes
import com.app.whakaara.ui.theme.Spacings.space20
import com.app.whakaara.ui.theme.Spacings.space200
import com.app.whakaara.ui.theme.Spacings.spaceMedium
Expand All @@ -44,7 +44,7 @@ fun WelcomeOnboarding(
Box(
Modifier
.size(space200)
.clip(RoundedCornerShape(25.dp))
.clip(Shapes.medium)
.background(color = lightBlueAnimation),
contentAlignment = Alignment.Center
) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/app/whakaara/ui/theme/Shape.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import androidx.compose.material3.Shapes
import androidx.compose.ui.unit.dp

val Shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
small = RoundedCornerShape(16.dp),
medium = RoundedCornerShape(25.dp),
large = RoundedCornerShape(50.dp),
extraLarge = RoundedCornerShape(100.dp)
)
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@
<string name="timer_notification_title_active">Timer active</string>
<string name="timer_notification_sub_text_active">Time left</string>
<string name="timer_notification_title_paused">Timer paused</string>
<string name="notification_sub_text_pasused">Paused</string>
<string name="notification_sub_text_paused">Paused</string>
<string name="upcoming_alarm_notification_content_title">Upcoming alarm</string>
<string name="upcoming_alarm_notification_sub_text">Time to alarm</string>


<string name="widget_next_alarm_description">Shows next active alarm</string>
<string name="widget_next_alarm_icon_description">Alarm icon</string>
Expand Down
Loading

0 comments on commit 7f601ca

Please sign in to comment.