Skip to content

Commit

Permalink
#1274 delete hilt and inject PurchasingUseCase into ConfigTriggerView…
Browse files Browse the repository at this point in the history
…Model
  • Loading branch information
sds100 committed Oct 16, 2024
1 parent a5ba747 commit 3b19cfb
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: "kotlinx-serialization"
apply plugin: "org.jetbrains.kotlin.plugin.parcelize"
apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "com.google.dagger.hilt.android"

android {

Expand Down Expand Up @@ -169,8 +168,6 @@ dependencies {
implementation "dev.rikka.shizuku:api:$shizuku_version"
implementation "dev.rikka.shizuku:provider:$shizuku_version"
implementation "org.lsposed.hiddenapibypass:hiddenapibypass:4.3"
implementation("com.google.dagger:hilt-android:2.51")
kapt("com.google.dagger:hilt-android-compiler:2.51")
proImplementation 'com.revenuecat.purchases:purchases:8.8.1'


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCase
import io.github.sds100.keymapper.mappings.keymaps.CreateKeyMapShortcutUseCase
import io.github.sds100.keymapper.mappings.keymaps.DisplayKeyMapUseCase
import io.github.sds100.keymapper.onboarding.OnboardingUseCase
import io.github.sds100.keymapper.purchasing.PurchasingUseCase
import io.github.sds100.keymapper.util.ui.ResourceProvider
import kotlinx.coroutines.CoroutineScope

Expand All @@ -19,6 +20,7 @@ class ConfigTriggerViewModel(
createKeyMapShortcut: CreateKeyMapShortcutUseCase,
displayKeyMap: DisplayKeyMapUseCase,
resourceProvider: ResourceProvider,
purchasingUseCase: PurchasingUseCase,
) : BaseConfigTriggerViewModel(
coroutineScope,
onboarding,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.sds100.keymapper.purchasing

import android.content.Context
import kotlinx.coroutines.CoroutineScope

class PurchasingManagerImpl(
context: Context,
private val coroutineScope: CoroutineScope,
) : PurchasingManager

interface PurchasingManager
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.sds100.keymapper.purchasing

class PurchasingUseCaseImpl(private val manager: PurchasingManager) : PurchasingUseCase

interface PurchasingUseCase
7 changes: 5 additions & 2 deletions app/src/main/java/io/github/sds100/keymapper/KeyMapperApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.multidex.MultiDexApplication
import com.google.android.material.color.DynamicColors
import dagger.hilt.android.HiltAndroidApp
import io.github.sds100.keymapper.data.Keys
import io.github.sds100.keymapper.data.entities.LogEntryEntity
import io.github.sds100.keymapper.logging.KeyMapperLoggingTree
import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerController
import io.github.sds100.keymapper.purchasing.PurchasingManagerImpl
import io.github.sds100.keymapper.settings.ThemeUtils
import io.github.sds100.keymapper.shizuku.ShizukuAdapterImpl
import io.github.sds100.keymapper.system.AndroidSystemFeatureAdapter
Expand Down Expand Up @@ -65,7 +65,6 @@ import java.util.Calendar
/**
* Created by sds100 on 19/05/2020.
*/
@HiltAndroidApp
class KeyMapperApp : MultiDexApplication() {
val appCoroutineScope = MainScope()

Expand Down Expand Up @@ -154,6 +153,10 @@ class KeyMapperApp : MultiDexApplication() {
)
}

val purchasingManager: PurchasingManagerImpl by lazy {
PurchasingManagerImpl(this.applicationContext, appCoroutineScope)
}

private val loggingTree by lazy {
KeyMapperLoggingTree(
appCoroutineScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.github.sds100.keymapper.data.repositories.RoomLogRepository
import io.github.sds100.keymapper.data.repositories.SettingsPreferenceRepository
import io.github.sds100.keymapper.logging.LogRepository
import io.github.sds100.keymapper.mappings.fingerprintmaps.FingerprintMapRepository
import io.github.sds100.keymapper.purchasing.PurchasingManagerImpl
import io.github.sds100.keymapper.shizuku.ShizukuAdapter
import io.github.sds100.keymapper.system.accessibility.AccessibilityServiceAdapter
import io.github.sds100.keymapper.system.airplanemode.AirplaneModeAdapter
Expand Down Expand Up @@ -252,6 +253,9 @@ object ServiceLocator {
fun appCoroutineScope(context: Context): CoroutineScope =
(context.applicationContext as KeyMapperApp).appCoroutineScope

fun purchasingManager(context: Context): PurchasingManagerImpl =
(context.applicationContext as KeyMapperApp).purchasingManager

private fun createDatabase(context: Context): AppDatabase = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerKeyViewM
import io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerViewModel
import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerUseCase
import io.github.sds100.keymapper.onboarding.OnboardingUseCase
import io.github.sds100.keymapper.purchasing.PurchasingUseCase
import io.github.sds100.keymapper.ui.utils.getJsonSerializable
import io.github.sds100.keymapper.ui.utils.putJsonSerializable
import io.github.sds100.keymapper.util.State
Expand All @@ -38,6 +39,7 @@ class ConfigKeyMapViewModel(
private val displayMapping: DisplayKeyMapUseCase,
createActionUseCase: CreateActionUseCase,
resourceProvider: ResourceProvider,
purchasingUseCase: PurchasingUseCase,
) : ViewModel(),
ConfigMappingViewModel,
ResourceProvider by resourceProvider {
Expand Down Expand Up @@ -70,6 +72,7 @@ class ConfigKeyMapViewModel(
createKeyMapShortcut,
displayMapping,
resourceProvider,
purchasingUseCase,
)

override val configConstraintsViewModel = ConfigConstraintsViewModel(
Expand Down Expand Up @@ -130,6 +133,7 @@ class ConfigKeyMapViewModel(
private val displayMapping: DisplayKeyMapUseCase,
private val createActionUseCase: CreateActionUseCase,
private val resourceProvider: ResourceProvider,
private val purchasingUseCase: PurchasingUseCase,
) : ViewModelProvider.Factory {

@Suppress("UNCHECKED_CAST")
Expand All @@ -143,6 +147,7 @@ class ConfigKeyMapViewModel(
displayMapping,
createActionUseCase,
resourceProvider,
purchasingUseCase,
) as T
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/io/github/sds100/keymapper/util/Inject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.github.sds100.keymapper.mappings.keymaps.CreateKeyMapShortcutViewModel
import io.github.sds100.keymapper.mappings.keymaps.ListKeyMapsUseCaseImpl
import io.github.sds100.keymapper.onboarding.AppIntroUseCaseImpl
import io.github.sds100.keymapper.onboarding.AppIntroViewModel
import io.github.sds100.keymapper.purchasing.PurchasingUseCaseImpl
import io.github.sds100.keymapper.reportbug.ReportBugUseCaseImpl
import io.github.sds100.keymapper.reportbug.ReportBugViewModel
import io.github.sds100.keymapper.settings.ConfigSettingsUseCaseImpl
Expand Down Expand Up @@ -129,6 +130,9 @@ object Inject {
ServiceLocator.resourceProvider(context),
)

fun purchasingUseCase(ctx: Context) =
PurchasingUseCaseImpl(ServiceLocator.purchasingManager(ctx))

fun configKeyMapViewModel(
ctx: Context,
): ConfigKeyMapViewModel.Factory = ConfigKeyMapViewModel.Factory(
Expand All @@ -140,6 +144,7 @@ object Inject {
UseCases.displayKeyMap(ctx),
UseCases.createAction(ctx),
ServiceLocator.resourceProvider(ctx),
purchasingUseCase(ctx),
)

fun configFingerprintMapViewModel(
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ buildscript {
classpath "org.jlleitschuh.gradle:ktlint-gradle:12.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.52"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 3b19cfb

Please sign in to comment.