Search in sources :

Example 1 with ScoreTeacher

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

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

the class ScoreTeacherAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ScoreTeacherAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    if (scoreTeacherArrayList != null && scoreTeacherArrayList.size() > 0) {
        ScoreTeacher scoreTeacherEntity = scoreTeacherArrayList.get(position);
        holder.score_manage_study_term.setText(scoreTeacherEntity.getTerm());
        holder.score_manage_student_grade.setText(scoreTeacherEntity.getGrade());
        holder.score_manage_student_sname.setText(scoreTeacherEntity.getSname());
        holder.score_manage_student_sid.setText(scoreTeacherEntity.getSid());
        holder.score_manage_course_id_cid.setText(scoreTeacherEntity.getCid());
        holder.score_manage_course_name_cname.setText(scoreTeacherEntity.getCname());
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @RequiresApi(api = Build.VERSION_CODES.P)
            @Override
            public boolean onLongClick(View view) {
                showAlertDialog(position, holder.score_manage_student_grade);
                return true;
            }
        });
    }
}
Also used : RequiresApi(androidx.annotation.RequiresApi) ScoreTeacher(com.shu.studentmanager.entity.ScoreTeacher) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Example 3 with ScoreTeacher

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

the class ScoreManageFragment method setScoreListRecyclerview.

private void setScoreListRecyclerview() {
    score_list_recyclerview.setHasFixedSize(true);
    score_list_recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
    scoreTeacherAdapter = new ScoreTeacherAdapter(getActivity());
    score_list_recyclerview.setAdapter(scoreTeacherAdapter);
    scoreManageViewModel.getMutableLiveData_score_list().observe(getActivity(), new Observer<ArrayList<ScoreTeacher>>() {

        @Override
        public void onChanged(ArrayList<ScoreTeacher> scoreTeachers) {
            scoreTeacherAdapter.updateScoreTeacherList(scoreTeachers);
        }
    });
}
Also used : ScoreTeacherAdapter(com.shu.studentmanager.adpater.ScoreTeacherAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ScoreTeacher(com.shu.studentmanager.entity.ScoreTeacher)

Aggregations

ScoreTeacher (com.shu.studentmanager.entity.ScoreTeacher)3 ArrayList (java.util.ArrayList)2 View (android.view.View)1 TextView (android.widget.TextView)1 RequiresApi (androidx.annotation.RequiresApi)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 StudentManagerApplication (com.shu.studentmanager.StudentManagerApplication)1 ScoreTeacherAdapter (com.shu.studentmanager.adpater.ScoreTeacherAdapter)1 IOException (java.io.IOException)1 MediaType (okhttp3.MediaType)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1 Response (okhttp3.Response)1 JSONObject (org.json.JSONObject)1