use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class ApiTests method testGetAnnouncement.
// TODO: Debug and fix test failure
@Ignore
@Test
public void testGetAnnouncement() throws Exception {
login();
// get a course id for this test
List<EnrolledCoursesResponse> courses = executeStrict(courseAPI.getEnrolledCourses());
assertTrue("Must have enrolled to at least one course", courses != null && courses.size() > 0);
String updatesUrl = courses.get(0).getCourse().getCourse_updates();
List<AnnouncementsModel> res = executeStrict(new TypeToken<List<AnnouncementsModel>>() {
}, okHttpClient.newCall(new Request.Builder().url(updatesUrl).get().build()));
assertTrue(res != null);
for (AnnouncementsModel r : res) {
print(r.getDate());
}
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseDashboardActivityTest method initializeTest.
/**
* {@inheritDoc}
*/
@Test
public void initializeTest() {
Intent intent = getIntent();
Bundle data = intent.getBundleExtra(Router.EXTRA_BUNDLE);
EnrolledCoursesResponse courseData = (EnrolledCoursesResponse) data.getSerializable(Router.EXTRA_COURSE_DATA);
ActivityController<? extends CourseDashboardActivity> controller = Robolectric.buildActivity(getActivityClass()).withIntent(intent);
CourseDashboardActivity activity = controller.get();
controller.create(null).postCreate(null);
Fragment fragment = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
assertNotNull(fragment);
assertThat(fragment).isInstanceOf(CourseDashboardFragment.class);
assertTrue(fragment.getRetainInstance());
Bundle args = fragment.getArguments();
assertNotNull(args);
assertEquals(courseData, args.getSerializable(CourseDashboardFragment.CourseData));
controller.resume().postResume().visible();
View fragmentView = fragment.getView();
assertNotNull(fragmentView);
// TODO: Create a separate test suite for CourseDashboardFragment views
// Test navigation to courseware
View rowsContainer = fragmentView.findViewById(R.id.dashboard_detail);
assertNotNull(rowsContainer);
assertThat(rowsContainer).isInstanceOf(ViewGroup.class);
ViewGroup rowsContainerGroup = (ViewGroup) rowsContainer;
int rowNum = 0;
View coursewareRowView = rowsContainerGroup.getChildAt(rowNum++);
assertRow(coursewareRowView, FontAwesomeIcons.fa_list_alt, R.string.courseware_title, R.string.courseware_subtitle);
if (config.isCourseVideosEnabled()) {
View videoRowView = rowsContainerGroup.getChildAt(rowNum++);
assertRow(videoRowView, FontAwesomeIcons.fa_film, R.string.videos_title, R.string.videos_subtitle);
}
if (config.isDiscussionsEnabled()) {
View discussionRowView = rowsContainerGroup.getChildAt(rowNum++);
assertRow(discussionRowView, FontAwesomeIcons.fa_comments_o, R.string.discussion_title, R.string.discussion_subtitle);
}
View handoutsRowView = rowsContainerGroup.getChildAt(rowNum++);
assertRow(handoutsRowView, FontAwesomeIcons.fa_file_text_o, R.string.handouts_title, R.string.handouts_subtitle);
View announcementRowView = rowsContainerGroup.getChildAt(rowNum++);
assertRow(announcementRowView, FontAwesomeIcons.fa_bullhorn, R.string.announcement_title, R.string.announcement_subtitle);
assertTrue(coursewareRowView.performClick());
Intent newIntent = assertNextStartedActivity(activity, CourseOutlineActivity.class);
Bundle newData = newIntent.getBundleExtra(Router.EXTRA_BUNDLE);
assertNotNull(newData);
assertEquals(courseData, newData.getSerializable(Router.EXTRA_COURSE_DATA));
// We don't seem to have one-to-one mapping between the course list and detail ids
/*assertEquals(courseData.getCourse().getId(),
newData.getString(Router.EXTRA_COURSE_COMPONENT_ID));*/
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseUnitWebViewFragmentTest method getHtmlUnit.
/**
* Method for iterating through the mock course response data, and
* returning the first video block leaf.
*
* @return The first {@link HtmlBlockModel} leaf in the mock course data
*/
private HtmlBlockModel getHtmlUnit() throws CourseContentNotValidException {
EnrolledCoursesResponse courseData;
try {
courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
String courseId = courseData.getCourse().getId();
CourseStructureV1Model model;
try {
model = executeStrict(courseAPI.getCourseStructure(courseId));
} catch (Exception e) {
throw new RuntimeException(e);
}
CourseComponent courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
List<CourseComponent> htmlBlockUnits = new ArrayList<>();
courseComponent.fetchAllLeafComponents(htmlBlockUnits, EnumSet.of(BlockType.HTML));
return (HtmlBlockModel) htmlBlockUnits.get(0);
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class OldMyCoursesListFragment method onLoadFinished.
@Override
public void onLoadFinished(Loader<AsyncTaskResult<List<EnrolledCoursesResponse>>> asyncTaskResultLoader, AsyncTaskResult<List<EnrolledCoursesResponse>> result) {
adapter.clear();
final Exception exception = result.getEx();
if (exception != null) {
if (exception instanceof AuthException) {
loginPrefs.clear();
getActivity().finish();
} else if (exception instanceof HttpStatusException) {
final HttpStatusException httpStatusException = (HttpStatusException) exception;
switch(httpStatusException.getStatusCode()) {
case HttpStatus.UNAUTHORIZED:
{
environment.getRouter().forceLogout(getContext(), environment.getAnalyticsRegistry(), environment.getNotificationDelegate());
break;
}
}
} else {
logger.error(exception);
}
errorNotification.showError(getActivity(), exception, R.string.lbl_reload, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (NetworkUtil.isConnected(getContext())) {
onRefresh();
}
}
});
} else if (result.getResult() != null) {
ArrayList<EnrolledCoursesResponse> newItems = new ArrayList<EnrolledCoursesResponse>(result.getResult());
updateDatabaseAfterDownload(newItems);
if (result.getResult().size() > 0) {
adapter.setItems(newItems);
adapter.notifyDataSetChanged();
}
if (adapter.isEmpty() && !environment.getConfig().getCourseDiscoveryConfig().isCourseDiscoveryEnabled()) {
errorNotification.showError(R.string.no_courses_to_display, FontAwesomeIcons.fa_exclamation_circle, 0, null);
binding.myCourseList.setVisibility(View.GONE);
} else {
binding.myCourseList.setVisibility(View.VISIBLE);
errorNotification.hideError();
}
}
binding.swipeContainer.setRefreshing(false);
binding.loadingIndicator.getRoot().setVisibility(View.GONE);
isInitialServerCallDone = true;
if (!(NetworkUtil.isConnected(getActivity()))) {
onOffline();
} else {
onOnline();
}
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class OldMyCoursesListFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
adapter = new MyCoursesAdapter(getActivity(), environment) {
@Override
public void onItemClicked(EnrolledCoursesResponse model) {
environment.getRouter().showCourseDashboardTabs(getActivity(), environment.getConfig(), model, false);
}
@Override
public void onAnnouncementClicked(EnrolledCoursesResponse model) {
environment.getRouter().showCourseDashboardTabs(getActivity(), environment.getConfig(), model, true);
}
};
EventBus.getDefault().register(this);
}
Aggregations