Search in sources :

Example 1 with Student

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

the class ManageStudentFragment method setStudentListRecycleview.

private void setStudentListRecycleview() {
    student_list_recyclerview.setHasFixedSize(true);
    student_list_recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
    studentAdapter = new StudentAdapter(getActivity());
    student_list_recyclerview.setAdapter(studentAdapter);
    manageStudentViewModel.getMutableLiveData_manage_student_list().observe(getActivity(), new Observer<ArrayList<Student>>() {

        @Override
        public void onChanged(ArrayList<Student> students) {
            studentAdapter.updateStudentList(students);
        }
    });
}
Also used : StudentAdapter(com.shu.studentmanager.adpater.StudentAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Student(com.shu.studentmanager.entity.Student)

Example 2 with Student

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

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

the class StudentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull StudentAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    if (studentList != null && studentList.size() > 0) {
        Student studentEntity = studentList.get(position);
        holder.student_id.setText(studentEntity.getSid());
        holder.student_name.setText(studentEntity.getSname());
        holder.student_password.setText(studentEntity.getPassword());
        holder.itemView.setOnClickListener(new View.OnClickListener() {

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

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

Example 4 with Student

use of com.shu.studentmanager.entity.Student 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

Student (com.shu.studentmanager.entity.Student)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 StudentAdapter (com.shu.studentmanager.adpater.StudentAdapter)1 Teacher (com.shu.studentmanager.entity.Teacher)1 IOException (java.io.IOException)1 MediaType (okhttp3.MediaType)1 RequestBody (okhttp3.RequestBody)1 JSONObject (org.json.JSONObject)1