package [Link].
ngo_app;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DonationHistory extends AppCompatActivity {
private LinearLayout historyContainer;
private TextView totalAmountText;
private DatabaseReference donationref;
private int totalDonated = 0;
TextView welcome;
ImageView homeicon,donationicon,profileicon,developericon,logouticon;
FirebaseAuth mauth;
DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_donation_history);
historyContainer = findViewById([Link]);
totalAmountText = findViewById([Link]);
String userId = [Link]().getCurrentUser().getUid();
donationref =
[Link]().getReference("Donation").child(userId);
fetchDonationHistory();
welcome = findViewById([Link]);
homeicon = findViewById([Link]);
donationicon = findViewById([Link]);
profileicon = findViewById([Link]);
developericon = findViewById([Link]);
logouticon = findViewById([Link]);
mauth = [Link]();
databaseReference = [Link]().getReference("Users");
FirebaseUser currentUser = [Link]();
if(currentUser != null)
{
String userID = [Link]();
[Link](userID).child("name").addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
String name = [Link]([Link]);
if(name != null)
{
[Link]("Welcome, "+name+" !");
}
else
{
[Link]("Welcome, Guest !");
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
[Link](getApplicationContext(),"Failed to load username
!",Toast.LENGTH_LONG).show();
}
});
}
else
{
[Link]("Welcome, Guest !");
}
[Link](new [Link]() {
@Override
public void onClick(View v) {
startActivity(new Intent([Link],[Link]));
finish();
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
startActivity(new Intent([Link],[Link]));
finish();
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
startActivity(new Intent([Link],[Link]));
finish();
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
startActivity(new Intent([Link],
[Link]));
finish();
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]().signOut();
startActivity(new Intent([Link],[Link]));
finish();
}
});
}
private void fetchDonationHistory()
{
[Link](new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
totalDonated = 0;
[Link]();
if(![Link]())
{
[Link](getApplicationContext(), "Donation not found",
Toast.LENGTH_SHORT).show();
return;
}
for(DataSnapshot donationSnap:[Link]())
{
Object amountObj = [Link]("Amount").getValue();
String date =
[Link]("Date").getValue([Link]);
if(amountObj != null && date != null)
{
int amount = 0;
if(amountObj instanceof Long)
{
amount = ((Long)amountObj).intValue();
}
else if(amountObj instanceof Integer)
{
amount = (Integer)amountObj;
}
else if(amountObj instanceof Double)
{
amount = (int) [Link]((Double) amountObj);
}
else
{
[Link](getApplicationContext(),"Error: Unknown
data type",Toast.LENGTH_LONG).show();
}
totalDonated += amount;
TextView entry = new TextView([Link]);
[Link]("Date: "+date+" | Amount:
"+amount);
[Link](20f);
[Link](entry);
}
else
{
[Link](getApplicationContext(),"Missing date or
amount !",Toast.LENGTH_LONG).show();
}
}
[Link]("Total Donated: ₹"+totalDonated);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
[Link](getApplicationContext(), "Failed to load data !",
Toast.LENGTH_LONG).show();
}
});
}
}