├── app ├── .gitignore ├── .settings │ └── org.eclipse.buildship.core.prefs ├── src │ ├── main │ │ ├── ic_launcher-web.png │ │ ├── res │ │ │ ├── font │ │ │ │ ├── roboto.ttf │ │ │ │ ├── roboto_bold.ttf │ │ │ │ ├── roboto_light.ttf │ │ │ │ └── roboto_medium.ttf │ │ │ ├── web_hi_res_512.png │ │ │ ├── mipmap-ldpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ ├── preference_keys.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── drawable │ │ │ │ ├── button_fab_extended.xml │ │ │ │ ├── button_close_activity.xml │ │ │ │ ├── shadow.xml │ │ │ │ ├── ic_add.xml │ │ │ │ ├── button_fab_extended_drawable.xml │ │ │ │ ├── button_fab_extended_no_background_drawable.xml │ │ │ │ ├── ic_close.xml │ │ │ │ ├── ic_list_ringtone.xml │ │ │ │ ├── ic_empty_alarms_list.xml │ │ │ │ ├── ic_bottom_navigation_sleepnow.xml │ │ │ │ ├── ic_bottom_naviagation_alarms.xml │ │ │ │ ├── ic_bottom_navigation_wakeupat.xml │ │ │ │ ├── ic_list_alarm_add.xml │ │ │ │ ├── ic_list_alarm_access.xml │ │ │ │ ├── ic_empty_wakeupat_list.xml │ │ │ │ ├── ic_list_ringtone_full_shape.xml │ │ │ │ ├── ic_list_alarm_add_full_shape.xml │ │ │ │ ├── button_close_activity_drawable.xml │ │ │ │ ├── ic_list_alarm_access_full_shape.xml │ │ │ │ └── button_fab_extended_no_background.xml │ │ │ ├── color │ │ │ │ ├── color_primary_selector.xml │ │ │ │ ├── navigation_bar_selector.xml │ │ │ │ └── color_secondary_selector.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── menu │ │ │ │ ├── three_dot_menu.xml │ │ │ │ └── bottom_navigation_menu.xml │ │ │ ├── layout │ │ │ │ ├── divider.xml │ │ │ │ ├── dialog_set_hour_to_wake_up_at.xml │ │ │ │ ├── activity_settings.xml │ │ │ │ ├── fragment_alarms.xml │ │ │ │ ├── item_empty_state.xml │ │ │ │ ├── fragment_wake_up_at.xml │ │ │ │ ├── dialog_item_ringtone.xml │ │ │ │ ├── activity_alarm.xml │ │ │ │ ├── item_alarm.xml │ │ │ │ ├── fragment_sleep_now.xml │ │ │ │ └── activity_main.xml │ │ │ ├── anim │ │ │ │ ├── fast_fade_out.xml │ │ │ │ └── grow_fade_in_center.xml │ │ │ ├── values-night │ │ │ │ └── colors.xml │ │ │ ├── xml │ │ │ │ └── preferences.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── gmail │ │ │ │ └── brunokawka │ │ │ │ └── poland │ │ │ │ └── sleepcyclealarm │ │ │ │ ├── events │ │ │ │ ├── RealmChangeEvent.java │ │ │ │ ├── SetHourButtonClickedEvent.java │ │ │ │ └── AddAlarmEvent.java │ │ │ │ ├── tabs │ │ │ │ ├── ui │ │ │ │ │ ├── dialog │ │ │ │ │ │ ├── ItemDialogContract.java │ │ │ │ │ │ └── ItemDialog.java │ │ │ │ │ ├── WakeUpAtSetHourButton.java │ │ │ │ │ └── EmptyStateRecyclerView.java │ │ │ │ ├── activealarms │ │ │ │ │ ├── AlarmsContract.java │ │ │ │ │ ├── AlarmScopeListener.java │ │ │ │ │ └── AlarmsPresenter.java │ │ │ │ ├── addalarm │ │ │ │ │ ├── wakeupat │ │ │ │ │ │ ├── WakeUpAtContract.java │ │ │ │ │ │ ├── WakeUpAtSetTimeView.java │ │ │ │ │ │ └── WakeUpAtPresenter.java │ │ │ │ │ ├── sleepnow │ │ │ │ │ │ └── SleepNowFragment.java │ │ │ │ │ └── AddDialogFragment.java │ │ │ │ └── adapters │ │ │ │ │ ├── AddAlarmsAdapter.java │ │ │ │ │ └── ActiveAlarmsAdapter.java │ │ │ │ ├── utils │ │ │ │ ├── itemsbuilder │ │ │ │ │ ├── ItemsBuilderStrategy.java │ │ │ │ │ ├── ItemsBuilder.java │ │ │ │ │ ├── ItemsBuilderAbstraction.java │ │ │ │ │ ├── SleepNowBuildingStrategy.java │ │ │ │ │ └── WakeUpAtBuildingStrategy.java │ │ │ │ ├── Const.java │ │ │ │ ├── ThemeUtils.java │ │ │ │ ├── TimeUtils.java │ │ │ │ └── AlarmContentUtils.java │ │ │ │ ├── app │ │ │ │ ├── RealmInitialData.java │ │ │ │ ├── CustomApp.java │ │ │ │ ├── base │ │ │ │ │ ├── MainContract.java │ │ │ │ │ └── MainPresenter.java │ │ │ │ └── RealmManager.java │ │ │ │ ├── schedule │ │ │ │ ├── AlarmReceiver.java │ │ │ │ ├── AlarmController.java │ │ │ │ ├── AlarmActivity.java │ │ │ │ └── AlarmService.java │ │ │ │ ├── data │ │ │ │ ├── ItemsBuilderData.java │ │ │ │ ├── pojo │ │ │ │ │ ├── Item.java │ │ │ │ │ └── Alarm.java │ │ │ │ └── AlarmDAO.java │ │ │ │ └── settings │ │ │ │ ├── SettingsActivity.java │ │ │ │ └── SettingsFragment.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ ├── android │ │ │ └── util │ │ │ │ └── Log.java │ │ │ └── com │ │ │ └── gmail │ │ │ └── brunokawka │ │ │ └── poland │ │ │ └── sleepcyclealarm │ │ │ ├── utils │ │ │ ├── ThemeUtilsTest.java │ │ │ ├── AlarmContentUtilsTest.java │ │ │ ├── TimeUtilsRounderTest.java │ │ │ └── itemsbuilder │ │ │ │ └── ItemsBuilderTest.java │ │ │ ├── tabs │ │ │ └── adapters │ │ │ │ └── AddAlarmsAdapterTest.java │ │ │ └── MainPresenterTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── gmail │ │ └── brunokawka │ │ └── poland │ │ └── sleepcyclealarm │ │ └── utils │ │ ├── AlarmContentUtilsTest.java │ │ └── itemsbuilder │ │ └── ItemsBuilderTest.java ├── .classpath ├── .project ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── preview ├── logo │ ├── master.ai │ ├── master.eps │ ├── logomark.png │ ├── logovertical.png │ ├── logohorizontal.png │ └── logomark.svg └── screenshot.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── vcs.xml ├── compiler.xml ├── runConfigurations.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── .settings └── org.eclipse.buildship.core.prefs ├── .project ├── .travis.yml ├── gradle.properties ├── .gitignore ├── gradlew.bat ├── README.md ├── CODE_OF_CONDUCT.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /preview/logo/master.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/preview/logo/master.ai -------------------------------------------------------------------------------- /preview/logo/master.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/preview/logo/master.eps -------------------------------------------------------------------------------- /preview/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/preview/screenshot.png -------------------------------------------------------------------------------- /app/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | connection.project.dir=.. 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /preview/logo/logomark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/preview/logo/logomark.png -------------------------------------------------------------------------------- /preview/logo/logovertical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/preview/logo/logovertical.png -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/res/font/roboto.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/app/src/main/res/font/roboto.ttf -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /preview/logo/logohorizontal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/preview/logo/logohorizontal.png -------------------------------------------------------------------------------- /app/src/main/res/web_hi_res_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/app/src/main/res/web_hi_res_512.png -------------------------------------------------------------------------------- /app/src/main/res/font/roboto_bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/app/src/main/res/font/roboto_bold.ttf -------------------------------------------------------------------------------- /app/src/main/res/font/roboto_light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/app/src/main/res/font/roboto_light.ttf -------------------------------------------------------------------------------- /app/src/main/res/font/roboto_medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/app/src/main/res/font/roboto_medium.ttf -------------------------------------------------------------------------------- /app/src/main/res/mipmap-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letelete/sleep-cycle-alarm/HEAD/app/src/main/res/mipmap-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/events/RealmChangeEvent.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.events; 2 | 3 | public class RealmChangeEvent { 4 | } 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/events/SetHourButtonClickedEvent.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.events; 2 | 3 | public class SetHourButtonClickedEvent { 4 | } 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_fab_extended.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 24 19:58:02 CEST 2018 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-4.6-all.zip 7 | -------------------------------------------------------------------------------- /.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | auto.sync=false 2 | build.scans.enabled=false 3 | connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) 4 | connection.project.dir= 5 | eclipse.preferences.version=1 6 | gradle.user.home= 7 | offline.mode=false 8 | override.workspace.settings=true 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_close_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shadow.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_primary_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/color/navigation_bar_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_secondary_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/menu/three_dot_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_add.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_fab_extended_drawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_fab_extended_no_background_drawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/events/AddAlarmEvent.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.events; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 4 | 5 | public class AddAlarmEvent { 6 | 7 | private Item item; 8 | 9 | public AddAlarmEvent(Item item) { 10 | this.item = item; 11 | } 12 | 13 | public Item getItem() { 14 | return item; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | sleep-cycle-alarm 4 | Project sleep-cycle-alarm created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/ui/dialog/ItemDialogContract.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.ui.dialog; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Alarm; 4 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 5 | 6 | public interface ItemDialogContract { 7 | 8 | void bind(Item item); 9 | 10 | void bind(Alarm alarm); 11 | 12 | void setRingtone(String itemRingtone); 13 | 14 | String getRingtone(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_list_ringtone.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_empty_alarms_list.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_bottom_navigation_sleepnow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/itemsbuilder/ItemsBuilderStrategy.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 4 | 5 | import org.joda.time.DateTime; 6 | 7 | import java.util.List; 8 | 9 | public interface ItemsBuilderStrategy { 10 | List getArrayOfItems(DateTime currentDate, DateTime executionDate); 11 | 12 | DateTime getNextAlarmDate(DateTime executionDate); 13 | 14 | boolean isPossibleToCreateNextItem(DateTime currentDate, DateTime dateToGoToSleep); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_bottom_naviagation_alarms.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_bottom_navigation_wakeupat.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_list_alarm_add.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/Const.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils; 2 | 3 | public class Const { 4 | 5 | public static class KEYS { 6 | public final static String ALARM_ID = "ALARM_ID"; 7 | public static final String RINGTONE_ID = "RINGTONE_ID"; 8 | } 9 | 10 | public static class DEFAULTS { 11 | public static final String ALARM_SOUND = "DEFAULT_SOUND"; 12 | public final static int RING_DURATION_MS = 5 * 60 * 1000; 13 | public static final String THEME_ID = "1"; 14 | public static final boolean ALARMS_HAVE_SAME_RINGTONE = false; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | android: 4 | components: 5 | - tools 6 | - platform-tools 7 | - build-tools-28.0.3 8 | - android-28 9 | - android-22 10 | - extra-android-m2repository 11 | - sys-img-armeabi-v7a-android-22 12 | 13 | before_script: 14 | - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a 15 | - emulator -avd test -no-skin -no-audio -no-window & 16 | - android-wait-for-emulator 17 | - adb shell input keyevent 82 & 18 | 19 | script: 20 | - ./gradlew build jacocoTestReport assembleAndroidTest 21 | - ./gradlew connectedCheck 22 | 23 | after_success: 24 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/app/RealmInitialData.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.app; 2 | 3 | 4 | import android.util.Log; 5 | 6 | import io.realm.Realm; 7 | 8 | public class RealmInitialData implements Realm.Transaction { 9 | @Override 10 | public void execute(Realm realm) { 11 | Log.d(getClass().getName(), "Execute RealmInitialData"); 12 | } 13 | 14 | @Override 15 | public int hashCode() { 16 | return RealmInitialData.class.hashCode(); 17 | } 18 | 19 | @Override 20 | public boolean equals(Object obj) { 21 | return obj instanceof RealmInitialData; 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_list_alarm_access.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_empty_wakeupat_list.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | app 4 | Project app created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_list_ringtone_full_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 10 | 11 | 14 | 15 | 16 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_list_alarm_add_full_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 10 | 11 | 14 | 15 | 16 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_close_activity_drawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 10 | 11 | 14 | 15 | 16 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_list_alarm_access_full_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 10 | 11 | 14 | 15 | 16 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/app/CustomApp.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.app; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import java.lang.ref.WeakReference; 7 | 8 | import io.realm.Realm; 9 | 10 | public class CustomApp extends Application { 11 | 12 | private static WeakReference contextWeakReference; 13 | 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | Realm.init(this); 18 | contextWeakReference = new WeakReference<>(getApplicationContext()); 19 | } 20 | 21 | public static Context getContext() { 22 | return contextWeakReference.get(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/activealarms/AlarmsContract.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.activealarms; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Alarm; 4 | 5 | public interface AlarmsContract { 6 | interface AlarmsView { 7 | 8 | void showEditAlarmDialog(Alarm alarm); 9 | 10 | void setupAdapter(); 11 | 12 | } 13 | 14 | interface AlarmsPresenter { 15 | void bindView(AlarmsContract.AlarmsView viewContract); 16 | 17 | void unbindView(); 18 | 19 | void handleRealmChange(); 20 | 21 | void showEditDialog(Alarm alarm); 22 | 23 | void deleteAlarmById(final String id); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_set_hour_to_wake_up_at.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/activealarms/AlarmScopeListener.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.activealarms; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | import com.gmail.brunokawka.poland.sleepcyclealarm.app.RealmManager; 6 | 7 | public class AlarmScopeListener extends Fragment { 8 | private AlarmsPresenter alarmsPresenter; 9 | 10 | public AlarmScopeListener() { 11 | setRetainInstance(true); 12 | RealmManager.incrementCount(); 13 | alarmsPresenter = new AlarmsPresenter(); 14 | } 15 | 16 | @Override 17 | public void onDestroy() { 18 | RealmManager.decrementCount(); 19 | super.onDestroy(); 20 | } 21 | 22 | public AlarmsPresenter getPresenter() { 23 | return alarmsPresenter; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/schedule/AlarmReceiver.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.schedule; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.util.Log; 8 | 9 | public class AlarmReceiver extends BroadcastReceiver { 10 | 11 | @Override 12 | public void onReceive(Context context, Intent intent) { 13 | Bundle extras = intent.getExtras(); 14 | Intent service = new Intent(context, AlarmService.class); 15 | if (extras != null) { 16 | service.putExtras(extras); 17 | } else { 18 | Log.e(getClass().getName(), "onReceive(): extras == null"); 19 | } 20 | context.startService(service); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/values/preference_keys.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | wakeupat_preferences 6 | key_last_execution_date 7 | 8 | key_select_theme 9 | key_alarm_vibrate_when_ringing 10 | key_alarms_has_same_ringtone 11 | key_ringtone_select 12 | key_ring_duration 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/menu/bottom_navigation_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 14 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_fab_extended_no_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/test/java/android/util/Log.java: -------------------------------------------------------------------------------- 1 | package android.util; 2 | 3 | public class Log { 4 | public static int d(String tag, String msg) { 5 | System.out.println("DEBUG: " + tag + ": " + msg); 6 | return 0; 7 | } 8 | 9 | public static int i(String tag, String msg) { 10 | System.out.println("INFO: " + tag + ": " + msg); 11 | return 0; 12 | } 13 | 14 | public static int w(String tag, String msg) { 15 | System.out.println("WARN: " + tag + ": " + msg); 16 | return 0; 17 | } 18 | 19 | public static int e(String tag, String msg) { 20 | System.out.println("ERROR: " + tag + ": " + msg); 21 | return 0; 22 | } 23 | 24 | public static int wtf(String tag, String msg) { 25 | System.out.println("WHAT A TERRIBLE FAILURE: " + tag + ": " + msg); 26 | return 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/test/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/ThemeUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils; 2 | 3 | import android.support.v7.app.AppCompatDelegate; 4 | 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class ThemeUtilsTest { 10 | 11 | @Test 12 | public void testIfCanReturnCurrentTheme() { 13 | assertEquals(AppCompatDelegate.MODE_NIGHT_NO, ThemeUtils.getCurrentTheme("1")); 14 | assertEquals(AppCompatDelegate.MODE_NIGHT_AUTO, ThemeUtils.getCurrentTheme("2")); 15 | assertEquals(AppCompatDelegate.MODE_NIGHT_YES, ThemeUtils.getCurrentTheme("3")); 16 | } 17 | 18 | @Test 19 | public void testIfCanReturnDefaultMode() { 20 | assertEquals(AppCompatDelegate.MODE_NIGHT_NO, ThemeUtils.getCurrentTheme("0")); 21 | assertEquals(AppCompatDelegate.MODE_NIGHT_NO, ThemeUtils.getCurrentTheme("4")); 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/data/ItemsBuilderData.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.data; 2 | 3 | public class ItemsBuilderData { 4 | private final static int MAX_AMOUNT_OF_ITEMS_IN_LIST = 8; 5 | private final static int ONE_SLEEP_CYCLE_DURATION_IN_MINUTES = 90; 6 | private final static int TIME_FOR_FALL_ASLEEP_IN_MINUTES = 15; 7 | 8 | public static int getMaxAmountOfItemsInList() { 9 | return MAX_AMOUNT_OF_ITEMS_IN_LIST; 10 | } 11 | 12 | public static int getOneSleepCycleDurationInMinutes() { 13 | return ONE_SLEEP_CYCLE_DURATION_IN_MINUTES; 14 | } 15 | 16 | public static int getTimeForFallAsleepInMinutes() { 17 | return TIME_FOR_FALL_ASLEEP_IN_MINUTES; 18 | } 19 | 20 | public static int getTotalOneSleepCycleDurationInMinutes() { 21 | return ONE_SLEEP_CYCLE_DURATION_IN_MINUTES + TIME_FOR_FALL_ASLEEP_IN_MINUTES; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/itemsbuilder/ItemsBuilder.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 4 | 5 | import org.joda.time.DateTime; 6 | 7 | import java.util.List; 8 | 9 | public class ItemsBuilder extends ItemsBuilderAbstraction { 10 | 11 | @Override 12 | public List getItems(DateTime currentDate, DateTime executionDate) { 13 | return getBuildingStrategy().getArrayOfItems(currentDate, executionDate); 14 | } 15 | 16 | @Override 17 | public DateTime getNextAlarmDate(DateTime executionDate) { 18 | return getBuildingStrategy().getNextAlarmDate(executionDate); 19 | } 20 | 21 | @Override 22 | public boolean isPossibleToCreateNextItem(DateTime currentDate, DateTime executionDate) { 23 | return getBuildingStrategy().isPossibleToCreateNextItem(currentDate, executionDate); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/ThemeUtils.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils; 2 | 3 | import android.support.v7.app.AppCompatDelegate; 4 | import android.util.Log; 5 | 6 | public class ThemeUtils { 7 | 8 | public static int getCurrentTheme(String themeId) { 9 | int currentTheme; 10 | 11 | switch(themeId) { 12 | case "1": 13 | currentTheme = AppCompatDelegate.MODE_NIGHT_NO; 14 | break; 15 | case "2": 16 | currentTheme = AppCompatDelegate.MODE_NIGHT_AUTO; 17 | break; 18 | case "3": 19 | currentTheme = AppCompatDelegate.MODE_NIGHT_YES; 20 | break; 21 | default: 22 | Log.e(ThemeUtils.class.getName(), "Default case in setAppTheme switch"); 23 | currentTheme = AppCompatDelegate.MODE_NIGHT_NO; 24 | break; 25 | } 26 | 27 | return currentTheme; 28 | } 29 | } -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/itemsbuilder/ItemsBuilderAbstraction.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 4 | 5 | import org.joda.time.DateTime; 6 | 7 | import java.util.List; 8 | 9 | public abstract class ItemsBuilderAbstraction { 10 | private ItemsBuilderStrategy buildingStrategy; 11 | 12 | public void setBuildingStrategy(ItemsBuilderStrategy buildingStrategy) { 13 | this.buildingStrategy = buildingStrategy; 14 | } 15 | 16 | public ItemsBuilderStrategy getBuildingStrategy() { 17 | return this.buildingStrategy; 18 | } 19 | 20 | public abstract List getItems(DateTime currentDate, DateTime executionDate); 21 | 22 | public abstract DateTime getNextAlarmDate(DateTime executionDate); 23 | 24 | public abstract boolean isPossibleToCreateNextItem(DateTime currentDate, 25 | DateTime executionDate); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fast_fade_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/app/base/MainContract.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.app.base; 2 | 3 | import android.os.Bundle; 4 | 5 | public interface MainContract { 6 | 7 | interface MainView { 8 | void setUpBottomNavigationBar(); 9 | void openLatestFragment(); 10 | void openDefaultFragment(); 11 | void setUpToolbar(); 12 | void openSleepNowFragment(); 13 | void openWakeUpAtFragment(); 14 | void openAlarmsFragment(); 15 | void showWakeUpAtActionButton(); 16 | void hideWakeUpAtActionButton(); 17 | void openSettingsActivity(); 18 | void showToastWithDoubleBackMessage(); 19 | void countDownInMilliseconds(int seconds); 20 | void moveAppToBack(); 21 | } 22 | 23 | interface MainPresenter { 24 | void setUpUi(Bundle savedInstanceState); 25 | void handleBottomNavigationTabClick(int menuItemId); 26 | void handleBackPress(); 27 | void handleMenuItemClick(int menuItemId); 28 | void onCountedDown(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/data/pojo/Item.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | public class Item { 6 | private String title; 7 | private String summary; 8 | private DateTime currentDate; 9 | private DateTime executionDate; 10 | 11 | public String getTitle() { 12 | return title; 13 | } 14 | 15 | public void setTitle(String title) { 16 | this.title = title; 17 | } 18 | 19 | public String getSummary() { 20 | return summary; 21 | } 22 | 23 | public void setSummary(String summary) { 24 | this.summary = summary; 25 | } 26 | 27 | public DateTime getCurrentDate() { 28 | return currentDate; 29 | } 30 | 31 | public void setCurrentDate(DateTime currentDate) { 32 | this.currentDate = currentDate; 33 | } 34 | 35 | public DateTime getExecutionDate() { 36 | return executionDate; 37 | } 38 | 39 | public void setExecutionDate(DateTime executionDate) { 40 | this.executionDate = executionDate; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #000000 5 | #000000 6 | 7 | #111111 8 | 9 | #33ffffff 10 | 11 | @color/colorWhite87 12 | @color/colorWhite54 13 | @color/colorWhite38 14 | 15 | @color/colorBlack87 16 | @color/colorBlack54 17 | @color/colorBlack38 18 | 19 | @color/colorTextPrimary 20 | @color/colorWhite12 21 | 22 | #DEFFFFFF 23 | #DEFFFFFF 24 | 25 | #8AFFFFFF 26 | 27 | -------------------------------------------------------------------------------- /app/src/test/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/adapters/AddAlarmsAdapterTest.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.adapters; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 4 | 5 | import org.junit.Test; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Collections; 9 | import java.util.List; 10 | 11 | import static java.util.Arrays.asList; 12 | import static org.hamcrest.CoreMatchers.equalTo; 13 | import static org.junit.Assert.assertThat; 14 | 15 | public class AddAlarmsAdapterTest { 16 | 17 | @Test 18 | public void testIfCanReturnItemCount() { 19 | Item item = new Item(); 20 | 21 | AddAlarmsAdapter addAlarmsAdapter = new AddAlarmsAdapter(asList(item, item, item)); 22 | assertThat(addAlarmsAdapter.getItemCount(), equalTo(3)); 23 | 24 | addAlarmsAdapter = new AddAlarmsAdapter(Collections.singletonList(item)); 25 | assertThat(addAlarmsAdapter.getItemCount(), equalTo(1)); 26 | 27 | List emptyList = new ArrayList<>(); 28 | addAlarmsAdapter = new AddAlarmsAdapter(emptyList); 29 | assertThat(addAlarmsAdapter.getItemCount(), equalTo(0)); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_alarms.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 23 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/addalarm/wakeupat/WakeUpAtContract.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.addalarm.wakeupat; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | public interface WakeUpAtContract { 6 | 7 | interface WakeUpAtView { 8 | 9 | void updateCurrentDate(); 10 | 11 | void showSetTimeDialog(); 12 | 13 | void setLastExecutionDate(DateTime newDate); 14 | 15 | void setLastExecutionDateFromPreferences(); 16 | 17 | void setupAdapter(); 18 | 19 | void saveExecutionDateToPreferencesAsString(); 20 | 21 | void updateDescription(); 22 | 23 | interface DialogContract { 24 | DateTime getDateTime(); 25 | } 26 | } 27 | 28 | interface WakeUpAtPresenter { 29 | void handleFloatingActionButtonClicked(); 30 | 31 | void bindView(WakeUpAtContract.WakeUpAtView view); 32 | 33 | void unbindView(); 34 | 35 | void setUpEnvironment(); 36 | 37 | void showTimeDialog(); 38 | 39 | void dismissTimeDialog(); 40 | 41 | void tryToGenerateAListWithGivenValues(DateTime newChosenExecutionDate, 42 | DateTime currentDate, DateTime lastExecutionDate); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_empty_state.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 23 | 24 | 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24dp 5 | 6 | 20sp 7 | 16sp 8 | 14sp 9 | 14sp 10 | 12sp 11 | 12sp 12 | 13 | 4dp 14 | 8dp 15 | 16dp 16 | 24dp 17 | 48dp 18 | 19 | 40dp 20 | 24dp 21 | 22 | 3dp 23 | 7dp 24 | 25 | 14sp 26 | 27 | 12dp 28 | 36dp 29 | 30 | 38dp 31 | 38dp 32 | 144dp 33 | 34 | 64sp 35 | 64dp 36 | 8dp 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/activealarms/AlarmsPresenter.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.activealarms; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.AlarmDAO; 4 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Alarm; 5 | 6 | public class AlarmsPresenter implements AlarmsContract.AlarmsPresenter { 7 | 8 | private AlarmsContract.AlarmsView view; 9 | private AlarmDAO alarmDAO; 10 | 11 | public static AlarmsPresenter getService() { 12 | return AlarmsFragment.getAlarmsPresenter(); 13 | } 14 | 15 | @Override 16 | public void bindView(AlarmsContract.AlarmsView view) { 17 | this.view = view; 18 | alarmDAO = new AlarmDAO(); 19 | } 20 | 21 | @Override 22 | public void unbindView() { 23 | this.view = null; 24 | alarmDAO.cleanUp(); 25 | } 26 | 27 | @Override 28 | public void handleRealmChange() { 29 | if (view != null) { 30 | view.setupAdapter(); 31 | } 32 | } 33 | 34 | @Override 35 | public void showEditDialog(Alarm alarm) { 36 | if(hasView()) { 37 | view.showEditAlarmDialog(alarm); 38 | } 39 | } 40 | 41 | @Override 42 | public void deleteAlarmById(final String id) { 43 | alarmDAO.removeFromRealmById(id); 44 | } 45 | 46 | private boolean hasView() { 47 | return view != null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | 12 | # Built application files 13 | *.apk 14 | *.ap_ 15 | 16 | # Files for the ART/Dalvik VM 17 | *.dex 18 | 19 | # Java class files 20 | *.class 21 | 22 | # Generated files 23 | bin/ 24 | gen/ 25 | out/ 26 | 27 | # Gradle files 28 | .gradle/ 29 | build/ 30 | 31 | # Local configuration file (sdk path, etc) 32 | local.properties 33 | 34 | # Proguard folder generated by Eclipse 35 | proguard/ 36 | 37 | # Log Files 38 | *.log 39 | 40 | # Android Studio Navigation editor temp files 41 | .navigation/ 42 | 43 | # Android Studio captures folder 44 | captures/ 45 | 46 | # IntelliJ 47 | *.iml 48 | .idea/workspace.xml 49 | .idea/tasks.xml 50 | .idea/gradle.xml 51 | .idea/assetWizardSettings.xml 52 | .idea/dictionaries 53 | .idea/libraries 54 | .idea/caches 55 | 56 | # Keystore files 57 | # Uncomment the following line if you do not want to check your keystore files in. 58 | #*.jks 59 | 60 | # External native build folder generated in Android Studio 2.2 and later 61 | .externalNativeBuild 62 | 63 | # Google Services (e.g. APIs or Firebase) 64 | google-services.json 65 | 66 | # Freeline 67 | freeline.py 68 | freeline/ 69 | freeline_project_description.json 70 | 71 | # fastlane 72 | fastlane/report.xml 73 | fastlane/Preview.html 74 | fastlane/screenshots 75 | fastlane/test_output 76 | fastlane/readme.md 77 | 78 | -------------------------------------------------------------------------------- /app/src/main/res/anim/grow_fade_in_center.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 27 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/data/pojo/Alarm.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo; 2 | 3 | import io.realm.RealmObject; 4 | import io.realm.annotations.PrimaryKey; 5 | import io.realm.annotations.Required; 6 | 7 | public class Alarm extends RealmObject { 8 | 9 | @PrimaryKey 10 | @Required 11 | private String id; 12 | 13 | private String title; 14 | private String summary; 15 | private String ringtone; 16 | private String currentDate; 17 | private String executionDate; 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | public void setId(String id) { 24 | this.id = id; 25 | } 26 | 27 | public String getTitle() { 28 | return title; 29 | } 30 | 31 | public void setTitle(String title) { 32 | this.title = title; 33 | } 34 | 35 | public String getSummary() { 36 | return summary; 37 | } 38 | 39 | public void setSummary(String summary) { 40 | this.summary = summary; 41 | } 42 | 43 | public String getRingtone() { 44 | return ringtone; 45 | } 46 | 47 | public void setRingtone(String ringtone) { 48 | this.ringtone = ringtone; 49 | } 50 | 51 | public String getCurrentDate() { 52 | return currentDate; 53 | } 54 | 55 | public void setCurrentDate(String currentDate) { 56 | this.currentDate = currentDate; 57 | } 58 | 59 | public String getExecutionDate() { 60 | return executionDate; 61 | } 62 | 63 | public void setExecutionDate(String executionDate) { 64 | this.executionDate = executionDate; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_wake_up_at.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 27 | 28 | 32 | 33 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_item_ringtone.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 21 | 22 | 29 | 30 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/TimeUtils.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | public class TimeUtils { 6 | 7 | public static DateTime getClosestTimeRound(DateTime dt) { 8 | if (isRoundToFullHourNeeded(dt)) { 9 | return getFullHourRound(dt); 10 | } else if (isRoundToHalfOfTenNeeded(dt)) { 11 | return getHalfOfTenRound(dt); 12 | } else { 13 | return getTheClosestTenRound(dt); 14 | } 15 | } 16 | 17 | private static boolean isRoundToFullHourNeeded(DateTime dt) { 18 | return dt.getMinuteOfHour() > 57 || dt.getMinuteOfHour() < 3; 19 | } 20 | 21 | private static boolean isRoundToHalfOfTenNeeded(DateTime dt) { 22 | int minuteOfMinutesOfHour = dt.getMinuteOfHour() % 10; 23 | return minuteOfMinutesOfHour >= 3 && minuteOfMinutesOfHour <= 7; 24 | } 25 | 26 | private static int getDifferenceBetweenMinuteAndHalfOfTen(int minute) { 27 | int halfOfTen = 5; 28 | return halfOfTen - (minute % 10); 29 | } 30 | 31 | private static DateTime getFullHourRound(DateTime dt) { 32 | return dt.hourOfDay().roundHalfFloorCopy(); 33 | } 34 | 35 | private static DateTime getHalfOfTenRound(DateTime dt) { 36 | return dt.plusMinutes(getDifferenceBetweenMinuteAndHalfOfTen(dt.getMinuteOfHour())); 37 | } 38 | 39 | private static DateTime getTheClosestTenRound(DateTime dt) { 40 | int minuteOfMinutesOfHour = dt.getMinuteOfHour() % 10; 41 | int diffToTen = 10 - minuteOfMinutesOfHour; 42 | return minuteOfMinutesOfHour >= diffToTen 43 | ? dt.plusMinutes(diffToTen) 44 | : dt.minusMinutes(minuteOfMinutesOfHour); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_alarm.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 22 | 23 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_alarm.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 19 | 20 | 29 | 30 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/test/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/AlarmContentUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils; 2 | 3 | import android.util.Log; 4 | 5 | import org.joda.time.DateTime; 6 | import org.joda.time.format.DateTimeFormat; 7 | import org.junit.Test; 8 | 9 | import static org.hamcrest.CoreMatchers.is; 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertThat; 12 | 13 | public class AlarmContentUtilsTest { 14 | 15 | private static DateTime getDateTime(String string) { 16 | return DateTimeFormat.forPattern("dd/MM/yyyy HH:mm").parseDateTime(string); 17 | } 18 | 19 | @Test 20 | public void testIfCanReturnTitle() { 21 | assertEquals("06:30", AlarmContentUtils.getTitle(getDateTime("04/02/2011 06:30"))); 22 | assertEquals("00:03", AlarmContentUtils.getTitle(getDateTime("04/02/2011 00:03"))); 23 | assertEquals("23:59", AlarmContentUtils.getTitle(getDateTime("04/02/2011 23:59"))); 24 | assertEquals("00:00", AlarmContentUtils.getTitle(getDateTime("04/02/2011 00:00"))); 25 | } 26 | 27 | @Test 28 | public void testIfCanReturnTitleForWakeUpAt() { 29 | assertThat(AlarmContentUtils.getTitleForWakeUpAt(getDateTime("01/01/2001 23:00"), getDateTime("02/01/2001 6:30")), 30 | is("23:00 -> 06:30")); 31 | assertThat(AlarmContentUtils.getTitleForWakeUpAt(getDateTime("02/01/2001 00:00"), getDateTime("02/01/2001 01:30")), 32 | is("00:00 -> 01:30")); 33 | } 34 | 35 | @Test 36 | public void testIfCanReturnSimpleDate() { 37 | DateTime complexDate = DateTime.now(); 38 | DateTime simpleDate = getDateTime(complexDate.getDayOfMonth() + "/" + complexDate.getMonthOfYear() + "/" 39 | + complexDate.getYear() + " " + complexDate.getHourOfDay() + ":" + complexDate.getMinuteOfHour()); 40 | Log.d(getClass().getName(), simpleDate.toString()); 41 | assertThat(AlarmContentUtils.getDateConvertedToSimple(complexDate), 42 | is(simpleDate)); 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #FFFFFF 5 | #FFFFFF 6 | #2ed573 7 | 8 | @color/colorPrimary 9 | 10 | 11 | #000000 12 | #DE000000 13 | #B3000000 14 | #8A000000 15 | #80000000 16 | #61000000 17 | #1F000000 18 | 19 | 20 | #FFFFFF 21 | #DEFFFFFF 22 | #B3FFFFFF 23 | #8AFFFFFF 24 | #8FFFFFF0 25 | #61FFFFFF 26 | #1FFFFFFF 27 | 28 | @color/colorBlack87 29 | @color/colorBlack54 30 | @color/colorBlack38 31 | 32 | @color/colorWhite100 33 | @color/colorWhite70 34 | @color/colorWhite50 35 | 36 | #82b1ff 37 | #1f000000 38 | 39 | #FFFFFF 40 | 41 | @color/colorTextPrimary 42 | @color/colorBlack12 43 | 44 | #DEFFFFFF 45 | #8A000000 46 | 47 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 20 | 21 | 28 | 29 | 34 | 35 | 40 | 41 | 44 | 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_sleep_now.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 14 | 15 | 19 | 20 | 27 | 28 | 34 | 35 | 36 | 37 | 38 | 39 | 48 | 49 | 53 | 54 | 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/itemsbuilder/SleepNowBuildingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.ItemsBuilderData; 4 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 5 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.AlarmContentUtils; 6 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.TimeUtils; 7 | 8 | import org.joda.time.DateTime; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import javax.annotation.Nullable; 14 | 15 | public class SleepNowBuildingStrategy implements ItemsBuilderStrategy { 16 | private List items; 17 | private DateTime currentDate; 18 | private DateTime executionDate; 19 | 20 | @Override 21 | public List getArrayOfItems(DateTime currentDate, @Nullable DateTime executionDate) { 22 | items = new ArrayList<>(); 23 | this.currentDate = currentDate; 24 | this.executionDate = currentDate; 25 | 26 | for (int i = 0; i < ItemsBuilderData.getMaxAmountOfItemsInList(); i++) { 27 | if (isPossibleToCreateNextItem(currentDate, this.executionDate)) { 28 | this.executionDate = getNextAlarmDate(this.executionDate); 29 | createNextItemAndAddItToArray(); 30 | } 31 | } 32 | 33 | return items; 34 | } 35 | 36 | @Override 37 | public DateTime getNextAlarmDate(DateTime executionDate) { 38 | return executionDate.plusMinutes(ItemsBuilderData.getOneSleepCycleDurationInMinutes()); 39 | } 40 | 41 | @Override 42 | public boolean isPossibleToCreateNextItem(DateTime currentDate, DateTime dateToGoToSleep) { 43 | return true; 44 | } 45 | 46 | private void createNextItemAndAddItToArray() { 47 | DateTime executionDatePlusTimeToFallAsleepWithRoundedTime = TimeUtils 48 | .getClosestTimeRound(executionDate 49 | .plusMinutes(ItemsBuilderData.getTimeForFallAsleepInMinutes())); 50 | 51 | Item item = new Item(); 52 | 53 | item.setTitle(AlarmContentUtils.getTitle(executionDatePlusTimeToFallAsleepWithRoundedTime)); 54 | item.setSummary(AlarmContentUtils.getSummary(currentDate, executionDate)); 55 | item.setCurrentDate(currentDate); 56 | item.setExecutionDate(executionDatePlusTimeToFallAsleepWithRoundedTime); 57 | 58 | items.add(item); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/app/RealmManager.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.app; 2 | 3 | import android.util.Log; 4 | 5 | import io.realm.Realm; 6 | import io.realm.RealmConfiguration; 7 | 8 | public class RealmManager { 9 | 10 | private static Realm realm; 11 | private static RealmConfiguration realmConfiguration; 12 | private static int activityCount = 0; 13 | 14 | public static void initializeRealmConfig() { 15 | if(realmConfiguration == null) { 16 | Log.d(RealmManager.class.getName(), "Initializing Realm configuration."); 17 | setRealmConfiguration(new RealmConfiguration.Builder() 18 | .initialData(new RealmInitialData()) 19 | .deleteRealmIfMigrationNeeded() 20 | .build()); 21 | } 22 | } 23 | 24 | private static void setRealmConfiguration(RealmConfiguration realmConfiguration) { 25 | RealmManager.realmConfiguration = realmConfiguration; 26 | Realm.setDefaultConfiguration(realmConfiguration); 27 | } 28 | 29 | public static Realm getRealm() { 30 | return realm; 31 | } 32 | 33 | public static void incrementCount() { 34 | if(activityCount == 0) { 35 | if(realm != null && !realm.isClosed()) { 36 | Log.w(RealmManager.class.getName(), "Unexpected open Realm found."); 37 | realm.close(); 38 | } 39 | Log.d(RealmManager.class.getName(), 40 | "Incrementing Activity Count [0]: opening Realm."); 41 | realm = Realm.getDefaultInstance(); 42 | } 43 | activityCount++; 44 | Log.d(RealmManager.class.getName(), "Increment: Count [" + activityCount + "]"); 45 | } 46 | 47 | public static void decrementCount() { 48 | activityCount--; 49 | Log.d(RealmManager.class.getName(), "Decrement: Count [" + activityCount + "]"); 50 | if(activityCount <= 0) { 51 | Log.d(RealmManager.class.getName(), "Decrementing Activity Count: closing Realm."); 52 | activityCount = 0; 53 | realm.close(); 54 | // realmConfiguration null on Android 6 (Test with xiaomi Mi4) 55 | if (realmConfiguration == null) initializeRealmConfig(); 56 | if(Realm.compactRealm(realmConfiguration)) { 57 | Log.d(RealmManager.class.getName(), "Realm compacted successfully."); 58 | } 59 | realm = null; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/data/AlarmDAO.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.data; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.util.Log; 5 | 6 | import com.gmail.brunokawka.poland.sleepcyclealarm.app.RealmManager; 7 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Alarm; 8 | 9 | import java.util.List; 10 | 11 | import io.realm.Realm; 12 | import io.realm.RealmQuery; 13 | 14 | public class AlarmDAO { 15 | 16 | public AlarmDAO() { 17 | RealmManager.incrementCount(); 18 | } 19 | 20 | public void saveIfNotDuplicate(final Alarm alarm) { 21 | Realm realm = RealmManager.getRealm(); 22 | realm.executeTransactionAsync(new Realm.Transaction() { 23 | @Override 24 | public void execute(@NonNull Realm realm) { 25 | if (isNotDuplicate(alarm, realm)) { 26 | realm.insertOrUpdate(alarm); 27 | } 28 | } 29 | }); 30 | } 31 | 32 | private boolean isNotDuplicate(Alarm alarm, Realm realm) { 33 | Alarm duplicateAlarm = realm.where(Alarm.class) 34 | .equalTo("executionDate", alarm.getExecutionDate()).findFirst(); 35 | return duplicateAlarm == null; 36 | } 37 | 38 | public void saveEvenIfDuplicate(final Alarm alarm) { 39 | Realm realm = RealmManager.getRealm(); 40 | realm.executeTransactionAsync(new Realm.Transaction() { 41 | @Override 42 | public void execute(@NonNull Realm realm) { 43 | realm.insertOrUpdate(alarm); 44 | } 45 | }); 46 | } 47 | 48 | public void removeFromRealmById(final String id) { 49 | Log.d(getClass().getName(), "Removing from realm..."); 50 | Realm realm = RealmManager.getRealm(); 51 | 52 | realm.executeTransactionAsync(new Realm.Transaction() { 53 | @Override 54 | public void execute(@NonNull Realm realm) { 55 | Alarm alarm = realm.where(Alarm.class).equalTo("id", id).findFirst(); 56 | if(alarm != null) { 57 | alarm.deleteFromRealm(); 58 | } 59 | } 60 | }); 61 | } 62 | 63 | public List getListOfAlarms() { 64 | Realm realm = RealmManager.getRealm(); 65 | RealmQuery query = realm.where(Alarm.class); 66 | return query.findAll(); 67 | } 68 | 69 | public void cleanUp() { 70 | RealmManager.decrementCount(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/AlarmContentUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.ItemsBuilderData; 4 | 5 | import org.joda.time.DateTime; 6 | import org.joda.time.format.DateTimeFormat; 7 | import org.junit.Test; 8 | 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | public class AlarmContentUtilsTest { 15 | 16 | private static final String CURRENT_DATE_STRING = "01/01/1111 22:20"; 17 | 18 | private static final List SUMMARY_VARIABLES_FOR_CURRENT_DATE_EQUALS_2220 = Arrays.asList( 19 | "02/01/1111 00:05", "1h 30min", "Unhealthy", 20 | "02/01/1111 01:35", "3h", "Unhealthy", 21 | "02/01/1111 03:05", "4h 30min", "Optimal", 22 | "02/01/1111 04:35", "6h", "Optimal", 23 | "02/01/1111 06:05", "7h 30min", "Healthy", 24 | "02/01/1111 07:35", "9h", "Healthy", 25 | "02/01/1111 09:05", "10h 30min", "Not recommended", 26 | "02/01/1111 10:35", "12h", "Not recommended" 27 | ); 28 | 29 | private static DateTime getDateTime(String string) { 30 | return DateTimeFormat.forPattern("dd/MM/yyyy HH:mm").parseDateTime(string); 31 | } 32 | 33 | @Test 34 | public void testIfCanReturnSummaries() { 35 | int amountOfUsedItemsOnOneLoopRun = 3; 36 | int maxIndex = SUMMARY_VARIABLES_FOR_CURRENT_DATE_EQUALS_2220.size() - 1; 37 | 38 | String executionDateString; 39 | String sleepDurationString; 40 | String sleepQuality; 41 | String expected; 42 | 43 | DateTime executionDateWithoutTimeToFallAsleep; 44 | 45 | for (int index = 0; index < maxIndex; index += amountOfUsedItemsOnOneLoopRun) { 46 | executionDateString = SUMMARY_VARIABLES_FOR_CURRENT_DATE_EQUALS_2220.get(index); 47 | sleepDurationString = SUMMARY_VARIABLES_FOR_CURRENT_DATE_EQUALS_2220.get(index+1); 48 | sleepQuality = SUMMARY_VARIABLES_FOR_CURRENT_DATE_EQUALS_2220.get(index+2); 49 | 50 | expected = String.format("%1$s of sleep | %2$s", sleepDurationString, sleepQuality); 51 | executionDateWithoutTimeToFallAsleep = getDateTime(executionDateString).minusMinutes(ItemsBuilderData.getTimeForFallAsleepInMinutes()); 52 | 53 | assertEquals(expected, AlarmContentUtils.getSummary(getDateTime(CURRENT_DATE_STRING), executionDateWithoutTimeToFallAsleep)); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/schedule/AlarmController.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.schedule; 2 | 3 | import android.app.AlarmManager; 4 | import android.app.PendingIntent; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.Build; 8 | 9 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Alarm; 10 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.Const; 11 | 12 | import org.joda.time.DateTime; 13 | 14 | import java.util.UUID; 15 | 16 | public class AlarmController { 17 | 18 | private Context context; 19 | private AlarmManager alarmManager; 20 | 21 | public AlarmController(Context context) { 22 | this.context = context; 23 | alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 24 | } 25 | 26 | public void setAlarm(Alarm alarm) { 27 | PendingIntent setAlarmPendingIntent 28 | = getAlarmPendingIntent(alarm, PendingIntent.FLAG_UPDATE_CURRENT); 29 | long executionDateMs = DateTime.parse(alarm.getExecutionDate()).getMillis(); 30 | 31 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 32 | alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, executionDateMs, 33 | setAlarmPendingIntent); 34 | } else { 35 | alarmManager.setExact(AlarmManager.RTC_WAKEUP, executionDateMs, setAlarmPendingIntent); 36 | } 37 | } 38 | 39 | public void cancelAlarm(Alarm alarm) { 40 | PendingIntent cancelServicePendingIntent = getAlarmPendingIntent(alarm, 0); 41 | alarmManager.cancel(cancelServicePendingIntent); 42 | } 43 | 44 | public void dismissCurrentlyPlayingAlarm() { 45 | context.stopService(new Intent(context, AlarmService.class)); 46 | } 47 | 48 | private PendingIntent getAlarmPendingIntent(Alarm alarm, int flag) { 49 | String alarmId = alarm.getId(); 50 | String ringtone = alarm.getRingtone(); 51 | Intent alarmIntent = new Intent(context, AlarmReceiver.class); 52 | alarmIntent.putExtra(Const.KEYS.ALARM_ID, alarmId); 53 | alarmIntent.putExtra(Const.KEYS.RINGTONE_ID, ringtone); 54 | 55 | int serviceId = getMostSignificantBits(alarmId); 56 | 57 | return PendingIntent.getBroadcast(context, serviceId, alarmIntent, flag); 58 | } 59 | 60 | private int getMostSignificantBits(String id) { 61 | return (int) Math 62 | .abs(UUID.fromString(id).getMostSignificantBits()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/addalarm/sleepnow/SleepNowFragment.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.addalarm.sleepnow; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.gmail.brunokawka.poland.sleepcyclealarm.R; 11 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 12 | import com.gmail.brunokawka.poland.sleepcyclealarm.tabs.adapters.AddAlarmsAdapter; 13 | import com.gmail.brunokawka.poland.sleepcyclealarm.tabs.addalarm.AddDialogFragment; 14 | import com.gmail.brunokawka.poland.sleepcyclealarm.tabs.ui.EmptyStateRecyclerView; 15 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.AlarmContentUtils; 16 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder.ItemsBuilder; 17 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder.SleepNowBuildingStrategy; 18 | 19 | import org.joda.time.DateTime; 20 | 21 | import java.util.List; 22 | 23 | import butterknife.BindView; 24 | import butterknife.ButterKnife; 25 | 26 | public class SleepNowFragment extends AddDialogFragment { 27 | 28 | private ItemsBuilder itemsBuilder; 29 | 30 | @BindView(R.id.rv_sleepnow) 31 | EmptyStateRecyclerView recycler; 32 | 33 | @Override 34 | public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup container, 35 | Bundle savedInstanceState) { 36 | View view = layoutInflater.inflate(R.layout.fragment_sleep_now, container, false); 37 | ButterKnife.bind(this, view); 38 | 39 | itemsBuilder = new ItemsBuilder(); 40 | itemsBuilder.setBuildingStrategy(new SleepNowBuildingStrategy()); 41 | 42 | return view; 43 | } 44 | 45 | @Override 46 | public void onActivityCreated(Bundle savedInstanceState) { 47 | super.onActivityCreated(savedInstanceState); 48 | setupRecycler(); 49 | } 50 | 51 | private void setupRecycler() { 52 | recycler.setLayoutManager(new LinearLayoutManager(getActivity())); 53 | DateTime currentDateFormatted = AlarmContentUtils.getDateConvertedToSimple(DateTime.now()); 54 | List items = itemsBuilder.getItems(currentDateFormatted, null); 55 | recycler.setAdapter(new AddAlarmsAdapter(items)); 56 | } 57 | 58 | @Override 59 | public void onDestroyView() { 60 | super.onDestroyView(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/addalarm/wakeupat/WakeUpAtSetTimeView.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.addalarm.wakeupat; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.support.annotation.Nullable; 6 | import android.util.AttributeSet; 7 | import android.widget.LinearLayout; 8 | import android.widget.TimePicker; 9 | 10 | import com.gmail.brunokawka.poland.sleepcyclealarm.R; 11 | 12 | import org.joda.time.DateTime; 13 | 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | 17 | public class WakeUpAtSetTimeView extends LinearLayout 18 | implements WakeUpAtContract.WakeUpAtView.DialogContract { 19 | 20 | @BindView(R.id.dateTimeSelect) protected TimePicker timePicker; 21 | 22 | private DateTime dateTime; 23 | 24 | public WakeUpAtSetTimeView(Context context) { 25 | super(context); 26 | } 27 | 28 | public WakeUpAtSetTimeView(Context context, @Nullable AttributeSet attrs) { 29 | super(context, attrs); 30 | } 31 | 32 | public WakeUpAtSetTimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 33 | super(context, attrs, defStyleAttr); 34 | } 35 | 36 | @TargetApi(21) 37 | public WakeUpAtSetTimeView(Context context, AttributeSet attrs, 38 | int defStyleAttr, int defStyleRes) { 39 | super(context, attrs, defStyleAttr, defStyleRes); 40 | } 41 | 42 | @Override 43 | protected void onFinishInflate() { 44 | super.onFinishInflate(); 45 | ButterKnife.bind(this); 46 | 47 | timePicker.setIs24HourView(true); 48 | timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { 49 | @Override 50 | public void onTimeChanged(TimePicker timePicker, int hourOfDay, int minute) { 51 | setDateTime(hourOfDay, minute); 52 | } 53 | }); 54 | } 55 | 56 | private void setDateTime(int hourOfDay, int minute) { 57 | DateTime currentDate = DateTime.now(); 58 | DateTime pickedDate = currentDate.withHourOfDay(hourOfDay) 59 | .withMinuteOfHour(minute); 60 | 61 | this.dateTime = currentDate.getHourOfDay() > hourOfDay 62 | ? pickedDate.plusDays(1) 63 | : pickedDate; 64 | } 65 | 66 | @Override 67 | public DateTime getDateTime() { 68 | if (dateTime == null) { 69 | dateTime = DateTime.now(); 70 | } 71 | return dateTime; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/ui/WakeUpAtSetHourButton.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.ui; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.ObjectAnimator; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class WakeUpAtSetHourButton extends AnimatorListenerAdapter { 10 | 11 | private final int ANIM_TIME_IN_MS = 400; 12 | private final float POS_TO_MAKE_BUTTON_GONE = 200f; 13 | private final float POS_TO_MAKE_BUTTON_VISIBLE = -150f; 14 | 15 | private int wakeUpAtButtonVisibilityAfterStartedAnimation = View.GONE; 16 | private ObjectAnimator wakeUpAtButtonAnimator; 17 | private Button wakeUpAtButton; 18 | private int finalViewId; 19 | 20 | public WakeUpAtSetHourButton(Button wakeUpAtButton) { 21 | this.wakeUpAtButton = wakeUpAtButton; 22 | } 23 | 24 | public void show() { 25 | this.finalViewId = View.VISIBLE; 26 | animateWakeUpAtButton(POS_TO_MAKE_BUTTON_GONE, POS_TO_MAKE_BUTTON_VISIBLE); 27 | } 28 | 29 | public void hide() { 30 | this.finalViewId = View.GONE; 31 | animateWakeUpAtButton(POS_TO_MAKE_BUTTON_VISIBLE, POS_TO_MAKE_BUTTON_GONE); 32 | } 33 | 34 | private void animateWakeUpAtButton(final float startPosY, final float endPosY) { 35 | if (wakeUpAtButtonVisibilityAfterStartedAnimation != finalViewId) { 36 | cancelAnimationIfNeeded(); 37 | 38 | wakeUpAtButtonVisibilityAfterStartedAnimation = finalViewId; 39 | wakeUpAtButtonAnimator = ObjectAnimator.ofFloat(wakeUpAtButton, 40 | "translationY", startPosY, endPosY); 41 | wakeUpAtButtonAnimator.setDuration(ANIM_TIME_IN_MS); 42 | wakeUpAtButtonAnimator.addListener(this); 43 | wakeUpAtButtonAnimator.start(); 44 | } 45 | } 46 | 47 | private void cancelAnimationIfNeeded() { 48 | if (wakeUpAtButtonAnimator !=null && wakeUpAtButtonAnimator.isRunning()){ 49 | wakeUpAtButtonAnimator.cancel(); 50 | } 51 | } 52 | 53 | @Override 54 | public void onAnimationEnd(Animator animation) { 55 | if (finalViewId != View.VISIBLE) { 56 | wakeUpAtButton.setVisibility(View.GONE); 57 | } 58 | } 59 | @Override 60 | public void onAnimationStart(Animator animation) { 61 | if (wakeUpAtButton.getVisibility() != View.VISIBLE) { 62 | wakeUpAtButton.setVisibility(View.VISIBLE); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/settings/SettingsActivity.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.settings; 2 | 3 | import android.content.SharedPreferences; 4 | import android.os.Bundle; 5 | import android.preference.PreferenceManager; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.app.FragmentTransaction; 8 | import android.support.v7.app.ActionBar; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.Toolbar; 11 | 12 | import com.gmail.brunokawka.poland.sleepcyclealarm.R; 13 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.Const; 14 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.ThemeUtils; 15 | 16 | import butterknife.BindView; 17 | import butterknife.ButterKnife; 18 | 19 | public class SettingsActivity extends AppCompatActivity { 20 | 21 | 22 | @BindView(R.id.tb_settings) 23 | Toolbar tbSettings; 24 | 25 | @Override 26 | public void onCreate(Bundle savedInstanceState) { 27 | setAppTheme(); 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_settings); 30 | ButterKnife.bind(this); 31 | 32 | setupToolbar(); 33 | 34 | if (savedInstanceState == null) { 35 | Fragment fragment = getSupportFragmentManager().findFragmentByTag(SettingsFragment.TAG); 36 | if (fragment == null) { 37 | fragment = new SettingsFragment(); 38 | } 39 | 40 | FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 41 | ft.replace(R.id.fl_settings_container, fragment, SettingsFragment.TAG); 42 | ft.commit(); 43 | } 44 | } 45 | 46 | private void setAppTheme() { 47 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); 48 | String key = getString(R.string.key_change_theme); 49 | int themeId = ThemeUtils.getCurrentTheme(pref.getString(key, Const.DEFAULTS.THEME_ID)); 50 | getDelegate().setLocalNightMode(themeId); 51 | } 52 | 53 | private void setupToolbar() { 54 | setSupportActionBar(tbSettings); 55 | ActionBar ab = getSupportActionBar(); 56 | if (ab != null) { 57 | ab.setHomeAsUpIndicator(R.drawable.ic_close); 58 | ab.setTitle(getString(R.string.menu_settings)); 59 | ab.setDisplayShowTitleEnabled(true); 60 | ab.setDisplayHomeAsUpEnabled(true); 61 | } 62 | } 63 | 64 | @Override 65 | public boolean onSupportNavigateUp() { 66 | onBackPressed(); 67 | return true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/addalarm/wakeupat/WakeUpAtPresenter.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.addalarm.wakeupat; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder.ItemsBuilder; 4 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder.WakeUpAtBuildingStrategy; 5 | 6 | import org.joda.time.DateTime; 7 | 8 | public class WakeUpAtPresenter implements WakeUpAtContract.WakeUpAtPresenter { 9 | 10 | private WakeUpAtContract.WakeUpAtView view; 11 | private boolean isDialogShowing; 12 | private ItemsBuilder itemsBuilder; 13 | 14 | @Override 15 | public void handleFloatingActionButtonClicked() { 16 | view.updateCurrentDate(); 17 | showTimeDialog(); 18 | } 19 | 20 | private boolean hasView() { 21 | return view != null; 22 | } 23 | 24 | @Override 25 | public void bindView(WakeUpAtContract.WakeUpAtView view) { 26 | this.view = view; 27 | 28 | this.itemsBuilder = new ItemsBuilder(); 29 | itemsBuilder.setBuildingStrategy(new WakeUpAtBuildingStrategy()); 30 | 31 | if (isDialogShowing) { 32 | showTimeDialog(); 33 | } 34 | } 35 | 36 | public void unbindView() { 37 | this.view = null; 38 | } 39 | 40 | @Override 41 | public void setUpEnvironment() { 42 | view.updateCurrentDate(); 43 | view.setLastExecutionDateFromPreferences(); 44 | } 45 | 46 | @Override 47 | public void showTimeDialog() { 48 | if (hasView() && !isDialogShowing) { 49 | isDialogShowing = true; 50 | view.showSetTimeDialog(); 51 | } 52 | } 53 | 54 | @Override 55 | public void dismissTimeDialog() { 56 | isDialogShowing = false; 57 | } 58 | 59 | @Override 60 | public void tryToGenerateAListWithGivenValues(DateTime newChosenExecutionDate, 61 | DateTime currentDate, 62 | DateTime lastExecutionDate) { 63 | if (itemsBuilder.isPossibleToCreateNextItem(currentDate, newChosenExecutionDate)) { 64 | updateLastExecutionDate(lastExecutionDate, newChosenExecutionDate); 65 | view.setupAdapter(); 66 | } 67 | } 68 | 69 | private void updateLastExecutionDate(DateTime lastExecutionDate, DateTime newExecutionDate) { 70 | if (!newExecutionDate.equals(lastExecutionDate)) { 71 | view.setLastExecutionDate(newExecutionDate); 72 | view.saveExecutionDateToPreferencesAsString(); 73 | view.updateDescription(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Screenshot](./preview/screenshot.png) 2 | 3 |

Sleep Cycle Alarm is a free material-designed Android app which helps waking up during a light sleep, it also is ad-free and open source under GPLv3 license.

4 | 5 |

6 | 7 | Build Status 9 | 10 | Coverage Status 12 | 13 | Clean Code Status 15 | 16 | Lines of Code 18 | 19 | Platform Support 21 | 22 | Chat on Discord 24 |

25 | 26 | #### Features 27 | 28 | * Custom alarm management system 29 | * Alarms customatization 30 | * Automatically cleans up used up alarms 31 | * Adds new alarm with only two taps from user 32 | * Shows list of hours to set alarm at to wake up with light sleep cycle 33 | * Shows list of hours to go to sleep at when user wants to wake up at specific hour 34 | * Dark and light theme 35 | * Informs user about sleep duration and quality of specific alarm 36 | 37 | #### Dependencies 38 | 39 | * [Butterknife](https://github.com/JakeWharton/butterknife) 40 | * [Realm](https://github.com/realm/realm-java) 41 | * [Android-Support-Preference-V7-Fix](https://github.com/Gericop/Android-Support-Preference-V7-Fix) 42 | * [Joda-time](https://github.com/JodaOrg/joda-time) 43 | * [EventBus](https://github.com/greenrobot/EventBus) 44 | 45 | #### Contributing 46 | 47 | You can trace the status of known issues [here](https://github.com/letelete/Sleep-Cycle-Alarm/issues), 48 | also feel free to file a new issue (helpful description, screenshots and logcat are appreciated), or join to my discord 49 | Chat on Discord and send a message on #programming text channel if you have any questions. 51 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'realm-android' 3 | apply plugin: 'jacoco-android' 4 | 5 | android { 6 | compileSdkVersion 28 7 | buildToolsVersion "28.0.3" 8 | 9 | defaultConfig { 10 | vectorDrawables.useSupportLibrary = true 11 | applicationId "com.gmail.brunokawka.poland.sleepcyclealarm" 12 | minSdkVersion 21 13 | targetSdkVersion 28 14 | versionCode 1 15 | versionName "0.9" 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | lintOptions { 19 | abortOnError false 20 | } 21 | } 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 26 | } 27 | debug { 28 | testCoverageEnabled true 29 | } 30 | } 31 | } 32 | 33 | realm { 34 | syncEnabled = true 35 | } 36 | 37 | dependencies { 38 | implementation fileTree(dir: 'libs', include: ['*.jar']) 39 | 40 | testImplementation 'junit:junit:4.12' 41 | testImplementation 'org.mockito:mockito-core:2.22.0' 42 | androidTestImplementation 'org.mockito:mockito-android:2.19.0' 43 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 45 | androidTestImplementation 'com.android.support.test:rules:1.0.2' 46 | 47 | implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" 48 | implementation "com.android.support:animated-vector-drawable:$rootProject.ext.supportLibraryVersion" 49 | implementation "com.android.support:cardview-v7:$rootProject.ext.supportLibraryVersion" 50 | implementation "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion" 51 | implementation "com.android.support:recyclerview-v7:$rootProject.ext.supportLibraryVersion" 52 | implementation "com.android.support:design:$rootProject.ext.supportLibraryVersion" 53 | implementation 'com.android.support:multidex:1.0.3' 54 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 55 | 56 | implementation 'com.jakewharton:butterknife:8.8.1' 57 | implementation 'io.realm:android-adapters:3.0.0' 58 | implementation 'com.takisoft.fix:preference-v7:28.0.0.0' 59 | implementation 'com.takisoft.fix:preference-v7-ringtone:28.0.0.0-alpha3' 60 | implementation group: 'joda-time', name: 'joda-time', version: '2.10' 61 | implementation 'org.greenrobot:eventbus:3.1.1' 62 | 63 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 64 | implementation 'org.jetbrains:annotations-java5:15.0' 65 | } 66 | -------------------------------------------------------------------------------- /preview/logo/logomark.svg: -------------------------------------------------------------------------------- 1 | master -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/app/base/MainPresenter.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.app.base; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.gmail.brunokawka.poland.sleepcyclealarm.R; 6 | 7 | 8 | public class MainPresenter implements MainContract.MainPresenter { 9 | 10 | private MainContract.MainView view; 11 | private boolean isButtonAfterFirstPress; 12 | 13 | public MainPresenter(MainContract.MainView view) { 14 | this.view = view; 15 | } 16 | 17 | @Override 18 | public void setUpUi(Bundle savedInstanceState) { 19 | view.setUpBottomNavigationBar(); 20 | view.setUpToolbar(); 21 | handleFragmentToDisplay(savedInstanceState); 22 | } 23 | 24 | private void handleFragmentToDisplay(Bundle savedInstanceState) { 25 | if (savedInstanceState == null) { 26 | view.openDefaultFragment(); 27 | } else { 28 | view.openLatestFragment(); 29 | } 30 | } 31 | 32 | @Override 33 | public void handleMenuItemClick(int menuItemId) { 34 | switch (menuItemId) { 35 | case R.id.menu_settings: 36 | view.openSettingsActivity(); 37 | break; 38 | default: 39 | break; 40 | } 41 | } 42 | 43 | @Override 44 | public void handleBottomNavigationTabClick(int menuItemId) { 45 | switch (menuItemId) { 46 | case R.id.action_wakeupat: 47 | view.openWakeUpAtFragment(); 48 | break; 49 | case R.id.action_alarms: 50 | view.openAlarmsFragment(); 51 | break; 52 | case R.id.action_sleepnow: 53 | default: 54 | view.openSleepNowFragment(); 55 | break; 56 | } 57 | 58 | handleWakeUpAtButtonVisibility(menuItemId); 59 | } 60 | 61 | private void handleWakeUpAtButtonVisibility(int menuItemId) { 62 | if (isWakeUpAtTabOpen(menuItemId)) { 63 | view.showWakeUpAtActionButton(); 64 | } else { 65 | view.hideWakeUpAtActionButton(); 66 | } 67 | } 68 | 69 | private boolean isWakeUpAtTabOpen(int menuItemId) { 70 | return menuItemId == R.id.action_wakeupat; 71 | } 72 | 73 | @Override 74 | public void handleBackPress() { 75 | int milliseconds = 2000; 76 | 77 | if (isButtonAfterFirstPress) { 78 | view.moveAppToBack(); 79 | } else { 80 | view.showToastWithDoubleBackMessage(); 81 | isButtonAfterFirstPress = true; 82 | view.countDownInMilliseconds(milliseconds); 83 | } 84 | } 85 | 86 | @Override 87 | public void onCountedDown() { 88 | isButtonAfterFirstPress = false; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/res/xml/preferences.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | 19 | 20 | 21 | 22 | 25 | 26 | 31 | 32 | 43 | 44 | 49 | 50 | 51 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/tabs/adapters/AddAlarmsAdapter.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.tabs.adapters; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.constraint.ConstraintLayout; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.gmail.brunokawka.poland.sleepcyclealarm.R; 13 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 14 | import com.gmail.brunokawka.poland.sleepcyclealarm.events.AddAlarmEvent; 15 | 16 | import org.greenrobot.eventbus.EventBus; 17 | 18 | import java.util.List; 19 | 20 | import butterknife.BindView; 21 | import butterknife.ButterKnife; 22 | 23 | public class AddAlarmsAdapter extends RecyclerView.Adapter { 24 | 25 | private List listItems; 26 | 27 | public AddAlarmsAdapter(List listItems) { 28 | this.listItems = listItems; 29 | } 30 | 31 | @NonNull 32 | @Override 33 | public ListAdapterHolder onCreateViewHolder(@NonNull final ViewGroup viewGroup, 34 | final int index) { 35 | return new ListAdapterHolder(LayoutInflater.from(viewGroup.getContext()) 36 | .inflate(R.layout.item_alarm, viewGroup, false)); 37 | } 38 | 39 | @Override 40 | public void onBindViewHolder(@NonNull ListAdapterHolder listAdapterHolder, int position) { 41 | final Item item = listItems.get(position); 42 | if (item != null) { 43 | listAdapterHolder.bind(item); 44 | } 45 | } 46 | 47 | public class ListAdapterHolder extends RecyclerView.ViewHolder { 48 | 49 | @BindView(R.id.cl_item_alarm_root) 50 | ConstraintLayout clRoot; 51 | 52 | @BindView(R.id.iv_item_alarm_icon) 53 | ImageView ivIcon; 54 | 55 | @BindView(R.id.tv_item_alarm_title) 56 | TextView tvTitle; 57 | 58 | @BindView(R.id.tv_item_alarm_subtitle) 59 | TextView tvSubtitle; 60 | 61 | ListAdapterHolder(View view) { 62 | super(view); 63 | ButterKnife.bind(this, view); 64 | } 65 | 66 | public void bind(final Item item) { 67 | ivIcon.setImageResource(R.drawable.ic_list_alarm_add_full_shape); 68 | tvTitle.setText(item.getTitle()); 69 | tvSubtitle.setText(item.getSummary()); 70 | 71 | clRoot.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View view) { 74 | EventBus.getDefault().post(new AddAlarmEvent(item)); 75 | } 76 | }); 77 | } 78 | } 79 | 80 | @Override 81 | public int getItemCount() { 82 | return listItems.size(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/gmail/brunokawka/poland/sleepcyclealarm/utils/itemsbuilder/WakeUpAtBuildingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.gmail.brunokawka.poland.sleepcyclealarm.utils.itemsbuilder; 2 | 3 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.ItemsBuilderData; 4 | import com.gmail.brunokawka.poland.sleepcyclealarm.data.pojo.Item; 5 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.AlarmContentUtils; 6 | import com.gmail.brunokawka.poland.sleepcyclealarm.utils.TimeUtils; 7 | 8 | import org.joda.time.DateTime; 9 | import org.joda.time.Interval; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class WakeUpAtBuildingStrategy implements ItemsBuilderStrategy { 15 | private List items; 16 | private DateTime executionDate; 17 | private DateTime timeToGoToSleep; 18 | 19 | @Override 20 | public List getArrayOfItems(DateTime currentDate, DateTime executionDate) { 21 | items = new ArrayList<>(); 22 | this.executionDate = executionDate; 23 | this.timeToGoToSleep = executionDate; 24 | 25 | int maxAmountOfItemsInList = ItemsBuilderData.getMaxAmountOfItemsInList(); 26 | 27 | for (int itemCounter = 0; itemCounter < maxAmountOfItemsInList; itemCounter++) { 28 | if (isPossibleToCreateNextItem(currentDate, timeToGoToSleep)) { 29 | timeToGoToSleep = getNextAlarmDate(timeToGoToSleep); 30 | createNextItemAndAddItToArray(); 31 | } else { 32 | break; 33 | } 34 | } 35 | 36 | return items; 37 | } 38 | 39 | @Override 40 | public DateTime getNextAlarmDate(DateTime executionDate) { 41 | return executionDate.minusMinutes(ItemsBuilderData.getOneSleepCycleDurationInMinutes()); 42 | } 43 | 44 | @Override 45 | public boolean isPossibleToCreateNextItem(DateTime currentDate, DateTime dateToGoToSleep) { 46 | if (dateToGoToSleep.isAfter(currentDate)) { 47 | long oneMinuteInMillis = 1000 * 60; 48 | long periodInMinutes = new Interval(currentDate, dateToGoToSleep) 49 | .toDurationMillis() / oneMinuteInMillis; 50 | 51 | return (periodInMinutes >= ItemsBuilderData.getTotalOneSleepCycleDurationInMinutes()); 52 | } else { 53 | return false; 54 | } 55 | } 56 | 57 | private void createNextItemAndAddItToArray() { 58 | int timeForFallAsleepInMinutes = ItemsBuilderData.getTimeForFallAsleepInMinutes(); 59 | DateTime dateToGoToSleepPlusTimeToFallAsleepWithRoundedTime = TimeUtils 60 | .getClosestTimeRound(timeToGoToSleep.minusMinutes(timeForFallAsleepInMinutes)); 61 | 62 | Item item = new Item(); 63 | 64 | item.setTitle(AlarmContentUtils 65 | .getTitleForWakeUpAt(dateToGoToSleepPlusTimeToFallAsleepWithRoundedTime, 66 | executionDate)); 67 | item.setSummary(AlarmContentUtils.getSummary(timeToGoToSleep, executionDate)); 68 | item.setCurrentDate(dateToGoToSleepPlusTimeToFallAsleepWithRoundedTime); 69 | item.setExecutionDate(executionDate); 70 | 71 | items.add(0, item); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at brunokawka@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 28 | 29 | 30 | 31 | 41 | 42 | 43 | 44 | 58 | 59 |