Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow device light to flash for alarms #75

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: "checkout"
uses: actions/checkout@v4.1.1
uses: actions/checkout@v4.2.2

- name: Kotlin Linter
uses: vroy/gha-kotlin-linter@v4
Expand Down Expand Up @@ -44,10 +44,10 @@ jobs:
ls /dev/kvm

- name: Checkout
uses: actions/checkout@v4.1.1
uses: actions/checkout@v4.2.2

- name: set up JDK 17
uses: actions/setup-java@v4.2.1
uses: actions/setup-java@v4.6.0
with:
java-version: '17'
distribution: 'temurin'
Expand All @@ -57,7 +57,7 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Set up Android SDK
uses: android-actions/[email protected].1
uses: android-actions/[email protected].2

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -69,7 +69,7 @@ jobs:
run: ./gradlew testDebugUnitTest

- name: Run instrumented test
uses: ReactiveCircus/android-emulator-runner@v2.30.1
uses: ReactiveCircus/android-emulator-runner@v2.33.0
with:
arch: 'x86_64'
api-level: 33
Expand All @@ -91,7 +91,7 @@ jobs:
update-comment: true

- name: Upload Test Reports Folder
uses: actions/upload-artifact@v4.3.1
uses: actions/upload-artifact@v4.6.0
if: ${{ always() }}
with:
name: reports
Expand All @@ -109,7 +109,7 @@ jobs:
if: ${{ always() }}
steps:
- name: Download Test Reports Folder
uses: actions/[email protected].4
uses: actions/[email protected].8
with:
name: reports

Expand Down
9 changes: 3 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App.Starting"
>
android:theme="@style/Theme.App.Starting">

<activity
android:name=".activities.MainActivity"
Expand All @@ -33,7 +32,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="app" android:host="mainactivity" />
</intent-filter>

<intent-filter>
Expand All @@ -58,8 +56,7 @@

<intent-filter>
<action android:name="android.intent.action.FullScreenNotificationActivity" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="app" android:host="fullscreennotificationactivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

</activity>
Expand Down Expand Up @@ -113,7 +110,7 @@
android:exported="false">
</receiver>

<receiver android:name=".receiver.UpcomingAlarmReceiver"
<receiver android:name="com.whakaara.feature.alarm.receiver.UpcomingAlarmReceiver"
android:exported="false"
android:enabled="true">
</receiver>
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/app/whakaara/ui/settings/AlarmSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ fun AlarmSettings(
}
)

SettingsSwitch(
modifier = Modifier.height(space100),
title = { Text(text = stringResource(id = R.string.settings_screen_flash_light_title)) },
subtitle = { Text(text = stringResource(id = R.string.settings_screen_flash_light_subtitle)) },
state = rememberBooleanSettingState(preferencesState.preferences.flashLight),
onCheckedChange = {
updatePreferences(
preferencesState.preferences.copy(
flashLight = it
)
)
}
)

SettingsListDropdown(
modifier = Modifier.height(space100),
state = rememberIntSettingState(defaultValue = preferencesState.preferences.autoSilenceTime.ordinal),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<string name="settings_screen_snooze_title">Snooze</string>
<string name="settings_screen_snooze_subtitle">Allow alarms to be snoozed</string>
<string name="settings_screen_delete_title">Delete</string>
<string name="settings_screen_flash_light_title">Flashlight</string>
<string name="settings_screen_flash_light_subtitle">Strobe light when alarms go off</string>
<string name="settings_screen_delete_subtitle">Alarms are deleted after they go off</string>
<string name="settings_screen_snooze_duration_title">Snooze duration</string>
<string name="settings_screen_auto_silence_title">Auto silence</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class PreferencesEntityImplTest {
autoRestartTimer = true,
timerSoundPath = "",
gradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
flashLight = false
)
val preferencesSlot = slot<PreferencesEntity>()
coEvery { preferencesDao.insert(any()) } returns mockk()
Expand Down Expand Up @@ -142,7 +143,8 @@ class PreferencesEntityImplTest {
autoRestartTimer = true,
timerSoundPath = "",
gradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
flashLight = false
)
val preferencesSlot = slot<PreferencesEntity>()
coEvery { preferencesDao.updatePreferences(any()) } returns mockk()
Expand Down
Binary file modified core/database/src/main/assets/database/preferences.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class DatabaseModule {
context,
PreferencesDatabase::class.java,
"preferences_database"
).createFromAsset("database/preferences.db").build()
).createFromAsset("database/preferences.db")
.build()

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ data class PreferencesEntity(
val autoRestartTimer: Boolean = true,
val timerSoundPath: String = "",
val gradualSoundDuration: GradualSoundDuration,
val timerGradualSoundDuration: GradualSoundDuration
val timerGradualSoundDuration: GradualSoundDuration,
val flashLight: Boolean = false
)

