Search in sources :

Example 36 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class CourseOutlineFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Bundle bundle = getArguments();
    courseData = (EnrolledCoursesResponse) bundle.getSerializable(Router.EXTRA_COURSE_DATA);
    courseComponentId = bundle.getString(Router.EXTRA_COURSE_COMPONENT_ID);
    isVideoMode = bundle.getBoolean(Router.EXTRA_IS_VIDEOS_MODE);
    isOnCourseOutline = bundle.getBoolean(Router.EXTRA_IS_ON_COURSE_OUTLINE);
    View view = inflater.inflate(R.layout.fragment_course_outline, container, false);
    listView = (ListView) view.findViewById(R.id.outline_list);
    initializeAdapter();
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (deleteMode != null) {
                deleteMode.finish();
            }
            listView.clearChoices();
            CourseOutlineAdapter.SectionRow row = adapter.getItem(position);
            CourseComponent comp = row.component;
            if (comp.isContainer()) {
                environment.getRouter().showCourseContainerOutline(CourseOutlineFragment.this, REQUEST_SHOW_COURSE_UNIT_DETAIL, courseData, comp.getId(), null, isVideoMode);
            } else {
                environment.getRouter().showCourseUnitDetail(CourseOutlineFragment.this, REQUEST_SHOW_COURSE_UNIT_DETAIL, courseData, comp.getId(), isVideoMode);
            }
        }
    });
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (((IconImageView) view.findViewById(R.id.bulk_download)).getIcon() == FontAwesomeIcons.fa_check) {
                ((AppCompatActivity) getActivity()).startSupportActionMode(deleteModelCallback);
                listView.setItemChecked(position, true);
                return true;
            }
            return false;
        }
    });
    return view;
}
Also used : IconImageView(com.joanzapata.iconify.widget.IconImageView) Bundle(android.os.Bundle) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) IconImageView(com.joanzapata.iconify.widget.IconImageView) TextView(android.widget.TextView) ListView(android.widget.ListView) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 37 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class CourseOutlineAdapter method getRowViewForContainer.

private void getRowViewForContainer(ViewHolder holder, final SectionRow row) {
    final CourseComponent component = row.component;
    String courseId = component.getCourseId();
    BlockPath path = component.getPath();
    // FIXME - we should add a new column in database - pathinfo.
    // then do the string match to get the record
    String chapterId = path.get(1) == null ? "" : path.get(1).getDisplayName();
    String sequentialId = path.get(2) == null ? "" : path.get(2).getDisplayName();
    holder.rowTitle.setText(component.getDisplayName());
    holder.numOfVideoAndDownloadArea.setVisibility(View.VISIBLE);
    if (component.isGraded()) {
        holder.bulkDownload.setVisibility(View.INVISIBLE);
        holder.rowSubtitlePanel.setVisibility(View.VISIBLE);
        holder.rowSubtitleIcon.setVisibility(View.VISIBLE);
        holder.rowSubtitle.setVisibility(View.VISIBLE);
        holder.rowSubtitle.setText(component.getFormat());
        holder.rowSubtitle.setTypeface(holder.rowSubtitle.getTypeface(), Typeface.BOLD);
        holder.rowSubtitle.setTextColor(ContextCompat.getColor(context, R.color.edx_brand_gray_dark));
        if (!TextUtils.isEmpty(component.getDueDate())) {
            try {
                holder.rowSubtitleDueDate.setText(getFormattedDueDate(component.getDueDate()));
                holder.rowSubtitleDueDate.setVisibility(View.VISIBLE);
            } catch (IllegalArgumentException e) {
                logger.error(e);
            }
        }
    }
    final int totalDownloadableVideos = component.getDownloadableVideosCount();
    // support video download for video type excluding the ones only viewable on web
    if (totalDownloadableVideos == 0) {
        holder.numOfVideoAndDownloadArea.setVisibility(View.GONE);
    } else {
        holder.bulkDownload.setVisibility(View.VISIBLE);
        holder.noOfVideos.setVisibility(View.VISIBLE);
        holder.noOfVideos.setText("" + totalDownloadableVideos);
        Integer downloadedCount = dbStore.getDownloadedVideosCountForSection(courseId, chapterId, sequentialId, null);
        if (downloadedCount == totalDownloadableVideos) {
            holder.noOfVideos.setVisibility(View.VISIBLE);
            setRowStateOnDownload(holder, DownloadEntry.DownloadedState.DOWNLOADED, null);
        } else if (dbStore.getDownloadingVideosCountForSection(courseId, chapterId, sequentialId, null) + downloadedCount == totalDownloadableVideos) {
            holder.noOfVideos.setVisibility(View.GONE);
            setRowStateOnDownload(holder, DownloadEntry.DownloadedState.DOWNLOADING, new View.OnClickListener() {

                @Override
                public void onClick(View downloadView) {
                    mDownloadListener.viewDownloadsStatus();
                }
            });
        } else {
            holder.noOfVideos.setVisibility(View.VISIBLE);
            setRowStateOnDownload(holder, DownloadEntry.DownloadedState.ONLINE, new View.OnClickListener() {

                @Override
                public void onClick(View downloadView) {
                    mDownloadListener.download(component.getVideos());
                }
            });
        }
    }
}
Also used : BlockPath(org.edx.mobile.model.course.BlockPath) View(android.view.View) IconImageView(com.joanzapata.iconify.widget.IconImageView) TextView(android.widget.TextView) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 38 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class NewCourseOutlineFragment method onLoadFinished.

