Search in sources :

Example 6 with Section

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

the class CanvasContextTest method toAPIString_TestSection.

@Test
public void toAPIString_TestSection() {
    Section section = new Section();
    section.setId(1234);
    assertEquals("/sections/1234", section.toAPIString());
}
Also used : Section(com.instructure.canvasapi2.models.Section) Test(org.junit.Test)

Example 7 with Section

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

the class SectionManager method getSection.

public static void getSection(long courseId, long sectionId, StatusCallback<Section> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        SectionAPI.getSection(courseId, sectionId, adapter, callback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 8 with Section

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

the class SectionManager method getAllSectionsForCourse.

public static void getAllSectionsForCourse(long courseId, StatusCallback<List<Section>> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).withShouldIgnoreToken(false).build();
        final RestBuilder adapter = new RestBuilder(callback);
        StatusCallback<List<Section>> depaginatedCallback = new ExhaustiveListCallback<Section>(callback) {

            @Override
            public void getNextPage(@NonNull StatusCallback<List<Section>> callback, @NonNull String nextUrl, boolean isCached) {
                SectionAPI.getNextPageSections(nextUrl, adapter, callback, params);
            }
        };
        adapter.setStatusCallback(depaginatedCallback);
        SectionAPI.getFirstSectionsForCourse(courseId, adapter, depaginatedCallback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) NonNull(android.support.annotation.NonNull) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) List(java.util.List) StatusCallback(com.instructure.canvasapi2.StatusCallback) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback) Section(com.instructure.canvasapi2.models.Section)

Example 9 with Section

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

the class PublishPollActivity method hasSectionUnpublished.

// check to see if there is a section that is unpublished
private boolean hasSectionUnpublished() {
    // we'll just use the count of open polls vs. sections in the course. If there are the same
    // amount of sections and sessions, then there all the poll sessions are published
    int sectionCount = sectionAdapter.getCount();
    if (sectionAdapter.getItem(0).getId() == Long.MIN_VALUE) {
        sectionCount--;
    }
    // now get the open sessions for this course
    int courseSessionCount = 0;
    if (currentCourse != null) {
        for (PollSession pollSession : openPollSessions) {
            if (pollSession.getCourse_id() == currentCourse.getId()) {
                courseSessionCount++;
            }
        }
    }
    if (courseSessionCount < sectionCount) {
        return true;
    } else {
        return false;
    }
}
Also used : PollSession(com.instructure.canvasapi2.models.PollSession)

Example 10 with Section

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

the class PublishPollActivity method setupSectionAdapter.

private void setupSectionAdapter(List<Section> sectionList) {
    sectionLabel.setVisibility(View.VISIBLE);
    sectionAdapter = new SectionListAdapter(this, android.R.layout.simple_spinner_dropdown_item, sectionList);
    if (openPollSessions.size() < sectionList.size() && sectionList.size() > 1 && !sectionList.get(0).getName().equals(getString(R.string.entireCourse))) {
        Section section = new Section();
        section.setId(Long.MIN_VALUE);
        section.setName(getString(R.string.entireCourse));
        sectionList.add(0, section);
        sectionAdapter.notifyDataSetChanged();
    }
    sectionListView.setAdapter(sectionAdapter);
    sectionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            SparseBooleanArray checked = sectionListView.getCheckedItemPositions();
            if (!hasSectionUnpublished()) {
                // we don't want them to check anything
                sectionListView.setItemChecked(position, false);
                AppMsg.makeText(PublishPollActivity.this, getString(R.string.alreadyPublishedForSection), AppMsg.STYLE_WARNING).show();
                return;
            }
            if (checked.get(0) && position == 0) {
                // if the "entire course" is selected, select all the other items
                for (int i = 0; i < sectionListView.getCount(); i++) {
                    if (!isSectionPublished((Section) sectionListView.getItemAtPosition(i))) {
                        sectionListView.setItemChecked(i, true);
                    }
                }
            } else if (!checked.get(0) && position == 0) {
                // if the "entire course" is unselected, unselect everything
                for (int i = 0; i < sectionListView.getCount(); i++) {
                    if (!isSectionPublished((Section) sectionListView.getItemAtPosition(i))) {
                        sectionListView.setItemChecked(i, false);
                    }
                }
            } else if (position != 0) {
                // If they aren't all selected, unselect "entire course"
                for (int i = 1; i < sectionListView.getCount(); i++) {
                    if (!checked.get(i)) {
                        sectionListView.setItemChecked(0, false);
                    }
                    // if a session is already published for a section, don't let them select it again
                    if (isSectionPublished((Section) sectionListView.getItemAtPosition(i))) {
                        sectionListView.setItemChecked(i, false);
                        if (i == position) {
                            AppMsg.makeText(PublishPollActivity.this, getString(R.string.alreadyPublishedForSection), AppMsg.STYLE_WARNING).show();
                        }
                    }
                }
            }
        }
    });
    // if there is only one section, auto select it
    if (sectionListView.getAdapter().getCount() == 1) {
        sectionListView.setItemChecked(0, true);
    }
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray) AdapterView(android.widget.AdapterView) Section(com.instructure.canvasapi2.models.Section) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView)

Aggregations

Section (com.instructure.canvasapi2.models.Section)7 PollSession (com.instructure.canvasapi2.models.PollSession)3 Test (org.junit.Test)3 NonNull (android.support.annotation.NonNull)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 CheckedTextView (android.widget.CheckedTextView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 StatusCallback (com.instructure.canvasapi2.StatusCallback)2 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)2 RestParams (com.instructure.canvasapi2.builders.RestParams)2 PollSessionResponse (com.instructure.canvasapi2.models.PollSessionResponse)2 ApiType (com.instructure.canvasapi2.utils.ApiType)2 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)2 List (java.util.List)2 Response (retrofit2.Response)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1