create Presenter
This commit is contained in:
parent
4e3fd47539
commit
9dd66c0dd5
|
@ -0,0 +1,76 @@
|
|||
package org.cutem.cutecalendar.presenter;
|
||||
|
||||
class CalendarUnit {
|
||||
|
||||
public static final int TODAY_FLAG = 1;
|
||||
|
||||
public static final int HAVE_TODO_FLAG = 1 << 1;
|
||||
|
||||
public static final int HOLIDAY_FLAG = 1 << 2;
|
||||
|
||||
public static final int WORKDAY_FLAG = 1 << 3;
|
||||
private final String mFestival;
|
||||
private int mFlags;
|
||||
|
||||
|
||||
private CalendarUnit(int flags, String festival) {
|
||||
mFlags = flags;
|
||||
mFestival = festival;
|
||||
}
|
||||
|
||||
public static CalendarUnit constructUnit(int flags, String festival) {
|
||||
return new CalendarUnit(flags, festival);
|
||||
}
|
||||
|
||||
public static CalendarUnit constructUnit(
|
||||
boolean todayFlag,
|
||||
boolean haveTodoFlag,
|
||||
boolean holidayFlag,
|
||||
boolean workdayFlag,
|
||||
String festival) {
|
||||
|
||||
int flags = 0;
|
||||
if (todayFlag) {
|
||||
flags |= TODAY_FLAG;
|
||||
}
|
||||
if (haveTodoFlag) {
|
||||
flags |= HAVE_TODO_FLAG;
|
||||
}
|
||||
if (holidayFlag) {
|
||||
flags |= HOLIDAY_FLAG;
|
||||
}
|
||||
if (workdayFlag) {
|
||||
flags |= WORKDAY_FLAG;
|
||||
}
|
||||
return constructUnit(flags, festival);
|
||||
}
|
||||
|
||||
public static CalendarUnit constructUnitWithoutFestival(int flags) {
|
||||
return constructUnit(flags, null);
|
||||
}
|
||||
|
||||
public static CalendarUnit constructUnitWithoutFestival(
|
||||
boolean todayFlag,
|
||||
boolean haveTodoFlag,
|
||||
boolean holidayFlag,
|
||||
boolean workdayFlag) {
|
||||
return constructUnit(todayFlag, haveTodoFlag, holidayFlag, workdayFlag, null);
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return mFlags;
|
||||
}
|
||||
|
||||
public boolean isSetFlag(int mask) {
|
||||
return (mFlags & mask) != 0;
|
||||
}
|
||||
|
||||
public boolean isFestival() {
|
||||
return mFestival != null;
|
||||
}
|
||||
|
||||
public String getFestivalName() {
|
||||
return mFestival;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package org.cutem.cutecalendar.presenter;
|
||||
|
||||
import org.cutem.cutecalendar.model.TodoItem;
|
||||
import org.cutem.cutecalendar.model.TodoItemManager;
|
||||
import org.cutem.cutecalendar.util.CalendarUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Presenter {
|
||||
|
||||
private TodoItemManager manager = TodoItemManager.getInstance();
|
||||
|
||||
abstract Calendar getCalendarShowingDate();
|
||||
|
||||
|
||||
abstract void showTodoItemDetail(TodoItem item);
|
||||
|
||||
abstract void showNewTodoItemStage();
|
||||
|
||||
|
||||
void addTodoItem(@NotNull TodoItem item) {
|
||||
manager.add(item);
|
||||
paintCalendar(getCalendarShowingDate());
|
||||
}
|
||||
|
||||
void removeTodoItem(@NotNull TodoItem item) {
|
||||
manager.remove(item);
|
||||
paintCalendar(getCalendarShowingDate());
|
||||
}
|
||||
|
||||
|
||||
abstract void paintCalendar(@NotNull Calendar date, @NotNull List<CalendarUnit> days);
|
||||
|
||||
void paintCalendar(@NotNull Calendar date) {
|
||||
Calendar c1 = CalendarUtil.getMonthBegin(date);
|
||||
Calendar c2 = CalendarUtil.getMonthEnd(date);
|
||||
Calendar today = Calendar.getInstance();
|
||||
|
||||
ArrayList<CalendarUnit> days = new ArrayList<>();
|
||||
while (!c1.after(c2)) {
|
||||
int flags = 0;
|
||||
if (CalendarUtil.isSameDay(c1, today)) {
|
||||
flags |= CalendarUnit.TODAY_FLAG;
|
||||
}
|
||||
if (manager.haveTodoItemOnSomeday(c1)) {
|
||||
flags |= CalendarUnit.HAVE_TODO_FLAG;
|
||||
}
|
||||
// todo: holiday flag and workday flag and festival
|
||||
|
||||
CalendarUnit unit = CalendarUnit.constructUnit(flags, null);
|
||||
days.add(unit);
|
||||
}
|
||||
|
||||
paintCalendar(date, days);
|
||||
}
|
||||
|
||||
abstract void listTodoItems(List<TodoItem> items);
|
||||
|
||||
void listTodoItemDuring(Calendar from, Calendar to) {
|
||||
listTodoItems(manager.queryTodoItemsDuring(from, to));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue