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 99a4c4b5..9aa1a48c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,19 +16,20 @@ 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 28 + compileSdk 34 defaultConfig { applicationId "com.example.android.trackmysleepquality" - minSdkVersion 19 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled true vectorDrawables.useSupportLibrary = true } buildTypes { @@ -39,15 +40,21 @@ android { } // Enables data binding. - dataBinding { - enabled = true + 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,19 +65,27 @@ 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" + + // 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.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + 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/database/SleepDatabaseDao.kt b/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt index 92eea9c6..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 @@ -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, @@ -68,7 +68,7 @@ interface SleepDatabaseDao { * 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/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 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 33b48fcb..05ad3f08 100644 --- a/build.gradle +++ b/build.gradle @@ -19,25 +19,26 @@ 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.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 @@ -46,8 +47,8 @@ buildscript { allprojects { repositories { + mavenCentral() google() - jcenter() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dcdf0f2d..ecebd858 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-8.8-bin.zip