Search in sources :

Example 26 with Student

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

the class StudentViewActivity method configureUserCarousel.

private void configureUserCarousel() {
    mCarouselViewPager = (ViewPager) findViewById(R.id.carouselPager);
    mCarouselAdapter = new CarouselPagerAdapter(this);
    mCarouselViewPager.addOnPageChangeListener(this);
    mCarouselViewPager.setPageTransformer(true, new CarouselTransformer());
    if (getIntent().getExtras().getParcelableArrayList(Const.USER) != null) {
        ArrayList<Student> students = getIntent().getExtras().getParcelableArrayList(Const.USER);
        if (students != null && students.size() > 0) {
            mCarouselAdapter.clear();
            mCarouselViewPager.setOffscreenPageLimit(students.size());
            mCarouselAdapter.addAll(students);
        }
    }
    mCarouselViewPager.post(new Runnable() {

        @Override
        public void run() {
            mCarouselViewPager.setAdapter(mCarouselAdapter);
            // Use this to set the offset for the viewpager
            int childWidth = (int) getResources().getDimension(R.dimen.carousel_avatar_size);
            double factor = 1.30;
            if (getResources().getBoolean(R.bool.isTablet)) {
                // adjust for tablets so the student's icons are closer together
                factor = 1.15;
            }
            double width = (mCarouselViewPager.getWidth() / factor) + (childWidth / 2);
            int truncWidth = (int) width;
            mCarouselViewPager.setPageMargin(-truncWidth);
            if (mCarouselAdapter.getCount() > 1) {
                Prefs prefs = new Prefs(StudentViewActivity.this, com.instructure.parentapp.util.Const.CANVAS_PARENT_SP);
                int pos = prefs.load(Const.POSITION, mCarouselAdapter.getCount() / 2);
                mCarouselViewPager.setCurrentItem(pos);
                onPageSelected(pos);
            } else if (mCarouselAdapter.getCount() == 1) {
                // need to call onPageSelected so that it shows the user's name
                onPageSelected(0);
            }
        }
    });
}
Also used : CarouselTransformer(com.instructure.parentapp.util.CarouselTransformer) CarouselPagerAdapter(com.instructure.parentapp.adapter.CarouselPagerAdapter) Student(com.instructure.canvasapi2.models.Student) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) Prefs(com.instructure.pandautils.utils.Prefs)

Example 27 with Student

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

the class UserManager_Test method getStudentsForParentAirwolf.

public static void getStudentsForParentAirwolf(String airwolfDomain, RestBuilder adapter, RestParams params, String parentId, StatusCallback<List<Student>> callback) {
    adapter.setStatusCallback(callback);
    Response response = new Response.Builder().code(200).message("success").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "success".getBytes())).addHeader("content-type", "application/json").build();
    retrofit2.Response response1 = retrofit2.Response.success(response);
    callback.onResponse(response1, new LinkHeaders(), ApiType.API);
}
Also used : Response(okhttp3.Response) ParentResponse(com.instructure.canvasapi2.models.ParentResponse) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 28 with Student

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

the class CourseTest method isObserver_noObserverEnrollment.

@Test
public void isObserver_noObserverEnrollment() {
    Course course = new Course();
    Enrollment enrollment = new Enrollment();
    enrollment.setType("student");
    ArrayList<Enrollment> enrollments = new ArrayList<>();
    enrollments.add(enrollment);
    course.setEnrollments(enrollments);
    assertEquals(false, course.isObserver());
}
Also used : ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 29 with Student

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

the class CourseTest method courseGrade_currentScoreMGP.

@Test
public void courseGrade_currentScoreMGP() {
    Course course = new Course();
    course.setHasGradingPeriods(true);
    double currentScore = 96.0;
    double finalScore = 47.0;
    Enrollment enrollment = new Enrollment();
    enrollment.setType("student");
    enrollment.setCurrentGradingPeriodId(27);
    enrollment.setMultipleGradingPeriodsEnabled(true);
    enrollment.setCurrentPeriodComputedCurrentScore(currentScore);
    enrollment.setCurrentPeriodComputedFinalScore(finalScore);
    ArrayList<Enrollment> enrollments = new ArrayList<>();
    enrollments.add(enrollment);
    course.setEnrollments(enrollments);
    assertTrue(course.getCourseGrade(false).getCurrentScore() == currentScore);
}
Also used : ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 30 with Student

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

the class CourseTest method courseHasNoCurrentGrade.

@Test
public void courseHasNoCurrentGrade() {
    Course course = new Course();
    Enrollment enrollment = new Enrollment();
    enrollment.setType("student");
    enrollment.setComputedCurrentGrade("");
    enrollment.setComputedCurrentScore(null);
    ArrayList<Enrollment> enrollments = new ArrayList<>();
    enrollments.add(enrollment);
    course.setEnrollments(enrollments);
    assertTrue(course.getCourseGrade(false).getNoCurrentGrade());
}
Also used : ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Aggregations

Enrollment (com.instructure.canvasapi2.models.Enrollment)24 Course (com.instructure.canvasapi2.models.Course)23 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 Student (com.instructure.canvasapi2.models.Student)6 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)6 ApiPrefs (com.instructure.canvasapi2.utils.ApiPrefs)4 ApiType (com.instructure.canvasapi2.utils.ApiType)4 Prefs (com.instructure.pandautils.utils.Prefs)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)3 Student (models.Student)3 Before (org.junit.Before)3 NonNull (android.support.annotation.NonNull)2 StatusCallback (com.instructure.canvasapi2.StatusCallback)2 BlockedStudentResponse (com.instructure.canvasapi2.models.BlockedStudentResponse)2 MismatchedRegionResponse (com.instructure.canvasapi2.models.MismatchedRegionResponse)2 ParentResponse (com.instructure.canvasapi2.models.ParentResponse)2 RevokedTokenResponse (com.instructure.canvasapi2.models.RevokedTokenResponse)2 Response (okhttp3.Response)2