@Override
public void onLoadFinished(Loader<AsyncTaskResult<CourseComponent>> loader, AsyncTaskResult<CourseComponent> result) {
    final CourseComponent courseComponent = result.getResult();
    if (courseComponent != null) {
        // Course data exist in persistable cache
        loadData(validateCourseComponent(courseComponent));
        loadingIndicator.setVisibility(View.GONE);
        // Send a server call in background for refreshed data
        getCourseComponentFromServer(false);
    } else {
        // Course data is neither available in app session cache nor available in persistable cache
        getCourseComponentFromServer(true);
    }
}
Also used : CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 39 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class NewCourseOutlineFragment method showLastAccessedView.

@Override
public void showLastAccessedView(String lastAccessedSubSectionId, String courseId, View view) {
    if (getActivity() == null)
        return;
    if (NetworkUtil.isConnected(getContext())) {
        if (courseId != null && lastAccessedSubSectionId != null) {
            CourseComponent lastAccessComponent = courseManager.getComponentByIdFromAppLevelCache(courseId, lastAccessedSubSectionId);
            if (lastAccessComponent != null) {
                if (!lastAccessComponent.isContainer()) {
                    // getting subsection
                    if (lastAccessComponent.getParent() != null)
                        lastAccessComponent = lastAccessComponent.getParent();
                    // now getting section
                    if (lastAccessComponent.getParent() != null) {
                        lastAccessComponent = lastAccessComponent.getParent();
                    }
                }
                // to be the course root component itself, then we don't need to show it
                if (!lastAccessComponent.getId().equals(courseId)) {
                    final CourseComponent finalLastAccessComponent = lastAccessComponent;
                    adapter.addLastAccessedView(finalLastAccessComponent, new View.OnClickListener() {

                        long lastClickTime = 0;

                        @Override
                        public void onClick(View v) {
                            // This has been used so that if user clicks continuously on the screen,
                            // two activities should not be opened
                            long currentTime = SystemClock.elapsedRealtime();
                            if (currentTime - lastClickTime > 1000) {
                                lastClickTime = currentTime;
                                environment.getRouter().showCourseContainerOutline(getActivity(), courseData, finalLastAccessComponent.getId());
                            }
                        }
                    });
                }
            }
        }
    }
}
Also used : View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) IconImageView(com.joanzapata.iconify.widget.IconImageView) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 40 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class NewCourseOutlineFragment method getCourseComponentFromServer.

public void getCourseComponentFromServer(boolean showProgress) {
    final TaskProgressCallback progressCallback = showProgress ? new TaskProgressCallback.ProgressViewController(loadingIndicator) : null;
    final String courseId = courseData.getCourse().getId();
    getHierarchyCall = courseApi.getCourseStructureWithoutStale(courseId);
    getHierarchyCall.enqueue(new CourseAPI.GetCourseStructureCallback(getActivity(), courseId, progressCallback, errorNotification, null, this) {

        @Override
        protected void onResponse(@NonNull final CourseComponent courseComponent) {
            courseManager.addCourseDataInAppLevelCache(courseId, courseComponent);
            loadData(validateCourseComponent(courseComponent));
        }

        @Override
        protected void onFailure(@NonNull Throwable error) {
            super.onFailure(error);
            if (error instanceof CourseContentNotValidException) {
                errorNotification.showError(getContext(), error);
                logger.error(error, true);
            }
        }

        @Override
        protected void onFinish() {
            if (!EventBus.getDefault().isRegistered(NewCourseOutlineFragment.this)) {
                EventBus.getDefault().registerSticky(NewCourseOutlineFragment.this);
            }
        }
    });
}
Also used : TaskProgressCallback(org.edx.mobile.view.common.TaskProgressCallback) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent) CourseAPI(org.edx.mobile.course.CourseAPI)

Aggregations

CourseComponent (org.edx.mobile.model.course.CourseComponent)43 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)10 ArrayList (java.util.ArrayList)9 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)9 Bundle (android.os.Bundle)8 BlockPath (org.edx.mobile.model.course.BlockPath)8 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)8 Test (org.junit.Test)7 View (android.view.View)6 IBlock (org.edx.mobile.model.course.IBlock)6 Intent (android.content.Intent)5 NonNull (android.support.annotation.NonNull)5 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)5 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)5 TextView (android.widget.TextView)4 IconImageView (com.joanzapata.iconify.widget.IconImageView)4 LinkedHashMap (java.util.LinkedHashMap)4 Fragment (android.support.v4.app.Fragment)3 HashMap (java.util.HashMap)3 CourseContentNotValidException (org.edx.mobile.exception.CourseContentNotValidException)3