diff --git a/app/src/main/java/ru/ulstu/is/pmu/api/ApiStatus.kt b/app/src/main/java/ru/ulstu/is/pmu/api/ApiStatus.kt new file mode 100644 index 0000000..127e66f --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/api/ApiStatus.kt @@ -0,0 +1,4 @@ +package ru.ulstu.is.pmu.api + +class ApiStatus { +} \ No newline at end of file diff --git a/app/src/main/java/ru/ulstu/is/pmu/api/report/ReportRemote.kt b/app/src/main/java/ru/ulstu/is/pmu/api/report/ReportRemote.kt new file mode 100644 index 0000000..2480719 --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/api/report/ReportRemote.kt @@ -0,0 +1,4 @@ +package ru.ulstu.is.pmu.api.report + +class ReportRemote { +} \ No newline at end of file diff --git a/app/src/main/java/ru/ulstu/is/pmu/common/MyViewModel.kt b/app/src/main/java/ru/ulstu/is/pmu/common/MyViewModel.kt new file mode 100644 index 0000000..6ee43f0 --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/common/MyViewModel.kt @@ -0,0 +1,48 @@ +package ru.ulstu.`is`.pmu.common + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.launch +import retrofit2.HttpException +import ru.ulstu.`is`.pmu.api.ApiStatus +import java.io.IOException + +open class MyViewModel : ViewModel() { + var apiStatus by mutableStateOf(ApiStatus.DONE) + private set + + var apiError by mutableStateOf("") + private set + + fun runInScope( + actionSuccess: suspend () -> Unit, + actionError: suspend () -> Unit + ) { + viewModelScope.launch { + apiStatus = ApiStatus.LOADING + runCatching { + actionSuccess() + apiStatus = ApiStatus.DONE + apiError = "" + }.onFailure { e: Throwable -> + when (e) { + is IOException, + is HttpException -> { + actionError() + apiStatus = ApiStatus.ERROR + apiError = e.localizedMessage ?: e.toString() + } + + else -> throw e + } + } + } + } + + fun runInScope(actionSuccess: suspend () -> Unit) { + runInScope(actionSuccess, actionError = {}) + } +} diff --git a/app/src/main/java/ru/ulstu/is/pmu/ui/NetworkUi.kt b/app/src/main/java/ru/ulstu/is/pmu/ui/NetworkUi.kt new file mode 100644 index 0000000..3e82af7 --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/ui/NetworkUi.kt @@ -0,0 +1,96 @@ +package ru.ulstu.`is`.pmu.ui + +import android.content.res.Configuration +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.TextUnit +import androidx.compose.ui.unit.TextUnitType +import androidx.compose.ui.unit.dp +import ru.ulstu.`is`.pmu.R +import ru.ulstu.`is`.pmu.ui.theme.PmudemoTheme + + +@Composable +fun ErrorPlaceholder(message: String, onBack: () -> Unit) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(10.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Text( + modifier = Modifier.fillMaxWidth(), + textAlign = TextAlign.Center, + fontSize = TextUnit(value = 20F, type = TextUnitType.Sp), + text = message, + color = Color(0xFFFF1744) + ) + Spacer(modifier = Modifier.padding(bottom = 10.dp)) + Button( + modifier = Modifier.fillMaxWidth(), + onClick = { onBack() } + ) { + Text(stringResource(id = R.string.back)) + } + } +} + +@Composable +fun LoadingPlaceholder() { + Column( + modifier = Modifier + .fillMaxSize() + .padding(10.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Text( + modifier = Modifier.fillMaxWidth(), + textAlign = TextAlign.Center, + fontSize = TextUnit(value = 25F, type = TextUnitType.Sp), + text = stringResource(id = R.string.loading) + ) + } +} + +@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) +@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +fun ErrorPlaceholderPreview() { + PmudemoTheme { + Surface( + color = MaterialTheme.colorScheme.background + ) { + ErrorPlaceholder("Error", onBack = {}) + } + } +} + +@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) +@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +fun LoadingPlaceholderPreview() { + PmudemoTheme { + Surface( + color = MaterialTheme.colorScheme.background + ) { + LoadingPlaceholder() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/ulstu/is/pmu/ui/ReportPage.kt b/app/src/main/java/ru/ulstu/is/pmu/ui/ReportPage.kt new file mode 100644 index 0000000..445bd32 --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/ui/ReportPage.kt @@ -0,0 +1,4 @@ +package ru.ulstu.is.pmu.ui + +class ReportPage { +} \ No newline at end of file diff --git a/app/src/main/java/ru/ulstu/is/pmu/ui/ReportViewModel.kt b/app/src/main/java/ru/ulstu/is/pmu/ui/ReportViewModel.kt new file mode 100644 index 0000000..9d8da7a --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/ui/ReportViewModel.kt @@ -0,0 +1,61 @@ +package ru.ulstu.`is`.pmu.ui + + +import android.util.Log +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.launch +import ru.ulstu.`is`.pmu.api.model.TaskRemote +import ru.ulstu.`is`.pmu.api.report.ReportRemote +import ru.ulstu.`is`.pmu.api.task.RestTaskRepository +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +class ReportViewModel(private val taskRepository: RestTaskRepository): ViewModel() { + var reportPageUiState by mutableStateOf(ReportPageUiState()) + private set + + var reportResultPageUiState by mutableStateOf(ReportResultPageUiState()) + private set + + fun onUpdate(reportDetails: ReportDetails) { + reportPageUiState = ReportPageUiState(reportDetails = reportDetails, isEntryValid = validateInput(reportDetails)) + } + + private fun validateInput(uiState: ReportDetails = reportPageUiState.reportDetails): Boolean { + Log.d("validateInput", uiState.endDate.toString()) + return with(uiState) { + startDate != Date(0) && endDate != Date(0) && startDate < endDate + } + } + + suspend fun getReport() { + val dateFormatter = SimpleDateFormat("dd.MM.yyyy", Locale.getDefault()) // Задаем желаемый формат даты + + // Преобразование даты в строку в формате "dd.mm.yyyy" + val startDateQueryParam = dateFormatter.format(reportPageUiState.reportDetails.startDate) + val endDateQueryParam = dateFormatter.format(reportPageUiState.reportDetails.endDate) + + // Вызов репозитория с отформатированными датами + val res = taskRepository.getReport(startDateQueryParam, endDateQueryParam) + reportResultPageUiState = ReportResultPageUiState(res) + } +} + +data class ReportDetails( + val startDate: Date = Date(0), + val endDate: Date = Date(0) +) + +data class ReportPageUiState( + val reportDetails: ReportDetails = ReportDetails(), + val isEntryValid: Boolean = false +) + +data class ReportResultPageUiState( + var resReport: List = emptyList() +) \ No newline at end of file diff --git a/app/src/main/java/ru/ulstu/is/pmu/ui/student/list/FavoriteTaskList.kt b/app/src/main/java/ru/ulstu/is/pmu/ui/student/list/FavoriteTaskList.kt new file mode 100644 index 0000000..f4543ce --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/ui/student/list/FavoriteTaskList.kt @@ -0,0 +1,4 @@ +package ru.ulstu.is.pmu.ui.student.list + +class FavoriteTaskList { +} \ No newline at end of file diff --git a/app/src/main/java/ru/ulstu/is/pmu/ui/student/list/FavoriteTaskListViewModel.kt b/app/src/main/java/ru/ulstu/is/pmu/ui/student/list/FavoriteTaskListViewModel.kt new file mode 100644 index 0000000..41a2d2e --- /dev/null +++ b/app/src/main/java/ru/ulstu/is/pmu/ui/student/list/FavoriteTaskListViewModel.kt @@ -0,0 +1,4 @@ +package ru.ulstu.is.pmu.ui.student.list + +class FavoriteTaskListViewModel { +} \ No newline at end of file