-
-
Save parzibyte/bac99755a894cae93233764346300933 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.parzibyte.administrate; | |
import android.support.annotation.NonNull; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.TextView; | |
import java.util.List; | |
import me.parzibyte.administrate.entidades.Gasto; | |
public class AdaptadorGastos extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | |
private List<Gasto> listaDeGastos; | |
private final int TIPO_NORMAL = 1; | |
private final int TIPO_VER_MAS = 0; | |
public void setListaDeGastos(List<Gasto> listaDeGastos) { | |
this.listaDeGastos = listaDeGastos; | |
} | |
public AdaptadorGastos(List<Gasto> gastos) { | |
this.listaDeGastos = gastos; | |
} | |
@NonNull | |
@Override | |
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { | |
switch (viewType) { | |
case TIPO_VER_MAS: | |
View filaVerMas = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fila_ver_mas, viewGroup, false); | |
return new ViewHolderVerMas(filaVerMas); | |
case TIPO_NORMAL: | |
default: | |
View filaGasto = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fila_gasto, viewGroup, false); | |
return new ViewHolderGasto(filaGasto); | |
} | |
} | |
@Override | |
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { | |
switch (holder.getItemViewType()) { | |
case TIPO_NORMAL: | |
ViewHolderGasto viewHolderGasto = (ViewHolderGasto) holder; | |
Gasto gasto = listaDeGastos.get(i); | |
viewHolderGasto.descripcion.setText(gasto.getDescripcion()); | |
viewHolderGasto.monto.setText(gasto.getMontoAsString()); | |
viewHolderGasto.categoria.setText(gasto.getCategoria().getNombre()); | |
viewHolderGasto.fecha.setText(gasto.getFechaFormateada()); | |
break; | |
case TIPO_VER_MAS: | |
default: | |
ViewHolderVerMas viewHolderVerMas = (ViewHolderVerMas) holder; | |
viewHolderVerMas.textoVerMas.getContext().getString(R.string.ver_todos_gastos); | |
viewHolderVerMas.textoVerMas.setText(viewHolderVerMas.textoVerMas.getContext().getString(R.string.ver_todos_gastos)); | |
break; | |
} | |
} | |
@Override | |
public int getItemCount() { | |
return listaDeGastos.size(); | |
} | |
@Override | |
public int getItemViewType(int position) { | |
if (position == listaDeGastos.size() - 1) return TIPO_VER_MAS; | |
return TIPO_NORMAL; | |
} | |
class ViewHolderGasto extends RecyclerView.ViewHolder { | |
TextView descripcion, monto, categoria, fecha; | |
ViewHolderGasto(View itemView) { | |
super(itemView); | |
this.descripcion = itemView.findViewById(R.id.tvDescripcionGasto); | |
this.monto = itemView.findViewById(R.id.tvMontoGasto); | |
this.categoria = itemView.findViewById(R.id.tvCategoriaGasto); | |
this.fecha = itemView.findViewById(R.id.tvFechaGasto); | |
} | |
} | |
class ViewHolderVerMas extends RecyclerView.ViewHolder { | |
TextView textoVerMas; | |
ViewHolderVerMas(View itemView) { | |
super(itemView); | |
this.textoVerMas = itemView.findViewById(R.id.tvVerMas); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment