Search in sources :

Example 1 with CourseStudent

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

the class CourseSelectFragment method initCourseSelectList.

private void initCourseSelectList() throws JSONException, IOException {
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("cid", courseSelectFragmentBinding.selectCourseFragmentInputClassNumber.getText().toString());
    json.put("cname", courseSelectFragmentBinding.selectCourseFragmentCourseName.getText().toString());
    json.put("tid", courseSelectFragmentBinding.selectCourseFragmentTeacherNumberTid.getText().toString());
    json.put("tname", courseSelectFragmentBinding.selectCourseFragmentTeacherNameTname.getText().toString());
    json.put("tFuzzy", courseSelectFragmentBinding.selectCourseCheckboxIsFuzzy.isChecked());
    json.put("cFuzzy", courseSelectFragmentBinding.selectCourseCheckboxIsFuzzy.isChecked());
    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/courseTeacher/findCourseTeacherInfo").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);
                    courseSelectViewModel.setMutableLiveData_student_select_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) Response(okhttp3.Response) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) CourseStudent(com.shu.studentmanager.entity.CourseStudent) MediaType(okhttp3.MediaType) RequestBody(okhttp3.RequestBody)

Example 2 with CourseStudent

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

the class CourseSelectFragment method setCourseSelectListRecycleview.

private void setCourseSelectListRecycleview() {
    course_select_list_recycleview.setHasFixedSize(true);
    course_select_list_recycleview.setLayoutManager(new LinearLayoutManager(getActivity()));
    studentCourseSelectAdapter = new StudentCourseSelectAdapter(getActivity());
    course_select_list_recycleview.setAdapter(studentCourseSelectAdapter);
    courseSelectViewModel.getMutableLiveData_student_select_course_list().observe(getActivity(), new Observer<ArrayList<CourseStudent>>() {

        @Override
        public void onChanged(ArrayList<CourseStudent> courseStudents) {
            studentCourseSelectAdapter.updateCourseSelectList(courseStudents);
        }
    });
}
Also used : StudentCourseSelectAdapter(com.shu.studentmanager.adpater.StudentCourseSelectAdapter) CourseStudent(com.shu.studentmanager.entity.CourseStudent) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 3 with CourseStudent

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

the class CourseOpenedAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull CourseOpenedAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    if (courseOpenedList != null && courseOpenedList.size() > 0) {
        CourseStudent courseStudentEntity = courseOpenedList.get(position);
        holder.student_opened_course_cid.setText(courseStudentEntity.getCid());
        holder.student_opened_course_cname.setText(courseStudentEntity.getCname());
        holder.student_opened_course_tid.setText(courseStudentEntity.getTid());
        holder.student_opened_course_tname.setText(courseStudentEntity.getTname());
        holder.student_opened_course_ccredit.setText(courseStudentEntity.getCcredit());
        holder.itemView.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);
                        enSureDelete(courseOpenedList.get(position));
                        courseOpenedList.remove(courseOpenedList.get(position));
                    }
                }).show();
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) CourseStudent(com.shu.studentmanager.entity.CourseStudent) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) SuppressLint(android.annotation.SuppressLint)

Example 4 with CourseStudent

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

the class StudentCourseAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull StudentCourseAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    if (courseStudentList != null && courseStudentList.size() > 0) {
        CourseStudent courseStudentEntity = courseStudentList.get(position);
        holder.student_course_cid.setText(courseStudentEntity.getCid());
        holder.student_course_cname.setText(courseStudentEntity.getCname());
        holder.student_course_tid.setText(courseStudentEntity.getTid());
        holder.student_course_tname.setText(courseStudentEntity.getTname());
        holder.student_course_ccredit.setText(courseStudentEntity.getCcredit());
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(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);
                        enSureDelete(courseStudentList.get(position));
                    }
                }).show();
                return false;
            }
        });
    } else {
        return;
    }
}
Also used : DialogInterface(android.content.DialogInterface) CourseStudent(com.shu.studentmanager.entity.CourseStudent) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) SuppressLint(android.annotation.SuppressLint)

Example 5 with CourseStudent

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

the class StudentCourseSelectAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull StudentCourseSelectAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    if (courseSelectList != null && courseSelectList.size() > 0) {
        CourseStudent courseStudentEntity = courseSelectList.get(position);
        holder.student_select_course_cid.setText(courseStudentEntity.getCid());
        holder.student_select_course_cname.setText(courseStudentEntity.getCname());
        holder.student_select_course_tid.setText(courseStudentEntity.getTid());
        holder.student_select_course_tname.setText(courseStudentEntity.getTname());
        holder.student_select_course_ccredit.setText(courseStudentEntity.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);
                        try {
                            enSureSelect(courseSelectList.get(position));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }).show();
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) CourseStudent(com.shu.studentmanager.entity.CourseStudent) JSONException(org.json.JSONException) 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

CourseStudent (com.shu.studentmanager.entity.CourseStudent)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 CourseOpenedAdapter (com.shu.studentmanager.adpater.CourseOpenedAdapter)1 StudentCourseAdapter (com.shu.studentmanager.adpater.StudentCourseAdapter)1