diff --git a/app/build.gradle b/app/build.gradle index 511b965480..bdf149b60c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -170,6 +170,7 @@ dependencies { implementation "dev.rikka.shizuku:provider:$shizuku_version" implementation "org.lsposed.hiddenapibypass:hiddenapibypass:4.3" implementation("com.google.dagger:hilt-android:2.51") + implementation("androidx.hilt:hilt-navigation-fragment:1.2.0") kapt("com.google.dagger:hilt-android-compiler:2.51") proImplementation 'com.revenuecat.purchases:purchases:8.8.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bfe982148c..2d859671bb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -233,7 +233,7 @@ diff --git a/app/src/main/java/io/github/sds100/keymapper/AppHiltModule.kt b/app/src/main/java/io/github/sds100/keymapper/AppHiltModule.kt new file mode 100644 index 0000000000..3898dfe1d3 --- /dev/null +++ b/app/src/main/java/io/github/sds100/keymapper/AppHiltModule.kt @@ -0,0 +1,19 @@ +package io.github.sds100.keymapper + +import android.content.Context +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.MainScope +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +class AppHiltModule { + @Singleton + @Provides + fun provideCoroutineScope(@ApplicationContext ctx: Context): CoroutineScope = MainScope() +} diff --git a/app/src/main/java/io/github/sds100/keymapper/KeyMapperApp.kt b/app/src/main/java/io/github/sds100/keymapper/KeyMapperApp.kt index 8f0c251013..479d7f0cf0 100644 --- a/app/src/main/java/io/github/sds100/keymapper/KeyMapperApp.kt +++ b/app/src/main/java/io/github/sds100/keymapper/KeyMapperApp.kt @@ -39,7 +39,7 @@ import io.github.sds100.keymapper.system.nfc.AndroidNfcAdapter import io.github.sds100.keymapper.system.notifications.AndroidNotificationAdapter import io.github.sds100.keymapper.system.notifications.ManageNotificationsUseCaseImpl import io.github.sds100.keymapper.system.notifications.NotificationController -import io.github.sds100.keymapper.system.notifications.NotificationReceiverAdapter +import io.github.sds100.keymapper.system.notifications.NotificationReceiverServiceAdapter import io.github.sds100.keymapper.system.permissions.AndroidPermissionAdapter import io.github.sds100.keymapper.system.permissions.AutoGrantPermissionController import io.github.sds100.keymapper.system.permissions.Permission @@ -108,14 +108,19 @@ class KeyMapperApp : MultiDexApplication() { this, appCoroutineScope, suAdapter, - notificationReceiverAdapter, + notificationReceiverServiceAdapter, ServiceLocator.settingsRepository(this), ) } val systemFeatureAdapter by lazy { AndroidSystemFeatureAdapter(this) } val accessibilityServiceAdapter by lazy { AccessibilityServiceAdapter(this, appCoroutineScope) } - val notificationReceiverAdapter by lazy { NotificationReceiverAdapter(this, appCoroutineScope) } + val notificationReceiverServiceAdapter by lazy { + NotificationReceiverServiceAdapter( + this, + appCoroutineScope, + ) + } val appShortcutAdapter by lazy { AndroidAppShortcutAdapter(this) } val fileAdapter by lazy { AndroidFileAdapter(this) } val popupMessageAdapter by lazy { AndroidToastAdapter(this) } diff --git a/app/src/main/java/io/github/sds100/keymapper/ServiceLocator.kt b/app/src/main/java/io/github/sds100/keymapper/ServiceLocator.kt index cab33f85f1..7aad77f50c 100755 --- a/app/src/main/java/io/github/sds100/keymapper/ServiceLocator.kt +++ b/app/src/main/java/io/github/sds100/keymapper/ServiceLocator.kt @@ -35,7 +35,7 @@ import io.github.sds100.keymapper.system.network.NetworkAdapter import io.github.sds100.keymapper.system.nfc.NfcAdapter import io.github.sds100.keymapper.system.notifications.AndroidNotificationAdapter import io.github.sds100.keymapper.system.notifications.NotificationController -import io.github.sds100.keymapper.system.notifications.NotificationReceiverAdapter +import io.github.sds100.keymapper.system.notifications.NotificationReceiverServiceAdapter import io.github.sds100.keymapper.system.permissions.AndroidPermissionAdapter import io.github.sds100.keymapper.system.permissions.SystemFeatureAdapter import io.github.sds100.keymapper.system.phone.PhoneAdapter @@ -189,8 +189,8 @@ object ServiceLocator { fun accessibilityServiceAdapter(context: Context): AccessibilityServiceAdapter = (context.applicationContext as KeyMapperApp).accessibilityServiceAdapter - fun notificationReceiverAdapter(context: Context): NotificationReceiverAdapter = - (context.applicationContext as KeyMapperApp).notificationReceiverAdapter + fun notificationReceiverAdapter(context: Context): NotificationReceiverServiceAdapter = + (context.applicationContext as KeyMapperApp).notificationReceiverServiceAdapter fun appShortcutAdapter(context: Context): AppShortcutAdapter = (context.applicationContext as KeyMapperApp).appShortcutAdapter diff --git a/app/src/main/java/io/github/sds100/keymapper/actions/ActionsHiltModule.kt b/app/src/main/java/io/github/sds100/keymapper/actions/ActionsHiltModule.kt new file mode 100644 index 0000000000..af736d01e5 --- /dev/null +++ b/app/src/main/java/io/github/sds100/keymapper/actions/ActionsHiltModule.kt @@ -0,0 +1,13 @@ +package io.github.sds100.keymapper.actions + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ViewModelComponent + +@Module +@InstallIn(ViewModelComponent::class) +abstract class ActionsHiltModule { + @Binds + abstract fun provideTestActionUseCase(impl: TestActionUseCaseImpl): TestActionUseCase +} diff --git a/app/src/main/java/io/github/sds100/keymapper/actions/TestActionUseCase.kt b/app/src/main/java/io/github/sds100/keymapper/actions/TestActionUseCase.kt index 6d4dd00ca1..c7256df91d 100644 --- a/app/src/main/java/io/github/sds100/keymapper/actions/TestActionUseCase.kt +++ b/app/src/main/java/io/github/sds100/keymapper/actions/TestActionUseCase.kt @@ -3,12 +3,13 @@ package io.github.sds100.keymapper.actions import io.github.sds100.keymapper.system.accessibility.ServiceAdapter import io.github.sds100.keymapper.util.Result import io.github.sds100.keymapper.util.ServiceEvent +import javax.inject.Inject /** * Created by sds100 on 20/02/2021. */ -class TestActionUseCaseImpl( +class TestActionUseCaseImpl @Inject constructor( private val serviceAdapter: ServiceAdapter, ) : TestActionUseCase { override suspend fun invoke(action: ActionData): Result<*> = diff --git a/app/src/main/java/io/github/sds100/keymapper/data/DataHiltModule.kt b/app/src/main/java/io/github/sds100/keymapper/data/DataHiltModule.kt new file mode 100644 index 0000000000..e48751bac1 --- /dev/null +++ b/app/src/main/java/io/github/sds100/keymapper/data/DataHiltModule.kt @@ -0,0 +1,41 @@ +package io.github.sds100.keymapper.data + +import android.content.Context +import androidx.datastore.preferences.preferencesDataStore +import androidx.room.Room +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import io.github.sds100.keymapper.data.db.AppDatabase +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object DataHiltModule { + private val Context.legacyFingerprintMapDataStore by preferencesDataStore("fingerprint_gestures") + + @Singleton + @Provides + fun provideAppDatabase(@ApplicationContext ctx: Context): AppDatabase { + return Room.databaseBuilder( + ctx, + AppDatabase::class.java, + AppDatabase.DATABASE_NAME, + ).addMigrations( + AppDatabase.MIGRATION_1_2, + AppDatabase.MIGRATION_2_3, + AppDatabase.MIGRATION_3_4, + AppDatabase.MIGRATION_4_5, + AppDatabase.MIGRATION_5_6, + AppDatabase.MIGRATION_6_7, + AppDatabase.MIGRATION_7_8, + AppDatabase.MIGRATION_8_9, + AppDatabase.MIGRATION_9_10, + AppDatabase.MIGRATION_10_11, + AppDatabase.RoomMigration11To12(ctx.legacyFingerprintMapDataStore), + AppDatabase.MIGRATION_12_13, + ).build() + } +} diff --git a/app/src/main/java/io/github/sds100/keymapper/data/repositories/RoomKeyMapRepository.kt b/app/src/main/java/io/github/sds100/keymapper/data/repositories/RoomKeyMapRepository.kt index 697a5c2594..ebb56d1e6e 100644 --- a/app/src/main/java/io/github/sds100/keymapper/data/repositories/RoomKeyMapRepository.kt +++ b/app/src/main/java/io/github/sds100/keymapper/data/repositories/RoomKeyMapRepository.kt @@ -15,11 +15,14 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import java.util.UUID +import javax.inject.Inject +import javax.inject.Singleton /** * Created by sds100 on 18/03/2021. */ -class RoomKeyMapRepository( +@Singleton +class RoomKeyMapRepository @Inject constructor( private val dao: KeyMapDao, private val coroutineScope: CoroutineScope, private val dispatchers: DispatcherProvider = DefaultDispatcherProvider(), diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/MappingsHiltModule.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/MappingsHiltModule.kt new file mode 100644 index 0000000000..120ff6c925 --- /dev/null +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/MappingsHiltModule.kt @@ -0,0 +1,41 @@ +package io.github.sds100.keymapper.mappings + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ViewModelComponent +import io.github.sds100.keymapper.mappings.fingerprintmaps.AreFingerprintGesturesSupportedUseCase +import io.github.sds100.keymapper.mappings.fingerprintmaps.AreFingerprintGesturesSupportedUseCaseImpl +import io.github.sds100.keymapper.mappings.fingerprintmaps.DetectFingerprintMapsUseCase +import io.github.sds100.keymapper.mappings.fingerprintmaps.DetectFingerprintMapsUseCaseImpl +import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCase +import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCaseImpl +import io.github.sds100.keymapper.mappings.keymaps.CreateKeyMapShortcutUseCase +import io.github.sds100.keymapper.mappings.keymaps.CreateKeyMapShortcutUseCaseImpl +import io.github.sds100.keymapper.mappings.keymaps.DisplayKeyMapUseCase +import io.github.sds100.keymapper.mappings.keymaps.DisplayKeyMapUseCaseImpl + +@Module +@InstallIn(ViewModelComponent::class) +abstract class MappingsHiltModule { + @Binds + abstract fun provideConfigKeyMapUseCase(impl: ConfigKeyMapUseCaseImpl): ConfigKeyMapUseCase + + @Binds + abstract fun provideDisplaySimpleMappingUseCase(impl: DisplaySimpleMappingUseCaseImpl): DisplaySimpleMappingUseCase + + @Binds + abstract fun providePauseMappingsUseCase(impl: PauseMappingsUseCaseImpl): PauseMappingsUseCase + + @Binds + abstract fun provideDetectFingerprintMapsUseCase(impl: DetectFingerprintMapsUseCaseImpl): DetectFingerprintMapsUseCase + + @Binds + abstract fun provideAreFingerprintGesturesSupportedUseCase(impl: AreFingerprintGesturesSupportedUseCaseImpl): AreFingerprintGesturesSupportedUseCase + + @Binds + abstract fun provideCreateKeyMapShortcutUseCase(impl: CreateKeyMapShortcutUseCaseImpl): CreateKeyMapShortcutUseCase + + @Binds + abstract fun provideDisplayKeyMapUseCase(impl: DisplayKeyMapUseCaseImpl): DisplayKeyMapUseCase +} diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapFragment.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapFragment.kt index af4caac18c..3932dd455d 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapFragment.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapFragment.kt @@ -3,10 +3,10 @@ package io.github.sds100.keymapper.mappings.keymaps import android.os.Bundle import android.view.View import androidx.fragment.app.setFragmentResultListener +import androidx.hilt.navigation.fragment.hiltNavGraphViewModels import androidx.lifecycle.Lifecycle import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs -import androidx.navigation.navGraphViewModels import io.github.sds100.keymapper.NavAppDirections import io.github.sds100.keymapper.R import io.github.sds100.keymapper.constraints.ChooseConstraintFragment @@ -17,7 +17,6 @@ import io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerOptionsF import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerFragment import io.github.sds100.keymapper.ui.utils.getJsonSerializable import io.github.sds100.keymapper.util.FragmentInfo -import io.github.sds100.keymapper.util.Inject import io.github.sds100.keymapper.util.int import io.github.sds100.keymapper.util.intArray import io.github.sds100.keymapper.util.launchRepeatOnLifecycle @@ -34,9 +33,7 @@ class ConfigKeyMapFragment : ConfigMappingFragment() { private val args by navArgs() - override val viewModel: ConfigKeyMapViewModel by navGraphViewModels(R.id.nav_config_keymap) { - Inject.configKeyMapViewModel(requireContext()) - } + override val viewModel: ConfigKeyMapViewModel by hiltNavGraphViewModels(R.id.nav_config_keymap) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt index 9a0a953c4c..6bbb96c2f4 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt @@ -27,11 +27,12 @@ import io.github.sds100.keymapper.util.ifIsData import io.github.sds100.keymapper.util.moveElement import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map +import javax.inject.Inject /** * Created by sds100 on 16/02/2021. */ -class ConfigKeyMapUseCaseImpl( +class ConfigKeyMapUseCaseImpl @Inject constructor( private val keyMapRepository: KeyMapRepository, private val devicesAdapter: DevicesAdapter, private val preferenceRepository: PreferenceRepository, diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt index f50029da10..a2f926da80 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt @@ -4,6 +4,7 @@ import android.os.Bundle import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope +import dagger.hilt.android.lifecycle.HiltViewModel import io.github.sds100.keymapper.actions.ConfigActionsViewModel import io.github.sds100.keymapper.actions.CreateActionUseCase import io.github.sds100.keymapper.actions.TestActionUseCase @@ -24,12 +25,14 @@ import io.github.sds100.keymapper.util.ui.ResourceProvider import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch +import javax.inject.Inject /** * Created by sds100 on 22/11/20. */ -class ConfigKeyMapViewModel( +@HiltViewModel +class ConfigKeyMapViewModel @Inject constructor( private val config: ConfigKeyMapUseCase, private val testAction: TestActionUseCase, private val onboarding: OnboardingUseCase, diff --git a/app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingHiltModule.kt b/app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingHiltModule.kt new file mode 100644 index 0000000000..cc52bc9d2f --- /dev/null +++ b/app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingHiltModule.kt @@ -0,0 +1,13 @@ +package io.github.sds100.keymapper.onboarding + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ViewModelComponent + +@Module +@InstallIn(ViewModelComponent::class) +abstract class OnboardingHiltModule { + @Binds + abstract fun provideOnboardingUseCase(impl: OnboardingUseCaseImpl): OnboardingUseCase +} diff --git a/app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingUseCase.kt b/app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingUseCase.kt index 8e69bfc3aa..a1ff0bae57 100644 --- a/app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingUseCase.kt +++ b/app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingUseCase.kt @@ -21,11 +21,12 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map +import javax.inject.Inject /** * Created by sds100 on 14/02/21. */ -class OnboardingUseCaseImpl( +class OnboardingUseCaseImpl @Inject constructor( private val preferenceRepository: PreferenceRepository, private val fileAdapter: FileAdapter, private val leanbackAdapter: LeanbackAdapter, @@ -74,7 +75,7 @@ class OnboardingUseCaseImpl( ) override val showWhatsNew = get(Keys.lastInstalledVersionCodeHomeScreen) - .map { it ?: -1 < Constants.VERSION_CODE } + .map { (it ?: -1) < Constants.VERSION_CODE } override fun showedWhatsNew() { set(Keys.lastInstalledVersionCodeHomeScreen, Constants.VERSION_CODE) diff --git a/app/src/main/java/io/github/sds100/keymapper/system/SystemHiltModule.kt b/app/src/main/java/io/github/sds100/keymapper/system/SystemHiltModule.kt new file mode 100644 index 0000000000..ba0dcc2c99 --- /dev/null +++ b/app/src/main/java/io/github/sds100/keymapper/system/SystemHiltModule.kt @@ -0,0 +1,164 @@ +package io.github.sds100.keymapper.system + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import io.github.sds100.keymapper.system.accessibility.ServiceAdapter +import io.github.sds100.keymapper.system.airplanemode.AirplaneModeAdapter +import io.github.sds100.keymapper.system.airplanemode.AndroidAirplaneModeAdapter +import io.github.sds100.keymapper.system.apps.AndroidAppShortcutAdapter +import io.github.sds100.keymapper.system.apps.AndroidPackageManagerAdapter +import io.github.sds100.keymapper.system.apps.AppShortcutAdapter +import io.github.sds100.keymapper.system.apps.PackageManagerAdapter +import io.github.sds100.keymapper.system.bluetooth.AndroidBluetoothAdapter +import io.github.sds100.keymapper.system.bluetooth.BluetoothAdapter +import io.github.sds100.keymapper.system.camera.AndroidCameraAdapter +import io.github.sds100.keymapper.system.camera.CameraAdapter +import io.github.sds100.keymapper.system.clipboard.AndroidClipboardAdapter +import io.github.sds100.keymapper.system.clipboard.ClipboardAdapter +import io.github.sds100.keymapper.system.devices.AndroidDevicesAdapter +import io.github.sds100.keymapper.system.devices.DevicesAdapter +import io.github.sds100.keymapper.system.display.AndroidDisplayAdapter +import io.github.sds100.keymapper.system.display.DisplayAdapter +import io.github.sds100.keymapper.system.files.AndroidFileAdapter +import io.github.sds100.keymapper.system.files.FileAdapter +import io.github.sds100.keymapper.system.inputmethod.AndroidInputMethodAdapter +import io.github.sds100.keymapper.system.inputmethod.InputMethodAdapter +import io.github.sds100.keymapper.system.intents.IntentAdapter +import io.github.sds100.keymapper.system.intents.IntentAdapterImpl +import io.github.sds100.keymapper.system.leanback.LeanbackAdapter +import io.github.sds100.keymapper.system.leanback.LeanbackAdapterImpl +import io.github.sds100.keymapper.system.lock.AndroidLockScreenAdapter +import io.github.sds100.keymapper.system.lock.LockScreenAdapter +import io.github.sds100.keymapper.system.media.AndroidMediaAdapter +import io.github.sds100.keymapper.system.media.MediaAdapter +import io.github.sds100.keymapper.system.network.AndroidNetworkAdapter +import io.github.sds100.keymapper.system.network.NetworkAdapter +import io.github.sds100.keymapper.system.nfc.AndroidNfcAdapter +import io.github.sds100.keymapper.system.nfc.NfcAdapter +import io.github.sds100.keymapper.system.notifications.AndroidNotificationAdapter +import io.github.sds100.keymapper.system.notifications.NotificationAdapter +import io.github.sds100.keymapper.system.notifications.NotificationReceiverServiceAdapter +import io.github.sds100.keymapper.system.permissions.AndroidPermissionAdapter +import io.github.sds100.keymapper.system.permissions.PermissionAdapter +import io.github.sds100.keymapper.system.phone.AndroidPhoneAdapter +import io.github.sds100.keymapper.system.phone.PhoneAdapter +import io.github.sds100.keymapper.system.power.AndroidPowerAdapter +import io.github.sds100.keymapper.system.power.PowerAdapter +import io.github.sds100.keymapper.system.root.SuAdapter +import io.github.sds100.keymapper.system.root.SuAdapterImpl +import io.github.sds100.keymapper.system.url.AndroidOpenUrlAdapter +import io.github.sds100.keymapper.system.url.OpenUrlAdapter +import javax.inject.Qualifier +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +abstract class SystemHiltModule { + @Singleton + @Binds + abstract fun providePackageManagerAdapter(impl: AndroidPackageManagerAdapter): PackageManagerAdapter + + @Singleton + @Binds + abstract fun provideAirplaneModeAdapter(impl: AndroidAirplaneModeAdapter): AirplaneModeAdapter + + @Singleton + @Binds + abstract fun provideAppShortcutAdapter(impl: AndroidAppShortcutAdapter): AppShortcutAdapter + + @Singleton + @Binds + abstract fun provideBluetoothAdapter(impl: AndroidBluetoothAdapter): BluetoothAdapter + + @Singleton + @Binds + abstract fun provideCameraAdapter(impl: AndroidCameraAdapter): CameraAdapter + + @Singleton + @Binds + abstract fun provideClipboardAdapter(impl: AndroidClipboardAdapter): ClipboardAdapter + + @Singleton + @Binds + abstract fun provideDevicesAdapter(impl: AndroidDevicesAdapter): DevicesAdapter + + @Singleton + @Binds + abstract fun provideDisplayAdapter(impl: AndroidDisplayAdapter): DisplayAdapter + + @Singleton + @Binds + abstract fun provideInputMethodAdapter(impl: AndroidInputMethodAdapter): InputMethodAdapter + + @Singleton + @Binds + abstract fun provideIntentAdapter(impl: IntentAdapterImpl): IntentAdapter + + @Singleton + @Binds + abstract fun provideLeanbackAdapter(impl: LeanbackAdapterImpl): LeanbackAdapter + + @Singleton + @Binds + abstract fun provideLockScreenAdapter(impl: AndroidLockScreenAdapter): LockScreenAdapter + + @Singleton + @Binds + abstract fun provideMediaAdapter(impl: AndroidMediaAdapter): MediaAdapter + + @Singleton + @Binds + abstract fun provideNetworkAdapter(impl: AndroidNetworkAdapter): NetworkAdapter + + @Singleton + @Binds + abstract fun provideNfcAdapter(impl: AndroidNfcAdapter): NfcAdapter + + @Singleton + @Binds + abstract fun provideNotificationAdapter(impl: AndroidNotificationAdapter): NotificationAdapter + + @Singleton + @Binds + @NotificationReceiverServiceAdapterAnnotation + abstract fun provideNotificationReceiverAdapter(impl: NotificationReceiverServiceAdapter): ServiceAdapter + + @Singleton + @Binds + abstract fun providePermissionAdapter(impl: AndroidPermissionAdapter): PermissionAdapter + + @Singleton + @Binds + abstract fun provideFileAdapter(impl: AndroidFileAdapter): FileAdapter + + @Singleton + @Binds + abstract fun providePhoneAdapter(impl: AndroidPhoneAdapter): PhoneAdapter + + @Singleton + @Binds + abstract fun providePowerAdapter(impl: AndroidPowerAdapter): PowerAdapter + + @Singleton + @Binds + abstract fun provideSuAdapter(impl: SuAdapterImpl): SuAdapter + + @Singleton + @Binds + abstract fun provideUrlAdapter(impl: AndroidOpenUrlAdapter): OpenUrlAdapter + + @Singleton + @Binds + @AccessibilityServiceAdapter + abstract fun provideAccessibilityServiceAdapter(impl: AccessibilityServiceAdapter): AccessibilityServiceAdapter +} + +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class NotificationReceiverServiceAdapterAnnotation + +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class AccessibilityServiceAdapter diff --git a/app/src/main/java/io/github/sds100/keymapper/system/apps/AndroidPackageManagerAdapter.kt b/app/src/main/java/io/github/sds100/keymapper/system/apps/AndroidPackageManagerAdapter.kt index 2a5870eede..290c5e8f13 100644 --- a/app/src/main/java/io/github/sds100/keymapper/system/apps/AndroidPackageManagerAdapter.kt +++ b/app/src/main/java/io/github/sds100/keymapper/system/apps/AndroidPackageManagerAdapter.kt @@ -18,6 +18,7 @@ import android.os.TransactionTooLargeException import android.provider.MediaStore import android.provider.Settings import androidx.core.content.ContextCompat +import dagger.hilt.android.qualifiers.ApplicationContext import io.github.sds100.keymapper.util.Error import io.github.sds100.keymapper.util.Result import io.github.sds100.keymapper.util.State @@ -31,12 +32,13 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import splitties.bitflags.withFlag +import javax.inject.Inject /** * Created by sds100 on 16/03/2021. */ -class AndroidPackageManagerAdapter( - context: Context, +class AndroidPackageManagerAdapter @Inject constructor( + @ApplicationContext context: Context, coroutineScope: CoroutineScope, ) : PackageManagerAdapter { private val ctx: Context = context.applicationContext diff --git a/app/src/main/java/io/github/sds100/keymapper/system/devices/AndroidDevicesAdapter.kt b/app/src/main/java/io/github/sds100/keymapper/system/devices/AndroidDevicesAdapter.kt index 60df1c611e..c5cbe103b4 100644 --- a/app/src/main/java/io/github/sds100/keymapper/system/devices/AndroidDevicesAdapter.kt +++ b/app/src/main/java/io/github/sds100/keymapper/system/devices/AndroidDevicesAdapter.kt @@ -7,6 +7,7 @@ import android.hardware.input.InputManager import android.os.Handler import android.view.InputDevice import androidx.core.content.getSystemService +import dagger.hilt.android.qualifiers.ApplicationContext import io.github.sds100.keymapper.system.bluetooth.BluetoothDeviceInfo import io.github.sds100.keymapper.system.permissions.Permission import io.github.sds100.keymapper.system.permissions.PermissionAdapter @@ -24,12 +25,13 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import splitties.mainthread.mainLooper +import javax.inject.Inject /** * Created by sds100 on 13/03/2021. */ -class AndroidDevicesAdapter( - context: Context, +class AndroidDevicesAdapter @Inject constructor( + @ApplicationContext context: Context, private val bluetoothAdapter: io.github.sds100.keymapper.system.bluetooth.BluetoothAdapter, private val permissionAdapter: PermissionAdapter, private val coroutineScope: CoroutineScope, diff --git a/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiver.kt b/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverService.kt similarity index 95% rename from app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiver.kt rename to app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverService.kt index a64b1df640..f07cc3b447 100644 --- a/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiver.kt +++ b/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverService.kt @@ -19,7 +19,7 @@ import timber.log.Timber /** * Created by sds100 on 14/11/20. */ -class NotificationReceiver : +class NotificationReceiverService : NotificationListenerService(), LifecycleOwner { private val mediaSessionManager: MediaSessionManager by lazy { getSystemService()!! } @@ -27,7 +27,7 @@ class NotificationReceiver : private val notificationListenerComponent by lazy { ComponentName( this, - NotificationReceiver::class.java, + NotificationReceiverService::class.java, ) } @@ -40,7 +40,7 @@ class NotificationReceiver : private var lastNotificationKey: String? = null - private val serviceAdapter: NotificationReceiverAdapter by lazy { + private val serviceAdapter: NotificationReceiverServiceAdapter by lazy { ServiceLocator.notificationReceiverAdapter(this) } diff --git a/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverAdapter.kt b/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverServiceAdapter.kt similarity index 98% rename from app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverAdapter.kt rename to app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverServiceAdapter.kt index b4bfd7887b..19880841cf 100644 --- a/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverAdapter.kt +++ b/app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationReceiverServiceAdapter.kt @@ -29,7 +29,7 @@ import splitties.bitflags.withFlag * Created by sds100 on 27/07/2021. */ -class NotificationReceiverAdapter( +class NotificationReceiverServiceAdapter( context: Context, private val coroutineScope: CoroutineScope, ) : ServiceAdapter {