diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7b34f12..0000000 --- a/.gitignore +++ /dev/null @@ -1,111 +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 - -# 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 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 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 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 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 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 +