You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Parcelize
data class TaskItem(
@SerializedName("id") val id: Int,
@SerializedName("comentario") val comentario: String,
@SerializedName("complemento") val complemento: String,
@SerializedName("direccion") val direccion: String,
@SerializedName("empresa") val empresa: String,
@SerializedName("fecha") val fecha: String,
@SerializedName("festivo") val festivo: String,
@SerializedName("obra") val obra: String,
@SerializedName("pagado") val pagado: String,
@SerializedName("poblacion") val poblacion: String,
@SerializedName("time_fin") val time_fin: String,
@SerializedName("time_ini") val time_ini: String,
@SerializedName("tipo") val tipo: String,
@SerializedName("total_time") val total_time: String,
@SerializedName("vehiculo") val vehiculo: String
) : Parcelable
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val viewModel : ProductViewModel by viewModels()
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState : Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SchedulecalendarcomposeTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Calendar(viewModel)
}
}
}
}
}
@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun Calendar(viewModel : ProductViewModel) {
val productsState by viewModel.products.collectAsState()
val currentDate = remember { mutableStateOf(LocalDate.now()) }
// Render UI for when connected
when (productsState) {
is ViewState.Success -> {
// Handle success state
val productList = (productsState as ViewState.Success).data
.filter { it.tipo == "Nacional" }
.sortedByDescending { it.fecha }
productList.forEach() {
println("schedule1 " + it.fecha)
val dateString = it.fecha
val parsedDate = LocalDate.parse(dateString)
val dateAsDay = parsedDate.dayOfMonth
val dateAsMonth = parsedDate.monthValue
val dateAsyear = parsedDate.year
}
}
is ViewState.Error -> {
val errorMessage = (productsState as ViewState.Error).message
}
is ViewState.Loading -> {
Box(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
) {
LinearProgressIndicator(
modifier = Modifier.align(Alignment.Center),
color = Color.Yellow
)
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center),
color = MaterialTheme.colorScheme.primary
)
}
}
}
val date1 = ScheduleDate.create(2024, 6, 1)
val date2 = ScheduleDate.create(2024, 6, 12)
val date3 = ScheduleDate.create(2024, 6, 3)
val date4 = ScheduleDate.create(2024, 6, 24)
val date5 = ScheduleDate.create(2024, 6, 14)
// Create ScheduleInfo objects
val info1 = ScheduleInfo(
false, listOf(
ScheduleData(
"schedule1",
Purple,
"Schedule Info 1",
)
)
)
val info2 = ScheduleInfo(
false, listOf(
ScheduleData(
"schedule2",
Blue,
"Schedule Info 2",
)
)
)
val info3 = ScheduleInfo(
false, listOf(
ScheduleData(
"schedule3",
Red,
"Schedule Info 3",
)
)
)
val info4 = ScheduleInfo(
true, listOf(
ScheduleData(
"schedule4",
Orange,
"Schedule Info 4",
)
)
)
val info5 = ScheduleInfo(
true, listOf(
ScheduleData(
"schedule5",
Yellow,
"Schedule Info 5",
),
ScheduleData(
"schedule6",
Orange,
"Schedule Info 6",
),
ScheduleData(
"schedule7",
Green,
"Schedule Info 7",
),
ScheduleData(
"schedule8",
Blue,
"Schedule Info 8",
),
ScheduleData(
"schedule9",
Purple,
"Schedule Info 9",
)
)
)
// Create a map with the dummy dates and schedule info
val schedules = mapOf(
date1 to info1,
date2 to info2,
date3 to info3,
date4 to info4,
date5 to info5
)
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
ScheduleCalendar(
schedules = schedules,
calendarFormat = ScheduleCalendarDefaults.formats().copy(
monthHeaderFormat = "YYYY - MMMM"
)
)
Text(
//text = formattedDay!!.replaceFirstChar(Char::titlecase) + formattedMonth + formattedYear,
text = "Fecha",
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Normal,
fontSize = 18.sp,
style = MaterialTheme.typography.titleLarge.copy(
shadow = Shadow(
offset = Offset(10f, 10f),
blurRadius = 10f,
color = Color.Green.copy(0.7f)
)
)
)
}
}
The text was updated successfully, but these errors were encountered:
How can I load my productList?
The text was updated successfully, but these errors were encountered: