Search in sources :

Example 1 with ScheduleServiceImpl

use of com.remswork.project.alice.service.impl.ScheduleServiceImpl in project classify-system by anverliedoit.

the class SliderScheduleFragment method setSchedule.

public void setSchedule(final int id) {
    switch(id) {
        case schedule_today_rb:
            new Thread(new Runnable() {

                @Override
                public void run() {
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            txtMsgNoContent.setVisibility(View.INVISIBLE);
                        }
                    });
                    try {
                        final List<Schedule> newSchedules = new ArrayList<>();
                        final TeacherHelper teacherHelper = new TeacherHelper(getContext());
                        if (teacherHelper.loadUser().get() != null) {
                            try {
                                for (Schedule schedule : new ScheduleServiceImpl().getScheduleListByTeacherId(teacherHelper.loadUser().get().getId())) newSchedules.add(schedule);
                            } catch (ScheduleException e) {
                                e.printStackTrace();
                            }
                        }
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                int size = scheduleAdapter.getItemCount();
                                for (int i = 0; i < size; i++) {
                                    if (scheduleList.size() > 0) {
                                        scheduleList.remove(0);
                                        scheduleAdapter.notifyItemRemoved(0);
                                    }
                                }
                                ScheduleHelper scheduleHelper = new ScheduleHelper();
                                int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
                                for (Schedule schedule : newSchedules) {
                                    if (scheduleHelper.dayInNumber(schedule.getDay()) == day) {
                                        scheduleList.add(schedule);
                                        scheduleAdapter.notifyItemRangeInserted(0, scheduleList.size());
                                    }
                                }
                                progressBar.setVisibility(View.INVISIBLE);
                                if (scheduleList.size() < 1)
                                    txtMsgNoContent.setVisibility(View.VISIBLE);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            break;
        case schedule_tomorrow_rb:
            new Thread(new Runnable() {

                @Override
                public void run() {
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            txtMsgNoContent.setVisibility(View.INVISIBLE);
                        }
                    });
                    try {
                        final List<Schedule> newSchedules = new ArrayList<>();
                        final TeacherHelper teacherHelper = new TeacherHelper(getContext());
                        if (teacherHelper.loadUser().get() != null) {
                            try {
                                for (Schedule schedule : new ScheduleServiceImpl().getScheduleListByTeacherId(teacherHelper.loadUser().get().getId())) newSchedules.add(schedule);
                            } catch (ScheduleException e) {
                                e.printStackTrace();
                            }
                        }
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                int size = scheduleAdapter.getItemCount();
                                for (int i = 0; i < size; i++) {
                                    if (scheduleList.size() > 0) {
                                        scheduleList.remove(0);
                                        scheduleAdapter.notifyItemRemoved(0);
                                    }
                                }
                                ScheduleHelper scheduleHelper = new ScheduleHelper();
                                int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) + 1;
                                for (Schedule schedule : newSchedules) {
                                    if (scheduleHelper.dayInNumber(schedule.getDay()) == day) {
                                        scheduleList.add(schedule);
                                        scheduleAdapter.notifyItemRangeInserted(0, scheduleList.size());
                                    }
                                }
                                progressBar.setVisibility(View.INVISIBLE);
                                if (scheduleList.size() < 1)
                                    txtMsgNoContent.setVisibility(View.VISIBLE);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            break;
        default:
            new Thread(new Runnable() {

                @Override
                public void run() {
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            txtMsgNoContent.setVisibility(View.INVISIBLE);
                        }
                    });
                    try {
                        final List<Schedule> newSchedules = new ArrayList<>();
                        final TeacherHelper teacherHelper = new TeacherHelper(getContext());
                        if (teacherHelper.loadUser().get() != null) {
                            try {
                                for (Schedule schedule : new ScheduleServiceImpl().getScheduleListByTeacherId(teacherHelper.loadUser().get().getId())) newSchedules.add(schedule);
                            } catch (ScheduleException e) {
                                e.printStackTrace();
                            }
                        }
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                int size = scheduleAdapter.getItemCount();
                                for (int i = 0; i < size; i++) {
                                    if (scheduleList.size() > 0) {
                                        scheduleList.remove(0);
                                        scheduleAdapter.notifyItemRemoved(0);
                                    }
                                }
                                for (Schedule schedule : newSchedules) {
                                    scheduleList.add(schedule);
                                    scheduleAdapter.notifyItemRangeInserted(0, scheduleList.size());
                                }
                                progressBar.setVisibility(View.INVISIBLE);
                                if (scheduleList.size() < 1)
                                    txtMsgNoContent.setVisibility(View.VISIBLE);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            break;
    }
}
Also used : ScheduleServiceImpl(com.remswork.project.alice.service.impl.ScheduleServiceImpl) ScheduleHelper(com.lieverandiver.thesisproject.helper.ScheduleHelper) Schedule(com.remswork.project.alice.model.Schedule) ArrayList(java.util.ArrayList) TeacherHelper(com.lieverandiver.thesisproject.helper.TeacherHelper) ScheduleException(com.remswork.project.alice.exception.ScheduleException) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Aggregations

ScheduleHelper (com.lieverandiver.thesisproject.helper.ScheduleHelper)1 TeacherHelper (com.lieverandiver.thesisproject.helper.TeacherHelper)1 ScheduleException (com.remswork.project.alice.exception.ScheduleException)1 Schedule (com.remswork.project.alice.model.Schedule)1 ScheduleServiceImpl (com.remswork.project.alice.service.impl.ScheduleServiceImpl)1 ArrayList (java.util.ArrayList)1