Search in sources :

Example 1 with DiscussionTopicHeader

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

the class DetailViewActivity method routeFromIntent.

private void routeFromIntent(Intent intent) {
    DETAIL_FRAGMENT fragmentType = (DETAIL_FRAGMENT) intent.getExtras().getSerializable(Const.FRAGMENT_TYPE);
    if (fragmentType != null) {
        Student student = intent.getExtras().getParcelable(Const.STUDENT);
        switch(fragmentType) {
            case WEEK:
                Student user = intent.getExtras().getParcelable(Const.USER);
                Course course = (Course) intent.getExtras().getSerializable(Const.COURSE);
                if (user != null && course != null) {
                    addFragment(CourseWeekFragment.newInstance(user, course));
                }
                break;
            case ASSIGNMENT:
                Assignment assignment = intent.getExtras().getParcelable(Const.ASSIGNMENT);
                String courseName = intent.getExtras().getString(Const.NAME);
                addFragment(AssignmentFragment.newInstance(assignment, courseName, student), false);
                break;
            case ANNOUNCEMENT:
                DiscussionTopicHeader announcement = intent.getExtras().getParcelable(Const.ANNOUNCEMENT);
                String announcementCourseName = intent.getExtras().getString(Const.NAME);
                addFragment(AnnouncementFragment.newInstance(announcement, announcementCourseName, student), false);
                break;
            case EVENT:
                ScheduleItem item = intent.getExtras().getParcelable(Const.SCHEDULE_ITEM);
                addFragment(EventFragment.newInstance(item, student), false);
                break;
            case SYLLABUS:
                Course syllabusCourse = (Course) intent.getExtras().getSerializable(Const.COURSE);
                addFragment(CourseSyllabusFragment.newInstance(syllabusCourse, student), false);
                break;
            case ACCOUNT_NOTIFICATION:
                AccountNotification accountNotification = intent.getExtras().getParcelable(Const.ACCOUNT_NOTIFICATION);
                addFragment(AccountNotificationFragment.newInstance(accountNotification, student));
        }
    }
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) Student(com.instructure.canvasapi2.models.Student) Course(com.instructure.canvasapi2.models.Course) AccountNotification(com.instructure.canvasapi2.models.AccountNotification)

Example 2 with DiscussionTopicHeader

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

the class ComposeNewDiscussionFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    applyTheme();
    if (isAnnouncement) {
        threaded.setVisibility(View.GONE);
        publish.setVisibility(View.GONE);
    } else {
        threaded.setVisibility(View.VISIBLE);
        publish.setVisibility(View.VISIBLE);
    }
    if (getCanvasContext() instanceof Course) {
        Course course = (Course) getCanvasContext();
        if (((course.isStudent() && !course.isTeacher()))) {
            // Students cannot post draft discussions.
            // We force it checked for when the api call is made and hide the option.
            publish.setChecked(true);
            publish.setVisibility(View.GONE);
        }
    } else if (getCanvasContext() instanceof Group) {
        // Always publish for groups
        publish.setChecked(true);
        publish.setVisibility(View.GONE);
    }
    setUpCallback();
    if (discussionTopicHeader != null) {
        populateViewsWithData();
    } else {
        // clear out views
        initViews();
    }
}
Also used : ViewGroup(android.view.ViewGroup) Group(com.instructure.canvasapi2.models.Group) Course(com.instructure.canvasapi2.models.Course)

Example 3 with DiscussionTopicHeader

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

the class DiscussionListRecyclerAdapterTest method testAreContentsTheSame_SameTitle.

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

Example 4 with DiscussionTopicHeader

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

the class DiscussionListRecyclerAdapterTest method testCompare_bothHaveNullDates.

// region Compare tests
@Test
public void testCompare_bothHaveNullDates() {
    DiscussionTopicHeader onlyTitle1 = new DiscussionTopicHeader();
    onlyTitle1.setTitle("discussion1");
    DiscussionTopicHeader onlyTitle2 = new DiscussionTopicHeader();
    onlyTitle2.setTitle("discussion2");
    assertEquals(-1, mAdapter.createItemCallback().compare("", onlyTitle1, onlyTitle2));
    assertEquals(1, mAdapter.createItemCallback().compare("", onlyTitle2, onlyTitle1));
    assertEquals(0, mAdapter.createItemCallback().compare("", onlyTitle1, onlyTitle1));
}
Also used : DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) Test(org.junit.Test)

Example 5 with DiscussionTopicHeader

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

the class DiscussionListRecyclerAdapterTest method testCompare_oneNullDatePostedAt.

@Test
public void testCompare_oneNullDatePostedAt() {
    DiscussionTopicHeader d1 = new DiscussionTopicHeader();
    d1.setTitle("discussion1");
    DateTime dateTime2 = new DateTime("2014-12-29");
    Date date = new Date(dateTime2.getMilliseconds(TimeZone.getDefault()));
    d1.setPostedAt(APIHelper.dateToString(date));
    DiscussionTopicHeader d2 = new DiscussionTopicHeader();
    d2.setTitle("discussion2");
    assertEquals(-1, mAdapter.createItemCallback().compare("", d1, d2));
    assertEquals(1, mAdapter.createItemCallback().compare("", d2, d1));
    assertEquals(0, mAdapter.createItemCallback().compare("", d1, d1));
}
Also used : DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) DateTime(hirondelle.date4j.DateTime) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)24 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)20 RestParams (com.instructure.canvasapi2.builders.RestParams)19 Test (org.junit.Test)17 List (java.util.List)6 StatusCallback (com.instructure.canvasapi2.StatusCallback)4 DiscussionEntry (com.instructure.canvasapi2.models.DiscussionEntry)4 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 DateTime (hirondelle.date4j.DateTime)3 Date (java.util.Date)3 Assignment (com.instructure.canvasapi2.models.Assignment)2 Course (com.instructure.canvasapi2.models.Course)2 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)2 Response (okhttp3.Response)2 ViewGroup (android.view.ViewGroup)1 AccountNotification (com.instructure.canvasapi2.models.AccountNotification)1 Group (com.instructure.canvasapi2.models.Group)1 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)1