Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep/store graph data in fb #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions app/src/main/java/com/mao/engage/FirebaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class FirebaseUtils {
public static HashMap<String, String> existingSections = new HashMap<>(); //K: section_name; V: section_ref;
public static HashMap<String, HashMap> sectionMap = new HashMap<>(); //K: section ref key; V: new Hashmap of MagicKeys, section_names, sectionSliders2.0
static int counter = 0; //counter for attendance [not sure if necessary]
public static ArrayList<Integer> saved_slider_vals = new ArrayList<>();


/*
Removes self (user) from local databases
Expand Down Expand Up @@ -354,29 +356,34 @@ public static void createSection(SectionSesh section) {
//Log.d("TEST", "sectionsMagicKey key: " + sectionsMagicKey.keySet() + " value: " + sectionsMagicKey.values());
FirebaseDatabase.getInstance().getReference("/MagicKeys").child("" + section.getMagic_key()).setValue(section.getRef_key());
// a Listener on a Section's user_ids to maintain local sectionSliders HashMap
createSavedSliderVals(section.ref_key);
}

/**[WIP: Deep]
// TODO: how to set saved_slider_vals array in firebase
//TODO: how to set saved_slider_vals array in firebase
public static void createSavedSliderVals(String sectionRefKey) {
mSectionRef.child(sectionRefKey).child("saved_slider_vals").setValue("50,");
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference myRef = db.getReference("/Sections").child(sectionRefKey).child("saved_slider_vals");
myRef.setValue("");
Log.d("TEST:", "Reached saved slider vals method!");
setSavedSliderValsListener(sectionRefKey);
}

// TODO: get saved_slider_vals array from firebase
//store values like this: 22, 33, 44, 55
public static ArrayList<Integer> getSavedSliderVals(String sectionRefKey) {

public static void setSavedSliderValsListener(String sectionRefKey) {
mSectionRef.child(sectionRefKey).child("saved_slider_vals").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
String values = dataSnapshot.getValue().toString();
String str[] = values.split(",");
List<String> saved_slider_vals = new ArrayList<>();
saved_slider_vals = Arrays.asList(str);
for (String s : saved_slider_vals) {
System.out.println(s);
if (values.equals("")) {
saved_slider_vals = new ArrayList<>();
} else {
String str[] = values.split(",");

List<String> temp = Arrays.asList(str);

for (String s : temp) {
saved_slider_vals.add(Integer.parseInt(s));
}
}

}
Expand All @@ -387,7 +394,11 @@ public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
return new ArrayList<Integer>();
}

public static ArrayList<Integer> getSavedSliderVals(String sectionRefKey) {
Log.d("TEST:", "Reached get saved slider vals method!");
return saved_slider_vals;
}

public static void setSavedSliderVals(String sectionRefKey, ArrayList<Integer> slider_vals) {
Expand All @@ -396,11 +407,10 @@ public static void setSavedSliderVals(String sectionRefKey, ArrayList<Integer> s
for (int i : slider_vals) {
sliderVals += i + ",";
}
Log.d("TEST", "in setSavedSliderVals" + sliderVals);
mSectionRef.child(sectionRefKey).child("saved_slider_vals").setValue(sliderVals);
}

**/


// Find SectionSesh corresponding to User's MagicWord
// Add UserID to corresponding Section's user_ids list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ sends information (magic word, section name, section ref key, and timeline data)
bundle.putString("section_name", getIntent().getStringExtra("section_name"));
mSectionRefKey = getIntent().getStringExtra("sectionRefKey");
bundle.putString("sectionRefKey", getIntent().getStringExtra("sectionRefKey"));
if(FirebaseUtils.getSavedSliderVals(mSectionRefKey) != null) {
Log.d("TEST", "reached to creating a OLD arraylist for teacher's datapoints " + FirebaseUtils.getSavedSliderVals(mSectionRefKey));
timelineData = FirebaseUtils.getSavedSliderVals(mSectionRefKey);
}
bundle.putIntegerArrayList("timelinedata", timelineData);
bundle.putString("start_time", getIntent().getStringExtra("start_time"));
bundle.putString("end_time", getIntent().getStringExtra("end_time"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,12 @@ private void retrieveData() {
mThreshold.setValueFormatter(new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
if(entry == mThreshold.getEntryForIndex(timelineData.size() - 1)) {
return "Threshold";
if(mThreshold.getEntryCount() >= timelineData.size() - 1) {
if(entry == mThreshold.getEntryForIndex(timelineData.size() - 1)) {
return "Threshold";
} else {
return "";
}
} else {
return "";
}
Expand Down Expand Up @@ -517,6 +521,28 @@ public interface OnFragmentInteractionListener {
public void onDestroyView() {
super.onDestroyView();
//[WIP: Deep] when the view is destroyed, save values to firebase, so they can be used again.
//FirebaseUtils.setSavedSliderVals(sectionRefKey, timelineData);
FirebaseUtils.setSavedSliderVals(sectionRefKey, timelineData);
}

@Override
public void onPause() {
super.onPause();
//[WIP: Deep] when the view is destroyed, save values to firebase, so they can be used again.
FirebaseUtils.setSavedSliderVals(sectionRefKey, timelineData);
}

@Override
public void onStop() {
super.onStop();
//[WIP: Deep] when the view is destroyed, save values to firebase, so they can be used again.
FirebaseUtils.setSavedSliderVals(sectionRefKey, timelineData);
}

@Override
public void onDestroy() {
super.onDestroy();
//[WIP: Deep] when the view is destroyed, save values to firebase, so they can be used again.
FirebaseUtils.setSavedSliderVals(sectionRefKey, timelineData);
}

}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_now.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:screenOrientation="portrait">

<TextView
android:id="@+id/sectionNameText"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_timeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:id="@+id/frameLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".teacherclassactivity.TimelineFragment">

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down