-
Notifications
You must be signed in to change notification settings - Fork 4
Migrate to Android Gradle Plugin 9 and upgrade packages #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
d651b81
5b31d3b
a1994b7
e878488
f272e67
ac7655a
d674b4b
8647019
a834699
7dfb902
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| package com.rickyhu.hushkeyboard | ||
|
|
||
| import android.app.Application | ||
| import dagger.hilt.android.HiltAndroidApp | ||
| import com.rickyhu.hushkeyboard.di.appModule | ||
| import org.koin.android.ext.koin.androidContext | ||
| import org.koin.core.context.GlobalContext | ||
| import org.koin.core.context.startKoin | ||
| import org.koin.core.context.stopKoin | ||
|
|
||
| @HiltAndroidApp | ||
| class HushApplication : Application() | ||
| class HushApplication : Application() { | ||
| override fun onCreate() { | ||
| super.onCreate() | ||
| if (GlobalContext.getOrNull() != null) stopKoin() | ||
ricky9667 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| startKoin { | ||
| androidContext(this@HushApplication) | ||
| modules(appModule) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.rickyhu.hushkeyboard.di | ||
|
|
||
| import com.rickyhu.hushkeyboard.data.SettingsRepository | ||
| import com.rickyhu.hushkeyboard.keyboard.KeyboardViewModel | ||
| import com.rickyhu.hushkeyboard.main.MainViewModel | ||
| import com.rickyhu.hushkeyboard.settings.SettingsViewModel | ||
| import org.koin.android.ext.koin.androidContext | ||
| import org.koin.core.module.dsl.viewModel | ||
| import org.koin.dsl.module | ||
|
|
||
| val appModule = | ||
| module { | ||
| single { SettingsRepository(androidContext()) } | ||
| viewModel { MainViewModel(get()) } | ||
| viewModel { SettingsViewModel(get()) } | ||
| viewModel { KeyboardViewModel(get()) } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.rickyhu.hushkeyboard.keyboard | ||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.ViewModelProvider | ||
| import com.rickyhu.hushkeyboard.data.SettingsRepository | ||
|
|
||
| class KeyboardViewModelFactory( | ||
| private val settingsRepository: SettingsRepository, | ||
| ) : ViewModelProvider.Factory { | ||
| override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
| if (modelClass.isAssignableFrom(KeyboardViewModel::class.java)) { | ||
| @Suppress("UNCHECKED_CAST") | ||
| return KeyboardViewModel(settingsRepository) as T | ||
| } | ||
| throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,34 @@ | ||
| package com.rickyhu.hushkeyboard.service | ||
|
|
||
| import android.view.View | ||
| import androidx.lifecycle.ViewModelProvider | ||
| import androidx.lifecycle.ViewModelStore | ||
| import androidx.lifecycle.ViewModelStoreOwner | ||
| import androidx.lifecycle.setViewTreeLifecycleOwner | ||
| import androidx.savedstate.SavedStateRegistryController | ||
| import androidx.savedstate.SavedStateRegistryOwner | ||
| import androidx.savedstate.setViewTreeSavedStateRegistryOwner | ||
| import com.rickyhu.hushkeyboard.data.SettingsRepository | ||
| import com.rickyhu.hushkeyboard.keyboard.HushKeyboardView | ||
| import com.rickyhu.hushkeyboard.keyboard.KeyboardViewModel | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
| import javax.inject.Inject | ||
| import com.rickyhu.hushkeyboard.keyboard.KeyboardViewModelFactory | ||
| import org.koin.android.ext.android.inject | ||
|
|
||
| @AndroidEntryPoint | ||
| class HushIMEService : | ||
| LifecycleInputMethodService(), | ||
| SavedStateRegistryOwner { | ||
| @Inject | ||
| SavedStateRegistryOwner, | ||
| ViewModelStoreOwner { | ||
| private val settingsRepository: SettingsRepository by inject() | ||
| lateinit var viewModel: KeyboardViewModel | ||
|
|
||
| private val savedStateRegistryController = SavedStateRegistryController.create(this) | ||
| override val savedStateRegistry = savedStateRegistryController.savedStateRegistry | ||
|
|
||
| override val lifecycle = dispatcher.lifecycle | ||
|
|
||
| private val _viewModelStore = ViewModelStore() | ||
| override val viewModelStore: ViewModelStore get() = _viewModelStore | ||
|
|
||
| override fun onCreateInputView(): View { | ||
| val view = HushKeyboardView(this) | ||
| window.window?.decorView.let { decorView -> | ||
|
|
@@ -34,5 +41,15 @@ class HushIMEService : | |
| override fun onCreate() { | ||
| super.onCreate() | ||
| savedStateRegistryController.performRestore(null) | ||
| viewModel = | ||
| ViewModelProvider( | ||
| owner = this, | ||
| factory = KeyboardViewModelFactory(settingsRepository), | ||
| )[KeyboardViewModel::class.java] | ||
|
||
| } | ||
|
|
||
| override fun onDestroy() { | ||
| super.onDestroy() | ||
| _viewModelStore.clear() | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Java version has been downgraded from 21 to 17. While this increases compatibility, please ensure this change is intentional and necessary. Java 21 is the latest LTS version and offers significant performance and feature improvements. If the downgrade is required for specific compatibility reasons, those reasons should be documented in the PR description or commit message.