Skip to content

Commit

Permalink
Merge pull request #46 from andy-cameron/redeem_screen
Browse files Browse the repository at this point in the history
Redeem screen
  • Loading branch information
andy-cameron committed Apr 9, 2019
2 parents 91c6b20 + 9ea67d1 commit 791733c
Show file tree
Hide file tree
Showing 15 changed files with 773 additions and 8 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
android:roundIcon="@mipmap/green_leaf"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".QRScannerScreenActivity"
<activity
android:name=".RedeemScreenActivity"
android:label="@string/title_activity_redeem_screen"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".QRScannerScreenActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".InformationScreenActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".InformationScreenActivity"
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".LeaderboardScreenActivity"
android:label="@string/title_activity_leaderboard_screen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
Button goToLeaderboard = (Button) findViewById(R.id.go_to_leaderboard);
Button goToInformation = (Button) findViewById(R.id.go_to_user_information);
Button goToScanQR = (Button) findViewById(R.id.go_to_scan_qr_code);
Button gotToRedeem = (Button) findViewById(R.id.go_to_redeem);
Button returnToLogin = (Button) findViewById(R.id.return_to_login);

final ImageView mondayPresentLight = (ImageView) findViewById(R.id.monday_panel_light);
Expand Down Expand Up @@ -88,6 +89,14 @@ public void onClick(View v) {
}
}));

gotToRedeem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(ProfileScreenActivity.this, RedeemScreenActivity.class);
startActivity(myIntent);
}
});

returnToLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package com.andrewcameron.green_leaf;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

public class RedeemScreenActivity extends AppCompatActivity {

private String uID;
private DatabaseReference mDatabase;
private FirebaseUser mUser;
private FirebaseAuth mAuth;
public long redeemValue;
// private Button btnReturn;

//Prompt
Dialog redeemLeavesPrompt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_redeem_screen);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
redeemLeavesPrompt = new Dialog(this);

Button redeemItem1 = (Button) findViewById(R.id.redeem_item_1);
Button redeemItem2 = (Button) findViewById(R.id.redeem_item_2);
Button redeemItem3 = (Button) findViewById(R.id.redeem_item_3);
Button returnToProfile = (Button) findViewById(R.id.return_to_profile);

returnToProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(RedeemScreenActivity.this, ProfileScreenActivity.class);
startActivity(myIntent);
}
});

redeemItem1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
redeemValue = 3;
ShowPrompt(v);
}
});

redeemItem2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
redeemValue = 5;
ShowPrompt(v);
}
});
}

public void ShowPrompt (View v) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
uID = user.getUid();
}

final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("Profiles").child(uID);
DatabaseReference updatePlants = ref.child("plants");

updatePlants.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
long numberOfPlants = (long) dataSnapshot.getValue();

if (numberOfPlants >= redeemValue) {
redeemLeavesPrompt.setContentView(R.layout.redeem_confirm_prompt);
Button btnReturn, btnConfirmPurchase;
btnReturn = (Button) redeemLeavesPrompt.findViewById(R.id.button_return_prompt_redeem);
btnConfirmPurchase = (Button) redeemLeavesPrompt.findViewById(R.id.confirm_purchase);
TextView redeemValuePrompt = (TextView) redeemLeavesPrompt.findViewById(R.id.redeem_reward_value_prompt);

redeemValuePrompt.setText(redeemValue + " Plants");
redeemLeavesPrompt.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
redeemLeavesPrompt.show();

btnReturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
redeemLeavesPrompt.dismiss();
}
});

btnConfirmPurchase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RedeemTransaction();
redeemLeavesPrompt.dismiss();
}
});

} else {
redeemLeavesPrompt.setContentView(R.layout.redeem_invalid_prompt);
redeemLeavesPrompt.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Button btnReturn;
btnReturn = (Button) redeemLeavesPrompt.findViewById(R.id.button_return_prompt);
redeemLeavesPrompt.show();

btnReturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
redeemLeavesPrompt.dismiss();
}
});
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}

public void RedeemTransaction () {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
uID = user.getUid();
}

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("Profiles").child(uID);
final DatabaseReference updatePlants = ref.child("plants");

updatePlants.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
long numberOfPlants = (long) dataSnapshot.getValue();

updatePlants.setValue(numberOfPlants - redeemValue);
redeemLeavesPrompt.dismiss();
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}

public void ConfirmRedeemPrompt () {
// redeemLeavesPrompt.setContentView(R.layout.redeem_confirm_prompt);
// redeemLeavesPrompt.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// redeemLeavesPrompt.show();

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
uID = user.getUid();
}

final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("Profiles").child(uID);
final DatabaseReference updatePlants = ref.child("plants");

updatePlants.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
final long numberOfPlants = (long) dataSnapshot.getValue();
//Button Return
Button btnReturn = (Button) findViewById(R.id.button_return_prompt_redeem);
btnReturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
redeemLeavesPrompt.dismiss();
}
});
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}
}
78 changes: 73 additions & 5 deletions app/src/main/res/layout/activity_profile_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@
android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/user_leaves_title"
android:orientation="horizontal"
android:padding="15dp">
android:padding="15dp"
android:layout_gravity="center_horizontal"
android:weightSum="2">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -322,14 +324,16 @@
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
android:layout_weight="1"
android:gravity="right">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/stampsheet_leaves20"
android:background="@drawable/circle_fine"/>
android:background="@drawable/circle_fine"
android:layout_marginLeft="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
Expand Down Expand Up @@ -379,6 +383,70 @@
android:layout_marginTop="5dp"/>
</LinearLayout>

<LinearLayout
android:id="@+id/redeem_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/content_panel"
android:orientation="vertical"
android:layout_marginBottom="25dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/redeem"
android:gravity="center"
android:textSize="20dp"
android:textStyle="bold"
android:paddingVertical="5dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4"
android:paddingHorizontal="30dp"
android:paddingVertical="15dp">
<TextView
android:layout_width= "wrap_content"
android:layout_height="wrap_content"
android:text="@string/redeem_info"
android:layout_weight="2"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@mipmap/stampsheet_leaves20"
android:layout_weight="5"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:textStyle="bold"
android:textSize="30sp"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:src="@mipmap/outline_card_giftcard_black_48"
android:layout_margin="5dp"
android:alpha="0.6"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/go_to_redeem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/content_panel_button"
android:text="@string/redeem_now" />
</LinearLayout>

<LinearLayout
android:id="@+id/user_information_panel"
android:layout_width="match_parent"
Expand Down
Loading

0 comments on commit 791733c

Please sign in to comment.