diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml
new file mode 100644
index 00000000..46fab053
--- /dev/null
+++ b/.github/workflows/manual.yml
@@ -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"
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..26d33521
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 00000000..fb7f4a8a
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 00000000..7c3a3d8e
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 00000000..a5f05cd8
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..ba9cfe8c
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CODEOWNERS b/CODEOWNERS
new file mode 100644
index 00000000..2a6bcb28
--- /dev/null
+++ b/CODEOWNERS
@@ -0,0 +1 @@
+* @udacity/active-public-content
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 940cbd74..5ca4e427 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -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"
@@ -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'
diff --git a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt
index bec13f9d..30dea2e3 100644
--- a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt
+++ b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt
@@ -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() {
@@ -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
@@ -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
diff --git a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt
index caa2f07d..ebbc6356 100644
--- a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt
+++ b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt
@@ -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) {
@@ -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)
@@ -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()
@@ -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
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index a91ed6c4..7d4e17fa 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,4 @@
-
-
-
+
diff --git a/app/src/main/res/layout/fragment_egg_timer.xml b/app/src/main/res/layout/fragment_egg_timer.xml
index b5eab981..ed19d7a9 100644
--- a/app/src/main/res/layout/fragment_egg_timer.xml
+++ b/app/src/main/res/layout/fragment_egg_timer.xml
@@ -1,5 +1,4 @@
-
-
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools">
+ name="eggTimerViewModel"
+ type="com.example.android.eggtimernotifications.ui.EggTimerViewModel" />
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".ui.EggTimerFragment">
-