Search in sources :

Example 11 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleViewActivity method initRView.

public void initRView(final long classId) {
    final Handler handler = new Handler(getMainLooper());
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final ClassServiceImpl classService = new ClassServiceImpl();
                final List<Schedule> scheduleList = new ArrayList<>();
                final Set<Schedule> scheduleSet = classService.getScheduleList(classId);
                for (Schedule schedule : scheduleSet) scheduleList.add(schedule);
                final ScheduleAdapter scheduleAdapter = new ScheduleAdapter(ScheduleViewActivity.this, scheduleList);
                final LinearLayoutManager layoutManager = new LinearLayoutManager(ScheduleViewActivity.this);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        recyclerView.setAdapter(scheduleAdapter);
                        recyclerView.setLayoutManager(layoutManager);
                        recyclerView.setItemAnimator(new DefaultItemAnimator());
                        if (scheduleSet.size() < 1)
                            txtMsgContent.setVisibility(View.VISIBLE);
                    }
                });
            } catch (ClassException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : ScheduleAdapter(com.lieverandiver.thesisproject.adapter.ScheduleAdapter) ArrayList(java.util.ArrayList) Handler(android.os.Handler) ClassException(com.remswork.project.alice.exception.ClassException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Schedule(com.remswork.project.alice.model.Schedule) ClassServiceImpl(com.remswork.project.alice.service.impl.ClassServiceImpl)

Example 12 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class Home_Schedule_Slidebar_Fragment method init.

public void init() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final List<Schedule> scheduleList = new ArrayList<>();
                TeacherHelper teacherHelper = new TeacherHelper(getContext());
                ClassServiceImpl classService = new ClassServiceImpl();
                Class _class = null;
                for (Class c : classService.getClassList()) {
                    if (c.getTeacher() == null)
                        continue;
                    if (c.getTeacher().getId() == teacherHelper.loadUser().get().getId()) {
                        _class = c;
                        Log.i("myTAG", "id : " + c.getId());
                        break;
                    }
                }
                // test
                _class = classService.getClassById(40);
                if (_class != null) {
                    for (Schedule schedule : classService.getScheduleList(_class.getId())) scheduleList.add(schedule);
                }
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        scheduleRecyclerView = (RecyclerView) customView.findViewById(R.id.shedule_recyclerview);
                        ScheduleAdapter scheduleAdapter = new ScheduleAdapter(getContext(), scheduleList);
                        scheduleRecyclerView.setAdapter(scheduleAdapter);
                        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
                        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                        scheduleRecyclerView.setLayoutManager(layoutManager);
                        scheduleRecyclerView.setItemAnimator(new DefaultItemAnimator());
                    }
                });
            } catch (ClassException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : ScheduleAdapter(com.lieverandiver.thesisproject.ScheduleAdapter) ArrayList(java.util.ArrayList) ClassException(com.remswork.project.alice.exception.ClassException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Schedule(com.remswork.project.alice.model.Schedule) ClassServiceImpl(com.remswork.project.alice.service.impl.ClassServiceImpl) Class(com.remswork.project.alice.model.Class) RecyclerView(android.support.v7.widget.RecyclerView) TeacherHelper(com.lieverandiver.thesisproject.helper.TeacherHelper)

Example 13 with Schedule

use of com.remswork.project.alice.model.Schedule 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)

Example 14 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ScheduleViewHolder holder, int position) {
    Schedule schedule = scheduleList.get(position);
    holder.setView(schedule, position);
}
Also used : Schedule(com.remswork.project.alice.model.Schedule)

Example 15 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ClassServiceImpl method deleteScheduleById.

@Override
public Schedule deleteScheduleById(long classId, long scheduleId) throws ClassException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(classId);
        uri.append("/");
        uri.append("schedule");
        uri.append("/");
        uri.append(scheduleId);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Builder builder = target.request();
        builder.accept("application/json");
        Response response = builder.delete();
        if (response.getStatus() == 200) {
            return (Schedule) response.readEntity(Schedule.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ClassServiceException(message.getMessage());
        } else
            throw new ClassServiceException("The request might invalid or server is down");
    } catch (ClassServiceException e) {
        throw new ClassException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ClassServiceException(com.remswork.project.alice.web.service.exception.ClassServiceException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Schedule(com.remswork.project.alice.model.Schedule) ClassException(com.remswork.project.alice.exception.ClassException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Aggregations

Schedule (com.remswork.project.alice.model.Schedule)36 ScheduleException (com.remswork.project.alice.exception.ScheduleException)22 Message (com.remswork.project.alice.model.support.Message)22 ClassException (com.remswork.project.alice.exception.ClassException)13 Client (javax.ws.rs.client.Client)10 WebTarget (javax.ws.rs.client.WebTarget)10 Response (javax.ws.rs.core.Response)10 ScheduleServiceException (com.remswork.project.alice.web.service.exception.ScheduleServiceException)6 ScheduleResourceLinks (com.remswork.project.alice.resource.links.ScheduleResourceLinks)5 ArrayList (java.util.ArrayList)5 ClientBuilder (javax.ws.rs.client.ClientBuilder)5 Builder (javax.ws.rs.client.Invocation.Builder)5 Session (org.hibernate.Session)5 ScheduleDaoException (com.remswork.project.alice.dao.exception.ScheduleDaoException)4 ClassScheduleListResourceLinks (com.remswork.project.alice.resource.links.ClassScheduleListResourceLinks)4 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)4 Set (java.util.Set)4 AsyncTask (android.os.AsyncTask)3 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3