Skip to content

Commit

Permalink
Update dependencies and fixed related issues
Browse files Browse the repository at this point in the history
Signed-off-by: Diraj H S <dirajhsdj@gmail.com>
  • Loading branch information
DirajHS committed Jun 14, 2024
1 parent 92b1fae commit 31ecb84
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 35 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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

Expand Down
23 changes: 13 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'

android {
compileSdkVersion 31
compileSdk 34
defaultConfig {
applicationId "com.example.android.trackmysleepqualityrecyclerview"
minSdkVersion 19
targetSdkVersion 31
minSdkVersion 21
targetSdkVersion 34
versionCode 1
versionName "1.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -42,12 +42,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 "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version_kotlin"

// Support libraries
implementation "androidx.appcompat:appcompat:$version_appcompat"
Expand All @@ -59,10 +65,7 @@ dependencies {

// Room and Lifecycle dependencies
implementation "androidx.room:room-runtime:$version_room"
annotationProcessor "androidx.room:room-compiler:$version_room"
// To use Kotlin annotation processing tool (kapt)
kapt "androidx.room:room-compiler:$version_room"
implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions"

// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle"
Expand All @@ -80,7 +83,7 @@ dependencies {

// Testing
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" android:exported="true">
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SleepDetailViewModelFactory(
private val sleepNightKey: Long,
private val dataSource: SleepDatabaseDao) : ViewModelProvider.Factory {
@Suppress("unchecked_cast")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(SleepDetailViewModel::class.java)) {
return SleepDetailViewModel(sleepNightKey, dataSource) as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SleepQualityViewModelFactory(
private val sleepNightKey: Long,
private val dataSource: SleepDatabaseDao) : ViewModelProvider.Factory {
@Suppress("unchecked_cast")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(SleepQualityViewModel::class.java)) {
return SleepQualityViewModel(sleepNightKey, dataSource) as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.map
import com.example.android.trackmysleepquality.database.SleepDatabaseDao
import com.example.android.trackmysleepquality.database.SleepNight
import com.example.android.trackmysleepquality.formatNights
Expand Down Expand Up @@ -60,29 +60,29 @@ class SleepTrackerViewModel(
/**
* Converted nights to Spanned for displaying.
*/
val nightsString = Transformations.map(nights) { nights ->
val nightsString = nights.map { nights ->
formatNights(nights, application.resources)
}

/**
* If tonight has not been set, then the START button should be visible.
*/
val startButtonVisible = Transformations.map(tonight) {
val startButtonVisible = tonight.map {
null == it
}

/**
* If tonight has been set, then the STOP button should be visible.
*/
val stopButtonVisible = Transformations.map(tonight) {
val stopButtonVisible = tonight.map {
null != it
}

/**
* If there are any nights in the database, show the CLEAR button.
*/
val clearButtonVisible = Transformations.map(nights) {
it?.isNotEmpty()
val clearButtonVisible = nights.map {
it.isNotEmpty()
}

/**
Expand All @@ -104,7 +104,7 @@ class SleepTrackerViewModel(
* This is private because we don't want to expose setting this value to the Fragment.
*/

private val _navigateToSleepQuality = MutableLiveData<SleepNight>()
private val _navigateToSleepQuality = MutableLiveData<SleepNight?>()
/**
* Call this immediately after calling `show()` on a toast.
*
Expand All @@ -119,7 +119,7 @@ class SleepTrackerViewModel(
/**
* If this is non-null, immediately navigate to [SleepQualityFragment] and call [doneNavigating]
*/
val navigateToSleepQuality: LiveData<SleepNight>
val navigateToSleepQuality: LiveData<SleepNight?>
get() = _navigateToSleepQuality

/**
Expand All @@ -132,7 +132,7 @@ class SleepTrackerViewModel(
_navigateToSleepQuality.value = null
}

private val _navigateToSleepDataQuality = MutableLiveData<Long>()
private val _navigateToSleepDataQuality = MutableLiveData<Long?>()
val navigateToSleepDataQuality
get() = _navigateToSleepDataQuality

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SleepTrackerViewModelFactory(
private val dataSource: SleepDatabaseDao,
private val application: Application) : ViewModelProvider.Factory {
@Suppress("unchecked_cast")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(SleepTrackerViewModel::class.java)) {
return SleepTrackerViewModel(dataSource, application) as T
}
Expand Down
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
buildscript {

ext {
version_core = '1.5.0'
version_coroutine = "1.3.7"
version_navigation = '2.4.1'
version_constraint_layout = '2.1.0-beta02'
version_gradle = '7.1.0'
version_kotlin = '1.4.31'
version_lifecycle_extensions = "2.2.0"
version_lifecycle = '2.3.1'
version_room = '2.4.2'
version_appcompat = '1.3.0'
version_fragment = '1.3.4'
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'
version_appcompat = "1.7.0"
version_fragment = "1.8.0"
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip

0 comments on commit 31ecb84

Please sign in to comment.