Skip to content

Commit

Permalink
Integrated WorkManager & Datastore Preference Library.
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek-singh-3212 committed Sep 18, 2022
1 parent 5c30210 commit 09e6b9e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
implementation 'com.github.ByteHamster:SearchPreference:v2.3.0'
implementation 'com.github.AppIntro:AppIntro:6.2.0'
implementation "androidx.work:work-runtime-ktx:2.7.1"
implementation "androidx.datastore:datastore-preferences:1.0.0"

// Cannot use debugImplementation since classes need to be imported in AnkiDroidApp
// and there's no no-op version for release build. Usage has been disabled for release
Expand Down
12 changes: 12 additions & 0 deletions AnkiDroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,18 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>

<!-- Using custom work manager initialization -->
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
</application>

</manifest>
11 changes: 10 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import java.util.regex.Pattern
*/
@KotlinCleanup("lots to do")
@KotlinCleanup("IDE Lint")
open class AnkiDroidApp : Application() {
open class AnkiDroidApp : Application(), androidx.work.Configuration.Provider {
/** An exception if the WebView subsystem fails to load */
private var mWebViewError: Throwable? = null
private val mNotifications = MutableLiveData<Void?>()
Expand Down Expand Up @@ -180,9 +180,11 @@ open class AnkiDroidApp : Application() {
}
}
}
// TODO: Notification CleanUP. Delete the Boot Service after successful implementation of Notification Work Manager.
Timber.i("AnkiDroidApp: Starting Services")
BootService().onReceive(this, Intent(this, BootService::class.java))

// TODO: Notification CleanUP. Delete the Notification Service after successful implementation of Notification Work Manager.
// Register for notifications
mNotifications.observeForever { NotificationService.triggerNotificationFor(this) }
Themes.systemIsInNightMode =
Expand Down Expand Up @@ -210,6 +212,13 @@ open class AnkiDroidApp : Application() {
}
}

/**
* Our configuration for custom work manager.
* We are using custom work manager because UNIT TESTS are failing.
* TODO: Remove custom implementation after implementing 14 tests using WorkManagerTestInitHelper. SEE: https://developer.android.com/topic/libraries/architecture/workmanager/how-to/integration-testing
*/
override fun getWorkManagerConfiguration() = androidx.work.Configuration.Builder().build()

/**
* A tree which logs necessary data for crash reporting.
*
Expand Down

0 comments on commit 09e6b9e

Please sign in to comment.