definições
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
package com.example.lifegrid.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.lifegrid.R;
|
||||
import com.example.lifegrid.models.Ativos;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AtivosAdapter extends RecyclerView.Adapter<AtivosAdapter.AtivosViewHolder> {
|
||||
|
||||
private List<Ativos> ativosList;
|
||||
private List<String> keysList;
|
||||
private Context context;
|
||||
private OnItemClickListener listener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onDeleteClick(int position, String key);
|
||||
void onRefreshClick(int position, String key, Ativos ativo);
|
||||
}
|
||||
|
||||
public AtivosAdapter(Context context, List<Ativos> ativosList, List<String> keysList, OnItemClickListener listener) {
|
||||
this.context = context;
|
||||
this.ativosList = ativosList;
|
||||
this.keysList = keysList;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AtivosViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_ativo, parent, false);
|
||||
return new AtivosViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull AtivosViewHolder holder, int position) {
|
||||
Ativos ativo = ativosList.get(position);
|
||||
String key = keysList.get(position);
|
||||
|
||||
holder.tvNome.setText(ativo.getNome());
|
||||
holder.tvTipo.setText(ativo.getTipo());
|
||||
|
||||
String info = String.format(Locale.getDefault(), "%s unidades x %.2f€", ativo.getQuantidade(), ativo.getPrecoCompra());
|
||||
holder.tvInfo.setText(info);
|
||||
|
||||
double precoAtual = ativo.getPrecoAtual();
|
||||
double precoCompra = ativo.getPrecoCompra();
|
||||
double qtd = 0;
|
||||
try {
|
||||
qtd = Double.parseDouble(ativo.getQuantidade().replace(",", "."));
|
||||
} catch (NumberFormatException e) {
|
||||
qtd = 0;
|
||||
}
|
||||
|
||||
double total = qtd * precoAtual;
|
||||
|
||||
holder.tvPrecoAtual.setText(String.format(Locale.getDefault(), "%.2f€", total));
|
||||
|
||||
double percentagem = 0.0;
|
||||
if (precoCompra > 0) {
|
||||
percentagem = ((precoAtual - precoCompra) / precoCompra) * 100;
|
||||
}
|
||||
|
||||
if (percentagem >= 0) {
|
||||
holder.tvPercentagem.setText(String.format(Locale.getDefault(), "+%.2f%%", percentagem));
|
||||
holder.tvPercentagem.setTextColor(Color.parseColor("#16a34a")); // Green
|
||||
holder.ivTrend.setImageResource(R.drawable.ic_trend_up);
|
||||
holder.ivTrend.setColorFilter(Color.parseColor("#16a34a"));
|
||||
holder.ivTrend.setBackgroundResource(R.drawable.bg_circle_green);
|
||||
} else {
|
||||
holder.tvPercentagem.setText(String.format(Locale.getDefault(), "%.2f%%", percentagem));
|
||||
holder.tvPercentagem.setTextColor(Color.parseColor("#ef4444")); // Red
|
||||
holder.ivTrend.setImageResource(R.drawable.ic_arrow_down); // Fallback if no specific icon
|
||||
holder.ivTrend.setColorFilter(Color.parseColor("#ef4444"));
|
||||
holder.ivTrend.setBackgroundResource(R.drawable.bg_circle_red);
|
||||
}
|
||||
|
||||
holder.btnDelete.setOnClickListener(v -> {
|
||||
if (listener != null) listener.onDeleteClick(position, key);
|
||||
});
|
||||
|
||||
holder.btnRefresh.setOnClickListener(v -> {
|
||||
if (listener != null) listener.onRefreshClick(position, key, ativo);
|
||||
Toast.makeText(context, "Ativo atualizado (Exemplo)", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return ativosList.size();
|
||||
}
|
||||
|
||||
public static class AtivosViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView ivTrend, btnDelete, btnRefresh;
|
||||
TextView tvNome, tvTipo, tvInfo, tvPrecoAtual, tvPercentagem;
|
||||
|
||||
public AtivosViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
ivTrend = itemView.findViewById(R.id.ivTrend);
|
||||
tvNome = itemView.findViewById(R.id.tvNome);
|
||||
tvTipo = itemView.findViewById(R.id.tvTipo);
|
||||
tvInfo = itemView.findViewById(R.id.tvInfo);
|
||||
tvPrecoAtual = itemView.findViewById(R.id.tvPrecoAtual);
|
||||
tvPercentagem = itemView.findViewById(R.id.tvPercentagem);
|
||||
btnDelete = itemView.findViewById(R.id.btnDelete);
|
||||
btnRefresh = itemView.findViewById(R.id.btnRefresh);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
app/src/main/res/drawable/ic_refresh.xml
Normal file
9
app/src/main/res/drawable/ic_refresh.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#1C4DF6"
|
||||
android:pathData="M12,4V1L8,5l4,4V6c3.31,0 6,2.69 6,6c0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12C20,7.58 16.42,4 12,4zM12,18c-3.31,0 -6,-2.69 -6,-6c0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4l-4,-4V18z"/>
|
||||
</vector>
|
||||
@@ -381,10 +381,11 @@
|
||||
android:id="@+id/alvoImageView"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginStart="57dp"
|
||||
android:layout_marginStart="40dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/graficoImageView"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.473"
|
||||
app:srcCompat="@drawable/alvo" />
|
||||
|
||||
<ImageView
|
||||
@@ -428,7 +429,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/setaImageView"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.578"
|
||||
app:layout_constraintVertical_bias="0.473"
|
||||
app:srcCompat="@drawable/grafico" />
|
||||
|
||||
<ImageView
|
||||
|
||||
@@ -10,60 +10,16 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout4"
|
||||
android:layout_width="379dp"
|
||||
android:layout_height="214dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:background="@drawable/button_background"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView20"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="28dp"
|
||||
android:text="Poupança Atual"
|
||||
android:textSize="18dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView21"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="36dp"
|
||||
android:text="0,00€"
|
||||
android:textSize="18dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView20" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView22"
|
||||
android:layout_width="282dp"
|
||||
android:layout_height="43dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Baseado nas suas receitas e despesas registradas"
|
||||
android:textSize="16dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView21" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/adicionarCardView"
|
||||
android:layout_width="374dp"
|
||||
android:layout_height="379dp"
|
||||
android:layout_marginTop="68dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:background="@drawable/cardview_background"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.486"
|
||||
app:layout_constraintHorizontal_bias="0.432"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/constraintLayout4">
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView12"
|
||||
|
||||
117
app/src/main/res/layout/item_ativo.xml
Normal file
117
app/src/main/res/layout/item_ativo.xml
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:background="@drawable/cardview_background"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- Icon on the left -->
|
||||
<ImageView
|
||||
android:id="@+id/ivTrend"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:background="@drawable/bg_circle_green"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/ic_trend_up"
|
||||
app:tint="#16a34a"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- Asset Name -->
|
||||
<TextView
|
||||
android:id="@+id/tvNome"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:textColor="@color/preto"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="normal"
|
||||
app:layout_constraintStart_toEndOf="@id/ivTrend"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="bitcoins" />
|
||||
|
||||
<!-- Asset Type Badge -->
|
||||
<TextView
|
||||
android:id="@+id/tvTipo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="@drawable/bg_badge_category"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:paddingVertical="4dp"
|
||||
android:textColor="@color/preto"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="@id/tvNome"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvNome"
|
||||
tools:text="Criptomoedas" />
|
||||
|
||||
<!-- Quantity and Purchase Price -->
|
||||
<TextView
|
||||
android:id="@+id/tvInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:textColor="#6b7280"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintStart_toStartOf="@id/tvNome"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvTipo"
|
||||
tools:text="12 unidades x 16.10€" />
|
||||
|
||||
<!-- Delete Button -->
|
||||
<ImageView
|
||||
android:id="@+id/btnDelete"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/ic_delete"
|
||||
app:tint="#ef4444"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- Refresh Button -->
|
||||
<ImageView
|
||||
android:id="@+id/btnRefresh"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/ic_refresh"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/btnDelete"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- Current Price -->
|
||||
<TextView
|
||||
android:id="@+id/tvPrecoAtual"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textColor="@color/preto"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="normal"
|
||||
app:layout_constraintBottom_toTopOf="@id/tvPercentagem"
|
||||
app:layout_constraintEnd_toStartOf="@id/btnRefresh"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
tools:text="193.19€" />
|
||||
|
||||
<!-- Percentage Change -->
|
||||
<TextView
|
||||
android:id="@+id/tvPercentagem"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="#16a34a"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/tvPrecoAtual"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPrecoAtual"
|
||||
tools:text="+15.00%" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user