├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── raw │ │ │ │ └── alarm.mp3 │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── ic_repeat_black_24dp.xml │ │ │ │ ├── ic_looks_one_black_24dp.xml │ │ │ │ ├── ic_alarm_black_24dp.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── fragment_listalarms.xml │ │ │ │ ├── activity_ring.xml │ │ │ │ ├── item_alarm.xml │ │ │ │ └── fragment_createalarm.xml │ │ │ ├── navigation │ │ │ │ └── nav_graph.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── learntodroid │ │ │ │ └── simplealarmclock │ │ │ │ ├── alarmslist │ │ │ │ ├── OnToggleAlarmListener.java │ │ │ │ ├── AlarmsListViewModel.java │ │ │ │ ├── AlarmRecyclerViewAdapter.java │ │ │ │ ├── AlarmViewHolder.java │ │ │ │ └── AlarmsListFragment.java │ │ │ │ ├── activities │ │ │ │ ├── MainActivity.java │ │ │ │ └── RingActivity.java │ │ │ │ ├── data │ │ │ │ ├── AlarmDao.java │ │ │ │ ├── AlarmRepository.java │ │ │ │ ├── AlarmDatabase.java │ │ │ │ └── Alarm.java │ │ │ │ ├── createalarm │ │ │ │ ├── TimePickerUtil.java │ │ │ │ ├── CreateAlarmViewModel.java │ │ │ │ ├── DayUtil.java │ │ │ │ └── CreateAlarmFragment.java │ │ │ │ ├── application │ │ │ │ └── App.java │ │ │ │ ├── service │ │ │ │ ├── RescheduleAlarmsService.java │ │ │ │ └── AlarmService.java │ │ │ │ └── broadcastreceiver │ │ │ │ └── AlarmBroadcastReceiver.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── learntodroid │ │ │ └── simplealarmclock │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── learntodroid │ │ └── simplealarmclock │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── .idea ├── .name ├── vcs.xml ├── misc.xml ├── runConfigurations.xml ├── gradle.xml ├── jarRepositories.xml └── codeStyles │ └── Project.xml ├── settings.gradle ├── .gitattributes ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Simple Alarm Clock -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='Simple Alarm Clock' 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /app/src/main/res/raw/alarm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/raw/alarm.mp3 -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Simple Alarm Clock 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learntodroid/SimpleAlarmClock/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 07 16:50:46 AEDT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/alarmslist/OnToggleAlarmListener.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.alarmslist; 2 | 3 | import com.learntodroid.simplealarmclock.data.Alarm; 4 | 5 | public interface OnToggleAlarmListener { 6 | void onToggle(Alarm alarm); 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_repeat_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_looks_one_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/learntodroid/simplealarmclock/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/activities/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.activities; 2 | 3 | import android.os.Bundle; 4 | 5 | import androidx.annotation.Nullable; 6 | import androidx.appcompat.app.AppCompatActivity; 7 | 8 | import com.learntodroid.simplealarmclock.R; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(@Nullable Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_alarm_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/data/AlarmDao.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.data; 2 | 3 | import androidx.lifecycle.LiveData; 4 | import androidx.room.Dao; 5 | import androidx.room.Insert; 6 | import androidx.room.Query; 7 | import androidx.room.Update; 8 | 9 | import java.util.List; 10 | 11 | @Dao 12 | public interface AlarmDao { 13 | @Insert 14 | void insert(Alarm alarm); 15 | 16 | @Query("DELETE FROM alarm_table") 17 | void deleteAll(); 18 | 19 | @Query("SELECT * FROM alarm_table ORDER BY created ASC") 20 | LiveData> getAlarms(); 21 | 22 | @Update 23 | void update(Alarm alarm); 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/createalarm/TimePickerUtil.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.createalarm; 2 | 3 | import android.os.Build; 4 | import android.widget.TimePicker; 5 | 6 | public final class TimePickerUtil { 7 | public static int getTimePickerHour(TimePicker tp) { 8 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 9 | return tp.getHour(); 10 | } else { 11 | return tp.getCurrentHour(); 12 | } 13 | } 14 | 15 | public static int getTimePickerMinute(TimePicker tp) { 16 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 17 | return tp.getMinute(); 18 | } else { 19 | return tp.getCurrentMinute(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/createalarm/CreateAlarmViewModel.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.createalarm; 2 | 3 | import android.app.Application; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.lifecycle.AndroidViewModel; 7 | 8 | import com.learntodroid.simplealarmclock.data.Alarm; 9 | import com.learntodroid.simplealarmclock.data.AlarmRepository; 10 | 11 | public class CreateAlarmViewModel extends AndroidViewModel { 12 | private AlarmRepository alarmRepository; 13 | 14 | public CreateAlarmViewModel(@NonNull Application application) { 15 | super(application); 16 | 17 | alarmRepository = new AlarmRepository(application); 18 | } 19 | 20 | public void insert(Alarm alarm) { 21 | alarmRepository.insert(alarm); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/createalarm/DayUtil.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.createalarm; 2 | 3 | import java.util.Calendar; 4 | 5 | public final class DayUtil { 6 | public static final String toDay(int day) throws Exception { 7 | switch (day) { 8 | case Calendar.SUNDAY: 9 | return "Sunday"; 10 | case Calendar.MONDAY: 11 | return "Monday"; 12 | case Calendar.TUESDAY: 13 | return "Tuesday"; 14 | case Calendar.WEDNESDAY: 15 | return "Wednesday"; 16 | case Calendar.THURSDAY: 17 | return "Thursday"; 18 | case Calendar.FRIDAY: 19 | return "Friday"; 20 | case Calendar.SATURDAY: 21 | return "Saturday"; 22 | } 23 | throw new Exception("Could not locate day"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/learntodroid/simplealarmclock/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("com.learntodroid.simplealarmclock", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/data/AlarmRepository.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.data; 2 | 3 | import android.app.Application; 4 | import androidx.lifecycle.LiveData; 5 | import java.util.List; 6 | 7 | public class AlarmRepository { 8 | private AlarmDao alarmDao; 9 | private LiveData> alarmsLiveData; 10 | 11 | public AlarmRepository(Application application) { 12 | AlarmDatabase db = AlarmDatabase.getDatabase(application); 13 | alarmDao = db.alarmDao(); 14 | alarmsLiveData = alarmDao.getAlarms(); 15 | } 16 | 17 | public void insert(Alarm alarm) { 18 | AlarmDatabase.databaseWriteExecutor.execute(() -> { 19 | alarmDao.insert(alarm); 20 | }); 21 | } 22 | 23 | public void update(Alarm alarm) { 24 | AlarmDatabase.databaseWriteExecutor.execute(() -> { 25 | alarmDao.update(alarm); 26 | }); 27 | } 28 | 29 | public LiveData> getAlarmsLiveData() { 30 | return alarmsLiveData; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/application/App.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.application; 2 | 3 | import android.app.Application; 4 | import android.app.NotificationChannel; 5 | import android.app.NotificationManager; 6 | import android.os.Build; 7 | 8 | public class App extends Application { 9 | public static final String CHANNEL_ID = "ALARM_SERVICE_CHANNEL"; 10 | 11 | @Override 12 | public void onCreate() { 13 | super.onCreate(); 14 | 15 | createNotificationChannnel(); 16 | } 17 | 18 | private void createNotificationChannnel() { 19 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 20 | NotificationChannel serviceChannel = new NotificationChannel( 21 | CHANNEL_ID, 22 | "Alarm Service Channel", 23 | NotificationManager.IMPORTANCE_DEFAULT 24 | ); 25 | 26 | NotificationManager manager = getSystemService(NotificationManager.class); 27 | manager.createNotificationChannel(serviceChannel); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/alarmslist/AlarmsListViewModel.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.alarmslist; 2 | 3 | import android.app.Application; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.lifecycle.AndroidViewModel; 7 | import androidx.lifecycle.LiveData; 8 | 9 | import com.learntodroid.simplealarmclock.data.Alarm; 10 | import com.learntodroid.simplealarmclock.data.AlarmRepository; 11 | 12 | import java.util.List; 13 | 14 | public class AlarmsListViewModel extends AndroidViewModel { 15 | private AlarmRepository alarmRepository; 16 | private LiveData> alarmsLiveData; 17 | 18 | public AlarmsListViewModel(@NonNull Application application) { 19 | super(application); 20 | 21 | alarmRepository = new AlarmRepository(application); 22 | alarmsLiveData = alarmRepository.getAlarmsLiveData(); 23 | } 24 | 25 | public void update(Alarm alarm) { 26 | alarmRepository.update(alarm); 27 | } 28 | 29 | public LiveData> getAlarmsLiveData() { 30 | return alarmsLiveData; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 16 | 17 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/data/AlarmDatabase.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.data; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.room.Database; 6 | import androidx.room.Room; 7 | import androidx.room.RoomDatabase; 8 | 9 | import java.util.concurrent.ExecutorService; 10 | import java.util.concurrent.Executors; 11 | 12 | @Database(entities = {Alarm.class}, version = 1, exportSchema = false) 13 | public abstract class AlarmDatabase extends RoomDatabase { 14 | public abstract AlarmDao alarmDao(); 15 | 16 | private static volatile AlarmDatabase INSTANCE; 17 | private static final int NUMBER_OF_THREADS = 4; 18 | static final ExecutorService databaseWriteExecutor = Executors.newFixedThreadPool(NUMBER_OF_THREADS); 19 | 20 | static AlarmDatabase getDatabase(final Context context) { 21 | if (INSTANCE == null) { 22 | synchronized (AlarmDatabase.class) { 23 | if (INSTANCE == null) { 24 | INSTANCE = Room.databaseBuilder( 25 | context.getApplicationContext(), 26 | AlarmDatabase.class, 27 | "alarm_database" 28 | ).build(); 29 | } 30 | } 31 | } 32 | return INSTANCE; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/learntodroid/simplealarmclock/service/RescheduleAlarmsService.java: -------------------------------------------------------------------------------- 1 | package com.learntodroid.simplealarmclock.service; 2 | 3 | import android.app.Application; 4 | import android.app.Service; 5 | import android.content.Intent; 6 | import android.os.IBinder; 7 | 8 | import androidx.annotation.Nullable; 9 | import androidx.lifecycle.LifecycleService; 10 | import androidx.lifecycle.Observer; 11 | 12 | import com.learntodroid.simplealarmclock.data.Alarm; 13 | import com.learntodroid.simplealarmclock.data.AlarmRepository; 14 | 15 | import java.util.List; 16 | 17 | public class RescheduleAlarmsService extends LifecycleService { 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | } 22 | 23 | @Override 24 | public int onStartCommand(Intent intent, int flags, int startId) { 25 | super.onStartCommand(intent, flags, startId); 26 | 27 | AlarmRepository alarmRepository = new AlarmRepository(getApplication()); 28 | 29 | alarmRepository.getAlarmsLiveData().observe(this, new Observer>() { 30 | @Override 31 | public void onChanged(List alarms) { 32 | for (Alarm a : alarms) { 33 | if (a.isStarted()) { 34 | a.schedule(getApplicationContext()); 35 | } 36 | } 37 | } 38 | }); 39 | 40 | return START_STICKY; 41 | } 42 | 43 | @Override 44 | public void onDestroy() { 45 | super.onDestroy(); 46 | } 47 | 48 | @Nullable 49 | @Override 50 | public IBinder onBind(Intent intent) { 51 | super.onBind(intent); 52 | return null; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_listalarms.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 21 | 22 | 27 | 28 | 29 | 30 |