use of ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCoreCourses in project ETSMobile-Android2 by ApplETS.
the class MoodleCourseDetailsFragment method onRequestSuccess.
@Override
public void onRequestSuccess(Object o) {
if (o instanceof MoodleCoreCourses) {
MoodleCoreCourses moodleCoreCourses = (MoodleCoreCourses) o;
// create empty data
listDataSectionName = new HashMap<HeaderText, Object[]>();
listDataHeader = new ArrayList<HeaderText>();
int positionSection = 0;
for (MoodleCoreCourse coreCourse : moodleCoreCourses) {
listMoodleLinkModules = new ArrayList<MoodleCoreModule>();
listMoodleResourceContents = new ArrayList<MoodleModuleContent>();
for (MoodleCoreModule coreModule : coreCourse.getModules()) {
if (coreModule.getModname().equals("folder")) {
if (coreModule.getContents() != null)
listMoodleResourceContents.addAll(coreModule.getContents());
} else if (coreModule.getModname().equals("url") || coreModule.getModname().equals("forum")) {
listMoodleLinkModules.add(coreModule);
} else if (coreModule.getModname().equals("resource")) {
listMoodleResourceContents.addAll(coreModule.getContents());
}
}
Object[] finalArray = ArrayUtils.addAll(listMoodleLinkModules.toArray(), listMoodleResourceContents.toArray());
if (finalArray.length != 0)
listDataSectionName.put(new HeaderText(coreCourse.getName(), positionSection), finalArray);
positionSection++;
}
listDataHeader.addAll(listDataSectionName.keySet());
Collections.sort(listDataHeader, new Comparator<HeaderText>() {
@Override
public int compare(HeaderText headerText1, HeaderText headerText2) {
if (headerText1.getPosition() < headerText2.getPosition()) {
return -1;
} else if (headerText1.getPosition() == headerText2.getPosition()) {
return 0;
} else {
return 1;
}
}
});
expandableListMoodleAdapter = new ExpandableListMoodleSectionAdapter(getActivity(), listDataHeader, listDataSectionName);
expListView.setAdapter(expandableListMoodleAdapter);
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Object object = expandableListMoodleAdapter.getChild(groupPosition, childPosition);
if (object instanceof MoodleModuleContent) {
MoodleModuleContent item = (MoodleModuleContent) object;
String url = item.getFileurl() + "&token=" + ApplicationManager.userCredentials.getMoodleToken();
Uri uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, item.getFilename());
// r.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
MimeTypeMap mimetype = MimeTypeMap.getSingleton();
String extension = FilenameUtils.getExtension(item.getFilename());
request.setMimeType(mimetype.getMimeTypeFromExtension(extension));
dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
enqueue = dm.enqueue(request);
AnalyticsHelper.getInstance(getActivity()).sendActionEvent(getClass().getSimpleName(), TELECHARGE_FICHIER_MOODLE);
}
if (object instanceof MoodleCoreModule) {
MoodleCoreModule item = (MoodleCoreModule) object;
String url = "";
if (item.getModname().equals("url")) {
url = item.getContents().get(0).getFileurl();
} else {
url = item.getUrl();
}
AnalyticsHelper.getInstance(getActivity()).sendActionEvent(getClass().getSimpleName(), CONSULTE_PAGE_MOODLE);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
return true;
}
});
super.onRequestSuccess(null);
}
}
Aggregations