From df55c8ee3b1397ca176351c4e8d86ad318f11f39 Mon Sep 17 00:00:00 2001 From: thecraftman Date: Tue, 4 Jun 2024 22:57:17 +0100 Subject: [PATCH 1/8] add m1 support to gradle.properties --- .vscode/settings.json | 3 +++ gradle.properties | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c53903d..685db79 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,3 +21,6 @@ android.enableJetifier=true kotlin.code.style=official #Enable incremental annotation processing kapt.incremental.apt=true +# m1 chip support +org.gradle.jvmargs=-Xmx1536M -XX:MaxMetaspaceSize=512m -XX:+UseG1GC -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true + From 618b1911b4c9d58bf626cad88c26d38be3cd0ce4 Mon Sep 17 00:00:00 2001 From: thecraftman Date: Tue, 4 Jun 2024 23:06:02 +0100 Subject: [PATCH 2/8] update module buid.gradle.kts --- app/build.gradle.kts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3fe5751..3988c9a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -83,11 +83,9 @@ android { } } - android { - sourceSets { - getByName("test").java.srcDir("src/sharedTest/java") - getByName("androidTest").java.srcDir("src/sharedTest/java") - } + sourceSets { + getByName("test").java.srcDir("src/sharedTest/java") + getByName("androidTest").java.srcDir("src/sharedTest/java") } hilt { @@ -107,11 +105,11 @@ android { } compileOptions { - sourceCompatibility(Config.javaVersion) - targetCompatibility(Config.javaVersion) + sourceCompatibility = Config.javaVersion + targetCompatibility = Config.javaVersion } - tasks.withType().all { + tasks.withType { kotlinOptions { jvmTarget = Config.javaVersion.toString() } @@ -162,7 +160,7 @@ dependencies { // Weather Image implementation(Utils.weatherImage) - // CalenderView + // CalendarView implementation(Utils.calendarView) // Google Play Services From bc3b187b4eb291e4a226c37985fbde0bb0ac69a8 Mon Sep 17 00:00:00 2001 From: thecraftman Date: Tue, 4 Jun 2024 23:19:08 +0100 Subject: [PATCH 3/8] Optimize app startup by deferring initialization of non-critical components --- .../com/mayokunadeniyi/instantweather/App.kt | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 app/src/main/java/com/mayokunadeniyi/instantweather/App.kt diff --git a/app/src/main/java/com/mayokunadeniyi/instantweather/App.kt b/app/src/main/java/com/mayokunadeniyi/instantweather/App.kt new file mode 100644 index 0000000..4727863 --- /dev/null +++ b/app/src/main/java/com/mayokunadeniyi/instantweather/App.kt @@ -0,0 +1,67 @@ +// App.kt +override fun onCreate() { + super.onCreate() + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val deferredComponentInitializer = DeferredComponentInitializer(this) + deferredComponentInitializer.initialize() + } else { + initializeComponents() + } +} + +private fun initializeComponents() { + initWorkManager() + initCrashlytics() + initAnalytics() +} + +// DeferredComponentInitializer.kt +class DeferredComponentInitializer(private val app: Application) { + + fun initialize() { + val componentInitializer = ComponentInitializer(app) + val initializeMessage = when { + isColdStart() -> "Deferred initialization from cold start" + else -> "Deferred initialization from warm start" + } + WorkManager.getInstance(app) + .beginUniqueWork( + "DeferredInitialization", + ExistingWorkPolicy.KEEP, + OneTimeWorkRequestBuilder() + .setInputData(workDataOf(DeferredWorker.KEY_INITIALIZE to initializeMessage)) + .build() + ) + .enqueue() + } + + private fun isColdStart(): Boolean { + return ProcessLifecycleOwner.get().lifecycle.currentState == Lifecycle.State.INITIALIZED + } + + private class DeferredWorker( + context: Context, + workerParams: WorkerParameters + ) : Worker(context, workerParams) { + override fun doWork(): Result { + val initializeMessage = inputData.getString(KEY_INITIALIZE) + initializeMessage?.let { + Log.d("DeferredInit", it) + } + ComponentInitializer(applicationContext).initialize() + return Result.success() + } + + companion object { + const val KEY_INITIALIZE = "KEY_INITIALIZE" + } + } + + private class ComponentInitializer(private val app: Application) { + fun initialize() { + initCrashlytics() + initAnalytics() + } + } +} \ No newline at end of file From 8d9206d93509db0c5d0590af32780ca82863d1a0 Mon Sep 17 00:00:00 2001 From: thecraftman Date: Tue, 4 Jun 2024 23:22:45 +0100 Subject: [PATCH 4/8] deferring the initialization of certain non-critical components like Crashlytics and Analytics until after the app has launched --- .../DeferredComponentInitializer.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 app/src/main/java/com/mayokunadeniyi/instantweather/initializers/DeferredComponentInitializer.kt diff --git a/app/src/main/java/com/mayokunadeniyi/instantweather/initializers/DeferredComponentInitializer.kt b/app/src/main/java/com/mayokunadeniyi/instantweather/initializers/DeferredComponentInitializer.kt new file mode 100644 index 0000000..7437790 --- /dev/null +++ b/app/src/main/java/com/mayokunadeniyi/instantweather/initializers/DeferredComponentInitializer.kt @@ -0,0 +1,63 @@ +package com.mayokunadeniyi.instantweather.initializers + +import android.app.Application +import android.content.Context +import android.os.Build +import android.util.Log +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.ProcessLifecycleOwner +import androidx.work.ExistingWorkPolicy +import androidx.work.OneTimeWorkRequestBuilder +import androidx.work.WorkManager +import androidx.work.Worker +import androidx.work.WorkerParameters +import androidx.work.workDataOf + +class DeferredComponentInitializer(private val app: Application) { + + fun initialize() { + val componentInitializer = ComponentInitializer(app) + val initializeMessage = when { + isColdStart() -> "Deferred initialization from cold start" + else -> "Deferred initialization from warm start" + } + WorkManager.getInstance(app) + .beginUniqueWork( + "DeferredInitialization", + ExistingWorkPolicy.KEEP, + OneTimeWorkRequestBuilder() + .setInputData(workDataOf(DeferredWorker.KEY_INITIALIZE to initializeMessage)) + .build() + ) + .enqueue() + } + + private fun isColdStart(): Boolean { + return ProcessLifecycleOwner.get().lifecycle.currentState == Lifecycle.State.INITIALIZED + } + + private class DeferredWorker( + context: Context, + workerParams: WorkerParameters + ) : Worker(context, workerParams) { + override fun doWork(): Result { + val initializeMessage = inputData.getString(KEY_INITIALIZE) + initializeMessage?.let { + Log.d("DeferredInit", it) + } + ComponentInitializer(applicationContext).initialize() + return Result.success() + } + + companion object { + const val KEY_INITIALIZE = "KEY_INITIALIZE" + } + } + + private class ComponentInitializer(private val app: Application) { + fun initialize() { + initCrashlytics() + initAnalytics() + } + } +} \ No newline at end of file From 535b051efcbdb514bfeb10e7173d9f0efae316ed Mon Sep 17 00:00:00 2001 From: thecraftman Date: Tue, 4 Jun 2024 23:26:37 +0100 Subject: [PATCH 5/8] update xml schema with app changes --- app/src/main/AndroidManifest.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f613d68..bf772e7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,8 +6,9 @@ + - @@ -24,10 +26,12 @@ + + \ No newline at end of file From 39675820736976edc892f18c261761cd4d45400d Mon Sep 17 00:00:00 2001 From: thecraftman Date: Tue, 4 Jun 2024 23:38:55 +0100 Subject: [PATCH 6/8] remove vscode --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 7b34f12..116ee9f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ *.ap_ *.aab +.vscode/settings.json + # Files for the ART/Dalvik VM *.dex From db34748b3a9ab3292d821732d1cc5553118f5781 Mon Sep 17 00:00:00 2001 From: Ore-Aruwaji Tola Date: Tue, 4 Jun 2024 23:41:05 +0100 Subject: [PATCH 7/8] Delete .vscode/settings.json --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index c5f3f6b..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "java.configuration.updateBuildConfiguration": "interactive" -} \ No newline at end of file From 20b408a2a2dab82a16422600601527562e1186cc Mon Sep 17 00:00:00 2001 From: Ore-Aruwaji Tola Date: Tue, 4 Jun 2024 23:41:24 +0100 Subject: [PATCH 8/8] Delete .gitignore --- .gitignore | 113 ----------------------------------------------------- 1 file changed, 113 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 116ee9f..0000000 --- a/.gitignore +++ /dev/null @@ -1,113 +0,0 @@ -# Created by https://www.toptal.com/developers/gitignore/api/android -# Edit at https://www.toptal.com/developers/gitignore?templates=android - -### Android ### -# Built application files -*.apk -*.aar -*.ap_ -*.aab - -.vscode/settings.json - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ -# Uncomment the following line in case you need and you don't have the release build type files in your app -# release/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# IntelliJ -*.iml -.idea/ -.idea/workspace.xml -.idea/tasks.xml -.idea/gradle.xml -.idea/assetWizardSettings.xml -.idea/dictionaries -.idea/libraries -.idea/jarRepositories.xml -# Android Studio 3 in .gitignore file. -.idea/caches -.idea/modules.xml -# Comment next line if keeping position of elements in Navigation Editor is relevant for you -.idea/navEditor.xml - -# Keystore files -# Uncomment the following lines if you do not want to check your keystore files in. -#*.jks -#*.keystore - -# External native build folder generated in Android Studio 2.2 and later -.externalNativeBuild -.cxx/ - -# Google Services (e.g. APIs or Firebase) -google-services.json - -.DS_Store - -# Freeline -freeline.py -freeline/ -freeline_project_description.json - -# fastlane -fastlane/report.xml -fastlane/Preview.html -fastlane/screenshots -fastlane/test_output -fastlane/readme.md - -# Version control -vcs.xml - -# lint -lint/intermediates/ -lint/generated/ -lint/outputs/ -lint/tmp/ -# lint/reports/ - -# Android Profiling -*.hprof - -### Android Patch ### -gen-external-apklibs -output.json - -keystore.properties -Instant-Weather-key - -buildSrc/build -buildSrc/.gradle - -# Replacement of .externalNativeBuild directories introduced -# with Android Studio 3.5. - -# End of https://www.toptal.com/developers/gitignore/api/android