From 794df5269fef6b2cf4762bfc7a52a961295b77c7 Mon Sep 17 00:00:00 2001 From: Yannine Alvarez Date: Tue, 19 May 2020 11:03:27 -0400 Subject: [PATCH] Agregar formato fecha en el cardview dias en numero y mes en letras. --- app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt b/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt index c55c9bb..ddc3178 100644 --- a/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt +++ b/app/src/main/java/com/example/ayudapy/ListaPedidoAdapter.kt @@ -1,12 +1,18 @@ package com.example.ayudapy import android.content.Context +import android.os.Build import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.annotation.RequiresApi import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.pendientes_items.view.* +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle class RecyclerViewAdapter(val pedido: List) : RecyclerView.Adapter(){ @@ -18,9 +24,29 @@ class RecyclerViewAdapter(val pedido: List) return ViewHolder(v) } + + + + @RequiresApi(Build.VERSION_CODES.O) override fun onBindViewHolder(holder: RecyclerViewAdapter.ViewHolder, position: Int) { + // localDate.getDayOfMonth(); + //localDate.getMonthValue(); + + val formatter = DateTimeFormatter.BASIC_ISO_DATE + val formatted = pedido[position].added.format(formatter) + + val fecha = formatted.substring(8..9) + + // dateTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM)) + val parsedDate = LocalDateTime.parse(pedido[position].added, DateTimeFormatter.ISO_DATE_TIME) + val formatteDate = parsedDate.format(DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm")) + + val mes = formatteDate.substring(3..5) + + println("Este es el substring de mes: $mes y este es formateadp $formatteDate") - holder.date_day.text = pedido[position].added + holder.date_day.text = fecha + holder.date_month.text = mes.toUpperCase() holder.title.text = pedido[position].title holder.message_view.text = pedido[position].message } @@ -39,6 +65,7 @@ class RecyclerViewAdapter(val pedido: List) class ViewHolder(itemView:View): RecyclerView.ViewHolder(itemView){ val date_day = itemView.date_day + val date_month = itemView.date_month val title = itemView.title val message_view = itemView.message_view } -- libgit2 0.26.0