From c973c87799e8554b440b1934a47047b7b9fa0475 Mon Sep 17 00:00:00 2001 From: mr-lonewolfer Date: Fri, 19 Apr 2024 11:46:37 +0530 Subject: [PATCH] Updgrade project to API level 34 and gradle version 8.4 --- app/build.gradle | 11 +++-- .../blueprints/todoapp/HiltExt.kt | 2 +- app/src/main/AndroidManifest.xml | 3 +- .../architecture/blueprints/todoapp/Event.kt | 5 +- .../blueprints/todoapp/TodoApplication.kt | 1 + .../todoapp/tasks/TasksViewModel.kt | 12 +++-- build.gradle | 47 ++++++++++--------- gradle/wrapper/gradle-wrapper.properties | 6 +-- 8 files changed, 49 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 699ba0ef4..4031cb301 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,14 +5,16 @@ apply plugin: 'dagger.hilt.android.plugin' apply plugin: 'androidx.navigation.safeargs.kotlin' android { - compileSdkVersion rootProject.compileSdkVersion + namespace = "com.example.android.architecture.blueprints.todoapp" + compileSdk rootProject.compileSdkVersion defaultConfig { applicationId "com.example.android.architecture.blueprints.master" - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion + minSdk rootProject.minSdkVersion + targetSdk rootProject.targetSdkVersion versionCode 1 versionName "1.0" + multiDexEnabled true testInstrumentationRunner "com.example.android.architecture.blueprints.todoapp.CustomTestRunner" @@ -177,4 +179,7 @@ dependencies { // Kotlin implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion" + + //MultiDex + implementation "androidx.multidex:multidex:$multiDexVersion" } diff --git a/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/HiltExt.kt b/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/HiltExt.kt index b2ec065ba..25a35f723 100644 --- a/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/HiltExt.kt +++ b/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/HiltExt.kt @@ -36,7 +36,7 @@ import androidx.test.core.app.ApplicationProvider */ inline fun launchFragmentInHiltContainer( fragmentArgs: Bundle? = null, - @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, + @StyleRes themeResId: Int = R.style.AppTheme, crossinline action: Fragment.() -> Unit = {} ) { val startActivityIntent = Intent.makeMainActivity( diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e85b438cf..36723a569 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,7 +28,8 @@ + android:theme="@style/AppTheme.OverlapSystemBar" + android:exported="true"> diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt index 77c6b4369..3b326d3f3 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt @@ -51,8 +51,9 @@ open class Event(private val content: T) { * [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled. */ class EventObserver(private val onEventUnhandledContent: (T) -> Unit) : Observer> { - override fun onChanged(event: Event?) { - event?.getContentIfNotHandled()?.let { + + override fun onChanged(event: Event) { + event.getContentIfNotHandled()?.let { onEventUnhandledContent(it) } } diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/TodoApplication.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/TodoApplication.kt index 257026a45..2d0bab920 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/TodoApplication.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/TodoApplication.kt @@ -17,6 +17,7 @@ package com.example.android.architecture.blueprints.todoapp import android.app.Application +import androidx.multidex.BuildConfig import dagger.hilt.android.HiltAndroidApp import timber.log.Timber import timber.log.Timber.DebugTree diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt index 8c007bc5a..fb6d58b75 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt @@ -20,9 +20,9 @@ import androidx.annotation.StringRes import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.SavedStateHandle -import androidx.lifecycle.Transformations import androidx.lifecycle.ViewModel import androidx.lifecycle.distinctUntilChanged +import androidx.lifecycle.map import androidx.lifecycle.switchMap import androidx.lifecycle.viewModelScope import com.example.android.architecture.blueprints.todoapp.Event @@ -91,9 +91,8 @@ class TasksViewModel @Inject constructor( val newTaskEvent: LiveData> = _newTaskEvent private var resultMessageShown: Boolean = false - - // This LiveData depends on another so we can use a transformation. - val empty: LiveData = Transformations.map(_items) { + + val empty: LiveData = _items.map { it.isEmpty() } @@ -121,12 +120,14 @@ class TasksViewModel @Inject constructor( R.drawable.logo_no_fill, true ) } + ACTIVE_TASKS -> { setFilter( R.string.label_active, R.string.no_tasks_active, R.drawable.ic_check_circle_96dp, false ) } + COMPLETED_TASKS -> { setFilter( R.string.label_completed, R.string.no_tasks_completed, @@ -229,13 +230,14 @@ class TasksViewModel @Inject constructor( ACTIVE_TASKS -> if (task.isActive) { tasksToShow.add(task) } + COMPLETED_TASKS -> if (task.isCompleted) { tasksToShow.add(task) } } } return tasksToShow - } + } fun refresh() { _forceUpdate.value = true diff --git a/build.gradle b/build.gradle index 9c8772837..47724bc10 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,15 @@ buildscript { - ext.kotlinVersion = '1.5.10' - ext.navigationVersion = '2.3.5' + ext.kotlinVersion = '1.9.23' + ext.navigationVersion = '2.7.7' ext.ktlintVersion = '0.33.0' - ext.hiltVersion = "2.36" + ext.hiltVersion = "2.51" repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.android.tools.build:gradle:8.3.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion" classpath "com.google.dagger:hilt-android-gradle-plugin:$hiltVersion" @@ -41,34 +41,35 @@ allprojects { // Define versions in a single place ext { // Sdk and tools - minSdkVersion = 21 - targetSdkVersion = 30 - compileSdkVersion = 30 + minSdkVersion = 24 + targetSdkVersion = 34 + compileSdkVersion = 34 // App dependencies androidXVersion = '1.0.0' - androidXTestCoreVersion = '1.3.0' - androidXTestExtKotlinRunnerVersion = '1.1.2' - androidXTestRulesVersion = '1.2.0' - androidXAnnotations = '1.2.0' + androidXTestCoreVersion = '1.5.0' + androidXTestExtKotlinRunnerVersion = '1.1.5' + androidXTestRulesVersion = '1.5.0' + androidXAnnotations = '1.7.1' androidXLegacySupport = '1.0.0' - appCompatVersion = '1.3.0' - archLifecycleVersion = '2.3.1' - archTestingVersion = '2.1.0' + appCompatVersion = '1.6.1' + archLifecycleVersion = '2.7.0' + archTestingVersion = '2.2.0' cardVersion = '1.0.0' - coroutinesVersion = '1.5.0' + coroutinesVersion = '1.8.0' dexMakerVersion = '2.12.1' - espressoVersion = '3.3.0' - fragmentVersion = '1.3.4' - fragmentKtxVersion = '1.3.4' + espressoVersion = '3.5.1' + fragmentVersion = '1.6.2' + fragmentKtxVersion = '1.6.2' hamcrestVersion = '1.3' junitVersion = '4.13.1' - materialVersion = '1.3.0' + materialVersion = '1.11.0' multiDexVersion = '2.0.1' - recyclerViewVersion = '1.2.0' - robolectricVersion = '4.5.1' - roomVersion = '2.3.0' + recyclerViewVersion = '1.3.2' + robolectricVersion = '4.7.3' + roomVersion = '2.6.1' rulesVersion = '1.0.1' - timberVersion = '4.7.1' + timberVersion = '5.0.1' truthVersion = '1.1.2' + multidex = '2.0.1' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8e772a49a..3ebc9ddd5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jun 01 08:01:38 UTC 2021 +#Fri Apr 19 10:35:11 IST 2024 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists