a acabar
This commit is contained in:
4
.idea/deploymentTargetSelector.xml
generated
4
.idea/deploymentTargetSelector.xml
generated
@@ -4,10 +4,10 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2026-05-12T14:44:48.637593Z">
|
<DropdownSelection timestamp="2026-06-03T14:39:06.554406Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=RZCX40Q6DDY" />
|
<DeviceId pluginId="LocalEmulator" identifier="path=/Users/230415/.android/avd/Pixel_9a.avd" />
|
||||||
</handle>
|
</handle>
|
||||||
</Target>
|
</Target>
|
||||||
</DropdownSelection>
|
</DropdownSelection>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.example.lifegrid.R;
|
import com.example.lifegrid.R;
|
||||||
import com.example.lifegrid.models.Transacao;
|
import com.example.lifegrid.models.Transacao;
|
||||||
|
import com.example.lifegrid.models.Ativos;
|
||||||
import com.google.firebase.auth.FirebaseAuth;
|
import com.google.firebase.auth.FirebaseAuth;
|
||||||
import com.google.firebase.auth.FirebaseUser;
|
import com.google.firebase.auth.FirebaseUser;
|
||||||
import com.google.firebase.database.DataSnapshot;
|
import com.google.firebase.database.DataSnapshot;
|
||||||
@@ -73,9 +74,74 @@ public class HomeFragment extends Fragment {
|
|||||||
.commit();
|
.commit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
root.findViewById(R.id.ativosCardView).setOnClickListener(v -> {
|
||||||
|
Fragment ativosFragment = new AtivosFragment();
|
||||||
|
requireActivity().getSupportFragmentManager().beginTransaction()
|
||||||
|
.replace(R.id.fragmentContainerView, ativosFragment)
|
||||||
|
.commit();
|
||||||
|
});
|
||||||
|
|
||||||
|
carregarDadosAtivos();
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void carregarDadosAtivos() {
|
||||||
|
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
||||||
|
if (user == null) return;
|
||||||
|
|
||||||
|
DatabaseReference ativosRef = FirebaseDatabase.getInstance().getReference()
|
||||||
|
.child("users").child(user.getUid()).child("ativos");
|
||||||
|
|
||||||
|
ativosRef.addValueEventListener(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
|
if (!isAdded()) return;
|
||||||
|
|
||||||
|
double totalInvestido = 0;
|
||||||
|
double valorTotalPortfolio = 0;
|
||||||
|
|
||||||
|
for (DataSnapshot ds : snapshot.getChildren()) {
|
||||||
|
Ativos ativo = ds.getValue(Ativos.class);
|
||||||
|
if (ativo != null) {
|
||||||
|
double qtd = 0;
|
||||||
|
try {
|
||||||
|
qtd = Double.parseDouble(ativo.getQuantidade().replace(",", "."));
|
||||||
|
} catch (Exception e) {}
|
||||||
|
|
||||||
|
totalInvestido += qtd * ativo.getPrecoCompra();
|
||||||
|
valorTotalPortfolio += qtd * ativo.getPrecoAtual();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tvValor4 != null) {
|
||||||
|
tvValor4.setText(String.format(Locale.getDefault(), "%.2f€", valorTotalPortfolio));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tvTransacoes4 != null) {
|
||||||
|
double roi = valorTotalPortfolio - totalInvestido;
|
||||||
|
double roiPct = 0;
|
||||||
|
if (totalInvestido > 0) {
|
||||||
|
roiPct = (roi / totalInvestido) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roi >= 0) {
|
||||||
|
tvTransacoes4.setText(String.format(Locale.getDefault(), "+%.2f%% ROI", roiPct));
|
||||||
|
tvTransacoes4.setTextColor(android.graphics.Color.parseColor("#22C55E"));
|
||||||
|
} else {
|
||||||
|
tvTransacoes4.setText(String.format(Locale.getDefault(), "%.2f%% ROI", roiPct));
|
||||||
|
tvTransacoes4.setTextColor(android.graphics.Color.parseColor("#FF0000"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|||||||
@@ -247,7 +247,7 @@
|
|||||||
android:layout_marginStart="7dp"
|
android:layout_marginStart="7dp"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
android:fontFamily="sans-serif"
|
android:fontFamily="sans-serif"
|
||||||
android:text="Valor do Ativos"
|
android:text="Valor de Ativos"
|
||||||
android:textColor="#4A5568"
|
android:textColor="#4A5568"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user