Skip to content

Commit

Permalink
Change event schema & add placeholder to event dropdown
Browse files Browse the repository at this point in the history
You must now first explicitly select the event you want to check-in applicants for, this eliminates the issues from losing state by rotating the screen
  • Loading branch information
chamkank committed Jan 23, 2019
1 parent f5eb720 commit aeaa610
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/io/nwhacks/nfc/EventsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.EditText;
import android.widget.Spinner;

import com.google.common.base.CaseFormat;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
Expand Down Expand Up @@ -81,23 +82,29 @@ public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable Fi
});
}

public static String formatEventName(String event_name){
event_name = event_name.toLowerCase().replace(" ", "_");
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, event_name);
}

public void addEvent() {
String name = eventName.getText().toString();
String eventId = formatEventName(name);
if (name.length() == 0) {
MainActivity.toast(getContext(), "Invalid event name");
return;
}
Event e = new Event();
e.name = name;
FirebaseFirestore db = FirebaseFirestore.getInstance();
DocumentReference eventRef = db.collection("nfc_events").document(name);
DocumentReference eventRef = db.collection("nfc_events").document(eventId);
eventRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.getData() != null) {
MainActivity.toast(getContext(), name+" already exists");
} else {
db.collection("nfc_events").document(name).set(e)
eventRef.set(e)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/io/nwhacks/nfc/ReadFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ReadFragment extends NFCFragment {
public static final int WARNING_COLOR = 0xFFff8000;
public static final int ERROR_COLOR = 0xFFFF0000;
public static final int DEFAULT_COLOR = 0xFFFFFFFF;
public static final String EVENT_DROPDOWN_PLACEHOLDER = "Select an event...";

@Override
public View onCreateView(LayoutInflater inflater,
Expand Down Expand Up @@ -86,6 +87,7 @@ public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable Fi
}
if (queryDocumentSnapshots != null) {
arguments = new ArrayList<>();
arguments.add(EVENT_DROPDOWN_PLACEHOLDER);
for (DocumentSnapshot documentSnapshot: queryDocumentSnapshots.getDocuments()) {
Event event = documentSnapshot.toObject(Event.class);
arguments.add(event.name);
Expand All @@ -98,8 +100,13 @@ public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable Fi

@Override
public void tagDiscovered(NFCManager mgr, Intent intent) {
ArrayList<String> records = mgr.readTagFromIntent(intent);
String selectedEvent = EventsFragment.formatEventName(events.getSelectedItem().toString());
if (selectedEvent.equals(EventsFragment.formatEventName(EVENT_DROPDOWN_PLACEHOLDER))){
MainActivity.toast(getContext(), "Please select an event first.");
return;
}

ArrayList<String> records = mgr.readTagFromIntent(intent);
if (records.size() == 0) {
MainActivity.toast(getContext(), "Tag is empty or not yet formatted.");
setColor(ERROR_COLOR);
Expand Down Expand Up @@ -129,7 +136,6 @@ public void onSuccess(DocumentSnapshot documentSnapshot) {
Hacker h = documentSnapshot.toObject(Hacker.class);
name.setText(h.firstName + " " + h.lastName);
email.setText(h.email);
String selectedEvent = formatEventName(events.getSelectedItem().toString());
if (h.events == null) {
h.events = new HashMap<String, Integer>();
}
Expand Down Expand Up @@ -180,10 +186,6 @@ public Boolean onEventJoin(String id, String event_name, Integer checkInCount){
return false;
}

public String formatEventName(String event_name){
return event_name.replaceAll(" ", "_").toLowerCase();
}

private void setColor(int color) {
rootView.setBackgroundColor(color);
}
Expand Down

0 comments on commit aeaa610

Please sign in to comment.