Search in sources :

Example 6 with StudentManagerApplication

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.activity_main);
    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    Log.d(TAG, "onCreate: " + bundle.getString("UserKind"));
    user_kind_string = bundle.getString("UserKind");
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    toolbar = findViewById(R.id.main_toolbar);
    setSupportActionBar(toolbar);
    drawerLayout = findViewById(R.id.drawer_layout);
    navigationView = findViewById(R.id.nav_view);
    Menu menu = navigationView.getMenu();
    if (user_kind_string.equals("student")) {
        Log.d(TAG, "onCreate: " + user_kind_string);
        menu.removeGroup(R.id.teacher_menu_group);
        menu.removeGroup(R.id.admin_menu_group);
    } else if (user_kind_string.equals("teacher")) {
        StudentManagerApplication application = (StudentManagerApplication) getApplication();
        if (application.getName().equals("admin")) {
            menu.removeGroup(R.id.student_menu_group);
            menu.removeGroup(R.id.teacher_menu_group);
        } else {
            menu.removeGroup(R.id.student_menu_group);
            menu.removeGroup(R.id.admin_menu_group);
        }
    }
    NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
    NavController navController = navHostFragment.getNavController();
    NavigationUI.setupWithNavController(navigationView, navController);
    NavigationUI.onNavDestinationSelected(menu.getItem(0), navController);
    navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {

        @Override
        public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
            toolbar.setTitle(destination.getLabel());
        // Toast.makeText(getApplicationContext(), destination.getLabel(), Toast.LENGTH_SHORT).show();
        }
    });
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.openNavDrawer, R.string.closeNavDrawer);
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();
    initUi();
    handler_main_activity = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            if (msg.what == RequestConstant.REQUEST_SUCCESS) {
                Snackbar snackbar = Snackbar.make(findViewById(R.id.move_linear_openclass), "操作成功", Snackbar.LENGTH_SHORT);
                snackbar.show();
            } else if (msg.what == RequestConstant.REQUEST_FAILURE) {
                Snackbar snackbar = Snackbar.make(findViewById(R.id.move_linear_openclass), "操作失败,请联系管理员", Snackbar.LENGTH_SHORT);
                snackbar.show();
            }
        }
    };
}
Also used : NavDestination(androidx.navigation.NavDestination) OnDestinationChangedListener(androidx.navigation.NavController.OnDestinationChangedListener) Message(android.os.Message) Bundle(android.os.Bundle) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) NavController(androidx.navigation.NavController) Handler(android.os.Handler) Intent(android.content.Intent) Menu(android.view.Menu) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) NavHostFragment(androidx.navigation.fragment.NavHostFragment) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 7 with StudentManagerApplication

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

the class CourseOpenAdapter method enSureOpen.

private void enSureOpen(CourseTeacher courseTeacher) {
    Log.d(TAG, "enSureOpen: " + courseTeacher.toString());
    StudentManagerApplication application = (StudentManagerApplication) context.getApplicationContext();
    String url = "http://101.35.20.64:10086/courseTeacher/insert/" + courseTeacher.getCid() + "/" + 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();
                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 8 with StudentManagerApplication

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

the class CourseOpenedAdapter method enSureDelete.

private void enSureDelete(CourseStudent courseStudent) {
    Log.d(TAG, "enSureDelete: select course");
    Log.d(TAG, "enSureDelete: " + courseStudent.toString());
    StudentManagerApplication application = (StudentManagerApplication) context.getApplicationContext();
    String url = "http://101.35.20.64:10086/course/deleteById/" + courseStudent.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 9 with StudentManagerApplication

use of com.shu.studentmanager.StudentManagerApplication 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)

Example 10 with StudentManagerApplication

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

the class LoginActivity method load_current_term.

private void load_current_term() throws IOException {
    OkHttpClient client = new OkHttpClient().newBuilder().build();
    Request request = new Request.Builder().url("http://101.35.20.64:10086/info/getCurrentTerm").method("GET", null).build();
    Response response = client.newCall(request).execute();
    if (response.isSuccessful()) {
        // Log.d(TAG, "run: "+response.body().string());
        // Boolean forbidCourseSelection = Boolean.parseBoolean(response.body().string());
        StudentManagerApplication application = (StudentManagerApplication) getApplication();
        application.setCurrentTerm(response.body().string());
    }
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication)

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