Skip to content

Commit

Permalink
Merge pull request #31 from andy-cameron/setting_dates
Browse files Browse the repository at this point in the history
Setting dates
  • Loading branch information
andy-cameron committed Mar 7, 2019
2 parents cf87a9e + 6094ffe commit 79ed832
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 39 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
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.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.andrewcameron.green_leaf"
minSdkVersion 15
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
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 @@ -6,6 +6,7 @@
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.firebase.auth.FirebaseAuth;
Expand Down Expand Up @@ -45,6 +46,12 @@ protected void onCreate(Bundle savedInstanceState) {
Button goToScanQR = (Button) findViewById(R.id.go_to_scan_qr_code);
Button returnToLogin = (Button) findViewById(R.id.return_to_login);

final ImageView mondayPresentLight = (ImageView) findViewById(R.id.monday_panel_light);
final ImageView tuesdayPresentLight = (ImageView) findViewById(R.id.tuesday_panel_light);
final ImageView wednesdayPresentLight = (ImageView) findViewById(R.id.wednesday_panel_light);
final ImageView thursdayPresentLight = (ImageView) findViewById(R.id.thursday_panel_light);
final ImageView fridayPresentLight = (ImageView) findViewById(R.id.friday_panel_light);

goToPreferences.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -92,14 +99,15 @@ public void onClick(View v) {

mDatabase = FirebaseDatabase.getInstance().getReference("Profiles");

//Getting basic User Info
mDatabase.child(uID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String userProfileName = (String) dataSnapshot.child("firstName").getValue();
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 All @@ -112,6 +120,48 @@ public void onCancelled(@NonNull DatabaseError databaseError) {
}
});

//Getting days present
mDatabase.child(uID).child("weekPreferences").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Boolean mondayPresent = (Boolean) dataSnapshot.child("presentMonday").getValue();
Boolean tuesdayPresent = (Boolean) dataSnapshot.child("presentTuesday").getValue();
Boolean wednesdayPresent = (Boolean) dataSnapshot.child("presentWednesday").getValue();
Boolean thursdayPresent = (Boolean) dataSnapshot.child("presentThursday").getValue();
Boolean fridayPresent = (Boolean) dataSnapshot.child("presentFriday").getValue();

if (mondayPresent) {
mondayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_green, null));
}
else mondayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_red, null));

if (tuesdayPresent) {
tuesdayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_green, null));
}
else tuesdayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_red, null));

if (wednesdayPresent) {
wednesdayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_green, null));
}
else wednesdayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_red, null));

if (thursdayPresent) {
thursdayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_green, null));
}
else thursdayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_red, null));

if (fridayPresent) {
fridayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_green, null));
}
else fridayPresentLight.setBackground(getResources().getDrawable(R.drawable.icon_light_red, null));
}

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

}
});

}

}
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()));
}

}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/icon_light_green.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/yesGreen"/>
<stroke android:color="@color/grey" android:width="1dp"/>
<size android:width="250dp" android:height="250dp"/>
</shape>
</item>
</selector>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/white"/>
<solid android:color="@color/noRed"/>
<stroke android:color="@color/grey" android:width="1dp"/>
<size android:width="250dp" android:height="250dp"/>
</shape>
Expand Down
Loading

0 comments on commit 79ed832

Please sign in to comment.