Search in sources :

Example 11 with StudentManagerApplication

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

the class MainActivity method initUi.

private void initUi() {
    StudentManagerApplication application = (StudentManagerApplication) getApplication();
    View header = binding.navView.getHeaderView(0);
    TextView text_user_name = header.findViewById(R.id.user_name_text);
    TextView text_user_id = header.findViewById(R.id.user_id_text);
    TextView text_current_term = header.findViewById(R.id.current_term_text);
    text_user_name.setText(application.getName());
    text_user_id.setText(application.getId());
    text_current_term.setText(application.getCurrentTerm());
}
Also used : TextView(android.widget.TextView) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) NavigationView(com.google.android.material.navigation.NavigationView) View(android.view.View) TextView(android.widget.TextView)

Example 12 with StudentManagerApplication

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

the class CourseManageAdapter method enSureDelete.

private void enSureDelete(CourseTeacher courseTeacher) {
    Log.d(TAG, "enSureDelete: " + courseTeacher.toString());
    StudentManagerApplication application = (StudentManagerApplication) context.getApplicationContext();
    String url = "http://101.35.20.64:10086/course/deleteById/" + courseTeacher.getCid();
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            Request request = new Request.Builder().url(url).method("GET", null).build();
            try {
                Response response = client.newCall(request).execute();
                if (response.isSuccessful()) {
                    // Log.d(TAG, "run: "+response.body().string());
                    Boolean insert_true = Boolean.parseBoolean(response.body().string());
                    final MainActivity mainActivity;
                    mainActivity = (MainActivity) context;
                    if (insert_true) {
                        Handler handler = mainActivity.getHandler_main_activity();
                        Message message = handler.obtainMessage();
                        message.what = RequestConstant.REQUEST_SUCCESS;
                        handler.sendMessage(message);
                    } else {
                        Handler handler = mainActivity.getHandler_main_activity();
                        Message message = handler.obtainMessage();
                        message.what = RequestConstant.REQUEST_FAILURE;
                        handler.sendMessage(message);
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Message(android.os.Message) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Request(okhttp3.Request) Handler(android.os.Handler) MainActivity(com.shu.studentmanager.activity.MainActivity) IOException(java.io.IOException) Response(okhttp3.Response) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication)

Example 13 with StudentManagerApplication

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

the class ScoreReviewFragment method initScoreReviewList.

private void initScoreReviewList() {
    StudentManagerApplication application = (StudentManagerApplication) getActivity().getApplication();
    String url = "http://101.35.20.64:10086/SCT/findBySid/" + application.getId() + "/" + application.getCurrentTerm();
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            Request request = new Request.Builder().url(url).method("GET", null).build();
            Response response;
            try {
                response = client.newCall(request).execute();
                if (response.isSuccessful()) {
                    ArrayList<Course> slist = null;
                    slist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<Course>>() {
                    }.getType());
                    scoreReviewViewModel.setMutableLiveData_score_review_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) Response(okhttp3.Response) TypeToken(com.google.gson.reflect.TypeToken) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) Course(com.shu.studentmanager.entity.Course)

Example 14 with StudentManagerApplication

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

the class StudentFragment method initStudentCourseList.

private void initStudentCourseList() throws IOException {
    StudentManagerApplication application = (StudentManagerApplication) getActivity().getApplication();
    String url = "http://101.35.20.64:10086/SCT/findBySid/" + application.getId() + "/" + application.getCurrentTerm();
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            Request request = new Request.Builder().url(url).method("GET", null).build();
            try {
                Response response = client.newCall(request).execute();
                // Log.d(TAG, "run: "+response.body().string());
                if (response.isSuccessful()) {
                    ArrayList<CourseStudent> tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<CourseStudent>>() {
                    }.getType());
                    // mlist.addAll(tlist);
                    studentViewModel.setMutableLiveData_student_course_list(tlist);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication)

Example 15 with StudentManagerApplication

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

the class StudentFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    studentViewModel = new ViewModelProvider(this).get(StudentViewModel.class);
    studentFragmentBinding = DataBindingUtil.inflate(inflater, R.layout.student_fragment, container, false);
    studentFragmentBinding.setStudentViewModel(studentViewModel);
    studentFragmentBinding.setLifecycleOwner(getActivity());
    StudentManagerApplication application = (StudentManagerApplication) getActivity().getApplication();
    studentFragmentBinding.studentFragmentStudentId.setText(application.getId());
    studentFragmentBinding.studentFragmentStudentName.setText(application.getName());
    student_course_list_recyclerview = studentFragmentBinding.studentFragmentCourseListRecycleview;
    setStudentCoureListRecycleView();
    View root = studentFragmentBinding.getRoot();
    try {
        initStudentCourseList();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return root;
// return inflater.inflate(R.layout.student_fragment, container, false);
}
Also used : IOException(java.io.IOException) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) StudentViewModel(com.shu.studentmanager.viewmodel.StudentViewModel) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

StudentManagerApplication (com.shu.studentmanager.StudentManagerApplication)16 OkHttpClient (okhttp3.OkHttpClient)11 Request (okhttp3.Request)11 Response (okhttp3.Response)11 IOException (java.io.IOException)10 Gson (com.google.gson.Gson)5 ArrayList (java.util.ArrayList)5 Handler (android.os.Handler)4 Message (android.os.Message)4 View (android.view.View)4 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)3 MainActivity (com.shu.studentmanager.activity.MainActivity)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 TypeToken (com.google.gson.reflect.TypeToken)2 MediaType (okhttp3.MediaType)2 RequestBody (okhttp3.RequestBody)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1