Search in sources :

Example 6 with Student

use of models.Student in project tutorials by eugenp.

the class StudentController method update.

public Result update() {
    JsonNode json = request().body().asJson();
    if (json == null) {
        return badRequest(Util.createResponse("Expecting Json data", false));
    }
    Student student = StudentStore.getInstance().updateStudent(Json.fromJson(json, Student.class));
    if (student == null) {
        return notFound(Util.createResponse("Student not found", false));
    }
    JsonNode jsonObject = Json.toJson(student);
    return ok(Util.createResponse(jsonObject, true));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Student(models.Student)

Example 7 with Student

use of 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 8 with Student

use of models.Student in project tutorials by eugenp.

the class StudentController method listStudents.

public Result listStudents() {
    Set<Student> result = StudentStore.getInstance().getAllStudents();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonData = mapper.convertValue(result, JsonNode.class);
    return ok(Util.createResponse(jsonData, true));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Student(models.Student) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with Student

use of models.Student in project tutorials by eugenp.

the class StudentController method create.

public Result create() {
    JsonNode json = request().body().asJson();
    if (json == null) {
        return badRequest(Util.createResponse("Expecting Json data", false));
    }
    Student student = StudentStore.getInstance().addStudent(Json.fromJson(json, Student.class));
    JsonNode jsonObject = Json.toJson(student);
    return created(Util.createResponse(jsonObject, true));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Student(models.Student)

Aggregations

Student (com.instructure.canvasapi2.models.Student)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Course (com.instructure.canvasapi2.models.Course)3 Student (models.Student)3 Before (org.junit.Before)3 ApiPrefs (com.instructure.canvasapi2.utils.ApiPrefs)2 Prefs (com.instructure.pandautils.utils.Prefs)2 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StatusCallback (com.instructure.canvasapi2.StatusCallback)1 AccountNotification (com.instructure.canvasapi2.models.AccountNotification)1 Alert (com.instructure.canvasapi2.models.Alert)1 Assignment (com.instructure.canvasapi2.models.Assignment)1 BlockedStudentResponse (com.instructure.canvasapi2.models.BlockedStudentResponse)1 DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)1 MismatchedRegionResponse (com.instructure.canvasapi2.models.MismatchedRegionResponse)1 RevokedTokenResponse (com.instructure.canvasapi2.models.RevokedTokenResponse)1 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)1