From d63d9e7635937339485013a80686b6eedbd38ce7 Mon Sep 17 00:00:00 2001 From: SudKul Date: Wed, 19 Aug 2020 21:00:53 +0530 Subject: [PATCH 1/9] Updated Gradle scripts --- app/build.gradle | 10 +++++----- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 940cbd74..30e723a9 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" @@ -44,12 +44,12 @@ android { 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/build.gradle b/build.gradle index ef9ef3ba..edab77f3 100644 --- a/build.gradle +++ b/build.gradle @@ -16,14 +16,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + 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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0da09962..47a3857d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip From 81abfe5b0b7ab642b40170fa07c27469602bf806 Mon Sep 17 00:00:00 2001 From: SudKul Date: Mon, 24 Aug 2020 20:04:39 +0530 Subject: [PATCH 2/9] Changed the deprecated ViewModelProviders.of() to ViewModelProvider(). --- .../android/eggtimernotifications/ui/EggTimerFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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..17508d52 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 @@ -27,7 +27,7 @@ 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 @@ -45,7 +45,7 @@ class EggTimerFragment : Fragment() { 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 From fd9cb0589e9d8cb1bfdbdfb665df9ef96304b7eb Mon Sep 17 00:00:00 2001 From: SudKul Date: Wed, 26 Aug 2020 12:53:37 +0530 Subject: [PATCH 3/9] Enable databinding using buildfeatures in app/build.gradle file --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 30e723a9..5ca4e427 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,8 +36,8 @@ android { } // Enables data binding. - dataBinding { - enabled = true + buildFeatures { + dataBinding true } } From eefb11983d32e8287ab71f3d983f2ad702a6af00 Mon Sep 17 00:00:00 2001 From: SudKul <48475411+SudKul@users.noreply.github.com> Date: Thu, 21 Oct 2021 18:58:14 +0530 Subject: [PATCH 4/9] Create CODEOWNERS --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS 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 From 4b7145bb1cdcfecfec1587cf1b8e35eb6010d29c Mon Sep 17 00:00:00 2001 From: SudKul <48475411+SudKul@users.noreply.github.com> Date: Fri, 12 Nov 2021 18:55:56 +0530 Subject: [PATCH 5/9] Add Github Action --- .github/workflows/manual.yml | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/manual.yml diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml new file mode 100644 index 00000000..acf46191 --- /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 [Assign the ND component] | 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":"Github PR"}], "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" From e6d17cf6f4d5bb74795c1b372b41a239621a0b1f Mon Sep 17 00:00:00 2001 From: Sudhanshu Kulshrestha <48475411+SudKul@users.noreply.github.com> Date: Tue, 28 Jun 2022 21:45:24 +0530 Subject: [PATCH 6/9] Update manual.yml --- .github/workflows/manual.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index acf46191..46fab053 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -33,14 +33,14 @@ jobs: project: CONUPDATE issuetype: Task summary: | - Github PR [Assign the ND component] | Repo: ${{ github.repository }} | PR# ${{github.event.number}} + 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":"Github PR"}], "customfield_16449":"https://classroom.udacity.com/", "customfield_16450":"Resolve the PR", "labels": ["github"], "priority":{"id": "4"}}' + 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" From 3a641f980d159a6d2f2307406d4a5fa7ee6426a2 Mon Sep 17 00:00:00 2001 From: Sweta Jain Date: Mon, 26 Sep 2022 13:24:24 +0530 Subject: [PATCH 7/9] Modified: # fragment_egg_timer: updated switch to switchCompat # EggTimerFragment and EggTimerViewModel: Fixed issue of running timer not changing with the change in the time selected from the Spinner. --- .idea/.gitignore | 3 ++ .idea/compiler.xml | 6 ++++ .idea/gradle.xml | 20 ++++++++++++ .idea/jarRepositories.xml | 25 +++++++++++++++ .idea/misc.xml | 10 ++++++ .idea/vcs.xml | 6 ++++ .../ui/EggTimerFragment.kt | 2 +- .../ui/EggTimerViewModel.kt | 31 ++++++++++++++----- .../main/res/layout/fragment_egg_timer.xml | 19 ++++++------ 9 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml 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/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt index 17508d52..b30c03f5 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 @@ -39,7 +39,7 @@ 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 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..cee68d2c 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,9 @@ class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) { private val timerLengthOptions: IntArray private val notifyPendingIntent: PendingIntent + private var _isStarted = false + 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 +101,7 @@ class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) { * @param isChecked, alarm status to be set. */ fun setAlarm(isChecked: Boolean) { + _isChecked = isChecked when (isChecked) { true -> timeSelection.value?.let { startTimer(it) } false -> cancelNotification() @@ -104,18 +115,24 @@ class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) { */ fun setTimeSelected(timerLengthSelection: Int) { _timeSelection.value = timerLengthSelection + + if (_isStarted) { + cancelNotification() + 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/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"> - Date: Mon, 26 Sep 2022 15:00:52 +0530 Subject: [PATCH 8/9] added comments --- .../android/eggtimernotifications/ui/EggTimerViewModel.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 cee68d2c..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 @@ -48,7 +48,9 @@ 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 @@ -101,6 +103,7 @@ 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) } @@ -115,9 +118,11 @@ 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) } } From 6849a9b48ffc775e97e7762d684c0e6ae491362e Mon Sep 17 00:00:00 2001 From: Sweta Jain Date: Mon, 26 Sep 2022 15:27:20 +0530 Subject: [PATCH 9/9] refactored --- .../eggtimernotifications/ui/EggTimerFragment.kt | 5 ++--- app/src/main/res/layout/activity_main.xml | 16 +++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) 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 b30c03f5..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.ViewModelProvider import com.example.android.eggtimernotifications.R import com.example.android.eggtimernotifications.databinding.FragmentEggTimerBinding -import com.google.firebase.messaging.FirebaseMessaging class EggTimerFragment : Fragment() { @@ -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/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 @@ - - - +