Search in sources :

Example 1 with Teacher

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

the class ManageTeacherFragment method setTeacherListRecycleview.

private void setTeacherListRecycleview() {
    teacher_list_recyclerview.setHasFixedSize(true);
    teacher_list_recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
    teacherAdapter = new TeacherAdapter(getActivity());
    teacher_list_recyclerview.setAdapter(teacherAdapter);
    manageTeacherViewModel.getMutableLiveData_manage_teacher_list().observe(getActivity(), new Observer<ArrayList<Teacher>>() {

        @Override
        public void onChanged(ArrayList<Teacher> teachers) {
            teacherAdapter.updateStudentList(teachers);
        }
    });
}
Also used : TeacherAdapter(com.shu.studentmanager.adpater.TeacherAdapter) ArrayList(java.util.ArrayList) Teacher(com.shu.studentmanager.entity.Teacher) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 2 with Teacher

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

the class TeacherAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull TeacherAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    if (teacherList != null && teacherList.size() > 0) {
        Teacher teacherEntity = teacherList.get(position);
        holder.teacher_id.setText(teacherEntity.getTid());
        holder.teacher_name.setText(teacherEntity.getTname());
        holder.teacher_password.setText(teacherEntity.getPassword());
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @RequiresApi(api = Build.VERSION_CODES.P)
            @Override
            public void onClick(View view) {
                showAlertDialogMode(position, holder.teacher_password);
            }
        });
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                showAlertDialoDelete(position);
                return true;
            }
        });
    }
}
Also used : Teacher(com.shu.studentmanager.entity.Teacher) RequiresApi(androidx.annotation.RequiresApi) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 3 with Teacher

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

the class ManageTeacherFragment method initTeacherList.

private void initTeacherList() throws JSONException, IOException {
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("tid", manageTeacherFragmentBinding.manageTeacherFragmentTeacherNumberTid.getText().toString());
    json.put("tname", manageTeacherFragmentBinding.manageTeacherFragmentTeacherNameTname.getText().toString());
    json.put("password", manageTeacherFragmentBinding.manageTeacherCheckboxIsFuzzy.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/teacher/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<Teacher> tlist = null;
                try {
                    // Log.d(TAG, "run: "+response.body().string());
                    tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<Teacher>>() {
                    }.getType());
                    // mlist.addAll(tlist);
                    manageTeacherViewModel.setMutableLiveData_manage_teacher_list(tlist);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Teacher(com.shu.studentmanager.entity.Teacher) Gson(com.google.gson.Gson) IOException(java.io.IOException) Response(okhttp3.Response) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) MediaType(okhttp3.MediaType) RequestBody(okhttp3.RequestBody)

Example 4 with Teacher

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

the class LoginActivity method load.

private void load(String username) throws IOException {
    String url = "http://101.35.20.64:10086/" + user_kind + "/findById/" + username;
    OkHttpClient client = new OkHttpClient().newBuilder().build();
    Request request = new Request.Builder().url(url).method("GET", null).build();
    Response response = client.newCall(request).execute();
    if (response.isSuccessful()) {
        if (user_kind == "student") {
            Student student = new Gson().fromJson(response.body().string(), Student.class);
            Log.d(TAG, "load: " + student.toString());
            StudentManagerApplication application = (StudentManagerApplication) getApplication();
            application.setId(student.getSid());
            application.setName(student.getSname());
            application.setToken(true);
            application.setType("student");
        } else if (user_kind == "teacher") {
            Teacher teacher = new Gson().fromJson(response.body().string(), Teacher.class);
            Log.d(TAG, "load: " + teacher.toString());
            StudentManagerApplication application = (StudentManagerApplication) getApplication();
            application.setId(teacher.getTid());
            application.setName(teacher.getTname());
            application.setToken(true);
            application.setType("teacher");
        }
    }
    load_select_ok();
    load_current_term();
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Teacher(com.shu.studentmanager.entity.Teacher) Gson(com.google.gson.Gson) Student(com.shu.studentmanager.entity.Student) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication)

Aggregations

Teacher (com.shu.studentmanager.entity.Teacher)4 Gson (com.google.gson.Gson)2 ArrayList (java.util.ArrayList)2 OkHttpClient (okhttp3.OkHttpClient)2 Request (okhttp3.Request)2 Response (okhttp3.Response)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 TypeToken (com.google.gson.reflect.TypeToken)1 StudentManagerApplication (com.shu.studentmanager.StudentManagerApplication)1 TeacherAdapter (com.shu.studentmanager.adpater.TeacherAdapter)1 Student (com.shu.studentmanager.entity.Student)1 IOException (java.io.IOException)1 MediaType (okhttp3.MediaType)1 RequestBody (okhttp3.RequestBody)1 JSONObject (org.json.JSONObject)1