Search in sources :

Example 6 with ModuleItem

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

the class CourseModuleProgressionFragment method getCurrentModuleItem.

/**
 * Iterate through the items to find the module item at the given position.  The module items are
 * an arrayList of arrayLists, so there isn't a built in way to get the moduleItem that we need.
 *
 * We sometimes want the overall position of the module item, but the data structure that we have
 * is an arrayList of arrayLists, so we don't know which module item is the 9th module item without
 * going through the arrayLists and counting.
 * @param position
 * @return
 */
private ModuleItem getCurrentModuleItem(int position) {
    ModuleItem moduleItem = null;
    int modulePos = 0;
    for (int i = 0; i < items.size(); i++) {
        if (position < items.get(i).size() + modulePos) {
            moduleItem = items.get(i).get(position - modulePos);
            if (moduleItem == null) {
                continue;
            }
            break;
        }
        modulePos += items.get(i).size();
    }
    return moduleItem;
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem)

Example 7 with ModuleItem

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

the class CourseModuleProgressionFragment method getParamForBookmark.

@Override
@NonNull
public HashMap<String, String> getParamForBookmark() {
    ModuleItem item = getCurrentModuleItem(currentPos);
    Uri uri = Uri.parse(item.getUrl());
    if (uri != null) {
        List<String> params = uri.getPathSegments();
        // get the last 2 segments for the type and type_id
        if (params.size() > 2) {
            String itemType = params.get(params.size() - 2);
            String itemTypeId = params.get(params.size() - 1);
            HashMap<String, String> map = super.getParamForBookmark();
            map.put(Param.MODULE_TYPE_SLASH_ID, itemType + "/" + itemTypeId);
            map.put(Param.MODULE_ITEM_ID, Long.toString(item.getId()));
            return map;
        }
    }
    return super.getParamForBookmark();
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull)

Example 8 with ModuleItem

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

the class ModuleListRecyclerAdapterTest method testAreContentsTheSame_DiffModule.

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

Example 9 with ModuleItem

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

the class ModuleUtilityTest method testGetFragment_externalurl_externaltool.

@Test
public void testGetFragment_externalurl_externaltool() {
    String url = "https://instructure.com";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("ExternalUrl");
    moduleItem.setId(4567);
    moduleItem.setTitle("Hello");
    moduleItem.setHtml_url(url);
    Course course = new Course();
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.INTERNAL_URL, "https://instructure.com?display=borderless");
    expectedBundle.putString(Const.ACTION_BAR_TITLE, "Hello");
    expectedBundle.putBoolean(Const.AUTHENTICATE, true);
    expectedBundle.putBoolean(com.instructure.pandautils.utils.Const.IS_EXTERNAL_TOOL, true);
    expectedBundle.putBoolean(com.instructure.pandautils.utils.Const.IS_UNSUPPORTED_FEATURE, true);
    ParentFragment parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(InternalWebviewFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
    // test external tool type
    moduleItem.setType("ExternalTool");
    parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(InternalWebviewFragment.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 10 with ModuleItem

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

the class ModuleUtilityTest method testGetFragment_quiz.

@Test
public void testGetFragment_quiz() {
    String url = "https://mobile.canvas.net/api/v1/courses/222/quizzes/123456789";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("Quiz");
    moduleItem.setId(4567);
    moduleItem.setUrl(url);
    Course course = new Course();
    String htmlUrl = "https://mobile.canvas.net/courses/222/quizzes/123456789";
    String apiUrl = "courses/222/quizzes/123456789";
    moduleItem.setHtml_url(htmlUrl);
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.URL, htmlUrl);
    expectedBundle.putString(Const.API_URL, apiUrl);
    ParentFragment parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(ModuleQuizDecider.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)

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