Skip to content

Commit

Permalink
Feat: delete transactions + ratings, suggestions to firebase + alert …
Browse files Browse the repository at this point in the history
…on multiple submission (#17)
  • Loading branch information
kaushikjadhav01 authored Nov 26, 2022
2 parents c966dcb + e599ce8 commit 5698a44
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 29 deletions.
17 changes: 0 additions & 17 deletions app/src/main/java/com/xa/xpensauditor/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,6 @@ public void onCancelled(FirebaseError firebaseError) {
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
viewPager.setCurrentItem(currentpage);
RefTran = RefUid.child("Transactions");
RefTran.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.getChildrenCount() == 0){
String text = "No transactions found. Please add a few.";
SpannableStringBuilder biggerText = new SpannableStringBuilder(text);
biggerText.setSpan(new RelativeSizeSpan(1.5f), 0, text.length(), 0);
Toast.makeText(getApplicationContext(), biggerText, Toast.LENGTH_LONG).show();
}
}

@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(getApplicationContext(), "Failed to load details", Toast.LENGTH_SHORT).show();
}
});

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

Expand Down
49 changes: 45 additions & 4 deletions app/src/main/java/com/xa/xpensauditor/Rate.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.xa.xpensauditor;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.Toast;

import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.firebase.auth.FirebaseAuth;

public class Rate extends AppCompatActivity {

RatingBar r;
Expand All @@ -15,17 +24,49 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rate);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
Firebase mRootRef, RefUid, RefRating;
FirebaseAuth auth= FirebaseAuth.getInstance();
mRootRef = new Firebase("https://xpensauditor-g11-default-rtdb.firebaseio.com/");
mRootRef.keepSynced(true);
String Uid = auth.getUid();
RefUid = mRootRef.child(Uid);
RefRating = RefUid.child("Rating");

r=(RatingBar)findViewById(R.id.ratingBar);
r.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
RefRating.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot DS) {
try {
if(DS.getValue() != null && fromUser == true){
AlertDialog.Builder builder = new AlertDialog.Builder(Rate.this);
builder.setMessage("You already submitted a rating. Rate Again ?");
builder.setTitle("Already Rated!");
builder.setCancelable(false);
builder.setPositiveButton("Yes", (DialogInterface.OnClickListener) (dialog, which) -> {
Toast.makeText(getApplicationContext(), String.valueOf(ratingBar.getRating()), Toast.LENGTH_LONG).show();
RefRating.setValue(String.valueOf(ratingBar.getRating()));
});
builder.setNegativeButton("No", (DialogInterface.OnClickListener) (dialog, which) -> {
dialog.cancel();
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
else if (fromUser == true) {
Toast.makeText(getApplicationContext(), String.valueOf(ratingBar.getRating()), Toast.LENGTH_LONG).show();
RefRating.setValue(String.valueOf(ratingBar.getRating()));
}
} catch (Exception e) {
e.printStackTrace();
}
}

if (fromUser == true) {
public void onCancelled(FirebaseError firebaseError) {

Toast.makeText(getApplicationContext(), String.valueOf(ratingBar.getRating()), Toast.LENGTH_LONG).show();
}
}
});
}
});
}
Expand Down
67 changes: 59 additions & 8 deletions app/src/main/java/com/xa/xpensauditor/Suggest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.xa.xpensauditor;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.firebase.auth.FirebaseAuth;

public class Suggest extends AppCompatActivity implements View.OnClickListener{

EditText e;
Expand All @@ -19,19 +27,62 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_suggest);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

Firebase mRootRef, RefUid, RefSuggestion;
FirebaseAuth auth= FirebaseAuth.getInstance();
mRootRef = new Firebase("https://xpensauditor-g11-default-rtdb.firebaseio.com/");
mRootRef.keepSynced(true);
String Uid = auth.getUid();
RefUid = mRootRef.child(Uid);
RefSuggestion = RefUid.child("Suggestion");


e=(EditText)findViewById(R.id.editText5);
b=(Button)findViewById(R.id.button3);
b.setOnClickListener(this);
}
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
RefSuggestion.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot DS) {
try {
String suggestion = e.getText().toString();
if (DS.getValue() != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Suggest.this);
builder.setMessage("You already submitted a rating. Rate Again ?");
builder.setTitle("Already Rated!");
builder.setCancelable(false);
builder.setPositiveButton("Yes", (DialogInterface.OnClickListener) (dialog, which) -> {
Toast.makeText(Suggest.this, "Suggestion submitted", Toast.LENGTH_SHORT).show();
RefSuggestion.setValue(suggestion);
Toast.makeText(Suggest.this, "Suggestion submitted", Toast.LENGTH_SHORT).show();
Intent i = new Intent(Suggest.this, HomeActivity.class);
startActivity(i);
});
builder.setNegativeButton("No", (DialogInterface.OnClickListener) (dialog, which) -> {
dialog.cancel();
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
} else {
RefSuggestion.setValue(suggestion);
Toast.makeText(Suggest.this, "Suggestion submitted", Toast.LENGTH_SHORT).show();
Intent i = new Intent(Suggest.this, HomeActivity.class);
startActivity(i);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void onCancelled(FirebaseError firebaseError) {

}
});

}
});
}

@Override
public void onClick(View v) {
String str=e.getText().toString();
Toast.makeText(this, "Suggestion submitted", Toast.LENGTH_SHORT).show();
Intent i = new Intent(this,HomeActivity.class);
startActivity(i);
public void onClick(View view) {

}
}

0 comments on commit 5698a44

Please sign in to comment.