use of ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCourse in project ETSMobile-Android2 by ApplETS.
the class MoodleCoursesAdapter method getView.
@SuppressLint("DefaultLocale")
@Override
public View getView(final int position, View view, ViewGroup parent) {
ViewHolder holder;
if (view != null) {
holder = (ViewHolder) view.getTag();
} else {
holder = new ViewHolder();
}
switch(getItemViewType(position)) {
case TYPE_COURSE:
view = inflater.inflate(R.layout.row_moodle_course, parent, false);
final MoodleCourse item = getItem(position);
holder.tvCourseName = (TextView) view.findViewById(R.id.tv_moodle_course_name);
holder.tvCourseSigle = (TextView) view.findViewById(R.id.tv_moodle_course_sigle);
// Extracts course and group
Pattern pattern = Pattern.compile("([A-Z]{3,3}\\d{3,3}(-.[^ ]*)?)");
Matcher matcher = pattern.matcher(item.getFullname());
if (matcher.find())
holder.tvCourseSigle.setText(matcher.group(1));
else {
holder.tvCourseSigle.setText(item.getFullname());
view.setTag(holder);
break;
}
//Extracts course's full name and session
pattern = Pattern.compile("(?:[^ ]* )(.*)");
matcher = pattern.matcher(item.getFullname());
if (matcher.find())
holder.tvCourseName.setText(matcher.group(1).replace("(", "{").split("\\{")[0]);
else {
holder.tvCourseName.setText(item.getFullname());
}
view.setTag(holder);
break;
case TYPE_SEPARATOR:
view = inflater.inflate(R.layout.list_separator_moodle, parent, false);
holder.tvCourseSeperator = (TextView) view.findViewById(R.id.textViewSeparator);
holder.tvCourseSeperator.setText(getItem(position).getFullname());
view.setTag(holder);
break;
}
return view;
}
use of ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCourse in project ETSMobile-Android2 by ApplETS.
the class MoodleFragment method onRequestSuccess.
@Override
public void onRequestSuccess(Object o) {
try {
if (o instanceof MoodleToken) {
MoodleToken moodleToken = (MoodleToken) o;
SecurePreferences securePreferences = new SecurePreferences(getActivity());
securePreferences.edit().putString(UserCredentials.MOODLE_TOKEN, moodleToken.getToken()).commit();
ApplicationManager.userCredentials.setMoodleToken(moodleToken.getToken());
if (moodleToken.getToken().equals("")) {
throw new Exception("Impossible de se connecter");
}
queryMoodleProfile(moodleToken);
}
if (o instanceof MoodleProfile) {
MoodleProfile moodleProfile = (MoodleProfile) o;
queryMoodleCourses(moodleProfile);
}
if (o instanceof MoodleCourses) {
MoodleCourses moodleCourses = (MoodleCourses) o;
moodleCoursesAdapter = new MoodleCoursesAdapter(getActivity(), R.layout.row_moodle_course, this);
Collections.sort(moodleCourses, new CourseComparator());
// To get the most current semester first
Collections.reverse(moodleCourses);
String semesterString;
List<String> semesterList = new ArrayList<>();
for (MoodleCourse moodleCourse : moodleCourses) {
if (moodleCourse.getFullname().matches("(.*)([AÉH](\\d){4})(.*)"))
semesterString = moodleCourse.getFullname().replace("(", "{").split("\\{")[1].replace(")", "");
else
semesterString = null;
semesterString = convertSemesterString(semesterString);
if (!semesterList.contains(semesterString)) {
semesterList.add(semesterString);
MoodleCourse courseSemesterSeparator = new MoodleCourse();
courseSemesterSeparator.setCourseSemester(semesterString);
moodleCoursesAdapter.addSectionHeader(courseSemesterSeparator);
moodleCoursesAdapter.addCourse(moodleCourse);
} else
moodleCoursesAdapter.addCourse(moodleCourse);
}
moodleCoursesListView.setAdapter(moodleCoursesAdapter);
moodleCoursesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MoodleCourse moodleCourse = (MoodleCourse) parent.getItemAtPosition(position);
if (moodleCourse.getId() != MoodleCourse.IS_SEMESTER) {
Intent i = new Intent(getActivity(), MoodleCourseActivity.class);
i.putExtra("idCours", moodleCourse.getId());
i.putExtra("nameCours", moodleCourse.getShortname());
getActivity().startActivity(i);
}
}
});
super.onRequestSuccess(null);
}
} catch (Exception e) {
Log.w("MoodleFragment", "Exception caught in onRequestSuccess: " + e);
if (getActivity() != null)
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
Aggregations