first commit
This commit is contained in:
parent
90aef7e59a
commit
71f82033ec
4
app/src/main/java/ru/ulstu/is/pmu/api/ApiStatus.kt
Normal file
4
app/src/main/java/ru/ulstu/is/pmu/api/ApiStatus.kt
Normal file
@ -0,0 +1,4 @@
|
||||
package ru.ulstu.is.pmu.api
|
||||
|
||||
class ApiStatus {
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package ru.ulstu.is.pmu.api.report
|
||||
|
||||
class ReportRemote {
|
||||
}
|
48
app/src/main/java/ru/ulstu/is/pmu/common/MyViewModel.kt
Normal file
48
app/src/main/java/ru/ulstu/is/pmu/common/MyViewModel.kt
Normal file
@ -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 = {})
|
||||
}
|
||||
}
|
96
app/src/main/java/ru/ulstu/is/pmu/ui/NetworkUi.kt
Normal file
96
app/src/main/java/ru/ulstu/is/pmu/ui/NetworkUi.kt
Normal file
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
4
app/src/main/java/ru/ulstu/is/pmu/ui/ReportPage.kt
Normal file
4
app/src/main/java/ru/ulstu/is/pmu/ui/ReportPage.kt
Normal file
@ -0,0 +1,4 @@
|
||||
package ru.ulstu.is.pmu.ui
|
||||
|
||||
class ReportPage {
|
||||
}
|
61
app/src/main/java/ru/ulstu/is/pmu/ui/ReportViewModel.kt
Normal file
61
app/src/main/java/ru/ulstu/is/pmu/ui/ReportViewModel.kt
Normal file
@ -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<ReportRemote> = emptyList()
|
||||
)
|
@ -0,0 +1,4 @@
|
||||
package ru.ulstu.is.pmu.ui.student.list
|
||||
|
||||
class FavoriteTaskList {
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package ru.ulstu.is.pmu.ui.student.list
|
||||
|
||||
class FavoriteTaskListViewModel {
|
||||
}
|
Loading…
Reference in New Issue
Block a user