diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 8eae1a0..6eaf52a 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/misc.xml b/.idea/misc.xml index cc04cd3..51fa3e5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -35,7 +35,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 8744cd6..2889b57 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ android { compileSdkVersion 28 defaultConfig { applicationId "com.andrewcameron.green_leaf" - minSdkVersion 15 + minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" diff --git a/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardAdapter.java b/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardAdapter.java index bd63485..3694a50 100644 --- a/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardAdapter.java +++ b/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardAdapter.java @@ -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 diff --git a/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardScreenFragment.java b/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardScreenFragment.java index 232aa4a..4aa42ba 100644 --- a/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardScreenFragment.java +++ b/app/src/main/java/com/andrewcameron/green_leaf/LeaderboardScreenFragment.java @@ -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)); diff --git a/app/src/main/java/com/andrewcameron/green_leaf/ProfileScreenActivity.java b/app/src/main/java/com/andrewcameron/green_leaf/ProfileScreenActivity.java index b7a79f9..29ff4eb 100644 --- a/app/src/main/java/com/andrewcameron/green_leaf/ProfileScreenActivity.java +++ b/app/src/main/java/com/andrewcameron/green_leaf/ProfileScreenActivity.java @@ -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; @@ -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) { @@ -92,6 +99,7 @@ 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) { @@ -99,7 +107,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); @@ -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) { + + } + }); + } } diff --git a/app/src/main/java/com/andrewcameron/green_leaf/RegisterScreenActivity.java b/app/src/main/java/com/andrewcameron/green_leaf/RegisterScreenActivity.java index 5526b15..9bacd9d 100644 --- a/app/src/main/java/com/andrewcameron/green_leaf/RegisterScreenActivity.java +++ b/app/src/main/java/com/andrewcameron/green_leaf/RegisterScreenActivity.java @@ -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; @@ -106,6 +99,7 @@ private void cancelRegistration () { private void createDBProfile () { long starterLeaves = 1; + long starterPlants = 0; //INVESTIGATE FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); @@ -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 diff --git a/app/src/main/java/com/andrewcameron/green_leaf/UserPreferences.java b/app/src/main/java/com/andrewcameron/green_leaf/UserPreferences.java new file mode 100644 index 0000000..08fb6ce --- /dev/null +++ b/app/src/main/java/com/andrewcameron/green_leaf/UserPreferences.java @@ -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; + } +} diff --git a/app/src/main/java/com/andrewcameron/green_leaf/UserProfile.java b/app/src/main/java/com/andrewcameron/green_leaf/UserProfile.java index cb0e353..0c72d6c 100644 --- a/app/src/main/java/com/andrewcameron/green_leaf/UserProfile.java +++ b/app/src/main/java/com/andrewcameron/green_leaf/UserProfile.java @@ -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; } @@ -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() { diff --git a/app/src/main/java/com/andrewcameron/green_leaf/WeekPreferenceScreen.java b/app/src/main/java/com/andrewcameron/green_leaf/WeekPreferenceScreen.java index f2b6eea..04e47c5 100644 --- a/app/src/main/java/com/andrewcameron/green_leaf/WeekPreferenceScreen.java +++ b/app/src/main/java/com/andrewcameron/green_leaf/WeekPreferenceScreen.java @@ -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); @@ -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 @@ -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())); + } + } diff --git a/app/src/main/res/drawable/icon_light_green.xml b/app/src/main/res/drawable/icon_light_green.xml new file mode 100644 index 0000000..4fd9cdf --- /dev/null +++ b/app/src/main/res/drawable/icon_light_green.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/icon_light.xml b/app/src/main/res/drawable/icon_light_red.xml similarity index 86% rename from app/src/main/res/drawable/icon_light.xml rename to app/src/main/res/drawable/icon_light_red.xml index 3490917..61744f5 100644 --- a/app/src/main/res/drawable/icon_light.xml +++ b/app/src/main/res/drawable/icon_light_red.xml @@ -2,7 +2,7 @@ - + diff --git a/app/src/main/res/layout/activity_profile_screen.xml b/app/src/main/res/layout/activity_profile_screen.xml index 76888d8..9e9587a 100644 --- a/app/src/main/res/layout/activity_profile_screen.xml +++ b/app/src/main/res/layout/activity_profile_screen.xml @@ -100,7 +100,7 @@ android:layout_width="15dp" android:layout_height="15dp" android:layout_marginTop="20dp" - android:background="@drawable/icon_light"/> + android:background="@drawable/icon_light_red"/> + android:background="@drawable/icon_light_red" /> + android:background="@drawable/icon_light_red" /> + android:background="@drawable/icon_light_red" /> + android:background="@drawable/icon_light_red" /> diff --git a/app/src/main/res/layout/content_week_preference_screen.xml b/app/src/main/res/layout/content_week_preference_screen.xml index 135dcd9..e0fdc43 100644 --- a/app/src/main/res/layout/content_week_preference_screen.xml +++ b/app/src/main/res/layout/content_week_preference_screen.xml @@ -58,15 +58,18 @@ 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"/> + android:layout_margin="5dp" + android:textOff="" + android:textOn=""/> + android:layout_margin="5dp" + android:textOff="" + android:textOn=""/> + android:layout_margin="5dp" + android:textOff="" + android:textOn=""/> + android:layout_margin="5dp" + android:textOff="" + android:textOn=""/> + android:layout_margin="5dp" + android:textOff="" + android:textOn=""/>