mirror of
https://github.com/openflocon/Flocon.git
synced 2026-05-02 02:30:37 +00:00
feat: [ANALYTICS] export as CSV (#250)
Co-authored-by: Florent Champigny <florent@bere.al>
This commit is contained in:
parent
4b2419ffe9
commit
7e0ec0d5dc
5 changed files with 94 additions and 5 deletions
|
|
@ -2,6 +2,7 @@ package io.github.openflocon.flocondesktop.features.analytics
|
|||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import io.github.openflocon.domain.analytics.usecase.ExportAnalyticsToCsvUseCase
|
||||
import io.github.openflocon.domain.analytics.usecase.ObserveCurrentDeviceAnalyticsContentUseCase
|
||||
import io.github.openflocon.domain.analytics.usecase.RemoveAnalyticsItemUseCase
|
||||
import io.github.openflocon.domain.analytics.usecase.RemoveAnalyticsItemsBeforeUseCase
|
||||
|
|
@ -11,7 +12,6 @@ import io.github.openflocon.domain.common.DispatcherProvider
|
|||
import io.github.openflocon.domain.common.combines
|
||||
import io.github.openflocon.domain.device.usecase.ObserveCurrentDeviceIdAndPackageNameUseCase
|
||||
import io.github.openflocon.domain.feedback.FeedbackDisplayer
|
||||
import io.github.openflocon.domain.network.usecase.RemoveOldSessionsNetworkRequestUseCase
|
||||
import io.github.openflocon.flocondesktop.features.analytics.delegate.AnalyticsSelectorDelegate
|
||||
import io.github.openflocon.flocondesktop.features.analytics.mapper.mapToUi
|
||||
import io.github.openflocon.flocondesktop.features.analytics.model.AnalyticsAction
|
||||
|
|
@ -40,7 +40,8 @@ class AnalyticsViewModel(
|
|||
private val removeAnalyticsItemUseCase: RemoveAnalyticsItemUseCase,
|
||||
private val removeAnalyticsItemsBeforeUseCase: RemoveAnalyticsItemsBeforeUseCase,
|
||||
private val removeOldSessionsAnalyticsUseCase: RemoveOldSessionsAnalyticsUseCase,
|
||||
) : ViewModel() {
|
||||
private val exportAnalyticsToCsv: ExportAnalyticsToCsvUseCase,
|
||||
) : ViewModel() {
|
||||
|
||||
private val _screenState = MutableStateFlow<AnalyticsScreenUiState>(
|
||||
AnalyticsScreenUiState(
|
||||
|
|
@ -120,8 +121,26 @@ class AnalyticsViewModel(
|
|||
is AnalyticsAction.ToggleAutoScroll -> _screenState.update { it.copy(autoScroll = !it.autoScroll) }
|
||||
is AnalyticsAction.InvertList -> _screenState.update { it.copy(invertList = action.value) }
|
||||
is AnalyticsAction.ClearOldSession -> removeOldSessionsAnalyticsUseCase()
|
||||
is AnalyticsAction.ExportCsv -> onExportCsv()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onExportCsv() {
|
||||
viewModelScope.launch(dispatcherProvider.viewModel) {
|
||||
exportAnalyticsToCsv().fold(
|
||||
doOnFailure = {
|
||||
feedbackDisplayer.displayMessage(
|
||||
"Error while exporting csv"
|
||||
)
|
||||
},
|
||||
doOnSuccess = { path ->
|
||||
feedbackDisplayer.displayMessage(
|
||||
"Csv exported at $path"
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,5 +18,8 @@ sealed interface AnalyticsAction {
|
|||
data object ClearOldSession : AnalyticsAction
|
||||
|
||||
data object ToggleAutoScroll : AnalyticsAction
|
||||
|
||||
data class InvertList(val value: Boolean) : AnalyticsAction
|
||||
|
||||
data object ExportCsv: AnalyticsAction
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import androidx.compose.foundation.rememberScrollState
|
|||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.List
|
||||
import androidx.compose.material.icons.outlined.CleaningServices
|
||||
import androidx.compose.material.icons.outlined.ImportExport
|
||||
import androidx.compose.material.icons.outlined.PlayCircle
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.runtime.Composable
|
||||
|
|
@ -144,13 +145,11 @@ fun AnalyticsScreen(
|
|||
},
|
||||
actions = {
|
||||
FloconOverflow {
|
||||
/* TODO
|
||||
FloconDropdownMenuItem(
|
||||
text = "Export CSV",
|
||||
leadingIcon = Icons.Outlined.ImportExport,
|
||||
onClick = { onAction(NetworkAction.ExportCsv) }
|
||||
onClick = { onAction(AnalyticsAction.ExportCsv) }
|
||||
)
|
||||
*/
|
||||
FloconDropdownMenuItem(
|
||||
checked = screenState.autoScroll,
|
||||
text = "Auto scroll",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue