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;
}
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();
}
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));
}
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());
}
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());
}
Aggregations