Skip to content

Commit

Permalink
DB profiles restructured to record days present
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-cameron committed Mar 7, 2019
1 parent cf87a9e commit 49723d9
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public void onBindViewHolder(MyViewHolder holder, int position) {
UserProfile userProfileList = mUserProfileList.get(position);
holder.name.setText(userProfileList.getFirstName() + " " + userProfileList.getLastName());
holder.numberOfLeaves.setText(userProfileList.getNumberOfLeaves().toString());
holder.numberOfLeaves.setText(userProfileList.getCurrentNumberOfLeaves().toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String firstName = (String) profileSnapshot.child("firstName").getValue();
String lastName = (String) profileSnapshot.child("lastName").getValue();
String organisation = (String) profileSnapshot.child("organisation").getValue();
Long numberOfLeaves = (Long) profileSnapshot.child("numberOfLeaves").getValue();
Long currentNumberOfLeaves = (Long) profileSnapshot.child("currentNumberOfLeaves").getValue();
Long totalNumberOfLeaves = (Long) profileSnapshot.child("totalNumberOfLeaves").getValue();
Long rewards = (Long) profileSnapshot.child("rewards").getValue();

UserProfile userProfile = new UserProfile(email, firstName, lastName, organisation, numberOfLeaves);
UserProfile userProfile = new UserProfile(email, firstName, lastName, organisation, currentNumberOfLeaves, totalNumberOfLeaves, rewards);
mUserProfileList.add(userProfile);
}
mRecyclerView.setAdapter(new LeaderboardAdapter(mUserProfileList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String userProfileLastName = (String) dataSnapshot.child("lastName").getValue();
String userProfileEmail = (String) dataSnapshot.child("email").getValue();
String userProfileOrganisation = (String) dataSnapshot.child("organisation").getValue();
Long userProfileLeaves = (Long) dataSnapshot.child("numberOfLeaves").getValue();
Long userProfileLeaves = (Long) dataSnapshot.child("currentNumberOfLeaves").getValue();
profileName.setText("/ " + userProfileName + " " + userProfileLastName);
// profileEmail.setText("/ Email: " + userProfileEmail);
profileOrganisation.setText("/ " +userProfileOrganisation);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package com.andrewcameron.green_leaf;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
Expand Down Expand Up @@ -106,6 +99,7 @@ private void cancelRegistration () {
private void createDBProfile () {

long starterLeaves = 1;
long starterPlants = 0;

//INVESTIGATE
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Expand All @@ -117,7 +111,7 @@ private void createDBProfile () {
DatabaseReference ref = database.getReference("Profiles");

DatabaseReference newProfile = ref.child(uID);
newProfile.setValue(new UserProfile(mEmailField.getText().toString(), mFirstName.getText().toString(), mLastName.getText().toString(), mOrganisation.getText().toString(), starterLeaves));
newProfile.setValue(new UserProfile(mEmailField.getText().toString(), mFirstName.getText().toString(), mLastName.getText().toString(), mOrganisation.getText().toString(), starterLeaves, starterLeaves, starterPlants));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.andrewcameron.green_leaf;

public class UserPreferences {
private Boolean presentMonday, presentTuesday, presentWednesday, presentThursday, presentFriday;

public UserPreferences(Boolean presentMonday, Boolean presentTuesday, Boolean presentWednesday, Boolean presentThursday, Boolean presentFriday) {
this.presentMonday = presentMonday;
this.presentTuesday = presentTuesday;
this.presentWednesday = presentWednesday;
this.presentThursday = presentThursday;
this.presentFriday = presentFriday;
}

public Boolean getPresentMonday() {
return presentMonday;
}

public void setPresentMonday(Boolean presentMonday) {
this.presentMonday = presentMonday;
}

public Boolean getPresentTuesday() {
return presentTuesday;
}

public void setPresentTuesday(Boolean presentTuesday) {
this.presentTuesday = presentTuesday;
}

public Boolean getPresentWednesday() {
return presentWednesday;
}

public void setPresentWednesday(Boolean presentWednesday) {
this.presentWednesday = presentWednesday;
}

public Boolean getPresentThursday() {
return presentThursday;
}

public void setPresentThursday(Boolean presentThursday) {
this.presentThursday = presentThursday;
}

public Boolean getPresentFriday() {
return presentFriday;
}

public void setPresentFriday(Boolean presentFriday) {
this.presentFriday = presentFriday;
}
}
32 changes: 25 additions & 7 deletions app/src/main/java/com/andrewcameron/green_leaf/UserProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

public class UserProfile {
private String email, firstName, lastName, organisation;
private Long numberOfLeaves;
private Long currentNumberOfLeaves, totalNumberOfLeaves, plants;

public UserProfile(){
}

public UserProfile(String email, String firstName, String lastName, String organisation, Long numberOfLeaves) {
public UserProfile(String email, String firstName, String lastName, String organisation, Long currentNumberOfLeaves, Long totalNumberOfLeaves, Long plants) {
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
this.organisation = organisation;
this.numberOfLeaves = numberOfLeaves;
this.currentNumberOfLeaves = currentNumberOfLeaves;
this.totalNumberOfLeaves = totalNumberOfLeaves;
this.plants = plants;
}


Expand All @@ -32,12 +34,28 @@ public void setOrganisation(String organisation) {
this.organisation = organisation;
}

public Long getNumberOfLeaves() {
return numberOfLeaves;
public Long getCurrentNumberOfLeaves() {
return currentNumberOfLeaves;
}

public void setNumberOfLeaves(Long numberOfLeaves) {
this.numberOfLeaves = numberOfLeaves;
public void setCurrentNumberOfLeaves(Long currentNumberOfLeaves) {
this.currentNumberOfLeaves = currentNumberOfLeaves;
}

public Long getTotalNumberOfLeaves() {
return totalNumberOfLeaves;
}

public void setTotalNumberOfLeaves(Long totalNumberOfLeaves) {
this.totalNumberOfLeaves = totalNumberOfLeaves;
}

public Long getPlants() {
return plants;
}

public void setPlants(Long plants) {
this.plants = plants;
}

public String getFirstName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;

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

public class WeekPreferenceScreen extends AppCompatActivity {

private FirebaseAuth mAuth;
private String uID;
private ToggleButton mondayChecked;
private ToggleButton tuesdayChecked;
private ToggleButton wednesdayChecked;
private ToggleButton thursdayChecked;
private ToggleButton fridayChecked;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -20,6 +31,11 @@ protected void onCreate(Bundle savedInstanceState) {

final Button returnToProfile = (Button) findViewById(R.id.return_to_profile);
final Button confirmPreferences = (Button) findViewById(R.id.confirm_preferences);
mondayChecked = (ToggleButton) findViewById(R.id.day_1_monday);
tuesdayChecked = (ToggleButton) findViewById(R.id.day_2_tuesday);
wednesdayChecked = (ToggleButton) findViewById(R.id.day_3_wednesday);
thursdayChecked = (ToggleButton) findViewById(R.id.day_4_thursday);
fridayChecked = (ToggleButton) findViewById(R.id.day_5_friday);

returnToProfile.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -32,10 +48,25 @@ public void onClick(View v) {
confirmPreferences.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

setPreferences();
Intent myIntent = new Intent(WeekPreferenceScreen.this, ProfileScreenActivity.class);
startActivity(myIntent);
}
});
}

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

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

DatabaseReference newPreferencesField = ref.child("weekPreferences");
newPreferencesField.setValue(new UserPreferences(mondayChecked.isChecked(),tuesdayChecked.isChecked(),wednesdayChecked.isChecked(),thursdayChecked.isChecked(),fridayChecked.isChecked()));
}

}
15 changes: 10 additions & 5 deletions app/src/main/res/layout/content_week_preference_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MON"
android:textSize="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:paddingTop="5dp"
android:paddingBottom="35dp"/>
<ToggleButton
android:id="@+id/day_1_monday"
android:background="@drawable/date_toggle"
android:layout_width="40dp"
android:layout_height="40dp"
Expand All @@ -79,11 +80,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TUE"
android:textSize="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:paddingTop="5dp"
android:paddingBottom="35dp"/>
<ToggleButton
android:id="@+id/day_2_tuesday"
android:background="@drawable/date_toggle"
android:layout_width="40dp"
android:layout_height="40dp"
Expand All @@ -100,11 +102,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WED"
android:textSize="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:paddingTop="5dp"
android:paddingBottom="35dp"/>
<ToggleButton
android:id="@+id/day_3_wednesday"
android:background="@drawable/date_toggle"
android:layout_width="40dp"
android:layout_height="40dp"
Expand All @@ -121,11 +124,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="THU"
android:textSize="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:paddingTop="5dp"
android:paddingBottom="35dp"/>
<ToggleButton
android:id="@+id/day_4_thursday"
android:background="@drawable/date_toggle"
android:layout_width="40dp"
android:layout_height="40dp"
Expand All @@ -142,11 +146,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FRI"
android:textSize="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:paddingTop="5dp"
android:paddingBottom="35dp"/>
<ToggleButton
android:id="@+id/day_5_friday"
android:background="@drawable/date_toggle"
android:layout_width="40dp"
android:layout_height="40dp"
Expand Down

0 comments on commit 49723d9

Please sign in to comment.