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