Код: Выделить всё
error: ComponentProcessingStep was unable to process 'com.example.ingale.IngaleApplication_HiltComponents.SingletonC' because 'com.example.ingale.feature_local.main.presentation.view.LocalMainContract.State' could not be resolved.
Dependency trace:
=> element (CLASS): com.example.ingale.feature_local.main.presentation.view.LocalMainViewModel
=> type (DECLARED superclass): com.example.ingale.mvi.BaseViewModel
=> type (ERROR type argument): com.example.ingale.feature_local.main.presentation.view.LocalMainContract.State
If type 'com.example.ingale.feature_local.main.presentation.view.LocalMainContract.State' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'com.example.ingale.feature_local.main.presentation.view.LocalMainContract.State' is on your classpath.
1 error
ComponentProcessingStep was unable to process 'com.example.ingale.IngaleApplication_HiltComponents.SingletonC' because 'com.example.ingale.feature_local.main.presentation.view.LocalMainContract.State' could not be resolved.
Это класс State, который не удалось разрешить
Код: Выделить всё
interface LocalMainContract {
sealed interface Event : UiEvent {
class PermissionResult(val permission: String, val isGranted: Boolean) : Event
data object DismissPermissionDialog : Event
class AlbumClicked(val songsSet: SongsSet) : Event
class ArtistClicked(val songsSet: SongsSet) : Event
class Search(val query: String) : Event
class PlaySong(val song: Song) : Event
}
sealed interface Effect : UiEffect {
data object ScrollToTop : Effect
data object RequestPermissions : Effect
}
@Immutable
data class State(
val searchTextField: String,
val allSongs: StableList,
val albums: StableList,
val artists: StableList,
val areSongsLoading: Boolean,
val visiblePermissionDialogQueue: StableList
): UiState {
companion object {
const val SECTION_SONGS = "Songs"
const val SECTION_ALBUMS = "Albums"
const val SECTION_ARTISTS = "Artists"
}
val sections: StableList = stableListOf(SECTION_SONGS, SECTION_ALBUMS, SECTION_ARTISTS)
}
}
Это LocalMainViewModel >
Код: Выделить всё
@HiltViewModel
class LocalMainViewModel @Inject constructor(
private val getSongsUseCase: GetSongsUseCase,
private val organizeSongsUseCase: OrganizeSongsUseCase,
private val filterUseCase: FilterUseCase,
) : BaseViewModel () {...}
Код: Выделить всё
abstract class BaseViewModel : ViewModel() {
private val initialState: State by lazy { defineInitialState() }
protected abstract fun defineInitialState(): State
private val _state = MutableStateFlow(initialState)
val state = _state.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), initialState)
private val _event = MutableSharedFlow()
private val _effect = Channel()
val effect = _effect.asFlow(viewModelScope)
val currentState: State
get() = _state.value
init {
subscribeEvents()
}
fun sendEvent(event: Event) {
viewModelScope.launch {
_event.emit(event)
}
}
private fun subscribeEvents() {
viewModelScope.launch {
_event.collect {
handleEvent(it)
}
}
}
protected abstract fun handleEvent(event: Event)
protected fun sendEffect(builder: () -> Effect) {
viewModelScope.launch {
_effect.send(builder())
}
}
protected fun updateState(modify: State.() -> State) {
viewModelScope.launch {
_state.emit(currentState.modify())
}
}
}
Здесь я внедряю LocalMainViewModel:
Код: Выделить всё
NavHost(
navController = navController,
startDestination = Screens.Local.MainScreen.route
) {
composable(
route = Screens.Local.MainScreen.route,
) {
LaunchedEffect(Unit) { bottomNavigationEffects.emit(BottomNavigationEffects.ShowBottomBar) }
val vm = hiltViewModel()
LocalMainScreen(
state = vm.state.collectAsState().value,
sendEvent = vm::sendEvent,
effects = vm.effect,
requiredPermissions = vm.requiredPermissions
)
}
}
//One more composable with Koin injection yet
}
Код: Выделить всё
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.hilt.android) apply false
}
Код: Выделить всё
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.hilt.android)
}
kapt {
correctErrorTypes = true
}
android {
namespace = "com.example.ingale"
compileSdk = 34
defaultConfig {
applicationId = "com.example.ingale"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildFeatures {
compose = true
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
// signingConfig = signingConfigs.debug
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.7"
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation(libs.androidx.ktx)
implementation(platform(libs.kotlin.bom))
implementation(libs.androidx.lifecycle)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.graphics)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
implementation(libs.google.material)
implementation(libs.androidx.media3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.compose.junit)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
// Compose constraint layout
implementation(libs.androidx.compose.constraintlayout)
// Compose Navigation
implementation(libs.androidx.compose.navigation)
// Koin for Kotlin apps
implementation("io.insert-koin:koin-core:3.4.3")
implementation("io.insert-koin:koin-android:3.4.3")
implementation("io.insert-koin:koin-androidx-compose:3.4.6")
// Dagger-Hilt
implementation(libs.hilt.android)
annotationProcessor(libs.hilt.compiler)
kapt(libs.hilt.compiler)
implementation(libs.androidx.hilt.navigation.compose)
// implementation("com.google.dagger:hilt-android:2.50")
// annotationProcessor("com.google.dagger:hilt-compiler:2.50")
// kapt("com.google.dagger:hilt-compiler:2.50")
// implementation("androidx.hilt:hilt-navigation-compose:1.1.0")
// Retrofit
implementation(libs.google.gson)
implementation(libs.squareup.retrofit2)
implementation(libs.squareup.retrofit2.converter.gson)
// Media Notification
implementation(libs.androidx.media)
}
Код: Выделить всё
[versions]
hilt-version = "2.50"
// other versions
...
[libraries]
hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt-version" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt-version" }
androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version = "1.1.0" }
// other libraries
[plugins]
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin-version" }
hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt-version" }
// other plugins
Подробнее здесь: https://stackoverflow.com/questions/777 ... nents-sing
Мобильная версия