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();
}
}
};
}
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();
}
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();
}
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();
}
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());
}
}
Aggregations