Skip to content

Commit f18531a

Browse files
authored
Merge pull request #5 from haroldadmin/auto-init
feat: Switch to androidx startup instead of content provider for init
2 parents 558223e + 5c9b74c commit f18531a

File tree

6 files changed

+43
-82
lines changed

6 files changed

+43
-82
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ buildscript {
2626
"espressoCore" : "3.2.0",
2727
"mockk" : "1.9.3",
2828
"robolectric" : "4.3.1",
29+
"startup" : "1.0.0-alpha01",
2930
]
3031

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

4143
"junit" : "junit:junit:${versions.junit}",

what-the-stack/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
implementation libs.fragmentKtx
4848
implementation libs.constraintLayout
4949
implementation libs.materialComponents
50+
implementation libs.startup
5051
implementation libs.insetter
5152

5253
testImplementation libs.junit

what-the-stack/src/main/AndroidManifest.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
23
package="com.haroldadmin.whatthestack">
34
<application>
45
<provider
5-
android:name=".WhatTheStackInitProvider"
6-
android:authorities="${applicationId}.WhatTheStackInitProvider"
6+
android:name="androidx.startup.InitializationProvider"
7+
android:authorities="${applicationId}.androidx-startup"
78
android:exported="false"
8-
android:enabled="true"/>
9+
tools:node="merge">
10+
<meta-data android:name="com.haroldadmin.whatthestack.WhatTheStackInitializer"
11+
android:value="androidx.startup" />
12+
</provider>
13+
914
<service
1015
android:name=".WhatTheStackService"
1116
android:process=":what_the_stack_process" />

what-the-stack/src/main/java/com/haroldadmin/whatthestack/WhatTheStack.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class WhatTheStack(private val applicationContext: Context) {
2121

2222
@Suppress("unused")
2323
fun init() {
24-
WhatTheStackInitializer.init(applicationContext)
24+
InitializationManager.init(applicationContext)
2525
}
2626
}
2727

28-
internal object WhatTheStackInitializer {
28+
internal object InitializationManager {
2929

3030
private var isInitialized: Boolean = false
3131

what-the-stack/src/main/java/com/haroldadmin/whatthestack/WhatTheStackInitProvider.kt

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.haroldadmin.whatthestack
2+
3+
import android.content.Context
4+
import androidx.startup.Initializer
5+
import java.lang.Class
6+
7+
/**
8+
* WhatTheStackInitializer is an [androidx.startup.Initializer] for WhatTheStack
9+
*
10+
* This particular initializer does not need to return anything, but it is required to return
11+
* a sensible value here so we return an instance of a dummy class [WhatTheStackInitializedToken]
12+
* instead.
13+
*/
14+
class WhatTheStackInitializer : Initializer<WhatTheStackInitializedToken> {
15+
16+
override fun create(context: Context): WhatTheStackInitializedToken {
17+
InitializationManager.init(context)
18+
return WhatTheStackInitializedToken()
19+
}
20+
21+
override fun dependencies(): List<Class<out Initializer<*>>> {
22+
return emptyList()
23+
}
24+
}
25+
26+
/**
27+
* A dummy class that does nothing but represent a type that can be returned by
28+
* [WhatTheStackInitializer]
29+
*/
30+
class WhatTheStackInitializedToken

0 commit comments

Comments
 (0)