fun PreferencesEntity.asExternalModel() = Preferences(
Expand All @@ -56,7 +57,8 @@ fun PreferencesEntity.asExternalModel() = Preferences(
autoRestartTimer = autoRestartTimer,
timerSoundPath = timerSoundPath,
gradualSoundDuration = gradualSoundDuration,
timerGradualSoundDuration = timerGradualSoundDuration
timerGradualSoundDuration = timerGradualSoundDuration,
flashLight = flashLight
)

fun Preferences.asInternalModel() = PreferencesEntity(
Expand All @@ -79,5 +81,6 @@ fun Preferences.asInternalModel() = PreferencesEntity(
autoRestartTimer = autoRestartTimer,
timerSoundPath = timerSoundPath,
gradualSoundDuration = gradualSoundDuration,
timerGradualSoundDuration = timerGradualSoundDuration
timerGradualSoundDuration = timerGradualSoundDuration,
flashLight = flashLight
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalView
Expand Down Expand Up @@ -293,8 +292,7 @@ fun WhakaaraTheme(
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ data class Preferences(
val autoRestartTimer: Boolean,
val timerSoundPath: String,
val gradualSoundDuration: GradualSoundDuration,
val timerGradualSoundDuration: GradualSoundDuration
val timerGradualSoundDuration: GradualSoundDuration,
val flashLight: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class PreferencesState(
autoRestartTimer = true,
timerSoundPath = "",
gradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
flashLight = false
)
)
3 changes: 2 additions & 1 deletion core/test/src/main/java/com/whakaara/test/MockUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ object MockUtil {
autoRestartTimer = true,
timerSoundPath = "",
gradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER
timerGradualSoundDuration = GradualSoundDuration.GRADUAL_INCREASE_DURATION_NEVER,
flashLight = false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun AlarmRoute(
create = viewModel::create,
delete = viewModel::delete,
disable = viewModel::disable,
enable = viewModel::disable,
enable = viewModel::enable,
reset = viewModel::reset,
getInitialTimeToAlarm = viewModel::getInitialTimeToAlarm,
getTimeUntilAlarmFormatted = viewModel::getTimeUntilAlarmFormatted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.app.AlarmManager
import android.app.Application
import android.app.PendingIntent
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
Expand All @@ -13,6 +12,7 @@ import com.chargemap.compose.numberpicker.Hours
import com.whakaara.core.LogUtils.logD
import com.whakaara.core.PendingIntentUtils
import com.whakaara.core.WidgetUpdater
import com.whakaara.core.constants.GeneralConstants.MAIN_ACTIVITY
import com.whakaara.core.constants.NotificationUtilsConstants
import com.whakaara.core.di.IoDispatcher
import com.whakaara.data.alarm.AlarmRepository
Expand Down Expand Up @@ -327,13 +327,18 @@ class AlarmViewModel @Inject constructor(
PendingIntent.FLAG_UPDATE_CURRENT
)

val deepLinkIntent = Intent(Intent.ACTION_VIEW).apply {
setClassName(
app.applicationContext.packageName,
MAIN_ACTIVITY
)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}

val alarmInfoPendingIntent = PendingIntentUtils.getActivity(
app,
NotificationUtilsConstants.INTENT_REQUEST_CODE,
Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("app://mainactivity")
flags = Intent.FLAG_ACTIVITY_NEW_TASK
},
deepLinkIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)

Expand All @@ -352,7 +357,7 @@ class AlarmViewModel @Inject constructor(
}
}

fun setUpcomingAlarm(
private fun setUpcomingAlarm(
alarmId: String,
alarmDate: Calendar,
upcomingAlarmNotificationEnabled: Boolean,
Expand Down Expand Up @@ -429,7 +434,7 @@ class AlarmViewModel @Inject constructor(
widgetUpdater.updateWidget()
}

fun cancelUpcomingAlarm(
private fun cancelUpcomingAlarm(
alarmId: String,
alarmDate: Calendar
) {
Expand Down
Loading
Loading