Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load my list #1

Open
Rafelcf opened this issue Jun 15, 2024 · 1 comment
Open

Load my list #1

Rafelcf opened this issue Jun 15, 2024 · 1 comment

Comments

@Rafelcf
Copy link

Rafelcf commented Jun 15, 2024

How can I load my productList?

@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)
                )
            )
        )

    }
}
@uuranus
Copy link
Owner

uuranus commented Jun 19, 2024

Currently, ScheduleCalendar does not recognize your productList. Try this way.

    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
        }

        Column(
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            ScheduleCalendar(
                schedules = productList,
                calendarFormat = ScheduleCalendarDefaults.formats().copy(
                    monthHeaderFormat = "YYYY - MMMM"
                )
            )
        }
    }
    // ...
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants