Search in sources :

Example 1 with ModuleItem

use of com.instructure.canvasapi2.models.ModuleItem in project instructure-android by instructure.

the class ModuleBinder method bind.

public static void bind(final ModuleViewHolder holder, final ModuleObject moduleObject, final ModuleItem moduleItem, final Context context, final ModuleAdapterToFragmentCallback adapterToFragmentCallback, final boolean isSequentiallEnabled, final int courseColor, final boolean isFirstItem, final boolean isLastItem) {
    boolean isLocked = ModuleUtility.isGroupLocked(moduleObject);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            adapterToFragmentCallback.onRowClicked(moduleObject, moduleItem, holder.getAdapterPosition(), true);
        }
    });
    // Title
    holder.title.setText(moduleItem.getTitle());
    if (moduleItem.getType().equals(ModuleItem.TYPE.Locked.toString()) || moduleItem.getType().equals(ModuleItem.TYPE.ChooseAssignmentGroup.toString())) {
        holder.title.setTypeface(null, Typeface.ITALIC);
        holder.title.setTextColor(context.getResources().getColor(R.color.secondaryText));
    } else {
        holder.title.setTypeface(null, Typeface.NORMAL);
        holder.title.setTextColor(context.getResources().getColor(R.color.primaryText));
    }
    // Description
    if (moduleItem.getCompletionRequirement() != null && moduleItem.getCompletionRequirement().getType() != null) {
        setVisible(holder.description);
        holder.description.setTextColor(context.getResources().getColor(R.color.canvasTextMedium));
        String requireText = moduleItem.getCompletionRequirement().getType();
        if (requireText.equals(ModuleObject.STATE.must_submit.toString())) {
            if (moduleItem.getCompletionRequirement().isCompleted()) {
                holder.description.setText(context.getString(R.string.moduleItemSubmitted));
                holder.description.setTextColor(courseColor);
            } else {
                holder.description.setText(context.getString(R.string.moduleItemSubmit));
            }
        } else if (requireText.equals(ModuleObject.STATE.must_view.toString())) {
            if (moduleItem.getCompletionRequirement().isCompleted()) {
                holder.description.setText(context.getString(R.string.moduleItemViewed));
            } else {
                holder.description.setText(context.getString(R.string.moduleItemMustView));
            }
        } else if (requireText.equals(ModuleObject.STATE.must_contribute.toString())) {
            if (moduleItem.getCompletionRequirement().isCompleted()) {
                holder.description.setText(context.getString(R.string.moduleItemContributed));
            } else {
                holder.description.setText(context.getString(R.string.moduleItemContribute));
            }
        } else // min_score only present when type == 'min_score'
        if (requireText.equals(ModuleObject.STATE.min_score.toString())) {
            if (moduleItem.getCompletionRequirement().isCompleted()) {
                holder.description.setText(context.getString(R.string.moduleItemMinScoreMet));
            } else {
                holder.description.setText(context.getString(R.string.moduleItemMinScore) + " " + moduleItem.getCompletionRequirement().getMin_score());
            }
        } else {
            holder.description.setText("");
            setGone(holder.description);
        }
    } else {
        holder.description.setText("");
        setGone(holder.description);
    }
    // Indicator
    setGone(holder.indicator);
    if (moduleItem.getCompletionRequirement() != null && moduleItem.getCompletionRequirement().isCompleted()) {
        Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_check_white_24dp, courseColor);
        holder.indicator.setImageDrawable(drawable);
        setVisible(holder.indicator);
    }
    if (isLocked) {
        Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_lock, courseColor);
        holder.indicator.setImageDrawable(drawable);
        setVisible(holder.indicator);
    }
    // Icon
    int drawableResource = -1;
    if (moduleItem.getType().equals(ModuleItem.TYPE.Assignment.toString())) {
        drawableResource = R.drawable.vd_assignment;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.Discussion.toString())) {
        drawableResource = R.drawable.vd_discussion;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.File.toString())) {
        drawableResource = R.drawable.vd_download;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.Page.toString())) {
        drawableResource = R.drawable.vd_pages;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.SubHeader.toString())) {
        setGone(holder.icon);
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.Quiz.toString())) {
        drawableResource = R.drawable.vd_quiz;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.ExternalUrl.toString())) {
        drawableResource = R.drawable.vd_link;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.ExternalTool.toString())) {
        drawableResource = R.drawable.vd_lti;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.Locked.toString())) {
        drawableResource = R.drawable.vd_lock;
    } else if (moduleItem.getType().equals(ModuleItem.TYPE.ChooseAssignmentGroup.toString())) {
        drawableResource = R.drawable.vd_pages;
    }
    if (drawableResource == -1) {
        setGone(holder.icon);
    } else {
        Drawable drawable = ColorKeeper.getColoredDrawable(context, drawableResource, courseColor);
        holder.icon.setImageDrawable(drawable);
    }
    // Details
    ModuleContentDetails details = moduleItem.getModuleDetails();
    if (details != null) {
        boolean hasDate, hasPoints;
        if (details.getDueDate() != null) {
            holder.date.setText(DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, details.getDueDate()));
            hasDate = true;
        } else {
            holder.date.setText("");
            hasDate = false;
        }
        String points = details.getPointsPossible();
        if (!TextUtils.isEmpty(points)) {
            holder.points.setText(context.getString(R.string.totalPoints, com.instructure.canvasapi2.utils.NumberHelper.formatDecimal(Double.parseDouble(points), 2, true)));
            hasPoints = true;
        } else {
            holder.points.setText("");
            hasPoints = false;
        }
        if (!hasDate && !hasPoints) {
            setGone(holder.date);
            setGone(holder.points);
        } else {
            if (hasDate)
                setVisible(holder.date);
            else
                setInvisible(holder.date);
            if (hasPoints)
                setVisible(holder.points);
            else
                setInvisible(holder.points);
        }
    } else {
        holder.points.setText("");
        holder.date.setText("");
        setGone(holder.date);
        setGone(holder.points);
    }
    updateShadows(isFirstItem, isLastItem, holder.shadowTop, holder.shadowBottom);
}
Also used : ModuleContentDetails(com.instructure.canvasapi2.models.ModuleContentDetails) Drawable(android.graphics.drawable.Drawable) View(android.view.View)

Example 2 with ModuleItem

use of com.instructure.canvasapi2.models.ModuleItem in project instructure-android by instructure.

the class ModuleListRecyclerAdapterTest method testAreContentsTheSame_SameModule.

@Test
public void testAreContentsTheSame_SameModule() {
    ModuleItem item = new ModuleItem();
    item.setTitle("item");
    assertTrue(mAdapter.createItemCallback().areContentsTheSame(item, item));
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) Test(org.junit.Test)

Example 3 with ModuleItem

use of com.instructure.canvasapi2.models.ModuleItem in project instructure-android by instructure.

the class ModuleUtilityTest method testGetFragment_page.

@Test
public void testGetFragment_page() {
    String url = "https://mobile.canvas.net/api/v1/courses/222/pages/hello-world";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("Page");
    moduleItem.setId(4567);
    moduleItem.setUrl(url);
    Course course = new Course();
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.PAGE_NAME, "hello-world");
    ParentFragment parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(PageDetailsFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) ParentFragment(com.instructure.candroid.fragment.ParentFragment) Bundle(android.os.Bundle) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 4 with ModuleItem

use of com.instructure.canvasapi2.models.ModuleItem in project instructure-android by instructure.

the class ModuleUtilityTest method testGetFragment_file.

@Test
public void testGetFragment_file() {
    String url = "https://mobile.canvas.net/api/v1/courses/222/assignments/123456789";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("File");
    moduleItem.setId(4567);
    moduleItem.setUrl(url);
    ModuleObject moduleObject = new ModuleObject();
    moduleObject.setId(1234);
    Course course = new Course();
    String expectedUrl = "courses/222/assignments/123456789";
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.FILE_URL, expectedUrl);
    expectedBundle.putLong(Const.MODULE_ID, moduleObject.getId());
    expectedBundle.putLong(Const.ITEM_ID, moduleItem.getId());
    ParentFragment parentFragment = callGetFragment(moduleItem, course, moduleObject);
    assertNotNull(parentFragment);
    assertEquals(FileDetailsFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
    // test module object is null
    moduleObject = null;
    expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.FILE_URL, expectedUrl);
    parentFragment = callGetFragment(moduleItem, course, moduleObject);
    assertNotNull(parentFragment);
    assertEquals(FileDetailsFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) ModuleObject(com.instructure.canvasapi2.models.ModuleObject) ParentFragment(com.instructure.candroid.fragment.ParentFragment) Bundle(android.os.Bundle) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 5 with ModuleItem

use of com.instructure.canvasapi2.models.ModuleItem in project instructure-android by instructure.

the class CourseModuleProgressionFragment method updateBottomNavBarButtons.

// the bottom navigation bar has prev and next arrows that sometimes show up and sometimes don't depending
// on where the user is (on the first module item there isn't a prev button).  We also may need to update these
// dynamically when we use an async task to get the next group of module items
private void updateBottomNavBarButtons() {
    // make them visible by default
    prev.setVisibility(View.VISIBLE);
    next.setVisibility(View.VISIBLE);
    // don't want to see the previous button if we're on the first item
    if (currentPos == 0) {
        prev.setVisibility(View.INVISIBLE);
    }
    // don't show the next button if we're on the last item
    if (currentPos + 1 >= NUM_ITEMS) {
        next.setVisibility(View.INVISIBLE);
    }
    // get the fragment and update the title
    Fragment fragment = adapter.getItem(currentPos);
    ModuleItem.CompletionRequirement completionRequirement = getCurrentModuleItem(currentPos).getCompletionRequirement();
    if (completionRequirement != null && ModuleItem.MUST_VIEW.equals(completionRequirement.getType())) {
        // reload the module object to update the items. By viewing this item subsequent items may now be unlocked
        adapter.notifyDataSetChanged();
        addLockedIconIfNeeded(modules, items, groupPos, childPos);
    }
    ModuleItem moduleItem = getCurrentModuleItem(currentPos);
    updateModuleMarkDoneView(moduleItem);
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) Fragment(android.support.v4.app.Fragment)

Aggregations

ModuleItem (com.instructure.canvasapi2.models.ModuleItem)16 Test (org.junit.Test)9 Course (com.instructure.canvasapi2.models.Course)8 Bundle (android.os.Bundle)7 ParentFragment (com.instructure.candroid.fragment.ParentFragment)7 NonNull (android.support.annotation.NonNull)3 View (android.view.View)2 ModuleObject (com.instructure.canvasapi2.models.ModuleObject)2 ArrayList (java.util.ArrayList)2 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 CardView (android.support.v7.widget.CardView)1 ModuleListRecyclerAdapter (com.instructure.candroid.adapter.ModuleListRecyclerAdapter)1 ModuleAdapterToFragmentCallback (com.instructure.candroid.interfaces.ModuleAdapterToFragmentCallback)1 ModuleProgressionUtility (com.instructure.candroid.util.ModuleProgressionUtility)1 AssignmentSet (com.instructure.canvasapi2.models.AssignmentSet)1 ModuleContentDetails (com.instructure.canvasapi2.models.ModuleContentDetails)1 ApiType (com.instructure.canvasapi2.utils.ApiType)1