Skip to content

Commit

Permalink
Merge pull request #5 from haroldadmin/auto-init
Browse files Browse the repository at this point in the history
feat: Switch to androidx startup instead of content provider for init
  • Loading branch information
haroldadmin authored Jun 20, 2020
2 parents 558223e + 5c9b74c commit f18531a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 82 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ buildscript {
"espressoCore" : "3.2.0",
"mockk" : "1.9.3",
"robolectric" : "4.3.1",
"startup" : "1.0.0-alpha01",
]

ext.libs = [
Expand All @@ -36,6 +37,7 @@ buildscript {
"materialComponents": "com.google.android.material:material:${versions.materialComponents}",
"constraintLayout" : "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}",
"fragmentKtx" : "androidx.fragment:fragment-ktx:${versions.fragment}",
"startup" : "androidx.startup:startup-runtime:${versions.startup}",
"insetter" : "dev.chrisbanes:insetter-ktx:${versions.insetter}",

"junit" : "junit:junit:${versions.junit}",
Expand Down
1 change: 1 addition & 0 deletions what-the-stack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation libs.fragmentKtx
implementation libs.constraintLayout
implementation libs.materialComponents
implementation libs.startup
implementation libs.insetter

testImplementation libs.junit
Expand Down
11 changes: 8 additions & 3 deletions what-the-stack/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.haroldadmin.whatthestack">
<application>
<provider
android:name=".WhatTheStackInitProvider"
android:authorities="${applicationId}.WhatTheStackInitProvider"
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
android:enabled="true"/>
tools:node="merge">
<meta-data android:name="com.haroldadmin.whatthestack.WhatTheStackInitializer"
android:value="androidx.startup" />
</provider>

<service
android:name=".WhatTheStackService"
android:process=":what_the_stack_process" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class WhatTheStack(private val applicationContext: Context) {

@Suppress("unused")
fun init() {
WhatTheStackInitializer.init(applicationContext)
InitializationManager.init(applicationContext)
}
}

internal object WhatTheStackInitializer {
internal object InitializationManager {

private var isInitialized: Boolean = false

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.haroldadmin.whatthestack

import android.content.Context
import androidx.startup.Initializer
import java.lang.Class

/**
* WhatTheStackInitializer is an [androidx.startup.Initializer] for WhatTheStack
*
* This particular initializer does not need to return anything, but it is required to return
* a sensible value here so we return an instance of a dummy class [WhatTheStackInitializedToken]
* instead.
*/
class WhatTheStackInitializer : Initializer<WhatTheStackInitializedToken> {

override fun create(context: Context): WhatTheStackInitializedToken {
InitializationManager.init(context)
return WhatTheStackInitializedToken()
}

override fun dependencies(): List<Class<out Initializer<*>>> {
return emptyList()
}
}

/**
* A dummy class that does nothing but represent a type that can be returned by
* [WhatTheStackInitializer]
*/
class WhatTheStackInitializedToken

0 comments on commit f18531a

Please sign in to comment.