From 4be9d717c7fc6aef91617ceacfd48e37f231aa09 Mon Sep 17 00:00:00 2001 From: SudKul Date: Thu, 20 Aug 2020 16:13:09 +0530 Subject: [PATCH 1/8] Update Gradle scripts --- app/build.gradle | 8 ++++---- build.gradle | 16 ++++++++-------- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 99a4c4b5..f1f6731e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,11 +21,11 @@ apply plugin: 'kotlin-kapt' apply plugin: 'androidx.navigation.safeargs' android { - compileSdkVersion 28 + compileSdkVersion 30 defaultConfig { applicationId "com.example.android.trackmysleepquality" minSdkVersion 19 - targetSdkVersion 28 + targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -70,7 +70,7 @@ dependencies { // Testing testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } diff --git a/build.gradle b/build.gradle index 33b48fcb..58e7d760 100644 --- a/build.gradle +++ b/build.gradle @@ -19,14 +19,14 @@ buildscript { ext { - version_core = "1.0.1" - version_coroutine = "1.1.0" - version_constraint_layout = "1.1.3" - version_gradle = '3.3.0' - version_kotlin = "1.3.21" - version_lifecycle_extensions = "2.0.0" - version_navigation = '1.0.0-beta02' - version_room = "2.0.0" + version_core = "1.3.1" + version_coroutine = "1.3.7" + version_constraint_layout = "2.0.0-rc1" + version_gradle = '4.0.1' + version_kotlin = "1.3.72" + version_lifecycle_extensions = "2.2.0" + version_navigation = '1.0.0' + version_room = "2.2.5" } repositories { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dcdf0f2d..49f80c0a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Oct 02 13:39:27 PDT 2018 +#Tue Aug 11 17:39:48 PDT 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip From 7e9ac2811e1b6e3222bc73e62db92717f924e295 Mon Sep 17 00:00:00 2001 From: SudKul Date: Wed, 26 Aug 2020 11:17:48 +0530 Subject: [PATCH 2/8] Enable databinding using buildfeatures --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f1f6731e..4ff2a2d3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,8 +39,8 @@ android { } // Enables data binding. - dataBinding { - enabled = true + buildFeatures { + dataBinding true } } From cde32bbcf312029a9ec6fbfd72ffb76f4f399442 Mon Sep 17 00:00:00 2001 From: SudKul Date: Wed, 2 Sep 2020 22:20:03 +0530 Subject: [PATCH 3/8] SleepDatabaseDao.kt - Use ViewmodelScope instead of creating coroutine scope --- app/build.gradle | 9 ++++++++- .../trackmysleepquality/database/SleepDatabaseDao.kt | 12 ++++++------ build.gradle | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4ff2a2d3..c0e9b9d6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,7 +28,7 @@ android { targetSdkVersion 30 versionCode 1 versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled true vectorDrawables.useSupportLibrary = true } buildTypes { @@ -68,6 +68,13 @@ dependencies { implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation" implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation" + // ViewModel and LiveData + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle" + + // Kotlin Extensions and Coroutines support for Room + implementation "androidx.room:room-ktx:$version_room" + + // Testing testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' diff --git a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt index 92eea9c6..6ad0f050 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt @@ -29,7 +29,7 @@ import androidx.room.Update interface SleepDatabaseDao { @Insert - fun insert(night: SleepNight) + suspend fun insert(night: SleepNight) /** * When updating a row with a value already set in a column, @@ -38,7 +38,7 @@ interface SleepDatabaseDao { * @param night new value to write */ @Update - fun update(night: SleepNight) + suspend fun update(night: SleepNight) /** * Selects and returns the row that matches the supplied start time, which is our key. @@ -46,7 +46,7 @@ interface SleepDatabaseDao { * @param key startTimeMilli to match */ @Query("SELECT * from daily_sleep_quality_table WHERE nightId = :key") - fun get(key: Long): SleepNight? + suspend fun get(key: Long): SleepNight? /** * Deletes all values from the table. @@ -54,7 +54,7 @@ interface SleepDatabaseDao { * This does not delete the table, only its contents. */ @Query("DELETE FROM daily_sleep_quality_table") - fun clear() + suspend fun clear() /** * Selects and returns all rows in the table, @@ -62,13 +62,13 @@ interface SleepDatabaseDao { * sorted by start time in descending order. */ @Query("SELECT * FROM daily_sleep_quality_table ORDER BY nightId DESC") - fun getAllNights(): LiveData> + suspend fun getAllNights(): LiveData> /** * Selects and returns the latest night. */ @Query("SELECT * FROM daily_sleep_quality_table ORDER BY nightId DESC LIMIT 1") - fun getTonight(): SleepNight? + suspend fun getTonight(): SleepNight? } diff --git a/build.gradle b/build.gradle index 58e7d760..05c9e99c 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,7 @@ buildscript { version_gradle = '4.0.1' version_kotlin = "1.3.72" version_lifecycle_extensions = "2.2.0" + version_lifecycle = "2.2.0" version_navigation = '1.0.0' version_room = "2.2.5" } From aa29c1aa74ed5b31795bdb7b7c05ab5eed92da8e Mon Sep 17 00:00:00 2001 From: SudKul Date: Wed, 2 Sep 2020 22:47:57 +0530 Subject: [PATCH 4/8] SleepTrackerViewModel.kt - Use ViewmodelScope instead of creating coroutine scope --- .../trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt index a041ee1a..23bf712c 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt @@ -17,6 +17,7 @@ package com.example.android.trackmysleepquality.sleeptracker import android.app.Application +import androidx.lifecycle.viewModelScope import androidx.lifecycle.AndroidViewModel import com.example.android.trackmysleepquality.database.SleepDatabaseDao From 1351f564e854565af4c295d1a32af41cb90b2c77 Mon Sep 17 00:00:00 2001 From: SudKul Date: Mon, 21 Sep 2020 01:03:42 +0530 Subject: [PATCH 5/8] Fix syntax error in SleepDatabaseDao.kt and SleepTrackerViewModel.kt --- .../database/SleepDatabaseDao.kt | 2 +- .../sleeptracker/SleepTrackerViewModel.kt | 176 +++++++++++++++++- 2 files changed, 176 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt index 6ad0f050..8a153b44 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt @@ -62,7 +62,7 @@ interface SleepDatabaseDao { * sorted by start time in descending order. */ @Query("SELECT * FROM daily_sleep_quality_table ORDER BY nightId DESC") - suspend fun getAllNights(): LiveData> + fun getAllNights(): LiveData> /** * Selects and returns the latest night. diff --git a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt index 23bf712c..d36609b8 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt @@ -19,7 +19,13 @@ package com.example.android.trackmysleepquality.sleeptracker import android.app.Application import androidx.lifecycle.viewModelScope import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Transformations import com.example.android.trackmysleepquality.database.SleepDatabaseDao +import com.example.android.trackmysleepquality.database.SleepNight +import com.example.android.trackmysleepquality.formatNights +import kotlinx.coroutines.* /** * ViewModel for SleepTrackerFragment. @@ -27,5 +33,173 @@ import com.example.android.trackmysleepquality.database.SleepDatabaseDao class SleepTrackerViewModel( val database: SleepDatabaseDao, application: Application) : AndroidViewModel(application) { -} + + private var tonight = MutableLiveData() + + private val nights = database.getAllNights() + + /** + * Converted nights to Spanned for displaying. + */ + val nightsString = Transformations.map(nights) { nights -> + formatNights(nights, application.resources) + } + + /** + * If tonight has not been set, then the START button should be visible. + */ + val startButtonVisible = Transformations.map(tonight) { + null == it + } + + /** + * If tonight has been set, then the STOP button should be visible. + */ + val stopButtonVisible = Transformations.map(tonight) { + null != it + } + + /** + * If there are any nights in the database, show the CLEAR button. + */ + val clearButtonVisible = Transformations.map(nights) { + it?.isNotEmpty() + } + + /** + * Request a toast by setting this value to true. + * + * This is private because we don't want to expose setting this value to the Fragment. + */ + private var _showSnackbarEvent = MutableLiveData() + + /** + * If this is true, immediately `show()` a toast and call `doneShowingSnackbar()`. + */ + val showSnackBarEvent: LiveData + get() = _showSnackbarEvent + + /** + * Variable that tells the Fragment to navigate to a specific [SleepQualityFragment] + * + * This is private because we don't want to expose setting this value to the Fragment. + */ + + private val _navigateToSleepQuality = MutableLiveData() + /** + * Call this immediately after calling `show()` on a toast. + * + * It will clear the toast request, so if the user rotates their phone it won't show a duplicate + * toast. + */ + + fun doneShowingSnackbar() { + _showSnackbarEvent.value = false + } + /** + * If this is non-null, immediately navigate to [SleepQualityFragment] and call [doneNavigating] + */ + val navigateToSleepQuality: LiveData + get() = _navigateToSleepQuality + + /** + * Call this immediately after navigating to [SleepQualityFragment] + * + * It will clear the navigation request, so if the user rotates their phone it won't navigate + * twice. + */ + fun doneNavigating() { + _navigateToSleepQuality.value = null + } + + init { + initializeTonight() + } + + private fun initializeTonight() { + viewModelScope.launch { + tonight.value = getTonightFromDatabase() + } + } + + /** + * Handling the case of the stopped app or forgotten recording, + * the start and end times will be the same.j + * + * If the start time and end time are not the same, then we do not have an unfinished + * recording. + */ + private suspend fun getTonightFromDatabase(): SleepNight? { + var night = database.getTonight() + if (night?.endTimeMilli != night?.startTimeMilli) { + night = null + } + return night + } + + private suspend fun clear() { + database.clear() + } + + private suspend fun update(night: SleepNight) { + database.update(night) + } + + private suspend fun insert(night: SleepNight) { + database.insert(night) + } + + /** + * Executes when the START button is clicked. + */ + fun onStartTracking() { + viewModelScope.launch { + // Create a new night, which captures the current time, + // and insert it into the database. + val newNight = SleepNight() + + insert(newNight) + + tonight.value = getTonightFromDatabase() + } + } + + /** + * Executes when the STOP button is clicked. + */ + fun onStopTracking() { + viewModelScope.launch { + // In Kotlin, the return@label syntax is used for specifying which function among + // several nested ones this statement returns from. + // In this case, we are specifying to return from launch(), + // not the lambda. + val oldNight = tonight.value ?: return@launch + + // Update the night in the database to add the end time. + oldNight.endTimeMilli = System.currentTimeMillis() + + update(oldNight) + + // Set state to navigate to the SleepQualityFragment. + _navigateToSleepQuality.value = oldNight + } + } + + /** + * Executes when the CLEAR button is clicked. + */ + fun onClear() { + viewModelScope.launch { + // Clear the database table. + clear() + + // And clear tonight since it's no longer in the database + tonight.value = null + } + + // Show a snackbar message, because it's friendly. + _showSnackbarEvent.value = true + } + +} From c0505a74b060241ae26be9d5057b5e423f008677 Mon Sep 17 00:00:00 2001 From: SudKul Date: Mon, 21 Sep 2020 01:06:19 +0530 Subject: [PATCH 6/8] Revert "Fix syntax error in SleepDatabaseDao.kt and SleepTrackerViewModel.kt" This reverts commit 1351f564e854565af4c295d1a32af41cb90b2c77. --- .../database/SleepDatabaseDao.kt | 2 +- .../sleeptracker/SleepTrackerViewModel.kt | 176 +----------------- 2 files changed, 2 insertions(+), 176 deletions(-) diff --git a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt index 8a153b44..6ad0f050 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt @@ -62,7 +62,7 @@ interface SleepDatabaseDao { * sorted by start time in descending order. */ @Query("SELECT * FROM daily_sleep_quality_table ORDER BY nightId DESC") - fun getAllNights(): LiveData> + suspend fun getAllNights(): LiveData> /** * Selects and returns the latest night. diff --git a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt index d36609b8..23bf712c 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt @@ -19,13 +19,7 @@ package com.example.android.trackmysleepquality.sleeptracker import android.app.Application import androidx.lifecycle.viewModelScope import androidx.lifecycle.AndroidViewModel -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.Transformations import com.example.android.trackmysleepquality.database.SleepDatabaseDao -import com.example.android.trackmysleepquality.database.SleepNight -import com.example.android.trackmysleepquality.formatNights -import kotlinx.coroutines.* /** * ViewModel for SleepTrackerFragment. @@ -33,173 +27,5 @@ import kotlinx.coroutines.* class SleepTrackerViewModel( val database: SleepDatabaseDao, application: Application) : AndroidViewModel(application) { - - - private var tonight = MutableLiveData() - - private val nights = database.getAllNights() - - /** - * Converted nights to Spanned for displaying. - */ - val nightsString = Transformations.map(nights) { nights -> - formatNights(nights, application.resources) - } - - /** - * If tonight has not been set, then the START button should be visible. - */ - val startButtonVisible = Transformations.map(tonight) { - null == it - } - - /** - * If tonight has been set, then the STOP button should be visible. - */ - val stopButtonVisible = Transformations.map(tonight) { - null != it - } - - /** - * If there are any nights in the database, show the CLEAR button. - */ - val clearButtonVisible = Transformations.map(nights) { - it?.isNotEmpty() - } - - /** - * Request a toast by setting this value to true. - * - * This is private because we don't want to expose setting this value to the Fragment. - */ - private var _showSnackbarEvent = MutableLiveData() - - /** - * If this is true, immediately `show()` a toast and call `doneShowingSnackbar()`. - */ - val showSnackBarEvent: LiveData - get() = _showSnackbarEvent - - /** - * Variable that tells the Fragment to navigate to a specific [SleepQualityFragment] - * - * This is private because we don't want to expose setting this value to the Fragment. - */ - - private val _navigateToSleepQuality = MutableLiveData() - /** - * Call this immediately after calling `show()` on a toast. - * - * It will clear the toast request, so if the user rotates their phone it won't show a duplicate - * toast. - */ - - fun doneShowingSnackbar() { - _showSnackbarEvent.value = false - } - /** - * If this is non-null, immediately navigate to [SleepQualityFragment] and call [doneNavigating] - */ - val navigateToSleepQuality: LiveData - get() = _navigateToSleepQuality - - /** - * Call this immediately after navigating to [SleepQualityFragment] - * - * It will clear the navigation request, so if the user rotates their phone it won't navigate - * twice. - */ - fun doneNavigating() { - _navigateToSleepQuality.value = null - } - - init { - initializeTonight() - } - - private fun initializeTonight() { - viewModelScope.launch { - tonight.value = getTonightFromDatabase() - } - } - - /** - * Handling the case of the stopped app or forgotten recording, - * the start and end times will be the same.j - * - * If the start time and end time are not the same, then we do not have an unfinished - * recording. - */ - private suspend fun getTonightFromDatabase(): SleepNight? { - var night = database.getTonight() - if (night?.endTimeMilli != night?.startTimeMilli) { - night = null - } - return night - } - - private suspend fun clear() { - database.clear() - } - - private suspend fun update(night: SleepNight) { - database.update(night) - } - - private suspend fun insert(night: SleepNight) { - database.insert(night) - } - - /** - * Executes when the START button is clicked. - */ - fun onStartTracking() { - viewModelScope.launch { - // Create a new night, which captures the current time, - // and insert it into the database. - val newNight = SleepNight() - - insert(newNight) - - tonight.value = getTonightFromDatabase() - } - } - - /** - * Executes when the STOP button is clicked. - */ - fun onStopTracking() { - viewModelScope.launch { - // In Kotlin, the return@label syntax is used for specifying which function among - // several nested ones this statement returns from. - // In this case, we are specifying to return from launch(), - // not the lambda. - val oldNight = tonight.value ?: return@launch - - // Update the night in the database to add the end time. - oldNight.endTimeMilli = System.currentTimeMillis() - - update(oldNight) - - // Set state to navigate to the SleepQualityFragment. - _navigateToSleepQuality.value = oldNight - } - } - - /** - * Executes when the CLEAR button is clicked. - */ - fun onClear() { - viewModelScope.launch { - // Clear the database table. - clear() - - // And clear tonight since it's no longer in the database - tonight.value = null - } - - // Show a snackbar message, because it's friendly. - _showSnackbarEvent.value = true - } - } + From b370746aecc8a8c3a8e059307cbcfe9691021416 Mon Sep 17 00:00:00 2001 From: SudKul Date: Mon, 21 Sep 2020 01:14:11 +0530 Subject: [PATCH 7/8] Fix syntax errors in SleepDatabaseDao.kt and SleepTrackerViewModel.kt --- .../android/trackmysleepquality/database/SleepDatabaseDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt index 6ad0f050..8a153b44 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt @@ -62,7 +62,7 @@ interface SleepDatabaseDao { * sorted by start time in descending order. */ @Query("SELECT * FROM daily_sleep_quality_table ORDER BY nightId DESC") - suspend fun getAllNights(): LiveData> + fun getAllNights(): LiveData> /** * Selects and returns the latest night. From a475e96673a2bc9c2b847334d08e2af1100ffb49 Mon Sep 17 00:00:00 2001 From: Diraj H S Date: Fri, 14 Jun 2024 11:34:17 +0530 Subject: [PATCH 8/8] Update dependencies and fixed issues Signed-off-by: Diraj H S --- README.md | 4 +++ app/build.gradle | 30 ++++++++++++------- app/src/main/AndroidManifest.xml | 3 +- .../SleepTrackerViewModelFactory.kt | 2 +- build.gradle | 24 +++++++-------- gradle/wrapper/gradle-wrapper.properties | 2 +- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ce873db2..04dd149a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ Access all branches from this tab. The branches are also accessible from the drop-down in the "Code" tab. +## Requirements + +1. Android Studio (Jellyfish or above) +2. JDK 21 with `JAVA_HOME` environment variable set. If you don't have JDK 21 installed or `JAVA_HOME` is not set, consider using a tool like `sdkman` to simplify the process. Refer to the sdkman documentation for installation instructions: [sdkman installation](https://sdkman.io/install) ## Working with the Course Code diff --git a/app/build.gradle b/app/build.gradle index c0e9b9d6..9aa1a48c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,16 +16,17 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +// Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported. +// apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'androidx.navigation.safeargs' android { - compileSdkVersion 30 + compileSdk 34 defaultConfig { applicationId "com.example.android.trackmysleepquality" - minSdkVersion 19 - targetSdkVersion 30 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 versionName "1.0" multiDexEnabled true @@ -42,12 +43,18 @@ android { buildFeatures { dataBinding true } + namespace = "com.example.android.trackmysleepquality" + compileOptions { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version_kotlin" + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version_kotlin" // Support libraries implementation "androidx.constraintlayout:constraintlayout:$version_constraint_layout" @@ -58,15 +65,16 @@ dependencies { // Room and Lifecycle dependencies implementation "androidx.room:room-runtime:$version_room" kapt "androidx.room:room-compiler:$version_room" - implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions" + // The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need. + // implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions" // Coroutines implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version_coroutine" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version_coroutine" // Navigation - implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation" - implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation" + implementation "androidx.navigation:navigation-fragment-ktx:$version_navigation" + implementation "androidx.navigation:navigation-ui-ktx:$version_navigation" // ViewModel and LiveData implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle" @@ -76,8 +84,8 @@ dependencies { // Testing - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 58a0b98e..d9da7522 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ android:roundIcon="@mipmap/ic_launcher_sleep_tracker_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModelFactory.kt b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModelFactory.kt index c9e23c28..41b80e73 100644 --- a/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModelFactory.kt +++ b/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModelFactory.kt @@ -30,7 +30,7 @@ class SleepTrackerViewModelFactory( private val dataSource: SleepDatabaseDao, private val application: Application) : ViewModelProvider.Factory { @Suppress("unchecked_cast") - override fun create(modelClass: Class): T { + override fun create(modelClass: Class): T { if (modelClass.isAssignableFrom(SleepTrackerViewModel::class.java)) { return SleepTrackerViewModel(dataSource, application) as T } diff --git a/build.gradle b/build.gradle index 05c9e99c..05ad3f08 100644 --- a/build.gradle +++ b/build.gradle @@ -19,26 +19,26 @@ buildscript { ext { - version_core = "1.3.1" - version_coroutine = "1.3.7" - version_constraint_layout = "2.0.0-rc1" - version_gradle = '4.0.1' - version_kotlin = "1.3.72" - version_lifecycle_extensions = "2.2.0" - version_lifecycle = "2.2.0" - version_navigation = '1.0.0' - version_room = "2.2.5" + version_core = "1.13.1" + version_coroutine = "1.8.1" + version_constraint_layout = "2.1.4" + version_gradle = '8.4.2' + version_kotlin = '1.9.23' + // version_lifecycle_extensions = "2.2.0" + version_lifecycle = '2.8.2' + version_navigation = '2.7.7' + version_room = '2.6.1' } repositories { + mavenCentral() google() - jcenter() } dependencies { classpath "com.android.tools.build:gradle:$version_gradle" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin" - classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$version_navigation" + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -47,8 +47,8 @@ buildscript { allprojects { repositories { + mavenCentral() google() - jcenter() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 49f80c0a..ecebd858 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-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip