Search in sources :

Example 1 with CourseTeacher

use of com.shu.studentmanager.entity.CourseTeacher in project student-manager by SYYANI.

the class ManageCourseFragment method setCourseOpenListRecycleview.

private void setCourseOpenListRecycleview() {
    course_manage_list_recycleview.setHasFixedSize(true);
    course_manage_list_recycleview.setLayoutManager(new LinearLayoutManager(getActivity()));
    courseManageAdapter = new CourseManageAdapter(getActivity());
    course_manage_list_recycleview.setAdapter(courseManageAdapter);
    manageCourseViewModel.getMutableLiveData_course_list().observe(getActivity(), new Observer<ArrayList<CourseTeacher>>() {

        @Override
        public void onChanged(ArrayList<CourseTeacher> courseTeachers) {
            courseManageAdapter.updateCourseList(courseTeachers);
        }
    });
}
Also used : CourseManageAdapter(com.shu.studentmanager.adpater.CourseManageAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CourseTeacher(com.shu.studentmanager.entity.CourseTeacher)

Example 2 with CourseTeacher

use of com.shu.studentmanager.entity.CourseTeacher 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 3 with CourseTeacher

use of com.shu.studentmanager.entity.CourseTeacher 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 4 with CourseTeacher

use of com.shu.studentmanager.entity.CourseTeacher in project student-manager by SYYANI.

the class OpenClassFragment method setCourseOpenListRecycleview.

private void setCourseOpenListRecycleview() {
    course_open_list_recycleview.setHasFixedSize(true);
    course_open_list_recycleview.setLayoutManager(new LinearLayoutManager(getActivity()));
    courseOpenAdapter = new CourseOpenAdapter(getActivity());
    course_open_list_recycleview.setAdapter(courseOpenAdapter);
    openClassViewModel.getMutableLiveData_course_list().observe(getActivity(), new Observer<ArrayList<CourseTeacher>>() {

        @Override
        public void onChanged(ArrayList<CourseTeacher> courseTeachers) {
            courseOpenAdapter.updateCourseList(courseTeachers);
        }
    });
}
Also used : CourseOpenAdapter(com.shu.studentmanager.adpater.CourseOpenAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CourseTeacher(com.shu.studentmanager.entity.CourseTeacher)

Example 5 with CourseTeacher

use of com.shu.studentmanager.entity.CourseTeacher in project student-manager by SYYANI.

the class CourseOpenAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull CourseOpenAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    if (courseOpenList != null && courseOpenList.size() > 0) {
        CourseTeacher courseEntity = courseOpenList.get(position);
        holder.course_id_cid.setText(courseEntity.getCid());
        holder.course_name_cname.setText(courseEntity.getCname());
        holder.course_credit_ccredit.setText(courseEntity.getCcredit());
        holder.button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new MaterialAlertDialogBuilder(context).setTitle("确认").setMessage("确定开设该课程?").setNeutralButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).setPositiveButton("确认", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d(TAG, "onClick: " + which + " " + position);
                        enSureOpen(courseOpenList.get(position));
                    }
                }).show();
            }
        });
    } else {
        return;
    }
}
Also used : DialogInterface(android.content.DialogInterface) CourseTeacher(com.shu.studentmanager.entity.CourseTeacher) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) SuppressLint(android.annotation.SuppressLint)

Aggregations

CourseTeacher (com.shu.studentmanager.entity.CourseTeacher)8 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)3 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 TextView (android.widget.TextView)3 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)3 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2 IOException (java.io.IOException)2 MediaType (okhttp3.MediaType)2 OkHttpClient (okhttp3.OkHttpClient)2 Request (okhttp3.Request)2 RequestBody (okhttp3.RequestBody)2 Response (okhttp3.Response)2 JSONObject (org.json.JSONObject)2 RequiresApi (androidx.annotation.RequiresApi)1 CourseAdapter (com.shu.studentmanager.adpater.CourseAdapter)1