use of ca.dal.cs.softeng.database.Course in project CSCI3130 by T-Caines.
the class CourseManager method search.
public ArrayList<Course> search(String input, int start, int end) {
ArrayList<Course> stringSearch = searchByString(input);
ArrayList<Course> search = new ArrayList<Course>();
for (Course c : stringSearch) {
if (c.timeStart >= start && c.timeEnd <= end && !search.contains(c))
search.add(c);
}
return search;
}
use of ca.dal.cs.softeng.database.Course in project CSCI3130 by T-Caines.
the class CourseViewer method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course_view);
spinner = findViewById(R.id.viewSpinner);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (spinner.getSelectedItem().toString().equals("Show All")) {
lock(true, false, false);
} else if (spinner.getSelectedItem().toString().equals("Show Non-Conflicting")) {
lock(false, true, false);
} else if (spinner.getSelectedItem().toString().equals("Show Schedule")) {
lock(false, false, true);
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
String uid = user.getUid();
mDatabase = FirebaseDatabase.getInstance().getReference().child("USERDATA").child(uid);
}
firebaseAdapter = new FirebaseListAdapter<Course>(this, Course.class, R.layout.list_view, FirebaseDatabase.getInstance().getReference("COURSE").child(ApplicationData.term.getTerm())) {
@Override
protected void populateView(View v, Course model, int position) {
TextView seats = (TextView) v.findViewById(R.id.seats);
seats.setText(String.format("%s/%s", model.enrollment, model.seatsAvailable));
TextView code = (TextView) v.findViewById(R.id.code);
code.setText(model.faculty + model.courseID);
TextView courseName = (TextView) v.findViewById(R.id.name);
courseName.setText(model.courseName);
TextView timeEnd = (TextView) v.findViewById(R.id.end);
timeEnd.setText("" + model.timeEnd);
TextView timeStart = (TextView) v.findViewById(R.id.start);
timeStart.setText("" + model.timeStart);
TextView days = (TextView) v.findViewById(R.id.days);
// TODO: Right method to convert binary 10101 -> MWF
days.setText("" + model.days);
}
};
// Create list view
listView = findViewById(R.id.list_view);
listView.setAdapter(firebaseAdapter);
switch(ApplicationData.term) {
case FALL:
RadioButton fallRB = findViewById(R.id.fall);
fallRB.setChecked(true);
break;
case WINTER:
RadioButton winterRB = findViewById(R.id.winter);
winterRB.setChecked(true);
break;
case SUMMER:
RadioButton summerRB = findViewById(R.id.summer);
summerRB.setChecked(true);
break;
}
// Set what happens when a list view item is clicked
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Grab selected item from firebase
selectedCourse = firebaseAdapter.getItem(position);
// If there is an item already selected, un-highlight
if (previousSelectedView != null) {
previousSelectedView.setBackgroundColor(getColor(R.color.defaultBackground));
}
// Used to unselect a course. Happens when you select the selected item.
if (previousSelectedView == view) {
previousSelectedView = null;
selectedCourse = null;
return;
}
// Highlight this item
view.setBackgroundColor(getColor(R.color.colorBalanced));
previousSelectedView = view;
}
});
Button addButton = findViewById(R.id.addbutton);
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedCourse == null)
return;
if (!courseManager.capReached(selectedCourse, v)) {
System.out.println("Adding failed");
}
}
});
Button dropButton = findViewById(R.id.dropbutton);
dropButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedCourse == null)
return;
if (selectedCourse.hasLab) {
courseManager.dropLabContinue(selectedCourse, v);
} else {
courseManager.confirmDrop(selectedCourse, v);
}
}
});
}
use of ca.dal.cs.softeng.database.Course in project CSCI3130 by T-Caines.
the class AddDropCourseActivityTest method dropButton.
@Test
public void dropButton() throws Exception {
main.getActivity();
dbAuth = FirebaseAuth.getInstance();
dbAuth.signInWithEmailAndPassword("test@test.ca", "password");
onView(withId(R.id.summer)).perform(click());
onView(withText("Comm Skills: Oral/Written")).perform(click());
onView(withId(R.id.addbutton)).perform(click());
String term = ApplicationData.term.getTerm();
Course firstCourse = cm.getUserInfo().get(0);
onView(withId(R.id.dropbutton)).perform(click());
onView(withText("Yes")).perform(click());
onView(withId(R.id.addbutton)).perform(click());
Course newCourse = cm.getUserInfo().get(0);
// assertEquals(firstCourse.enrollmentSummer,newCourse.enrollmentSummer);
onView(withId(R.id.dropbutton)).perform(click());
onView(withText("Yes")).perform(click());
}
use of ca.dal.cs.softeng.database.Course in project CSCI3130 by T-Caines.
the class AddDropCourseActivityTest method confirmDropCourseCancel.
/*
@Test
public void confirmDropCourseConfirm() throws Exception{
onView(withText("Comm Skills: Oral/Written")).perform(click());
onView(withId(R.id.addbutton)).perform((click()));
String term = ApplicationData.term.getTerm();
Course newCourse = cm.getUserInfo().get(0);
cm.decrement(newCourse);
onView(withId(R.id.dropbutton)).perform(click());
onView(withText("Are you sure you want to drop this class ?")).check(matches(isDisplayed()));
onView(withText("Yes")).perform(click());
onView(withText("Are you sure you want to drop this class ?")).check(doesNotExist());
assertEquals(false,cm.getUserInfo().contains(newCourse));
}
*/
@Test
public void confirmDropCourseCancel() throws Exception {
onView(withText("Comm Skills: Oral/Written")).perform(click());
onView(withId(R.id.addbutton)).perform((click()));
String term = ApplicationData.term.getTerm();
Course newCourse = cm.getUserInfo().get(0);
cm.decrement(newCourse);
onView(withId(R.id.dropbutton)).perform(click());
onView(withText("Are you sure you want to drop this class ?")).check(matches(isDisplayed()));
onView(withText("Cancel")).perform(click());
onView(withText("Are you sure you want to drop this class ?")).check(doesNotExist());
System.out.println(cm.getUserInfo());
assertEquals(true, cm.getUserInfo().contains(newCourse));
}
use of ca.dal.cs.softeng.database.Course in project CSCI3130 by T-Caines.
the class CourseManagerTest method conflictingTestTrue.
@Test
public void conflictingTestTrue() throws InterruptedException {
dbAuth = FirebaseAuth.getInstance();
dbAuth.signInWithEmailAndPassword("test@test.ca", "password");
entry = courses.get(0);
entry.timeStart = 0100;
entry.timeEnd = 0200;
ApplicationData.term = Constants.Term.FALL;
cm.addCourse(entry);
pause();
Course entry2 = entry = courses.get(3);
entry2.timeStart = 0130;
entry2.timeEnd = 0330;
assertEquals(true, cm.isConflicting(entry2));
}
Aggregations