Testing
15
.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
Smart Alarm
|
||||
6
.idea/AndroidProjectSystem.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AndroidProjectSystem">
|
||||
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
||||
</component>
|
||||
</project>
|
||||
26
.idea/appInsightsSettings.xml
generated
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AppInsightsSettings">
|
||||
<option name="tabSettings">
|
||||
<map>
|
||||
<entry key="Firebase Crashlytics">
|
||||
<value>
|
||||
<InsightsFilterSettings>
|
||||
<option name="connection">
|
||||
<ConnectionSetting>
|
||||
<option name="appId" value="PLACEHOLDER" />
|
||||
<option name="mobileSdkAppId" value="" />
|
||||
<option name="projectId" value="" />
|
||||
<option name="projectNumber" value="" />
|
||||
</ConnectionSetting>
|
||||
</option>
|
||||
<option name="signal" value="SIGNAL_UNSPECIFIED" />
|
||||
<option name="timeIntervalDays" value="THIRTY_DAYS" />
|
||||
<option name="visibilityType" value="ALL" />
|
||||
</InsightsFilterSettings>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/deploymentTargetSelector.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetSelector">
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
</project>
|
||||
13
.idea/deviceManager.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DeviceTable">
|
||||
<option name="columnSorters">
|
||||
<list>
|
||||
<ColumnSorterState>
|
||||
<option name="column" value="Name" />
|
||||
<option name="order" value="ASCENDING" />
|
||||
</ColumnSorterState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
19
.idea/gradle.xml
generated
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
61
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,61 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
10
.idea/migrations.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectMigrations">
|
||||
<option name="MigrateToGradleLocalJavaHome">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
9
.idea/misc.xml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
17
.idea/runConfigurations.xml
generated
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
|
||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
|
||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
||||
86
app/build.gradle.kts
Normal file
@ -0,0 +1,86 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("com.google.devtools.ksp")
|
||||
id("kotlin-parcelize")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.example.smartalarm"
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.example.smartalarm"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
dataBinding = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Core Android
|
||||
implementation("androidx.core:core-ktx:1.12.0")
|
||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||
implementation("com.google.android.material:material:1.11.0")
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
|
||||
// Lifecycle & ViewModel
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
|
||||
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
|
||||
|
||||
// Navigation
|
||||
implementation("androidx.navigation:navigation-fragment-ktx:2.7.6")
|
||||
implementation("androidx.navigation:navigation-ui-ktx:2.7.6")
|
||||
|
||||
// Room Database
|
||||
implementation("androidx.room:room-runtime:2.6.1")
|
||||
implementation("androidx.room:room-ktx:2.6.1")
|
||||
ksp("androidx.room:room-compiler:2.6.1")
|
||||
|
||||
// DataStore
|
||||
implementation("androidx.datastore:datastore-preferences:1.0.0")
|
||||
|
||||
// Coroutines
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
|
||||
|
||||
// WorkManager (untuk alarm yang lebih reliable)
|
||||
implementation("androidx.work:work-runtime-ktx:2.9.0")
|
||||
|
||||
// Chart/Graph (untuk statistik)
|
||||
implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
|
||||
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
|
||||
// Testing
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
}
|
||||
22
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
-keepattributes *Annotation*
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
-keep public class * extends java.lang.Exception
|
||||
|
||||
# Room
|
||||
-keep class * extends androidx.room.RoomDatabase
|
||||
-keep @androidx.room.Entity class *
|
||||
-dontwarn androidx.room.paging.**
|
||||
|
||||
# Kotlin
|
||||
-keep class kotlin.** { *; }
|
||||
-keep class org.jetbrains.** { *; }
|
||||
|
||||
# Coroutines
|
||||
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
|
||||
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
|
||||
|
||||
# DataStore
|
||||
-keepclassmembers class * extends androidx.datastore.preferences.protobuf.GeneratedMessageLite {
|
||||
<fields>;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.example.smartalarm
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.example.smartalarm", appContext.packageName)
|
||||
}
|
||||
}
|
||||
87
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<!-- Permissions -->
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
|
||||
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||
|
||||
<application
|
||||
android:name=".AlarmApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.SmartAlarm"
|
||||
tools:targetApi="31">
|
||||
|
||||
<!-- Main Activity -->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.SmartAlarm">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Alarm Ring Activity -->
|
||||
<activity
|
||||
android:name=".ui.alarm.AlarmRingActivity"
|
||||
android:exported="false"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:showOnLockScreen="true"
|
||||
android:showWhenLocked="true"
|
||||
android:turnScreenOn="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.SmartAlarm.FullScreen"/>
|
||||
|
||||
<!-- Alarm Service -->
|
||||
<service
|
||||
android:name=".service.AlarmService"
|
||||
android:exported="false"
|
||||
android:enabled="true"
|
||||
android:foregroundServiceType="mediaPlayback"
|
||||
android:stopWithTask="false"/>
|
||||
|
||||
<!-- Alarm Receiver -->
|
||||
<receiver
|
||||
android:name=".service.AlarmReceiver"
|
||||
android:exported="false"
|
||||
android:enabled="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- Boot Receiver (to reschedule alarms after reboot) -->
|
||||
<receiver
|
||||
android:name=".service.BootReceiver"
|
||||
android:exported="true"
|
||||
android:enabled="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
15
app/src/main/java/com/example/smartalarm/AlarmApplication.kt
Normal file
@ -0,0 +1,15 @@
|
||||
// AlarmApplication.kt
|
||||
package com.example.smartalarm
|
||||
|
||||
import android.app.Application
|
||||
import com.example.smartalarm.utils.NotificationHelper
|
||||
|
||||
class AlarmApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
// Initialize notification channel
|
||||
NotificationHelper.createNotificationChannel(this)
|
||||
}
|
||||
}
|
||||
159
app/src/main/java/com/example/smartalarm/MainActivity.kt
Normal file
@ -0,0 +1,159 @@
|
||||
package com.example.smartalarm
|
||||
|
||||
import android.Manifest
|
||||
import android.app.AlarmManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.example.smartalarm.databinding.ActivityMainBinding
|
||||
import com.example.smartalarm.utils.NotificationHelper
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
|
||||
companion object {
|
||||
private const val PERMISSION_REQUEST_CODE = 100
|
||||
private const val EXACT_ALARM_PERMISSION_REQUEST = 101
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setupNavigation()
|
||||
requestNecessaryPermissions()
|
||||
checkExactAlarmPermission()
|
||||
checkBatteryOptimization()
|
||||
NotificationHelper.createNotificationChannel(this)
|
||||
}
|
||||
|
||||
private fun checkBatteryOptimization() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
val pm = getSystemService(Context.POWER_SERVICE) as android.os.PowerManager
|
||||
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Battery Optimization")
|
||||
.setMessage("For reliable alarms, please disable battery optimization for this app.")
|
||||
.setPositiveButton("Open Settings") { _, _ ->
|
||||
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
||||
data = Uri.parse("package:$packageName")
|
||||
}
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Later", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupNavigation() {
|
||||
val navHostFragment = supportFragmentManager
|
||||
.findFragmentById(R.id.navHostFragment) as NavHostFragment
|
||||
val navController = navHostFragment.navController
|
||||
|
||||
binding.bottomNavigation.setupWithNavController(navController)
|
||||
}
|
||||
|
||||
private fun checkExactAlarmPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
if (!alarmManager.canScheduleExactAlarms()) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Permission Required")
|
||||
.setMessage("This app needs permission to schedule exact alarms. Please grant the permission in settings.")
|
||||
.setPositiveButton("Open Settings") { _, _ ->
|
||||
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM).apply {
|
||||
data = Uri.parse("package:$packageName")
|
||||
}
|
||||
startActivityForResult(intent, EXACT_ALARM_PERMISSION_REQUEST)
|
||||
}
|
||||
.setNegativeButton("Cancel", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestNecessaryPermissions() {
|
||||
val permissions = mutableListOf<String>()
|
||||
|
||||
// Notification permission for Android 13+
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
permissions.add(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
}
|
||||
|
||||
// Add other permissions if needed
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.VIBRATE
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
permissions.add(Manifest.permission.VIBRATE)
|
||||
}
|
||||
|
||||
if (permissions.isNotEmpty()) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
permissions.toTypedArray(),
|
||||
PERMISSION_REQUEST_CODE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
|
||||
if (requestCode == PERMISSION_REQUEST_CODE) {
|
||||
if (grantResults.any { it != PackageManager.PERMISSION_GRANTED }) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Permissions Required")
|
||||
.setMessage("This app needs notification and vibration permissions to function properly.")
|
||||
.setPositiveButton("OK", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
|
||||
if (requestCode == EXACT_ALARM_PERMISSION_REQUEST) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
if (!alarmManager.canScheduleExactAlarms()) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Permission Denied")
|
||||
.setMessage("Without exact alarm permission, alarms may not work reliably.")
|
||||
.setPositiveButton("OK", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package com.example.smartalarm.data.datastore
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.*
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
|
||||
|
||||
class PreferencesManager(private val context: Context) {
|
||||
|
||||
companion object {
|
||||
val SHAKE_SENSITIVITY = intPreferencesKey("shake_sensitivity")
|
||||
val GRADUAL_MODE_DURATION = intPreferencesKey("gradual_mode_duration")
|
||||
val DEFAULT_RINGTONE = stringPreferencesKey("default_ringtone")
|
||||
val VIBRATE_DEFAULT = booleanPreferencesKey("vibrate_default")
|
||||
val SNOOZE_DURATION = intPreferencesKey("snooze_duration")
|
||||
val THEME_MODE = stringPreferencesKey("theme_mode")
|
||||
}
|
||||
|
||||
val shakeSensitivity: Flow<Int> = context.dataStore.data
|
||||
.map { it[SHAKE_SENSITIVITY] ?: 3 }
|
||||
|
||||
val gradualModeDuration: Flow<Int> = context.dataStore.data
|
||||
.map { it[GRADUAL_MODE_DURATION] ?: 300 } // 5 minutes in seconds
|
||||
|
||||
val defaultRingtone: Flow<String> = context.dataStore.data
|
||||
.map { it[DEFAULT_RINGTONE] ?: "" }
|
||||
|
||||
val vibrateDefault: Flow<Boolean> = context.dataStore.data
|
||||
.map { it[VIBRATE_DEFAULT] ?: true }
|
||||
|
||||
val snoozeDuration: Flow<Int> = context.dataStore.data
|
||||
.map { it[SNOOZE_DURATION] ?: 5 }
|
||||
|
||||
val themeMode: Flow<String> = context.dataStore.data
|
||||
.map { it[THEME_MODE] ?: "system" }
|
||||
|
||||
suspend fun updateShakeSensitivity(value: Int) {
|
||||
context.dataStore.edit { it[SHAKE_SENSITIVITY] = value }
|
||||
}
|
||||
|
||||
suspend fun updateGradualModeDuration(value: Int) {
|
||||
context.dataStore.edit { it[GRADUAL_MODE_DURATION] = value }
|
||||
}
|
||||
|
||||
suspend fun updateDefaultRingtone(uri: String) {
|
||||
context.dataStore.edit { it[DEFAULT_RINGTONE] = uri }
|
||||
}
|
||||
|
||||
suspend fun updateVibrateDefault(value: Boolean) {
|
||||
context.dataStore.edit { it[VIBRATE_DEFAULT] = value }
|
||||
}
|
||||
|
||||
suspend fun updateSnoozeDuration(value: Int) {
|
||||
context.dataStore.edit { it[SNOOZE_DURATION] = value }
|
||||
}
|
||||
|
||||
suspend fun updateThemeMode(mode: String) {
|
||||
context.dataStore.edit { it[THEME_MODE] = mode }
|
||||
}
|
||||
}
|
||||
32
app/src/main/java/com/example/smartalarm/data/db/AlarmDao.kt
Normal file
@ -0,0 +1,32 @@
|
||||
package com.example.smartalarm.data.db
|
||||
|
||||
import androidx.room.*
|
||||
import com.example.smartalarm.data.db.entities.AlarmEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface AlarmDao {
|
||||
@Query("SELECT * FROM alarms ORDER BY hour, minute")
|
||||
fun getAllAlarms(): Flow<List<AlarmEntity>>
|
||||
|
||||
@Query("SELECT * FROM alarms WHERE id = :id")
|
||||
suspend fun getAlarmById(id: Long): AlarmEntity?
|
||||
|
||||
@Query("SELECT * FROM alarms WHERE isEnabled = 1")
|
||||
fun getEnabledAlarms(): Flow<List<AlarmEntity>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAlarm(alarm: AlarmEntity): Long
|
||||
|
||||
@Update
|
||||
suspend fun updateAlarm(alarm: AlarmEntity)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteAlarm(alarm: AlarmEntity)
|
||||
|
||||
@Query("DELETE FROM alarms WHERE id = :id")
|
||||
suspend fun deleteAlarmById(id: Long)
|
||||
|
||||
@Query("UPDATE alarms SET isEnabled = :enabled WHERE id = :id")
|
||||
suspend fun updateAlarmEnabled(id: Long, enabled: Boolean)
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.example.smartalarm.data.db
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.example.smartalarm.data.db.entities.AlarmEntity
|
||||
import com.example.smartalarm.data.db.entities.StatisticsEntity
|
||||
|
||||
@Database(
|
||||
entities = [AlarmEntity::class, StatisticsEntity::class],
|
||||
version = 1,
|
||||
exportSchema = false
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlarmDatabase : RoomDatabase() {
|
||||
abstract fun alarmDao(): AlarmDao
|
||||
abstract fun statisticsDao(): StatisticsDao
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: AlarmDatabase? = null
|
||||
|
||||
fun getDatabase(context: Context): AlarmDatabase {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
val instance = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
AlarmDatabase::class.java,
|
||||
"smart_alarm_database"
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
INSTANCE = instance
|
||||
instance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.example.smartalarm.data.db
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
class Converters {
|
||||
private val gson = Gson()
|
||||
|
||||
@TypeConverter
|
||||
fun fromIntList(value: List<Int>): String {
|
||||
return gson.toJson(value)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toIntList(value: String): List<Int> {
|
||||
val type = object : TypeToken<List<Int>>() {}.type
|
||||
return gson.fromJson(value, type) ?: emptyList()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.example.smartalarm.data.db
|
||||
|
||||
import androidx.room.*
|
||||
import com.example.smartalarm.data.db.entities.StatisticsEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface StatisticsDao {
|
||||
@Query("SELECT * FROM statistics ORDER BY triggeredAt DESC LIMIT 100")
|
||||
fun getAllStatistics(): Flow<List<StatisticsEntity>>
|
||||
|
||||
@Query("SELECT * FROM statistics WHERE alarmId = :alarmId ORDER BY triggeredAt DESC")
|
||||
fun getStatisticsByAlarmId(alarmId: Long): Flow<List<StatisticsEntity>>
|
||||
|
||||
@Query("SELECT * FROM statistics WHERE triggeredAt >= :startTime")
|
||||
fun getStatisticsSince(startTime: Long): Flow<List<StatisticsEntity>>
|
||||
|
||||
@Insert
|
||||
suspend fun insertStatistics(stats: StatisticsEntity): Long
|
||||
|
||||
@Update
|
||||
suspend fun updateStatistics(stats: StatisticsEntity)
|
||||
|
||||
@Query("DELETE FROM statistics WHERE triggeredAt < :beforeTime")
|
||||
suspend fun deleteOldStatistics(beforeTime: Long)
|
||||
|
||||
@Query("SELECT COUNT(*) FROM statistics WHERE alarmId = :alarmId AND stopMethod = 'shake'")
|
||||
suspend fun getShakeStopCount(alarmId: Long): Int
|
||||
|
||||
@Query("SELECT AVG(snoozedCount) FROM statistics WHERE alarmId = :alarmId")
|
||||
suspend fun getAverageSnoozedCount(alarmId: Long): Float?
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.example.smartalarm.data.db.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
import com.example.smartalarm.data.db.Converters
|
||||
|
||||
@Entity(tableName = "alarms")
|
||||
@TypeConverters(Converters::class)
|
||||
data class AlarmEntity(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val id: Long = 0,
|
||||
val hour: Int,
|
||||
val minute: Int,
|
||||
val label: String = "",
|
||||
val isEnabled: Boolean = true,
|
||||
val repeatDays: List<Int> = emptyList(), // 0=Sun, 1=Mon, ..., 6=Sat
|
||||
val ringtoneUri: String = "",
|
||||
val vibrate: Boolean = true,
|
||||
val shakeToStop: Boolean = false,
|
||||
val shakeIntensity: Int = 3, // 1-5
|
||||
val gradualMode: Boolean = false,
|
||||
val snoozeEnabled: Boolean = true,
|
||||
val snoozeDuration: Int = 5, // minutes
|
||||
val createdAt: Long = System.currentTimeMillis()
|
||||
)
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.smartalarm.data.db.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "statistics")
|
||||
data class StatisticsEntity(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val id: Long = 0,
|
||||
val alarmId: Long,
|
||||
val triggeredAt: Long,
|
||||
val stoppedAt: Long? = null,
|
||||
val snoozedCount: Int = 0,
|
||||
val stopMethod: String = "unknown" // "button", "shake", "timeout"
|
||||
)
|
||||
34
app/src/main/java/com/example/smartalarm/data/model/Alarm.kt
Normal file
@ -0,0 +1,34 @@
|
||||
package com.example.smartalarm.data.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class Alarm(
|
||||
val id: Long = 0,
|
||||
val hour: Int,
|
||||
val minute: Int,
|
||||
val label: String = "",
|
||||
val isEnabled: Boolean = true,
|
||||
val repeatDays: List<Int> = emptyList(),
|
||||
val ringtoneUri: String = "",
|
||||
val vibrate: Boolean = true,
|
||||
val shakeToStop: Boolean = false,
|
||||
val shakeIntensity: Int = 3,
|
||||
val gradualMode: Boolean = false,
|
||||
val snoozeEnabled: Boolean = true,
|
||||
val snoozeDuration: Int = 5,
|
||||
val createdAt: Long = System.currentTimeMillis()
|
||||
) : Parcelable {
|
||||
fun getTimeString(): String {
|
||||
return String.format("%02d:%02d", hour, minute)
|
||||
}
|
||||
|
||||
fun getRepeatDaysString(): String {
|
||||
if (repeatDays.isEmpty()) return "Once"
|
||||
if (repeatDays.size == 7) return "Every day"
|
||||
|
||||
val days = listOf("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
|
||||
return repeatDays.sorted().joinToString(", ") { days[it] }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package com.example.smartalarm.data.model
|
||||
|
||||
enum class AlarmMode {
|
||||
VIBRATE_ONLY,
|
||||
SOUND_ONLY,
|
||||
VIBRATE_THEN_SOUND,
|
||||
GRADUAL // progressive volume
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.example.smartalarm.data.model
|
||||
|
||||
data class AlarmPreset(
|
||||
val name: String,
|
||||
val hour: Int,
|
||||
val minute: Int,
|
||||
val label: String,
|
||||
val repeatDays: List<Int>,
|
||||
val shakeToStop: Boolean = false,
|
||||
val gradualMode: Boolean = false
|
||||
) {
|
||||
companion object {
|
||||
fun getDefaultPresets(): List<AlarmPreset> {
|
||||
return listOf(
|
||||
AlarmPreset("Morning", 6, 30, "Wake Up", listOf(1, 2, 3, 4, 5), true, true),
|
||||
AlarmPreset("Work Start", 8, 0, "Work Time", listOf(1, 2, 3, 4, 5), false, false),
|
||||
AlarmPreset("Lunch", 12, 0, "Lunch Break", listOf(1, 2, 3, 4, 5), false, false),
|
||||
AlarmPreset("Afternoon Nap", 14, 0, "Power Nap", emptyList(), false, false),
|
||||
AlarmPreset("Evening", 18, 0, "Finish Work", listOf(1, 2, 3, 4, 5), false, false),
|
||||
AlarmPreset("Night", 22, 0, "Sleep Time", emptyList(), false, true)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.example.smartalarm.data.model
|
||||
|
||||
data class ShakePattern(
|
||||
val shakeCount: Int = 0,
|
||||
val intensity: Float = 0f,
|
||||
val duration: Long = 0L
|
||||
) {
|
||||
fun isValid(requiredIntensity: Int): Boolean {
|
||||
return shakeCount >= requiredIntensity && intensity >= requiredIntensity * 2f
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.smartalarm.data.model
|
||||
|
||||
data class Statistics(
|
||||
val id: Long = 0,
|
||||
val alarmId: Long,
|
||||
val triggeredAt: Long,
|
||||
val stoppedAt: Long? = null,
|
||||
val snoozedCount: Int = 0,
|
||||
val stopMethod: String = "unknown"
|
||||
) {
|
||||
fun getDurationMinutes(): Int {
|
||||
if (stoppedAt == null) return 0
|
||||
return ((stoppedAt - triggeredAt) / 60000).toInt()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.example.smartalarm.data.repository
|
||||
|
||||
import com.example.smartalarm.data.db.AlarmDao
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.domain.mapper.AlarmMapper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class AlarmRepository(private val alarmDao: AlarmDao) {
|
||||
|
||||
val allAlarms: Flow<List<Alarm>> = alarmDao.getAllAlarms()
|
||||
.map { entities -> entities.map { AlarmMapper.toDomain(it) } }
|
||||
|
||||
val enabledAlarms: Flow<List<Alarm>> = alarmDao.getEnabledAlarms()
|
||||
.map { entities -> entities.map { AlarmMapper.toDomain(it) } }
|
||||
|
||||
suspend fun getAlarmById(id: Long): Alarm? {
|
||||
return alarmDao.getAlarmById(id)?.let { AlarmMapper.toDomain(it) }
|
||||
}
|
||||
|
||||
suspend fun insertAlarm(alarm: Alarm): Long {
|
||||
return alarmDao.insertAlarm(AlarmMapper.toEntity(alarm))
|
||||
}
|
||||
|
||||
suspend fun updateAlarm(alarm: Alarm) {
|
||||
alarmDao.updateAlarm(AlarmMapper.toEntity(alarm))
|
||||
}
|
||||
|
||||
suspend fun deleteAlarm(alarm: Alarm) {
|
||||
alarmDao.deleteAlarm(AlarmMapper.toEntity(alarm))
|
||||
}
|
||||
|
||||
suspend fun deleteAlarmById(id: Long) {
|
||||
alarmDao.deleteAlarmById(id)
|
||||
}
|
||||
|
||||
suspend fun updateAlarmEnabled(id: Long, enabled: Boolean) {
|
||||
alarmDao.updateAlarmEnabled(id, enabled)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.example.smartalarm.data.repository
|
||||
|
||||
import com.example.smartalarm.data.db.StatisticsDao
|
||||
import com.example.smartalarm.data.model.Statistics
|
||||
import com.example.smartalarm.domain.mapper.AlarmMapper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class StatisticsRepository(private val statisticsDao: StatisticsDao) {
|
||||
|
||||
val allStatistics: Flow<List<Statistics>> = statisticsDao.getAllStatistics()
|
||||
.map { entities -> entities.map { AlarmMapper.statisticsToDomain(it) } }
|
||||
|
||||
fun getStatisticsByAlarmId(alarmId: Long): Flow<List<Statistics>> {
|
||||
return statisticsDao.getStatisticsByAlarmId(alarmId)
|
||||
.map { entities -> entities.map { AlarmMapper.statisticsToDomain(it) } }
|
||||
}
|
||||
|
||||
fun getStatisticsSince(startTime: Long): Flow<List<Statistics>> {
|
||||
return statisticsDao.getStatisticsSince(startTime)
|
||||
.map { entities -> entities.map { AlarmMapper.statisticsToDomain(it) } }
|
||||
}
|
||||
|
||||
suspend fun insertStatistics(stats: Statistics): Long {
|
||||
return statisticsDao.insertStatistics(AlarmMapper.statisticsToEntity(stats))
|
||||
}
|
||||
|
||||
suspend fun updateStatistics(stats: Statistics) {
|
||||
statisticsDao.updateStatistics(AlarmMapper.statisticsToEntity(stats))
|
||||
}
|
||||
|
||||
suspend fun deleteOldStatistics(beforeTime: Long) {
|
||||
statisticsDao.deleteOldStatistics(beforeTime)
|
||||
}
|
||||
|
||||
suspend fun getShakeStopCount(alarmId: Long): Int {
|
||||
return statisticsDao.getShakeStopCount(alarmId)
|
||||
}
|
||||
|
||||
suspend fun getAverageSnoozedCount(alarmId: Long): Float {
|
||||
return statisticsDao.getAverageSnoozedCount(alarmId) ?: 0f
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package com.example.smartalarm.domain.mapper
|
||||
|
||||
import com.example.smartalarm.data.db.entities.AlarmEntity
|
||||
import com.example.smartalarm.data.db.entities.StatisticsEntity
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.data.model.Statistics
|
||||
|
||||
object AlarmMapper {
|
||||
fun toEntity(alarm: Alarm): AlarmEntity {
|
||||
return AlarmEntity(
|
||||
id = alarm.id,
|
||||
hour = alarm.hour,
|
||||
minute = alarm.minute,
|
||||
label = alarm.label,
|
||||
isEnabled = alarm.isEnabled,
|
||||
repeatDays = alarm.repeatDays,
|
||||
ringtoneUri = alarm.ringtoneUri,
|
||||
vibrate = alarm.vibrate,
|
||||
shakeToStop = alarm.shakeToStop,
|
||||
shakeIntensity = alarm.shakeIntensity,
|
||||
gradualMode = alarm.gradualMode,
|
||||
snoozeEnabled = alarm.snoozeEnabled,
|
||||
snoozeDuration = alarm.snoozeDuration,
|
||||
createdAt = alarm.createdAt
|
||||
)
|
||||
}
|
||||
|
||||
fun toDomain(entity: AlarmEntity): Alarm {
|
||||
return Alarm(
|
||||
id = entity.id,
|
||||
hour = entity.hour,
|
||||
minute = entity.minute,
|
||||
label = entity.label,
|
||||
isEnabled = entity.isEnabled,
|
||||
repeatDays = entity.repeatDays,
|
||||
ringtoneUri = entity.ringtoneUri,
|
||||
vibrate = entity.vibrate,
|
||||
shakeToStop = entity.shakeToStop,
|
||||
shakeIntensity = entity.shakeIntensity,
|
||||
gradualMode = entity.gradualMode,
|
||||
snoozeEnabled = entity.snoozeEnabled,
|
||||
snoozeDuration = entity.snoozeDuration,
|
||||
createdAt = entity.createdAt
|
||||
)
|
||||
}
|
||||
|
||||
fun statisticsToEntity(stats: Statistics): StatisticsEntity {
|
||||
return StatisticsEntity(
|
||||
id = stats.id,
|
||||
alarmId = stats.alarmId,
|
||||
triggeredAt = stats.triggeredAt,
|
||||
stoppedAt = stats.stoppedAt,
|
||||
snoozedCount = stats.snoozedCount,
|
||||
stopMethod = stats.stopMethod
|
||||
)
|
||||
}
|
||||
|
||||
fun statisticsToDomain(entity: StatisticsEntity): Statistics {
|
||||
return Statistics(
|
||||
id = entity.id,
|
||||
alarmId = entity.alarmId,
|
||||
triggeredAt = entity.triggeredAt,
|
||||
stoppedAt = entity.stoppedAt,
|
||||
snoozedCount = entity.snoozedCount,
|
||||
stopMethod = entity.stopMethod
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.example.smartalarm.domain.usecase
|
||||
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.data.repository.AlarmRepository
|
||||
|
||||
class AddAlarmUseCase(private val repository: AlarmRepository) {
|
||||
suspend operator fun invoke(alarm: Alarm): Long {
|
||||
return repository.insertAlarm(alarm)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.example.smartalarm.domain.usecase
|
||||
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.data.repository.AlarmRepository
|
||||
|
||||
class DeleteAlarmUseCase(private val repository: AlarmRepository) {
|
||||
suspend operator fun invoke(alarm: Alarm) {
|
||||
repository.deleteAlarm(alarm)
|
||||
}
|
||||
|
||||
suspend fun byId(id: Long) {
|
||||
repository.deleteAlarmById(id)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.smartalarm.domain.usecase
|
||||
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.data.repository.AlarmRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class GetAllAlarmsUseCase(private val repository: AlarmRepository) {
|
||||
operator fun invoke(): Flow<List<Alarm>> {
|
||||
return repository.allAlarms
|
||||
}
|
||||
|
||||
fun getEnabled(): Flow<List<Alarm>> {
|
||||
return repository.enabledAlarms
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.example.smartalarm.domain.usecase
|
||||
|
||||
import com.example.smartalarm.data.model.AlarmPreset
|
||||
|
||||
class GetPresetsUseCase {
|
||||
operator fun invoke(): List<AlarmPreset> {
|
||||
return AlarmPreset.getDefaultPresets()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.example.smartalarm.domain.usecase
|
||||
|
||||
import com.example.smartalarm.data.model.Statistics
|
||||
import com.example.smartalarm.data.repository.StatisticsRepository
|
||||
|
||||
class SaveStatisticsUseCase(private val repository: StatisticsRepository) {
|
||||
suspend operator fun invoke(stats: Statistics): Long {
|
||||
return repository.insertStatistics(stats)
|
||||
}
|
||||
|
||||
suspend fun update(stats: Statistics) {
|
||||
repository.updateStatistics(stats)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.example.smartalarm.domain.usecase
|
||||
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.data.repository.AlarmRepository
|
||||
|
||||
class UpdateAlarmUseCase(private val repository: AlarmRepository) {
|
||||
suspend operator fun invoke(alarm: Alarm) {
|
||||
repository.updateAlarm(alarm)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.example.smartalarm.service
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
class AlarmReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val alarmId = intent.getLongExtra("ALARM_ID", -1)
|
||||
if (alarmId == -1L) return
|
||||
|
||||
val serviceIntent = Intent(context, AlarmService::class.java).apply {
|
||||
putExtras(intent)
|
||||
}
|
||||
|
||||
context.startForegroundService(serviceIntent)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
package com.example.smartalarm.service
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import java.util.*
|
||||
|
||||
class AlarmScheduler(private val context: Context) {
|
||||
|
||||
private val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
fun scheduleAlarm(alarm: Alarm) {
|
||||
val intent = Intent(context, AlarmReceiver::class.java).apply {
|
||||
putExtra("ALARM_ID", alarm.id)
|
||||
putExtra("ALARM_LABEL", alarm.label)
|
||||
putExtra("SHAKE_TO_STOP", alarm.shakeToStop)
|
||||
putExtra("SHAKE_INTENSITY", alarm.shakeIntensity)
|
||||
putExtra("GRADUAL_MODE", alarm.gradualMode)
|
||||
putExtra("VIBRATE", alarm.vibrate)
|
||||
putExtra("RINGTONE_URI", alarm.ringtoneUri)
|
||||
}
|
||||
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
alarm.id.toInt(),
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
val calendar = getAlarmCalendar(alarm)
|
||||
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (alarmManager.canScheduleExactAlarms()) {
|
||||
alarmManager.setAlarmClock(
|
||||
AlarmManager.AlarmClockInfo(calendar.timeInMillis, pendingIntent),
|
||||
pendingIntent
|
||||
)
|
||||
} else {
|
||||
// Fallback to inexact alarm
|
||||
alarmManager.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
calendar.timeInMillis,
|
||||
pendingIntent
|
||||
)
|
||||
}
|
||||
} else {
|
||||
alarmManager.setAlarmClock(
|
||||
AlarmManager.AlarmClockInfo(calendar.timeInMillis, pendingIntent),
|
||||
pendingIntent
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// Final fallback
|
||||
alarmManager.set(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
calendar.timeInMillis,
|
||||
pendingIntent
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelAlarm(alarmId: Long) {
|
||||
val intent = Intent(context, AlarmReceiver::class.java)
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
alarmId.toInt(),
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
alarmManager.cancel(pendingIntent)
|
||||
}
|
||||
|
||||
private fun getAlarmCalendar(alarm: Alarm): Calendar {
|
||||
val calendar = Calendar.getInstance().apply {
|
||||
set(Calendar.HOUR_OF_DAY, alarm.hour)
|
||||
set(Calendar.MINUTE, alarm.minute)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
}
|
||||
|
||||
// If alarm time has passed today, schedule for tomorrow
|
||||
if (calendar.timeInMillis <= System.currentTimeMillis()) {
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1)
|
||||
}
|
||||
|
||||
return calendar
|
||||
}
|
||||
}
|
||||
334
app/src/main/java/com/example/smartalarm/service/AlarmService.kt
Normal file
@ -0,0 +1,334 @@
|
||||
package com.example.smartalarm.service
|
||||
|
||||
import android.app.*
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioManager
|
||||
import android.media.MediaPlayer
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.*
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.example.smartalarm.ui.alarm.AlarmRingActivity
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
class AlarmService : Service() {
|
||||
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
private var vibrator: Vibrator? = null
|
||||
private var gradualVolumeJob: Job? = null
|
||||
private val serviceScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
|
||||
private var audioManager: AudioManager? = null
|
||||
private var shakeDetector: ShakeDetector? = null
|
||||
|
||||
private var currentAlarmId: Long = -1
|
||||
private var shakeToStop: Boolean = false
|
||||
private var shakeIntensity: Int = 3
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "alarm_channel"
|
||||
const val NOTIFICATION_ID = 1001
|
||||
const val ACTION_STOP_ALARM = "STOP_ALARM"
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
createNotificationChannel()
|
||||
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
||||
vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val vibratorManager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
||||
vibratorManager.defaultVibrator
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
when (intent?.action) {
|
||||
ACTION_STOP_ALARM -> {
|
||||
stopAlarm()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
}
|
||||
|
||||
currentAlarmId = intent?.getLongExtra("ALARM_ID", -1) ?: -1
|
||||
val label = intent?.getStringExtra("ALARM_LABEL") ?: "Alarm"
|
||||
shakeToStop = intent?.getBooleanExtra("SHAKE_TO_STOP", false) ?: false
|
||||
shakeIntensity = intent?.getIntExtra("SHAKE_INTENSITY", 3) ?: 3
|
||||
val gradualMode = intent?.getBooleanExtra("GRADUAL_MODE", false) ?: false
|
||||
val vibrate = intent?.getBooleanExtra("VIBRATE", true) ?: true
|
||||
val ringtoneUri = intent?.getStringExtra("RINGTONE_URI")
|
||||
|
||||
startForeground(NOTIFICATION_ID, createNotification(label))
|
||||
|
||||
// Set audio to max volume for alarm
|
||||
setAlarmVolume()
|
||||
|
||||
// Play ringtone
|
||||
playAlarm(ringtoneUri, gradualMode)
|
||||
|
||||
// Vibrate if enabled
|
||||
if (vibrate) {
|
||||
startVibration()
|
||||
}
|
||||
|
||||
// Start shake detector if enabled
|
||||
if (shakeToStop) {
|
||||
startShakeDetector()
|
||||
}
|
||||
|
||||
// Start alarm ring activity
|
||||
if (intent != null) {
|
||||
val activityIntent = Intent(this, AlarmRingActivity::class.java).apply {
|
||||
this.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
putExtras(intent)
|
||||
}
|
||||
startActivity(activityIntent)
|
||||
}
|
||||
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
private fun startShakeDetector() {
|
||||
shakeDetector = ShakeDetector(this) { shakeCount, intensity ->
|
||||
// Check if shake pattern is valid
|
||||
if (shakeCount >= shakeIntensity && intensity >= shakeIntensity * 2f) {
|
||||
// Broadcast to activity to update UI
|
||||
val broadcastIntent = Intent("ALARM_SHAKE_DETECTED").apply {
|
||||
putExtra("SHAKE_COUNT", shakeCount)
|
||||
putExtra("SHAKE_INTENSITY", intensity)
|
||||
}
|
||||
sendBroadcast(broadcastIntent)
|
||||
|
||||
// Stop alarm
|
||||
stopAlarmByShake()
|
||||
} else {
|
||||
// Update progress
|
||||
val progressIntent = Intent("ALARM_SHAKE_PROGRESS").apply {
|
||||
putExtra("SHAKE_COUNT", shakeCount)
|
||||
putExtra("REQUIRED_INTENSITY", shakeIntensity)
|
||||
}
|
||||
sendBroadcast(progressIntent)
|
||||
}
|
||||
}
|
||||
shakeDetector?.start()
|
||||
}
|
||||
|
||||
private fun stopAlarmByShake() {
|
||||
// Broadcast to activity that alarm stopped by shake
|
||||
val intent = Intent("ALARM_STOPPED_BY_SHAKE")
|
||||
sendBroadcast(intent)
|
||||
|
||||
stopAlarm()
|
||||
}
|
||||
|
||||
private fun setAlarmVolume() {
|
||||
try {
|
||||
audioManager?.let { am ->
|
||||
// Save current volume
|
||||
val currentVolume = am.getStreamVolume(AudioManager.STREAM_ALARM)
|
||||
val maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_ALARM)
|
||||
|
||||
// Set alarm volume to at least 70%
|
||||
val targetVolume = (maxVolume * 0.7).toInt()
|
||||
if (currentVolume < targetVolume) {
|
||||
am.setStreamVolume(
|
||||
AudioManager.STREAM_ALARM,
|
||||
targetVolume,
|
||||
0
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun playAlarm(ringtoneUriString: String?, gradual: Boolean) {
|
||||
try {
|
||||
// Stop existing player if any
|
||||
mediaPlayer?.stop()
|
||||
mediaPlayer?.release()
|
||||
mediaPlayer = null
|
||||
|
||||
val uri = if (!ringtoneUriString.isNullOrEmpty()) {
|
||||
Uri.parse(ringtoneUriString)
|
||||
} else {
|
||||
// Try alarm first, then ringtone, then notification
|
||||
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)
|
||||
?: RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
|
||||
?: RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||
}
|
||||
|
||||
mediaPlayer = MediaPlayer().apply {
|
||||
// Reset before setting data source
|
||||
reset()
|
||||
|
||||
setDataSource(applicationContext, uri)
|
||||
|
||||
setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_ALARM)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setLegacyStreamType(AudioManager.STREAM_ALARM)
|
||||
.build()
|
||||
)
|
||||
|
||||
isLooping = true
|
||||
|
||||
// Prepare first
|
||||
prepare()
|
||||
|
||||
// Set volume after prepare
|
||||
if (gradual) {
|
||||
setVolume(0.1f, 0.1f)
|
||||
} else {
|
||||
setVolume(1.0f, 1.0f)
|
||||
}
|
||||
|
||||
// Start playing
|
||||
start()
|
||||
|
||||
// Start gradual increase if enabled
|
||||
if (gradual) {
|
||||
startGradualVolumeIncrease()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// Fallback to system ringtone
|
||||
try {
|
||||
val defaultUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
|
||||
?: RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||
|
||||
mediaPlayer = MediaPlayer().apply {
|
||||
reset()
|
||||
setDataSource(applicationContext, defaultUri)
|
||||
setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_ALARM)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setLegacyStreamType(AudioManager.STREAM_ALARM)
|
||||
.build()
|
||||
)
|
||||
isLooping = true
|
||||
prepare()
|
||||
setVolume(1.0f, 1.0f)
|
||||
start()
|
||||
}
|
||||
} catch (fallbackException: Exception) {
|
||||
fallbackException.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startGradualVolumeIncrease() {
|
||||
gradualVolumeJob = serviceScope.launch {
|
||||
var volume = 0.1f
|
||||
while (volume < 1.0f && isActive) {
|
||||
delay(5000) // increase every 5 seconds
|
||||
volume += 0.15f
|
||||
if (volume > 1.0f) volume = 1.0f
|
||||
|
||||
try {
|
||||
mediaPlayer?.setVolume(volume, volume)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startVibration() {
|
||||
val pattern = longArrayOf(0, 1000, 1000) // vibrate 1s, pause 1s
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator?.vibrate(
|
||||
VibrationEffect.createWaveform(pattern, 0),
|
||||
AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_ALARM)
|
||||
.build()
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator?.vibrate(pattern, 0)
|
||||
}
|
||||
}
|
||||
|
||||
fun stopAlarm() {
|
||||
gradualVolumeJob?.cancel()
|
||||
shakeDetector?.stop()
|
||||
shakeDetector = null
|
||||
|
||||
try {
|
||||
mediaPlayer?.stop()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
mediaPlayer?.release()
|
||||
mediaPlayer = null
|
||||
vibrator?.cancel()
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
private fun createNotification(label: String): Notification {
|
||||
val intent = Intent(this, AlarmRingActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
this, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
val stopIntent = Intent(this, AlarmService::class.java).apply {
|
||||
action = ACTION_STOP_ALARM
|
||||
}
|
||||
val stopPendingIntent = PendingIntent.getService(
|
||||
this, 1, stopIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
return NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
.setContentTitle("Alarm Ringing")
|
||||
.setContentText(label)
|
||||
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setCategory(NotificationCompat.CATEGORY_ALARM)
|
||||
.setFullScreenIntent(pendingIntent, true)
|
||||
.setOngoing(true)
|
||||
.addAction(
|
||||
android.R.drawable.ic_menu_close_clear_cancel,
|
||||
"Stop",
|
||||
stopPendingIntent
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun createNotificationChannel() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = NotificationChannel(
|
||||
CHANNEL_ID,
|
||||
"Alarm Notifications",
|
||||
NotificationManager.IMPORTANCE_HIGH
|
||||
).apply {
|
||||
description = "Alarm notifications"
|
||||
setSound(null, null)
|
||||
enableVibration(true)
|
||||
setBypassDnd(true)
|
||||
}
|
||||
val notificationManager = getSystemService(NotificationManager::class.java)
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
stopAlarm()
|
||||
serviceScope.cancel()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.example.smartalarm.service
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.example.smartalarm.data.db.AlarmDatabase
|
||||
import com.example.smartalarm.data.repository.AlarmRepository
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class BootReceiver : BroadcastReceiver() {
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == Intent.ACTION_BOOT_COMPLETED ||
|
||||
intent.action == "android.intent.action.QUICKBOOT_POWERON") {
|
||||
|
||||
// Reschedule all enabled alarms
|
||||
scope.launch {
|
||||
val database = AlarmDatabase.getDatabase(context)
|
||||
val repository = AlarmRepository(database.alarmDao())
|
||||
val scheduler = AlarmScheduler(context)
|
||||
|
||||
repository.enabledAlarms.first().forEach { alarm ->
|
||||
scheduler.scheduleAlarm(alarm)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
// service/ShakeDetector.kt
|
||||
package com.example.smartalarm.service
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.Sensor
|
||||
import android.hardware.SensorEvent
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import kotlin.math.sqrt
|
||||
|
||||
class ShakeDetector(
|
||||
context: Context,
|
||||
private val onShakeDetected: (shakeCount: Int, intensity: Float) -> Unit
|
||||
) : SensorEventListener {
|
||||
|
||||
private val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||
private val accelerometer: Sensor? = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
|
||||
|
||||
private var shakeCount = 0
|
||||
private var lastShakeTime = 0L
|
||||
private var lastX = 0f
|
||||
private var lastY = 0f
|
||||
private var lastZ = 0f
|
||||
private var shakeIntensity = 0f
|
||||
|
||||
companion object {
|
||||
private const val SHAKE_THRESHOLD = 15f
|
||||
private const val SHAKE_TIMEOUT = 500L
|
||||
private const val SHAKE_RESET_TIMEOUT = 3000L
|
||||
}
|
||||
|
||||
fun start() {
|
||||
accelerometer?.let {
|
||||
sensorManager.registerListener(
|
||||
this,
|
||||
it,
|
||||
SensorManager.SENSOR_DELAY_UI
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
sensorManager.unregisterListener(this)
|
||||
reset()
|
||||
}
|
||||
|
||||
private fun reset() {
|
||||
shakeCount = 0
|
||||
shakeIntensity = 0f
|
||||
lastShakeTime = 0L
|
||||
}
|
||||
|
||||
override fun onSensorChanged(event: SensorEvent?) {
|
||||
if (event?.sensor?.type != Sensor.TYPE_ACCELEROMETER) return
|
||||
|
||||
val x = event.values[0]
|
||||
val y = event.values[1]
|
||||
val z = event.values[2]
|
||||
|
||||
val currentTime = System.currentTimeMillis()
|
||||
|
||||
if (lastShakeTime > 0 && currentTime - lastShakeTime > SHAKE_RESET_TIMEOUT) {
|
||||
reset()
|
||||
}
|
||||
|
||||
val deltaX = x - lastX
|
||||
val deltaY = y - lastY
|
||||
val deltaZ = z - lastZ
|
||||
|
||||
val acceleration = sqrt(
|
||||
deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ
|
||||
)
|
||||
|
||||
if (acceleration > SHAKE_THRESHOLD) {
|
||||
if (currentTime - lastShakeTime > SHAKE_TIMEOUT) {
|
||||
shakeCount++
|
||||
shakeIntensity = maxOf(shakeIntensity, acceleration)
|
||||
lastShakeTime = currentTime
|
||||
|
||||
onShakeDetected(shakeCount, shakeIntensity)
|
||||
}
|
||||
}
|
||||
|
||||
lastX = x
|
||||
lastY = y
|
||||
lastZ = z
|
||||
}
|
||||
|
||||
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {
|
||||
// Not needed
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
// ui/alarm/AlarmAdapter.kt
|
||||
package com.example.smartalarm.ui.alarm
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.databinding.ItemAlarmBinding
|
||||
import com.example.smartalarm.utils.TimeFormatter
|
||||
|
||||
class AlarmAdapter(
|
||||
private val onAlarmClick: (Alarm) -> Unit,
|
||||
private val onToggleClick: (Alarm, Boolean) -> Unit,
|
||||
private val onDeleteClick: (Alarm) -> Unit
|
||||
) : ListAdapter<Alarm, AlarmAdapter.AlarmViewHolder>(AlarmDiffCallback()) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AlarmViewHolder {
|
||||
val binding = ItemAlarmBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
return AlarmViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: AlarmViewHolder, position: Int) {
|
||||
holder.bind(getItem(position))
|
||||
}
|
||||
|
||||
inner class AlarmViewHolder(
|
||||
private val binding: ItemAlarmBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(alarm: Alarm) {
|
||||
binding.tvTime.text = alarm.getTimeString()
|
||||
binding.tvLabel.text = alarm.label.ifEmpty { "Alarm" }
|
||||
binding.tvRepeatDays.text = alarm.getRepeatDaysString()
|
||||
binding.tvTimeUntil.text = TimeFormatter.getTimeUntilAlarm(alarm.hour, alarm.minute)
|
||||
|
||||
binding.switchEnabled.isChecked = alarm.isEnabled
|
||||
binding.switchEnabled.setOnCheckedChangeListener { _, isChecked ->
|
||||
onToggleClick(alarm, isChecked)
|
||||
}
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
onAlarmClick(alarm)
|
||||
}
|
||||
|
||||
binding.btnDelete.setOnClickListener {
|
||||
onDeleteClick(alarm)
|
||||
}
|
||||
|
||||
// Show badges
|
||||
if (alarm.shakeToStop) {
|
||||
binding.badgeShake.visibility = android.view.View.VISIBLE
|
||||
} else {
|
||||
binding.badgeShake.visibility = android.view.View.GONE
|
||||
}
|
||||
|
||||
if (alarm.gradualMode) {
|
||||
binding.badgeGradual.visibility = android.view.View.VISIBLE
|
||||
} else {
|
||||
binding.badgeGradual.visibility = android.view.View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AlarmDiffCallback : DiffUtil.ItemCallback<Alarm>() {
|
||||
override fun areItemsTheSame(oldItem: Alarm, newItem: Alarm): Boolean {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: Alarm, newItem: Alarm): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
// ui/alarm/AlarmDetailFragment.kt
|
||||
package com.example.smartalarm.ui.alarm
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.example.smartalarm.R
|
||||
import com.example.smartalarm.databinding.FragmentAlarmDetailBinding
|
||||
import com.example.smartalarm.utils.TimeFormatter
|
||||
import com.example.smartalarm.viewmodels.AlarmViewModel
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class AlarmDetailFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentAlarmDetailBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var viewModel: AlarmViewModel
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentAlarmDetailBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel = ViewModelProvider(requireActivity())[AlarmViewModel::class.java]
|
||||
|
||||
setupUI()
|
||||
observeViewModel()
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
binding.btnEdit.setOnClickListener {
|
||||
findNavController().navigate(R.id.action_alarmDetail_to_alarmEdit)
|
||||
}
|
||||
|
||||
binding.btnDelete.setOnClickListener {
|
||||
showDeleteConfirmation()
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
viewModel.selectedAlarm.observe(viewLifecycleOwner) { alarm ->
|
||||
if (alarm != null) {
|
||||
binding.tvTime.text = alarm.getTimeString()
|
||||
binding.tvLabel.text = alarm.label.ifEmpty { "Alarm" }
|
||||
binding.tvRepeatDays.text = alarm.getRepeatDaysString()
|
||||
binding.tvTimeUntil.text = "Rings in ${TimeFormatter.getTimeUntilAlarm(alarm.hour, alarm.minute)}"
|
||||
|
||||
binding.switchEnabled.isChecked = alarm.isEnabled
|
||||
binding.switchVibrate.isChecked = alarm.vibrate
|
||||
binding.switchShakeToStop.isChecked = alarm.shakeToStop
|
||||
binding.switchGradualMode.isChecked = alarm.gradualMode
|
||||
binding.switchSnooze.isChecked = alarm.snoozeEnabled
|
||||
|
||||
if (alarm.shakeToStop) {
|
||||
binding.tvShakeIntensity.visibility = View.VISIBLE
|
||||
binding.tvShakeIntensity.text = "Shake Intensity: ${alarm.shakeIntensity}"
|
||||
} else {
|
||||
binding.tvShakeIntensity.visibility = View.GONE
|
||||
}
|
||||
|
||||
binding.switchEnabled.setOnCheckedChangeListener { _, isChecked ->
|
||||
viewModel.toggleAlarm(alarm.id, isChecked)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDeleteConfirmation() {
|
||||
val alarm = viewModel.selectedAlarm.value ?: return
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle("Delete Alarm")
|
||||
.setMessage("Are you sure you want to delete this alarm?")
|
||||
.setPositiveButton("Delete") { _, _ ->
|
||||
viewModel.deleteAlarm(alarm)
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
.setNegativeButton("Cancel", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,213 @@
|
||||
// ui/alarm/AlarmEditFragment.kt
|
||||
package com.example.smartalarm.ui.alarm
|
||||
|
||||
import android.app.TimePickerDialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.SeekBar
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.databinding.FragmentAlarmEditBinding
|
||||
import com.example.smartalarm.viewmodels.AlarmViewModel
|
||||
import com.google.android.material.chip.Chip
|
||||
import java.util.*
|
||||
|
||||
class AlarmEditFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentAlarmEditBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var viewModel: AlarmViewModel
|
||||
private var editingAlarm: Alarm? = null
|
||||
|
||||
private var selectedHour = 8
|
||||
private var selectedMinute = 0
|
||||
private val selectedDays = mutableSetOf<Int>()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentAlarmEditBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel = ViewModelProvider(requireActivity())[AlarmViewModel::class.java]
|
||||
|
||||
setupUI()
|
||||
observeViewModel()
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
// Set current time as default
|
||||
val calendar = Calendar.getInstance()
|
||||
selectedHour = calendar.get(Calendar.HOUR_OF_DAY)
|
||||
selectedMinute = calendar.get(Calendar.MINUTE)
|
||||
|
||||
updateTimeDisplay()
|
||||
|
||||
binding.btnPickTime.setOnClickListener {
|
||||
showTimePicker()
|
||||
}
|
||||
|
||||
setupDayChips()
|
||||
setupShakeIntensitySeekBar()
|
||||
setupSaveButton()
|
||||
}
|
||||
|
||||
private fun showTimePicker() {
|
||||
TimePickerDialog(
|
||||
requireContext(),
|
||||
{ _, hourOfDay, minute ->
|
||||
selectedHour = hourOfDay
|
||||
selectedMinute = minute
|
||||
updateTimeDisplay()
|
||||
},
|
||||
selectedHour,
|
||||
selectedMinute,
|
||||
true
|
||||
).show()
|
||||
}
|
||||
|
||||
private fun updateTimeDisplay() {
|
||||
binding.tvSelectedTime.text = String.format("%02d:%02d", selectedHour, selectedMinute)
|
||||
}
|
||||
|
||||
private fun setupDayChips() {
|
||||
val days = listOf("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
|
||||
|
||||
days.forEachIndexed { index, day ->
|
||||
val chip = Chip(requireContext()).apply {
|
||||
text = day
|
||||
isCheckable = true
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
selectedDays.add(index)
|
||||
} else {
|
||||
selectedDays.remove(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.chipGroupDays.addView(chip)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupShakeIntensitySeekBar() {
|
||||
binding.seekBarShakeIntensity.max = 5
|
||||
binding.seekBarShakeIntensity.progress = 3
|
||||
|
||||
binding.seekBarShakeIntensity.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
val intensity = maxOf(1, progress)
|
||||
binding.tvShakeIntensity.text = "Intensity: $intensity"
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
||||
})
|
||||
|
||||
// Show/hide shake settings
|
||||
binding.switchShakeToStop.setOnCheckedChangeListener { _, isChecked ->
|
||||
binding.layoutShakeSettings.visibility = if (isChecked) View.VISIBLE else View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSaveButton() {
|
||||
binding.btnSave.setOnClickListener {
|
||||
saveAlarm()
|
||||
}
|
||||
|
||||
binding.btnCancel.setOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveAlarm() {
|
||||
val label = binding.etLabel.text.toString()
|
||||
val vibrate = binding.switchVibrate.isChecked
|
||||
val shakeToStop = binding.switchShakeToStop.isChecked
|
||||
val gradualMode = binding.switchGradualMode.isChecked
|
||||
val snoozeEnabled = binding.switchSnooze.isChecked
|
||||
|
||||
val shakeIntensity = if (shakeToStop) {
|
||||
maxOf(1, binding.seekBarShakeIntensity.progress)
|
||||
} else 3
|
||||
|
||||
val alarm = if (editingAlarm != null) {
|
||||
editingAlarm!!.copy(
|
||||
hour = selectedHour,
|
||||
minute = selectedMinute,
|
||||
label = label,
|
||||
repeatDays = selectedDays.toList(),
|
||||
vibrate = vibrate,
|
||||
shakeToStop = shakeToStop,
|
||||
shakeIntensity = shakeIntensity,
|
||||
gradualMode = gradualMode,
|
||||
snoozeEnabled = snoozeEnabled
|
||||
)
|
||||
} else {
|
||||
Alarm(
|
||||
hour = selectedHour,
|
||||
minute = selectedMinute,
|
||||
label = label,
|
||||
repeatDays = selectedDays.toList(),
|
||||
vibrate = vibrate,
|
||||
shakeToStop = shakeToStop,
|
||||
shakeIntensity = shakeIntensity,
|
||||
gradualMode = gradualMode,
|
||||
snoozeEnabled = snoozeEnabled
|
||||
)
|
||||
}
|
||||
|
||||
if (editingAlarm != null) {
|
||||
viewModel.updateAlarm(alarm)
|
||||
} else {
|
||||
viewModel.addAlarm(alarm)
|
||||
}
|
||||
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
viewModel.selectedAlarm.observe(viewLifecycleOwner) { alarm ->
|
||||
if (alarm != null) {
|
||||
editingAlarm = alarm
|
||||
populateFields(alarm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun populateFields(alarm: Alarm) {
|
||||
selectedHour = alarm.hour
|
||||
selectedMinute = alarm.minute
|
||||
updateTimeDisplay()
|
||||
|
||||
binding.etLabel.setText(alarm.label)
|
||||
binding.switchVibrate.isChecked = alarm.vibrate
|
||||
binding.switchShakeToStop.isChecked = alarm.shakeToStop
|
||||
binding.switchGradualMode.isChecked = alarm.gradualMode
|
||||
binding.switchSnooze.isChecked = alarm.snoozeEnabled
|
||||
binding.seekBarShakeIntensity.progress = alarm.shakeIntensity
|
||||
|
||||
// Set repeat days
|
||||
alarm.repeatDays.forEach { dayIndex ->
|
||||
selectedDays.add(dayIndex)
|
||||
(binding.chipGroupDays.getChildAt(dayIndex) as? Chip)?.isChecked = true
|
||||
}
|
||||
|
||||
binding.layoutShakeSettings.visibility = if (alarm.shakeToStop) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
// ui/alarm/AlarmListFragment.kt
|
||||
package com.example.smartalarm.ui.alarm
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.example.smartalarm.R
|
||||
import com.example.smartalarm.databinding.FragmentAlarmListBinding
|
||||
import com.example.smartalarm.viewmodels.AlarmViewModel
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
class AlarmListFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentAlarmListBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var viewModel: AlarmViewModel
|
||||
private lateinit var adapter: AlarmAdapter
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentAlarmListBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel = ViewModelProvider(requireActivity())[AlarmViewModel::class.java]
|
||||
|
||||
setupRecyclerView()
|
||||
setupFab()
|
||||
observeViewModel()
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
adapter = AlarmAdapter(
|
||||
onAlarmClick = { alarm ->
|
||||
viewModel.selectAlarm(alarm)
|
||||
findNavController().navigate(R.id.action_alarmList_to_alarmDetail)
|
||||
},
|
||||
onToggleClick = { alarm, isEnabled ->
|
||||
viewModel.toggleAlarm(alarm.id, isEnabled)
|
||||
},
|
||||
onDeleteClick = { alarm ->
|
||||
viewModel.deleteAlarm(alarm)
|
||||
}
|
||||
)
|
||||
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
private fun setupFab() {
|
||||
binding.fabAddAlarm.setOnClickListener {
|
||||
viewModel.selectAlarm(null)
|
||||
findNavController().navigate(R.id.action_alarmList_to_alarmEdit)
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
viewModel.allAlarms.observe(viewLifecycleOwner) { alarms ->
|
||||
adapter.submitList(alarms)
|
||||
|
||||
if (alarms.isEmpty()) {
|
||||
binding.emptyView.visibility = View.VISIBLE
|
||||
binding.recyclerView.visibility = View.GONE
|
||||
} else {
|
||||
binding.emptyView.visibility = View.GONE
|
||||
binding.recyclerView.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.operationStatus.observe(viewLifecycleOwner) { status ->
|
||||
when (status) {
|
||||
is AlarmViewModel.OperationStatus.Success -> {
|
||||
Snackbar.make(binding.root, status.message, Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
is AlarmViewModel.OperationStatus.Error -> {
|
||||
Snackbar.make(binding.root, status.message, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
// ui/alarm/AlarmPresetFragment.kt
|
||||
package com.example.smartalarm.ui.alarm
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.example.smartalarm.databinding.FragmentAlarmPresetBinding
|
||||
import com.example.smartalarm.viewmodels.AlarmViewModel
|
||||
import com.example.smartalarm.viewmodels.PresetViewModel
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
|
||||
class AlarmPresetFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentAlarmPresetBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var presetViewModel: PresetViewModel
|
||||
private lateinit var alarmViewModel: AlarmViewModel
|
||||
private lateinit var adapter: PresetAdapter
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentAlarmPresetBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
presetViewModel = ViewModelProvider(this)[PresetViewModel::class.java]
|
||||
alarmViewModel = ViewModelProvider(requireActivity())[AlarmViewModel::class.java]
|
||||
|
||||
setupRecyclerView()
|
||||
observeViewModel()
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
adapter = PresetAdapter { preset ->
|
||||
// Convert preset to alarm and add it
|
||||
val alarm = Alarm(
|
||||
hour = preset.hour,
|
||||
minute = preset.minute,
|
||||
label = preset.label,
|
||||
repeatDays = preset.repeatDays,
|
||||
shakeToStop = preset.shakeToStop,
|
||||
gradualMode = preset.gradualMode
|
||||
)
|
||||
alarmViewModel.addAlarm(alarm)
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
presetViewModel.presets.observe(viewLifecycleOwner) { presets ->
|
||||
adapter.submitList(presets)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,192 @@
|
||||
package com.example.smartalarm.ui.alarm
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.example.smartalarm.databinding.ActivityAlarmRingBinding
|
||||
import com.example.smartalarm.data.model.Statistics
|
||||
import com.example.smartalarm.service.AlarmService
|
||||
import com.example.smartalarm.service.ShakeDetector
|
||||
import com.example.smartalarm.utils.ShakePatternAnalyzer
|
||||
import com.example.smartalarm.utils.TimeFormatter
|
||||
import com.example.smartalarm.viewmodels.StatisticsViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class AlarmRingActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityAlarmRingBinding
|
||||
private lateinit var statisticsViewModel: StatisticsViewModel
|
||||
private var shakeDetector: ShakeDetector? = null
|
||||
|
||||
private var alarmId: Long = -1
|
||||
private var shakeToStop = false
|
||||
private var shakeIntensity = 3
|
||||
private var statisticsId: Long = -1
|
||||
private var snoozeCount = 0
|
||||
private var triggeredTime = 0L
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Show activity even when locked
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||
setShowWhenLocked(true)
|
||||
setTurnScreenOn(true)
|
||||
} else {
|
||||
window.addFlags(
|
||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||
)
|
||||
}
|
||||
|
||||
binding = ActivityAlarmRingBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
statisticsViewModel = ViewModelProvider(this)[StatisticsViewModel::class.java]
|
||||
|
||||
setupFromIntent()
|
||||
setupUI()
|
||||
setupShakeDetector()
|
||||
setupBackPressHandler()
|
||||
saveInitialStatistics()
|
||||
}
|
||||
|
||||
private fun setupFromIntent() {
|
||||
alarmId = intent.getLongExtra("ALARM_ID", -1)
|
||||
val label = intent.getStringExtra("ALARM_LABEL") ?: "Alarm"
|
||||
shakeToStop = intent.getBooleanExtra("SHAKE_TO_STOP", false)
|
||||
shakeIntensity = intent.getIntExtra("SHAKE_INTENSITY", 3)
|
||||
|
||||
binding.tvAlarmLabel.text = label
|
||||
binding.tvAlarmTime.text = TimeFormatter.formatTimestamp(System.currentTimeMillis())
|
||||
|
||||
triggeredTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
if (shakeToStop) {
|
||||
binding.btnDismiss.text = "Shake to Stop"
|
||||
binding.tvShakeInfo.text = "Shake your phone ${shakeIntensity} times"
|
||||
binding.tvShakeInfo.visibility = android.view.View.VISIBLE
|
||||
binding.shakeProgress.visibility = android.view.View.VISIBLE
|
||||
binding.shakeProgress.max = shakeIntensity
|
||||
} else {
|
||||
binding.btnDismiss.text = "Dismiss"
|
||||
binding.tvShakeInfo.visibility = android.view.View.GONE
|
||||
binding.shakeProgress.visibility = android.view.View.GONE
|
||||
|
||||
binding.btnDismiss.setOnClickListener {
|
||||
stopAlarm("button")
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnSnooze.setOnClickListener {
|
||||
snoozeAlarm()
|
||||
}
|
||||
|
||||
// Update clock every second
|
||||
lifecycleScope.launch {
|
||||
while (true) {
|
||||
binding.tvAlarmTime.text = TimeFormatter.formatTimestamp(System.currentTimeMillis())
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupShakeDetector() {
|
||||
if (!shakeToStop) return
|
||||
|
||||
shakeDetector = ShakeDetector(this) { shakeCount, intensity ->
|
||||
binding.shakeProgress.progress = shakeCount
|
||||
binding.tvShakeInfo.text = "Shake ${shakeCount}/${shakeIntensity}"
|
||||
|
||||
if (ShakePatternAnalyzer.isValidPattern(shakeCount, intensity, shakeIntensity)) {
|
||||
stopAlarm("shake")
|
||||
}
|
||||
}
|
||||
shakeDetector?.start()
|
||||
}
|
||||
|
||||
private fun saveInitialStatistics() {
|
||||
val stats = Statistics(
|
||||
alarmId = alarmId,
|
||||
triggeredAt = triggeredTime,
|
||||
stoppedAt = null,
|
||||
snoozedCount = 0,
|
||||
stopMethod = "unknown"
|
||||
)
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
statisticsId = statisticsViewModel.saveStatistics(stats) as? Long ?: 0L
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopAlarm(method: String) {
|
||||
val stats = Statistics(
|
||||
id = statisticsId,
|
||||
alarmId = alarmId,
|
||||
triggeredAt = triggeredTime,
|
||||
stoppedAt = System.currentTimeMillis(),
|
||||
snoozedCount = snoozeCount,
|
||||
stopMethod = method
|
||||
)
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
if (statisticsId > 0) {
|
||||
statisticsViewModel.updateStatistics(stats)
|
||||
} else {
|
||||
statisticsViewModel.saveStatistics(stats)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
stopService(android.content.Intent(this, AlarmService::class.java))
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun snoozeAlarm() {
|
||||
snoozeCount++
|
||||
|
||||
// Schedule snooze (typically 5 minutes)
|
||||
val snoozeIntent = android.content.Intent(this, AlarmService::class.java).apply {
|
||||
putExtras(intent)
|
||||
}
|
||||
|
||||
stopService(android.content.Intent(this, AlarmService::class.java))
|
||||
|
||||
// Reschedule for 5 minutes later
|
||||
lifecycleScope.launch {
|
||||
delay(5 * 60 * 1000) // 5 minutes
|
||||
startForegroundService(snoozeIntent)
|
||||
}
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
shakeDetector?.stop()
|
||||
}
|
||||
|
||||
private fun setupBackPressHandler() {
|
||||
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
// Prevent back button from dismissing alarm
|
||||
// User must use dismiss or snooze button
|
||||
// Do nothing - block back press
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
// ui/alarm/PresetAdapter.kt
|
||||
package com.example.smartalarm.ui.alarm
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.smartalarm.data.model.AlarmPreset
|
||||
import com.example.smartalarm.databinding.ItemPresetBinding
|
||||
|
||||
class PresetAdapter(
|
||||
private val onPresetClick: (AlarmPreset) -> Unit
|
||||
) : ListAdapter<AlarmPreset, PresetAdapter.PresetViewHolder>(PresetDiffCallback()) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PresetViewHolder {
|
||||
val binding = ItemPresetBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
return PresetViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PresetViewHolder, position: Int) {
|
||||
holder.bind(getItem(position))
|
||||
}
|
||||
|
||||
inner class PresetViewHolder(
|
||||
private val binding: ItemPresetBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(preset: AlarmPreset) {
|
||||
binding.tvPresetName.text = preset.name
|
||||
binding.tvPresetTime.text = String.format("%02d:%02d", preset.hour, preset.minute)
|
||||
binding.tvPresetLabel.text = preset.label
|
||||
|
||||
val days = preset.repeatDays.sorted().joinToString(", ") {
|
||||
listOf("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")[it]
|
||||
}
|
||||
binding.tvPresetDays.text = if (days.isEmpty()) "Once" else days
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
onPresetClick(preset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PresetDiffCallback : DiffUtil.ItemCallback<AlarmPreset>() {
|
||||
override fun areItemsTheSame(oldItem: AlarmPreset, newItem: AlarmPreset): Boolean {
|
||||
return oldItem.name == newItem.name
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: AlarmPreset, newItem: AlarmPreset): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
// ui/statistics/StatisticsFragment.kt
|
||||
package com.example.smartalarm.ui.statistics
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.smartalarm.databinding.FragmentStatisticsBinding
|
||||
import com.example.smartalarm.viewmodels.StatisticsViewModel
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class StatisticsFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentStatisticsBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var viewModel: StatisticsViewModel
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentStatisticsBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel = ViewModelProvider(this)[StatisticsViewModel::class.java]
|
||||
|
||||
setupUI()
|
||||
observeViewModel()
|
||||
loadStatistics()
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
binding.chipWeek.setOnClickListener {
|
||||
loadStatistics(7)
|
||||
}
|
||||
|
||||
binding.chipMonth.setOnClickListener {
|
||||
loadStatistics(30)
|
||||
}
|
||||
|
||||
binding.chipAll.setOnClickListener {
|
||||
loadStatistics()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadStatistics(days: Int? = null) {
|
||||
if (days != null) {
|
||||
val startTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(days.toLong())
|
||||
viewModel.loadStatisticsSince(startTime)
|
||||
} else {
|
||||
// Load all statistics
|
||||
viewModel.loadStatisticsSince(0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
viewModel.summaryData.observe(viewLifecycleOwner) { summary ->
|
||||
binding.tvTotalAlarms.text = summary.totalAlarms.toString()
|
||||
binding.tvTotalSnoozes.text = summary.totalSnoozes.toString()
|
||||
binding.tvShakeStops.text = summary.shakeStops.toString()
|
||||
binding.tvAvgDuration.text = "${summary.averageDurationMinutes} min"
|
||||
}
|
||||
|
||||
viewModel.allStatistics.observe(viewLifecycleOwner) { statistics ->
|
||||
// Could show a chart here using MPAndroidChart
|
||||
updateChart(statistics)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateChart(statistics: List<com.example.smartalarm.data.model.Statistics>) {
|
||||
// TODO: Implement chart visualization
|
||||
// This would use MPAndroidChart library
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
// utils/AlarmModeController.kt
|
||||
package com.example.smartalarm.utils
|
||||
|
||||
import com.example.smartalarm.data.model.AlarmMode
|
||||
|
||||
object AlarmModeController {
|
||||
|
||||
fun getVolumeForGradualMode(
|
||||
elapsedSeconds: Int,
|
||||
maxDurationSeconds: Int
|
||||
): Float {
|
||||
if (elapsedSeconds >= maxDurationSeconds) return 1.0f
|
||||
|
||||
val progress = elapsedSeconds.toFloat() / maxDurationSeconds
|
||||
return 0.1f + (progress * 0.9f)
|
||||
}
|
||||
|
||||
fun shouldVibrate(mode: AlarmMode, elapsedSeconds: Int): Boolean {
|
||||
return when (mode) {
|
||||
AlarmMode.VIBRATE_ONLY -> true
|
||||
AlarmMode.SOUND_ONLY -> false
|
||||
AlarmMode.VIBRATE_THEN_SOUND -> elapsedSeconds < 30
|
||||
AlarmMode.GRADUAL -> true
|
||||
}
|
||||
}
|
||||
|
||||
fun getModeDescription(mode: AlarmMode): String {
|
||||
return when (mode) {
|
||||
AlarmMode.VIBRATE_ONLY -> "Vibration only"
|
||||
AlarmMode.SOUND_ONLY -> "Sound only"
|
||||
AlarmMode.VIBRATE_THEN_SOUND -> "Vibrate first, then sound"
|
||||
AlarmMode.GRADUAL -> "Progressive volume increase"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
// utils/NotificationHelper.kt
|
||||
package com.example.smartalarm.utils
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
|
||||
object NotificationHelper {
|
||||
|
||||
private const val CHANNEL_ID = "smart_alarm_channel"
|
||||
private const val CHANNEL_NAME = "Smart Alarm"
|
||||
|
||||
fun createNotificationChannel(context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = NotificationChannel(
|
||||
CHANNEL_ID,
|
||||
CHANNEL_NAME,
|
||||
NotificationManager.IMPORTANCE_HIGH
|
||||
).apply {
|
||||
description = "Notifications for Smart Alarm app"
|
||||
enableVibration(true)
|
||||
enableLights(true)
|
||||
}
|
||||
|
||||
val notificationManager = context.getSystemService(NotificationManager::class.java)
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
|
||||
fun showNotification(
|
||||
context: Context,
|
||||
title: String,
|
||||
message: String,
|
||||
notificationId: Int = 1
|
||||
) {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
val builder = NotificationCompat.Builder(context, CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setAutoCancel(true)
|
||||
|
||||
notificationManager.notify(notificationId, builder.build())
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.example.smartalarm.utils
|
||||
|
||||
import com.example.smartalarm.data.model.ShakePattern
|
||||
|
||||
object ShakePatternAnalyzer {
|
||||
|
||||
fun isValidPattern(
|
||||
shakeCount: Int,
|
||||
intensity: Float,
|
||||
requiredIntensity: Int
|
||||
): Boolean {
|
||||
val pattern = ShakePattern(
|
||||
shakeCount = shakeCount,
|
||||
intensity = intensity,
|
||||
duration = 0L
|
||||
)
|
||||
return pattern.isValid(requiredIntensity)
|
||||
}
|
||||
|
||||
fun getProgressPercentage(
|
||||
currentShakes: Int,
|
||||
requiredIntensity: Int
|
||||
): Int {
|
||||
return ((currentShakes.toFloat() / requiredIntensity) * 100).toInt()
|
||||
.coerceIn(0, 100)
|
||||
}
|
||||
|
||||
fun getIntensityDescription(intensity: Int): String {
|
||||
return when (intensity) {
|
||||
1 -> "Very Light"
|
||||
2 -> "Light"
|
||||
3 -> "Medium"
|
||||
4 -> "Strong"
|
||||
5 -> "Very Strong"
|
||||
else -> "Unknown"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
// utils/TimeFormatter.kt
|
||||
package com.example.smartalarm.utils
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
object TimeFormatter {
|
||||
|
||||
private val timeFormat24 = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||
private val timeFormat12 = SimpleDateFormat("hh:mm a", Locale.getDefault())
|
||||
private val dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale.getDefault())
|
||||
private val dateTimeFormat = SimpleDateFormat("MMM dd, yyyy HH:mm", Locale.getDefault())
|
||||
|
||||
fun formatTime24(hour: Int, minute: Int): String {
|
||||
val calendar = Calendar.getInstance().apply {
|
||||
set(Calendar.HOUR_OF_DAY, hour)
|
||||
set(Calendar.MINUTE, minute)
|
||||
}
|
||||
return timeFormat24.format(calendar.time)
|
||||
}
|
||||
|
||||
fun formatTime12(hour: Int, minute: Int): String {
|
||||
val calendar = Calendar.getInstance().apply {
|
||||
set(Calendar.HOUR_OF_DAY, hour)
|
||||
set(Calendar.MINUTE, minute)
|
||||
}
|
||||
return timeFormat12.format(calendar.time)
|
||||
}
|
||||
|
||||
fun formatTimestamp(timestamp: Long, use24Hour: Boolean = true): String {
|
||||
val format = if (use24Hour) timeFormat24 else timeFormat12
|
||||
return format.format(Date(timestamp))
|
||||
}
|
||||
|
||||
fun formatDate(timestamp: Long): String {
|
||||
return dateFormat.format(Date(timestamp))
|
||||
}
|
||||
|
||||
fun formatDateTime(timestamp: Long): String {
|
||||
return dateTimeFormat.format(Date(timestamp))
|
||||
}
|
||||
|
||||
fun getTimeUntilAlarm(alarmHour: Int, alarmMinute: Int): String {
|
||||
val now = Calendar.getInstance()
|
||||
val alarm = Calendar.getInstance().apply {
|
||||
set(Calendar.HOUR_OF_DAY, alarmHour)
|
||||
set(Calendar.MINUTE, alarmMinute)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
}
|
||||
|
||||
if (alarm.before(now)) {
|
||||
alarm.add(Calendar.DAY_OF_MONTH, 1)
|
||||
}
|
||||
|
||||
val diffMillis = alarm.timeInMillis - now.timeInMillis
|
||||
val hours = (diffMillis / (1000 * 60 * 60)).toInt()
|
||||
val minutes = ((diffMillis / (1000 * 60)) % 60).toInt()
|
||||
|
||||
return when {
|
||||
hours > 0 -> "$hours hr $minutes min"
|
||||
else -> "$minutes min"
|
||||
}
|
||||
}
|
||||
|
||||
fun getDayName(dayIndex: Int): String {
|
||||
return when (dayIndex) {
|
||||
0 -> "Sunday"
|
||||
1 -> "Monday"
|
||||
2 -> "Tuesday"
|
||||
3 -> "Wednesday"
|
||||
4 -> "Thursday"
|
||||
5 -> "Friday"
|
||||
6 -> "Saturday"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
fun getDayShortName(dayIndex: Int): String {
|
||||
return when (dayIndex) {
|
||||
0 -> "Sun"
|
||||
1 -> "Mon"
|
||||
2 -> "Tue"
|
||||
3 -> "Wed"
|
||||
4 -> "Thu"
|
||||
5 -> "Fri"
|
||||
6 -> "Sat"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,112 @@
|
||||
// viewmodel/AlarmViewModel.kt
|
||||
package com.example.smartalarm.viewmodels
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.smartalarm.data.db.AlarmDatabase
|
||||
import com.example.smartalarm.data.model.Alarm
|
||||
import com.example.smartalarm.data.repository.AlarmRepository
|
||||
import com.example.smartalarm.domain.usecase.*
|
||||
import com.example.smartalarm.service.AlarmScheduler
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class AlarmViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
private val database = AlarmDatabase.getDatabase(application)
|
||||
private val repository = AlarmRepository(database.alarmDao())
|
||||
|
||||
private val getAllAlarmsUseCase = GetAllAlarmsUseCase(repository)
|
||||
private val addAlarmUseCase = AddAlarmUseCase(repository)
|
||||
private val updateAlarmUseCase = UpdateAlarmUseCase(repository)
|
||||
private val deleteAlarmUseCase = DeleteAlarmUseCase(repository)
|
||||
|
||||
private val scheduler = AlarmScheduler(application)
|
||||
|
||||
val allAlarms: LiveData<List<Alarm>> = getAllAlarmsUseCase().asLiveData()
|
||||
val enabledAlarms: LiveData<List<Alarm>> = getAllAlarmsUseCase.getEnabled().asLiveData()
|
||||
|
||||
private val _selectedAlarm = MutableLiveData<Alarm?>()
|
||||
val selectedAlarm: LiveData<Alarm?> = _selectedAlarm
|
||||
|
||||
private val _operationStatus = MutableLiveData<OperationStatus>()
|
||||
val operationStatus: LiveData<OperationStatus> = _operationStatus
|
||||
|
||||
fun addAlarm(alarm: Alarm) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val id = addAlarmUseCase(alarm)
|
||||
if (alarm.isEnabled) {
|
||||
scheduler.scheduleAlarm(alarm.copy(id = id))
|
||||
}
|
||||
_operationStatus.value = OperationStatus.Success("Alarm added")
|
||||
} catch (e: Exception) {
|
||||
_operationStatus.value = OperationStatus.Error(e.message ?: "Failed to add alarm")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateAlarm(alarm: Alarm) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
updateAlarmUseCase(alarm)
|
||||
scheduler.cancelAlarm(alarm.id)
|
||||
if (alarm.isEnabled) {
|
||||
scheduler.scheduleAlarm(alarm)
|
||||
}
|
||||
_operationStatus.value = OperationStatus.Success("Alarm updated")
|
||||
} catch (e: Exception) {
|
||||
_operationStatus.value = OperationStatus.Error(e.message ?: "Failed to update alarm")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteAlarm(alarm: Alarm) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
deleteAlarmUseCase(alarm)
|
||||
scheduler.cancelAlarm(alarm.id)
|
||||
_operationStatus.value = OperationStatus.Success("Alarm deleted")
|
||||
} catch (e: Exception) {
|
||||
_operationStatus.value = OperationStatus.Error(e.message ?: "Failed to delete alarm")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleAlarm(alarmId: Long, enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
repository.updateAlarmEnabled(alarmId, enabled)
|
||||
val alarm = repository.getAlarmById(alarmId)
|
||||
if (alarm != null) {
|
||||
if (enabled) {
|
||||
scheduler.scheduleAlarm(alarm)
|
||||
} else {
|
||||
scheduler.cancelAlarm(alarmId)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
_operationStatus.value = OperationStatus.Error(e.message ?: "Failed to toggle alarm")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun selectAlarm(alarm: Alarm?) {
|
||||
_selectedAlarm.value = alarm
|
||||
}
|
||||
|
||||
fun getAlarmById(id: Long) {
|
||||
viewModelScope.launch {
|
||||
val alarm = repository.getAlarmById(id)
|
||||
_selectedAlarm.value = alarm
|
||||
}
|
||||
}
|
||||
|
||||
sealed class OperationStatus {
|
||||
data class Success(val message: String) : OperationStatus()
|
||||
data class Error(val message: String) : OperationStatus()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
// viewmodel/PresetViewModel.kt
|
||||
package com.example.smartalarm.viewmodels
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.example.smartalarm.data.model.AlarmPreset
|
||||
import com.example.smartalarm.domain.usecase.GetPresetsUseCase
|
||||
|
||||
class PresetViewModel : ViewModel() {
|
||||
|
||||
private val getPresetsUseCase = GetPresetsUseCase()
|
||||
|
||||
private val _presets = MutableLiveData<List<AlarmPreset>>()
|
||||
val presets: LiveData<List<AlarmPreset>> = _presets
|
||||
|
||||
private val _selectedPreset = MutableLiveData<AlarmPreset?>()
|
||||
val selectedPreset: LiveData<AlarmPreset?> = _selectedPreset
|
||||
|
||||
init {
|
||||
loadPresets()
|
||||
}
|
||||
|
||||
private fun loadPresets() {
|
||||
_presets.value = getPresetsUseCase()
|
||||
}
|
||||
|
||||
fun selectPreset(preset: AlarmPreset) {
|
||||
_selectedPreset.value = preset
|
||||
}
|
||||
|
||||
fun clearSelection() {
|
||||
_selectedPreset.value = null
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package com.example.smartalarm.viewmodels
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.smartalarm.data.db.AlarmDatabase
|
||||
import com.example.smartalarm.data.model.Statistics
|
||||
import com.example.smartalarm.data.repository.StatisticsRepository
|
||||
import com.example.smartalarm.domain.usecase.SaveStatisticsUseCase
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class StatisticsViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
private val database = AlarmDatabase.getDatabase(application)
|
||||
private val repository = StatisticsRepository(database.statisticsDao())
|
||||
|
||||
private val saveStatisticsUseCase = SaveStatisticsUseCase(repository)
|
||||
|
||||
val allStatistics: LiveData<List<Statistics>> = repository.allStatistics.asLiveData()
|
||||
|
||||
private val _alarmStatistics = MutableLiveData<List<Statistics>>()
|
||||
val alarmStatistics: LiveData<List<Statistics>> = _alarmStatistics
|
||||
|
||||
private val _summaryData = MutableLiveData<StatisticsSummary>()
|
||||
val summaryData: LiveData<StatisticsSummary> = _summaryData
|
||||
|
||||
fun saveStatistics(stats: Statistics): Long {
|
||||
var id = 0L
|
||||
viewModelScope.launch {
|
||||
id = saveStatisticsUseCase(stats)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
fun updateStatistics(stats: Statistics) {
|
||||
viewModelScope.launch {
|
||||
saveStatisticsUseCase.update(stats)
|
||||
}
|
||||
}
|
||||
|
||||
fun loadStatisticsForAlarm(alarmId: Long) {
|
||||
viewModelScope.launch {
|
||||
repository.getStatisticsByAlarmId(alarmId).asLiveData().observeForever {
|
||||
_alarmStatistics.value = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadStatisticsSince(startTime: Long) {
|
||||
viewModelScope.launch {
|
||||
repository.getStatisticsSince(startTime).asLiveData().observeForever { stats ->
|
||||
calculateSummary(stats)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateSummary(statistics: List<Statistics>) {
|
||||
val totalAlarms = statistics.size
|
||||
val totalSnoozes = statistics.sumOf { it.snoozedCount }
|
||||
val shakeStops = statistics.count { it.stopMethod == "shake" }
|
||||
val avgDuration = if (statistics.isNotEmpty()) {
|
||||
statistics.mapNotNull { it.stoppedAt?.let { stop -> (stop - it.triggeredAt) / 60000 } }
|
||||
.average()
|
||||
} else 0.0
|
||||
|
||||
_summaryData.value = StatisticsSummary(
|
||||
totalAlarms = totalAlarms,
|
||||
totalSnoozes = totalSnoozes,
|
||||
shakeStops = shakeStops,
|
||||
averageDurationMinutes = avgDuration.toInt()
|
||||
)
|
||||
}
|
||||
|
||||
fun cleanOldStatistics(daysToKeep: Int = 30) {
|
||||
viewModelScope.launch {
|
||||
val cutoffTime = System.currentTimeMillis() - (daysToKeep * 24 * 60 * 60 * 1000L)
|
||||
repository.deleteOldStatistics(cutoffTime)
|
||||
}
|
||||
}
|
||||
|
||||
data class StatisticsSummary(
|
||||
val totalAlarms: Int,
|
||||
val totalSnoozes: Int,
|
||||
val shakeStops: Int,
|
||||
val averageDurationMinutes: Int
|
||||
)
|
||||
}
|
||||
5
app/src/main/res/drawable/bg_badge.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#E0E0E0"/>
|
||||
<corners android:radius="8dp"/>
|
||||
</shape>
|
||||
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
30
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
85
app/src/main/res/layout/activity_alarm_ring.xml
Normal file
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAlarmTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="08:00"
|
||||
android:textSize="72sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/tvAlarmLabel"
|
||||
app:layout_constraintVertical_chainStyle="packed"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAlarmLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wake Up"
|
||||
android:textSize="24sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAlarmTime"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/tvShakeInfo"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShakeInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Shake your phone to stop"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_marginTop="32dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAlarmLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/shakeProgress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="gone"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvShakeInfo"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnDismiss"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="64dp"
|
||||
android:text="Dismiss"
|
||||
android:textSize="18sp"
|
||||
app:cornerRadius="32dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/btnSnooze"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnSnooze"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="64dp"
|
||||
android:text="Snooze"
|
||||
android:textSize="18sp"
|
||||
app:cornerRadius="32dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
29
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/navHostFragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:defaultNavHost="true"
|
||||
app:navGraph="@navigation/nav_graph"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/bottomNavigation"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottomNavigation"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:menu="@menu/bottom_menu"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
178
app/src/main/res/layout/fragment_alarm_detail.xml
Normal file
@ -0,0 +1,178 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/cardMain"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="8dp"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="08:00"
|
||||
android:textSize="64sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wake Up"
|
||||
android:textSize="24sp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvTime"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRepeatDays"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Mon, Tue, Wed, Thu, Fri"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTimeUntil"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Rings in 8 hr 30 min"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvRepeatDays"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSettingsTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Settings"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/cardMain"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchEnabled"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Alarm Enabled"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSettingsTitle"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchVibrate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Vibrate"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:enabled="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchEnabled"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchShakeToStop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Shake to Stop"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:enabled="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchVibrate"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShakeIntensity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Shake Intensity: 3"
|
||||
android:textSize="14sp"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchShakeToStop"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchGradualMode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Gradual Volume"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:enabled="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvShakeIntensity"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchSnooze"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Snooze Enabled"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:enabled="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchGradualMode"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="32dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchSnooze">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnEdit"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Edit"
|
||||
android:layout_marginEnd="8dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnDelete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Delete"
|
||||
android:layout_marginStart="8dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
182
app/src/main/res/layout/fragment_alarm_edit.xml
Normal file
@ -0,0 +1,182 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/cardTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="4dp"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSelectedTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="08:00"
|
||||
android:textSize="56sp"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnPickTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Change Time"
|
||||
android:layout_marginTop="16dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/layoutLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Label"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/cardTime">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/etLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"/>
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRepeatLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Repeat"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/layoutLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/chipGroupDays"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
app:singleSelection="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvRepeatLabel"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchVibrate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Vibrate"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:checked="true"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/chipGroupDays"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchShakeToStop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Shake to Stop"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchVibrate"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutShakeSettings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:background="@drawable/bg_badge"
|
||||
android:visibility="gone"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchShakeToStop">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShakeIntensity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Intensity: 3"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarShakeIntensity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchGradualMode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Gradual Volume Increase"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/layoutShakeSettings"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchSnooze"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enable Snooze"
|
||||
android:textSize="16sp"
|
||||
android:padding="16dp"
|
||||
android:checked="true"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchGradualMode"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchSnooze"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnCancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Cancel"
|
||||
android:layout_marginEnd="8dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Save"
|
||||
android:layout_marginStart="8dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
35
app/src/main/res/layout/fragment_alarm_list.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:padding="8dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emptyView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="No alarms yet\nTap + to add one"
|
||||
android:textSize="18sp"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabAddAlarm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:contentDescription="Add Alarm"
|
||||
app:srcCompat="@android:drawable/ic_input_add"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
28
app/src/main/res/layout/fragment_alarm_preset.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Alarm Presets"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:padding="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:padding="8dp"
|
||||
android:clipToPadding="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvTitle"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
197
app/src/main/res/layout/fragment_statistics.xml
Normal file
@ -0,0 +1,197 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Alarm Statistics"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/chipGroupFilter"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
app:singleSelection="true"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvTitle">
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chipWeek"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Last 7 Days"
|
||||
android:checked="true"
|
||||
style="@style/Widget.MaterialComponents.Chip.Choice"/>
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chipMonth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Last 30 Days"
|
||||
style="@style/Widget.MaterialComponents.Chip.Choice"/>
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chipAll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="All Time"
|
||||
style="@style/Widget.MaterialComponents.Chip.Choice"/>
|
||||
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/cardStats"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/chipGroupFilter">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTotalAlarms"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="?attr/colorPrimary"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Total Alarms"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTotalSnoozes"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="?attr/colorSecondary"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Total Snoozes"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
android:layout_marginVertical="16dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShakeStops"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Shake Stops"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAvgDuration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0 min"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Avg Duration"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
107
app/src/main/res/layout/item_alarm.xml
Normal file
@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
app:cardElevation="4dp"
|
||||
app:cardCornerRadius="12dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="08:00"
|
||||
android:textSize="48sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchEnabled"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLabel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wake Up"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvTime"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/btnDelete"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRepeatDays"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Mon, Tue, Wed, Thu, Fri"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/btnDelete"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTimeUntil"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="in 8 hr 30 min"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvRepeatDays"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/badgeShake"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/badgeShake"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="🤚 Shake"
|
||||
android:textSize="10sp"
|
||||
android:padding="4dp"
|
||||
android:background="@drawable/bg_badge"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvRepeatDays"
|
||||
app:layout_constraintStart_toEndOf="@id/tvTimeUntil"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/badgeGradual"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="📈 Gradual"
|
||||
android:textSize="10sp"
|
||||
android:padding="4dp"
|
||||
android:background="@drawable/bg_badge"
|
||||
android:layout_marginStart="4dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toTopOf="@id/badgeShake"
|
||||
app:layout_constraintStart_toEndOf="@id/badgeShake"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnDelete"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@android:drawable/ic_menu_delete"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="Delete"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchEnabled"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
63
app/src/main/res/layout/item_preset.xml
Normal file
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="4dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPresetName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Morning"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/tvPresetTime"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPresetTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="06:30"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPresetLabel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wake Up"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPresetName"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPresetDays"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Mon, Tue, Wed, Thu, Fri"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPresetLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
17
app/src/main/res/menu/bottom_menu.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/alarmListFragment"
|
||||
android:icon="@android:drawable/ic_lock_idle_alarm"
|
||||
android:title="Alarms"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/alarmPresetFragment"
|
||||
android:icon="@android:drawable/ic_menu_add"
|
||||
android:title="Presets"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/statisticsFragment"
|
||||
android:icon="@android:drawable/ic_menu_info_details"
|
||||
android:title="Statistics"/>
|
||||
</menu>
|
||||
6
app/src/main/res/mipmap-anydpi/ic_launcher.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
6
app/src/main/res/mipmap-anydpi/ic_launcher_round.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 982 B |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
44
app/src/main/res/navigation/nav_graph.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/nav_graph"
|
||||
app:startDestination="@id/alarmListFragment">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/alarmListFragment"
|
||||
android:name="com.example.smartalarm.ui.alarm.AlarmListFragment"
|
||||
android:label="Alarms">
|
||||
<action
|
||||
android:id="@+id/action_alarmList_to_alarmDetail"
|
||||
app:destination="@id/alarmDetailFragment"/>
|
||||
<action
|
||||
android:id="@+id/action_alarmList_to_alarmEdit"
|
||||
app:destination="@id/alarmEditFragment"/>
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/alarmDetailFragment"
|
||||
android:name="com.example.smartalarm.ui.alarm.AlarmDetailFragment"
|
||||
android:label="Alarm Details">
|
||||
<action
|
||||
android:id="@+id/action_alarmDetail_to_alarmEdit"
|
||||
app:destination="@id/alarmEditFragment"/>
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/alarmEditFragment"
|
||||
android:name="com.example.smartalarm.ui.alarm.AlarmEditFragment"
|
||||
android:label="Edit Alarm"/>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/alarmPresetFragment"
|
||||
android:name="com.example.smartalarm.ui.alarm.AlarmPresetFragment"
|
||||
android:label="Presets"/>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/statisticsFragment"
|
||||
android:name="com.example.smartalarm.ui.statistics.StatisticsFragment"
|
||||
android:label="Statistics"/>
|
||||
|
||||
</navigation>
|
||||
12
app/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="blue_500">#FF2196F3</color>
|
||||
<color name="blue_700">#FF1976D2</color>
|
||||
</resources>
|
||||
21
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Smart Alarm</string>
|
||||
<string name="alarm_ringing">Alarm Ringing</string>
|
||||
<string name="dismiss">Dismiss</string>
|
||||
<string name="snooze">Snooze</string>
|
||||
<string name="shake_to_stop">Shake to Stop</string>
|
||||
<string name="add_alarm">Add Alarm</string>
|
||||
<string name="edit_alarm">Edit Alarm</string>
|
||||
<string name="delete_alarm">Delete Alarm</string>
|
||||
<string name="alarm_label">Alarm Label</string>
|
||||
<string name="repeat">Repeat</string>
|
||||
<string name="once">Once</string>
|
||||
<string name="every_day">Every day</string>
|
||||
<string name="vibrate">Vibrate</string>
|
||||
<string name="gradual_volume">Gradual Volume</string>
|
||||
<string name="shake_intensity">Shake Intensity</string>
|
||||
<string name="statistics">Statistics</string>
|
||||
<string name="presets">Presets</string>
|
||||
<string name="alarms">Alarms</string>
|
||||
</resources>
|
||||
18
app/src/main/res/values/themes.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Theme.SmartAlarm" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<item name="colorPrimary">@color/blue_500</item>
|
||||
<item name="colorPrimaryVariant">@color/blue_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.SmartAlarm.FullScreen" parent="Theme.SmartAlarm">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="android:windowShowWallpaper">false</item>
|
||||
</style>
|
||||
</resources>
|
||||
13
app/src/main/res/xml/backup_rules.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample backup rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/guide/topics/data/autobackup
|
||||
for details.
|
||||
Note: This file is ignored for devices older than API 31
|
||||
See https://developer.android.com/about/versions/12/backup-restore
|
||||
-->
|
||||
<full-backup-content>
|
||||
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
|
||||
</full-backup-content>
|
||||
19
app/src/main/res/xml/data_extraction_rules.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!-- TODO: Use <include> and <exclude> to control what is backed up. -->
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
17
app/src/test/java/com/example/smartalarm/ExampleUnitTest.kt
Normal file
@ -0,0 +1,17 @@
|
||||
package com.example.smartalarm
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
14
build.gradle.kts
Normal file
@ -0,0 +1,14 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url = uri("https://jitpack.io") }
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("com.android.application") version "8.7.3" apply false
|
||||
id("com.android.library") version "8.7.3" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
|
||||
id("com.google.devtools.ksp") version "2.1.0-1.0.29" apply false
|
||||
}
|
||||
18
gradle.properties
Normal file
@ -0,0 +1,18 @@
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
kotlin.code.style=official
|
||||
android.nonTransitiveRClass=true
|
||||
|
||||
# Performance optimizations
|
||||
org.gradle.daemon=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.configuration-cache=true
|
||||
|
||||
# Kotlin compiler
|
||||
kotlin.daemon.jvmargs=-Xmx2048m
|
||||
|
||||
# Fix KAPT issues
|
||||
kapt.use.worker.api=true
|
||||
kapt.incremental.apt=true
|
||||
32
gradle/libs.versions.toml
Normal file
@ -0,0 +1,32 @@
|
||||
[versions]
|
||||
agp = "8.13.1"
|
||||
kotlin = "2.0.21"
|
||||
coreKtx = "1.17.0"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.3.0"
|
||||
espressoCore = "3.7.0"
|
||||
lifecycleRuntimeKtx = "2.10.0"
|
||||
activityCompose = "1.12.1"
|
||||
composeBom = "2024.09.00"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
|
||||
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
|
||||
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
|
||||
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
|
||||
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
|
||||
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
|
||||
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
|
||||
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
185
gradlew
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
89
gradlew.bat
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||