Search in sources :

Example 1 with MoodleModuleContent

use of ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent 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);
    }
}
Also used : MimeTypeMap(android.webkit.MimeTypeMap) Uri(android.net.Uri) DownloadManager(android.app.DownloadManager) MoodleModuleContent(ca.etsmtl.applets.etsmobile.model.Moodle.MoodleModuleContent) ExpandableListMoodleSectionAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListMoodleSectionAdapter) ExpandableListView(android.widget.ExpandableListView) MoodleCoreModule(ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCoreModule) MoodleCoreCourse(ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCoreCourse) MoodleCoreCourses(ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCoreCourses) SpringAndroidSpiceRequest(com.octo.android.robospice.request.springandroid.SpringAndroidSpiceRequest) Intent(android.content.Intent) View(android.view.View) ExpandableListView(android.widget.ExpandableListView)

Example 2 with MoodleModuleContent

use of ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent in project ETSMobile-Android2 by ApplETS.

the class MoodleCourseDetailsFragment method displayMoodleCourses.

/**
 * Takes moodle courses for a given class and displays them in an {@link ExpandableListView}
 *
 * @param courses the list of courses for a given class
 */
private void displayMoodleCourses(List<MoodleCoreCourse> courses) {
    // create empty data
    HashMap<HeaderText, Object[]> listDataSectionName = new HashMap<>();
    List<HeaderText> listDataHeader = new ArrayList<>();
    int positionSection = 0;
    for (MoodleCoreCourse coreCourse : courses) {
        ArrayList<MoodleCoreModule> listMoodleLinkModules = new ArrayList<>();
        ArrayList<MoodleModuleContent> listMoodleResourceContents = new ArrayList<>();
        for (MoodleCoreModule coreModule : coreCourse.getModules()) {
            ArrayList<MoodleModuleContent> contents = coreModule.getContents();
            switch(coreModule.getModname()) {
                case "folder":
                    if (contents != null)
                        listMoodleResourceContents.addAll(contents);
                    break;
                case "url":
                case "forum":
                    listMoodleLinkModules.add(coreModule);
                    break;
                case "resource":
                    if (contents != null)
                        listMoodleResourceContents.addAll(contents);
                    break;
            }
        }
        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, (headerText1, headerText2) -> Integer.compare(headerText1.getPosition(), headerText2.getPosition()));
    if (getActivity() == null)
        return;
    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) {
                MoodleCourseDetailsFragmentPermissionsDispatcher.downloadMoodleObjectWithPermissionCheck(MoodleCourseDetailsFragment.this, (MoodleModuleContent) object);
            }
            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();
                }
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);
            }
            return true;
        }
    });
    onRequestSuccess(null);
}
Also used : MoodleCoreModule(ca.etsmtl.applets.etsmobile.model.moodle.MoodleCoreModule) HashMap(java.util.HashMap) MoodleCoreCourse(ca.etsmtl.applets.etsmobile.model.moodle.MoodleCoreCourse) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) ExpandableListView(android.widget.ExpandableListView) MoodleModuleContent(ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent) ExpandableListMoodleSectionAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListMoodleSectionAdapter) ExpandableListView(android.widget.ExpandableListView)

Example 3 with MoodleModuleContent

use of ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent in project ETSMobile-Android2 by ApplETS.

the class ExpandableListMoodleSectionAdapter method getChildView.

@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    Object object = getChild(groupPosition, childPosition);
    if (convertView == null) {
        convertView = this.__infalInflater.inflate(R.layout.list_item, null);
    }
    String childText = "";
    if (object instanceof MoodleModuleContent) {
        MoodleModuleContent moodleModuleContent = (MoodleModuleContent) object;
        childText = moodleModuleContent.getFilename();
    }
    if (object instanceof MoodleCoreModule) {
        MoodleCoreModule moodleCoreModule = (MoodleCoreModule) object;
        childText = moodleCoreModule.getName();
    }
    TextView text = (TextView) convertView.findViewById(R.id.lblListItem);
    text.setText(childText);
    return convertView;
}
Also used : MoodleModuleContent(ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent) MoodleCoreModule(ca.etsmtl.applets.etsmobile.model.moodle.MoodleCoreModule) TextView(android.widget.TextView)

Example 4 with MoodleModuleContent

use of ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent in project ETSMobile-Android2 by ApplETS.

the class ExpandableListMoodleAdapter method getChildView.

@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item, null);
    }
    String childText = "";
    TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
    Object object = getChild(groupPosition, childPosition);
    if (object instanceof MoodleModuleContent) {
        MoodleModuleContent moodleModuleContent = (MoodleModuleContent) getChild(groupPosition, childPosition);
        childText = moodleModuleContent.getFilename();
    }
    if (object instanceof MoodleCoreModule) {
        MoodleCoreModule moodleCoreModule = (MoodleCoreModule) getChild(groupPosition, childPosition);
        childText = moodleCoreModule.getName();
    }
    txtListChild.setText(childText);
    return convertView;
}
Also used : MoodleModuleContent(ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent) MoodleCoreModule(ca.etsmtl.applets.etsmobile.model.moodle.MoodleCoreModule) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView)

Aggregations

MoodleCoreModule (ca.etsmtl.applets.etsmobile.model.moodle.MoodleCoreModule)3 MoodleModuleContent (ca.etsmtl.applets.etsmobile.model.moodle.MoodleModuleContent)3 Intent (android.content.Intent)2 View (android.view.View)2 ExpandableListView (android.widget.ExpandableListView)2 TextView (android.widget.TextView)2 ExpandableListMoodleSectionAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListMoodleSectionAdapter)2 DownloadManager (android.app.DownloadManager)1 Uri (android.net.Uri)1 LayoutInflater (android.view.LayoutInflater)1 MimeTypeMap (android.webkit.MimeTypeMap)1 MoodleCoreCourse (ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCoreCourse)1 MoodleCoreCourses (ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCoreCourses)1 MoodleCoreModule (ca.etsmtl.applets.etsmobile.model.Moodle.MoodleCoreModule)1 MoodleModuleContent (ca.etsmtl.applets.etsmobile.model.Moodle.MoodleModuleContent)1 MoodleCoreCourse (ca.etsmtl.applets.etsmobile.model.moodle.MoodleCoreCourse)1 SpringAndroidSpiceRequest (com.octo.android.robospice.request.springandroid.SpringAndroidSpiceRequest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1