Skip to content

Commit

Permalink
[SHARED] Add base for licenses parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kamgurgul committed Jan 21, 2025
1 parent 94adebd commit 35018cd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.kgurgul.cpuinfo.features.information.sensors.SensorsInfoViewModel
import com.kgurgul.cpuinfo.features.information.storage.StorageInfoViewModel
import com.kgurgul.cpuinfo.features.processes.ProcessesViewModel
import com.kgurgul.cpuinfo.features.settings.SettingsViewModel
import com.kgurgul.cpuinfo.features.settings.licenses.LicensesViewModel
import com.kgurgul.cpuinfo.features.temperature.TemperatureViewModel
import org.koin.core.module.dsl.viewModelOf
import org.koin.dsl.module
Expand All @@ -32,4 +33,5 @@ val viewModelModule = module {
viewModelOf(::SettingsViewModel)
viewModelOf(::StorageInfoViewModel)
viewModelOf(::TemperatureViewModel)
viewModelOf(::LicensesViewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.kgurgul.cpuinfo.domain.observable.SensorsDataObservable
import com.kgurgul.cpuinfo.domain.observable.StorageDataObservable
import com.kgurgul.cpuinfo.domain.observable.TemperatureDataObservable
import com.kgurgul.cpuinfo.domain.result.GetHardwareDataInteractor
import com.kgurgul.cpuinfo.domain.result.GetLicensesInteractor
import com.kgurgul.cpuinfo.domain.result.GetPackageNameInteractor
import com.kgurgul.cpuinfo.domain.result.GetScreenDataInteractor
import org.koin.core.module.dsl.factoryOf
Expand All @@ -34,4 +35,5 @@ val domainModule = module {
factoryOf(::GetOsDataInteractor)
factoryOf(::GetPackageNameInteractor)
factoryOf(::GetScreenDataInteractor)
factoryOf(::GetLicensesInteractor)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kgurgul.cpuinfo.domain.model

data class License(
val moduleName: String,
val moduleVersion: String,
val license: String,
val licenseUrl: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.kgurgul.cpuinfo.domain.result

import com.kgurgul.cpuinfo.domain.ResultInteractor
import com.kgurgul.cpuinfo.domain.model.License
import com.kgurgul.cpuinfo.utils.IDispatchersProvider
import kotlinx.coroutines.CoroutineDispatcher

class GetLicensesInteractor(
private val dispatchersProvider: IDispatchersProvider,
) : ResultInteractor<Unit, Result<List<License>>>() {

override val dispatcher: CoroutineDispatcher
get() = dispatchersProvider.io

override suspend fun doWork(params: Unit): Result<List<License>> {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.kgurgul.cpuinfo.shared.Res
import com.kgurgul.cpuinfo.shared.licenses
import com.kgurgul.cpuinfo.ui.components.PrimaryTopAppBar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
package com.kgurgul.cpuinfo.features.settings.licenses

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.kgurgul.cpuinfo.domain.model.License
import com.kgurgul.cpuinfo.domain.result.GetLicensesInteractor
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.stateIn

class LicensesViewModel : ViewModel() {

class LicensesViewModel(
getLicensesInteractor: GetLicensesInteractor,
) : ViewModel() {

val uiState = flow {
emit(UiState(isLoading = true))
getLicensesInteractor(Unit)
.onSuccess {
emit(UiState(isLoading = false, licenses = it.toImmutableList()))
}
.onFailure {
emit(UiState(isLoading = false, isError = true))
}
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), UiState())

data class UiState(
val isLoading: Boolean = false,
val isError: Boolean = false,
val licenses: ImmutableList<License> = persistentListOf(),
)
}

0 comments on commit 35018cd

Please sign in to comment.