Skip to content
This repository was archived by the owner on Nov 19, 2023. It is now read-only.

Resets the timer on the screen and change the alarm simultaneously, while keeping the switch on. #58

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Workflow to ensure whenever a Github PR is submitted,
# a JIRA ticket gets created automatically.
name: Manual Workflow

# Controls when the action will run.
on:
# Triggers the workflow on pull request events but only for the master branch
pull_request_target:
types: [opened, reopened]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
test-transition-issue:
name: Convert Github Issue to Jira Issue
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Login
uses: atlassian/gajira-login@master
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}

- name: Create NEW JIRA ticket
id: create
uses: atlassian/gajira-create@master
with:
project: CONUPDATE
issuetype: Task
summary: |
Github PR nd940 - Android Kotlin Developer | Repo: ${{ github.repository }} | PR# ${{github.event.number}}
description: |
Repo link: https://github.com/${{ github.repository }}
PR no. ${{ github.event.pull_request.number }}
PR title: ${{ github.event.pull_request.title }}
PR description: ${{ github.event.pull_request.description }}
In addition, please resolve other issues, if any.
fields: '{"components": [{"name":"nd940 - Android Kotlin Developer"}], "customfield_16449":"https://classroom.udacity.com/", "customfield_16450":"Resolve the PR", "labels": ["github"], "priority":{"id": "4"}}'

- name: Log created issue
run: echo "Issue ${{ steps.create.outputs.issue }} was created"
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @udacity/active-public-content
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 29
compileSdkVersion 30
defaultConfig {
applicationId "com.example.android.eggtimernotifications"
minSdkVersion 19
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -36,20 +36,20 @@ android {
}

// Enables data binding.
dataBinding {
enabled = true
buildFeatures {
dataBinding true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-rc01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-rc01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import com.example.android.eggtimernotifications.R
import com.example.android.eggtimernotifications.databinding.FragmentEggTimerBinding
import com.google.firebase.messaging.FirebaseMessaging

class EggTimerFragment : Fragment() {

Expand All @@ -39,13 +37,13 @@ class EggTimerFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {

val binding: FragmentEggTimerBinding = DataBindingUtil.inflate(
inflater, R.layout.fragment_egg_timer, container, false
)

val viewModel = ViewModelProviders.of(this).get(EggTimerViewModel::class.java)
val viewModel = ViewModelProvider(this).get(EggTimerViewModel::class.java)

binding.eggTimerViewModel = viewModel
binding.lifecycleOwner = this.viewLifecycleOwner
Expand Down Expand Up @@ -75,7 +73,8 @@ class EggTimerFragment : Fragment() {
notificationChannel.enableLights(true)
notificationChannel.lightColor = Color.RED
notificationChannel.enableVibration(true)
notificationChannel.description = getString(R.string.breakfast_notification_channel_description)
notificationChannel.description =
getString(R.string.breakfast_notification_channel_description)

val notificationManager = requireActivity().getSystemService(
NotificationManager::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.eggtimernotifications.ui

import android.app.*
import android.app.AlarmManager
import android.app.Application
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.CountDownTimer
import android.os.SystemClock
import androidx.core.app.AlarmManagerCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.*
import com.example.android.eggtimernotifications.receiver.AlarmReceiver
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.android.eggtimernotifications.R
import com.example.android.eggtimernotifications.receiver.AlarmReceiver
import com.example.android.eggtimernotifications.util.cancelNotifications
import com.example.android.eggtimernotifications.util.sendNotification
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) {

Expand All @@ -41,6 +48,11 @@ class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) {
private val timerLengthOptions: IntArray
private val notifyPendingIntent: PendingIntent

// boolean to check if the timer was started. False by default
private var _isStarted = false
// boolean to check if the switch was checked. False by default
private var _isChecked = false

private val alarmManager = app.getSystemService(Context.ALARM_SERVICE) as AlarmManager
private var prefs =
app.getSharedPreferences("com.example.android.eggtimernotifications", Context.MODE_PRIVATE)
Expand Down Expand Up @@ -91,6 +103,8 @@ class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) {
* @param isChecked, alarm status to be set.
*/
fun setAlarm(isChecked: Boolean) {
// updated the private _isChecked boolean
_isChecked = isChecked
when (isChecked) {
true -> timeSelection.value?.let { startTimer(it) }
false -> cancelNotification()
Expand All @@ -104,18 +118,26 @@ class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) {
*/
fun setTimeSelected(timerLengthSelection: Int) {
_timeSelection.value = timerLengthSelection
// If the timer has started/initialized
if (_isStarted) {
//cancel the current timer
cancelNotification()
//start the new timer and alarm
setAlarm(_isChecked)
}
}

/**
* Creates a new alarm, notification and timer
*/
private fun startTimer(timerLengthSelection: Int) {
_isStarted = true
_alarmOn.value?.let {
if (!it) {
_alarmOn.value = true
val selectedInterval = when (timerLengthSelection) {
0 -> second * 10 //For testing only
else ->timerLengthOptions[timerLengthSelection] * minute
else -> timerLengthOptions[timerLengthSelection] * minute
}
val triggerTime = SystemClock.elapsedRealtime() + selectedInterval

Expand Down
16 changes: 7 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2019 Google Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,10 +14,9 @@
~ limitations under the License.
-->

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />
19 changes: 9 additions & 10 deletions app/src/main/res/layout/fragment_egg_timer.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2019 Google Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,20 +15,20 @@
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="eggTimerViewModel"
type="com.example.android.eggtimernotifications.ui.EggTimerViewModel" />
name="eggTimerViewModel"
type="com.example.android.eggtimernotifications.ui.EggTimerViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.EggTimerFragment">
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.EggTimerFragment">

<TextView
android:id="@+id/textView"
Expand Down Expand Up @@ -58,7 +57,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/on_off_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.5.31'
ext.kotlin_version = '1.3.72'
repositories {
google()
mavenCentral()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -32,7 +33,8 @@ buildscript {
allprojects {
repositories {
google()
mavenCentral()
jcenter()

}
}

Expand Down
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip