Search in sources :

Example 71 with MediaType

use of com.reprezen.kaizen.oasparser.model3.MediaType in project student-manager by SYYANI.

the class ManageCourseFragment method initCourseList.

private void initCourseList() throws IOException, JSONException {
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("cid", manageCourseFragmentBinding.manageCourseFragmentInputClassNumber.getText().toString());
    json.put("cname", manageCourseFragmentBinding.manageCourseFragmentCourseName.getText().toString());
    json.put("fuzzy", manageCourseFragmentBinding.manageCourseCheckboxIsFuzzy.isChecked());
    json.put("highBound", manageCourseFragmentBinding.manageCourseFragmentCourseCreditHigh.getText().toString());
    json.put("lowBound", manageCourseFragmentBinding.manageCourseFragmentCourseCreditLow.getText().toString());
    // Log.d(TAG, "initCourseList: "+ json.toString() );
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(JSON, json.toString());
            Request request = new Request.Builder().url("http://101.35.20.64:10086/course/findBySearch").method("POST", body).addHeader("Content-Type", "application/json").build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (response.isSuccessful()) {
                ArrayList<CourseTeacher> tlist = null;
                try {
                    // Log.d(TAG, "run: "+response.body().string());
                    tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<CourseTeacher>>() {
                    }.getType());
                    // mlist.addAll(tlist);
                    manageCourseViewModel.setMutableLiveData_course_list(tlist);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) CourseTeacher(com.shu.studentmanager.entity.CourseTeacher) Response(okhttp3.Response) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) MediaType(okhttp3.MediaType) RequestBody(okhttp3.RequestBody)

Example 72 with MediaType

use of com.reprezen.kaizen.oasparser.model3.MediaType in project student-manager by SYYANI.

the class ManageStudentFragment method initStudentList.

private void initStudentList() throws JSONException, IOException {
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("sid", manageStudentFragmentBinding.manageStudentFragmentStudentNumberSid.getText().toString());
    json.put("sname", manageStudentFragmentBinding.manageStudentFragmentStudentNameSname.getText().toString());
    json.put("password", manageStudentFragmentBinding.manageStudentCheckboxIsFuzzy.isChecked());
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(JSON, json.toString());
            Request request = new Request.Builder().url("http://101.35.20.64:10086/student/findBySearch").method("POST", body).addHeader("Content-Type", "application/json").build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (response.isSuccessful()) {
                ArrayList<Student> tlist = null;
                try {
                    // Log.d(TAG, "run: "+response.body().string());
                    tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<Student>>() {
                    }.getType());
                    // mlist.addAll(tlist);
                    manageStudentViewModel.setMutableLiveData_manage_student_list(tlist);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) Student(com.shu.studentmanager.entity.Student) Response(okhttp3.Response) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) MediaType(okhttp3.MediaType) RequestBody(okhttp3.RequestBody)

Example 73 with MediaType

use of com.reprezen.kaizen.oasparser.model3.MediaType in project student-manager by SYYANI.

the class OpenClassFragment method initCourseList.

private void initCourseList() throws IOException, JSONException {
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("cid", openClassFragmentBinding.openClassFragmentInputClassNumber.getText().toString());
    json.put("cname", openClassFragmentBinding.openClassFragmentCourseName.getText().toString());
    json.put("fuzzy", openClassFragmentBinding.checkboxIsFuzzy.isChecked());
    json.put("highBound", openClassFragmentBinding.openClassFragmentCourseCreditHigh.getText().toString());
    json.put("lowBound", openClassFragmentBinding.openClassFragmentCourseCreditLow.getText().toString());
    // Log.d(TAG, "initCourseList: "+ json.toString() );
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(JSON, json.toString());
            Request request = new Request.Builder().url("http://101.35.20.64:10086/course/findBySearch").method("POST", body).addHeader("Content-Type", "application/json").build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (response.isSuccessful()) {
                ArrayList<CourseTeacher> tlist = null;
                try {
                    // Log.d(TAG, "run: "+response.body().string());
                    tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<CourseTeacher>>() {
                    }.getType());
                    // mlist.addAll(tlist);
                    openClassViewModel.setMutableLiveData_course_list(tlist);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) CourseTeacher(com.shu.studentmanager.entity.CourseTeacher) Response(okhttp3.Response) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) MediaType(okhttp3.MediaType) RequestBody(okhttp3.RequestBody)

Example 74 with MediaType

use of com.reprezen.kaizen.oasparser.model3.MediaType in project student-manager by SYYANI.

the class ScoreManageFragment method initScoreList.

private void initScoreList() throws JSONException {
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    StudentManagerApplication application = (StudentManagerApplication) getActivity().getApplication();
    JSONObject json = new JSONObject();
    json.put("cid", scoreManageFragmentBinding.scoreManageFragmentCourseNumber.getText().toString());
    json.put("cname", scoreManageFragmentBinding.scoreManageFragmentCourseName.getText().toString());
    json.put("cFuzzy", scoreManageFragmentBinding.scoreManageFragmentFuzzySearch.isChecked());
    json.put("highBound", scoreManageFragmentBinding.scoreManageFragmentHigh.getText().toString());
    json.put("lowBound", scoreManageFragmentBinding.scoreManageFragmentLow.getText().toString());
    json.put("sid", scoreManageFragmentBinding.scoreManageFragmentStudentNumber.getText().toString());
    json.put("sname", scoreManageFragmentBinding.scoreManageFragmentStudentName.getText().toString());
    json.put("sFuzzy", scoreManageFragmentBinding.scoreManageFragmentFuzzySearch.isChecked());
    json.put("term", scoreManageFragmentBinding.scoreManageTermSelect.getText().toString());
    if (application.getName().equals("admin")) {
        json.put("tid", "");
        json.put("tname", "");
    } else {
        json.put("tid", application.getId());
        json.put("tname", application.getName());
    }
    json.put("tFuzzy", scoreManageFragmentBinding.scoreManageFragmentFuzzySearch.isChecked());
    // Log.d(TAG, "initCourseList: "+ json.toString() );
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(JSON, json.toString());
            Request request = new Request.Builder().url("http://101.35.20.64:10086/SCT/findBySearch").method("POST", body).addHeader("Content-Type", "application/json").build();
            Response response;
            try {
                response = client.newCall(request).execute();
                if (response.isSuccessful()) {
                    ArrayList<ScoreTeacher> slist = null;
                    slist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<ScoreTeacher>>() {
                    }.getType());
                    scoreManageViewModel.setMutableLiveData_score_list(slist);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) ScoreTeacher(com.shu.studentmanager.entity.ScoreTeacher) Response(okhttp3.Response) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) MediaType(okhttp3.MediaType) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) RequestBody(okhttp3.RequestBody)

Example 75 with MediaType

use of com.reprezen.kaizen.oasparser.model3.MediaType in project student-manager by SYYANI.

the class StudentCourseSelectAdapter method enSureSelect.

private void enSureSelect(CourseStudent courseStudent) throws JSONException {
    Log.d(TAG, "enSureSelect: select course");
    StudentManagerApplication application = (StudentManagerApplication) context.getApplicationContext();
    Toast.makeText(context, "选课成功", Toast.LENGTH_SHORT);
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("cid", courseStudent.getCid());
    json.put("tid", courseStudent.getTid());
    json.put("sid", application.getId());
    json.put("term", application.getCurrentTerm());
    Log.d(TAG, "initCourseSelectList: " + json.toString());
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(JSON, json.toString());
            Request request = new Request.Builder().url("http://101.35.20.64:10086/SCT/save").method("POST", body).addHeader("Content-Type", "application/json").build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (response.isSuccessful()) {
                ArrayList<CourseStudent> tlist = null;
                try {
                    Log.d(TAG, "run: " + response.body().string());
                // tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<CourseStudent>>() {}.getType());
                // mlist.addAll(tlist);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) JSONObject(org.json.JSONObject) Request(okhttp3.Request) ArrayList(java.util.ArrayList) MediaType(okhttp3.MediaType) IOException(java.io.IOException) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) RequestBody(okhttp3.RequestBody)

Aggregations

MediaType (okhttp3.MediaType)297 RequestBody (okhttp3.RequestBody)186 Request (okhttp3.Request)179 Response (okhttp3.Response)158 IOException (java.io.IOException)137 ResponseBody (okhttp3.ResponseBody)71 OkHttpClient (okhttp3.OkHttpClient)68 Charset (java.nio.charset.Charset)50 Buffer (okio.Buffer)50 Headers (okhttp3.Headers)48 JSONObject (org.json.JSONObject)38 BufferedSource (okio.BufferedSource)36 MultipartBody (okhttp3.MultipartBody)34 HttpUrl (okhttp3.HttpUrl)30 Map (java.util.Map)24 BufferedSink (okio.BufferedSink)23 File (java.io.File)22 InputStream (java.io.InputStream)21 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21