fix some bugs

This commit is contained in:
hlq07 2018-05-27 03:13:05 +08:00
parent fcdc983f59
commit d12daf221d
3 changed files with 66 additions and 18 deletions

View File

@ -271,7 +271,7 @@ public class TodoItem {
* @return the title property value if any; {@code null} otherwise
*/
public String getTitle() {
return mStringProperties.getOrDefault(TITLE, null);
return getStringProperty(TITLE);
}
/**
@ -280,7 +280,7 @@ public class TodoItem {
* @return the location property value if any; {@code null} otherwise
*/
public String getLocation() {
return mStringProperties.getOrDefault(LOCATION, null);
return getStringProperty(LOCATION);
}
/**
@ -289,7 +289,7 @@ public class TodoItem {
* @return the description property value if any; {@code null} otherwise
*/
public String getDescription() {
return mStringProperties.getOrDefault(DESCRIPTION, null);
return getStringProperty(DESCRIPTION);
}
/**

View File

@ -83,6 +83,10 @@ public class TodoItemManager {
return mIdCache.getOrDefault(id, null);
}
public Set<TodoItem> getItems() {
return mUnmodifiableItems;
}
public List<TodoItem> queryTodoItemsDuring(@NotNull Calendar from, @NotNull Calendar to) {
ArrayList<TodoItem> result = new ArrayList<>();
for (TodoItem i : mItems) {

View File

@ -131,7 +131,10 @@ public class TodoItemUtil {
} else if (i2.getType() == ANNIVERSARY) {
return isIntersectedWithAnniversary(i2, i1);
} else {
return isIntersected(calculateRepeatArray(i1), calculateRepeatArray(i2));
List<GenericPair<Calendar, Calendar>> ints1 = calculateRepeatArray(i1);
List<GenericPair<Calendar, Calendar>> ints2 = calculateRepeatArray(i2);
return isIntersected(ints1, ints2);
}
}
@ -153,10 +156,10 @@ public class TodoItemUtil {
}
public static boolean isIn(
@NotNull Collection<GenericPair<Calendar, Calendar>> l1,
@NotNull Collection<GenericPair<Calendar, Calendar>> l2) {
for (GenericPair<Calendar, Calendar> p1 : l1) {
for (GenericPair<Calendar, Calendar> p2 : l2) {
@NotNull Collection<GenericPair<Calendar, Calendar>> outInts,
@NotNull Collection<GenericPair<Calendar, Calendar>> inInts) {
for (GenericPair<Calendar, Calendar> p1 : outInts) {
for (GenericPair<Calendar, Calendar> p2 : inInts) {
Calendar c1 = p1.getFirst();
Calendar c2 = p1.getSecond();
Calendar c3 = p2.getFirst();
@ -200,9 +203,7 @@ public class TodoItemUtil {
@NotNull TodoItem anniversary,
@NotNull TodoItem item) {
if (item.getType() == ANNIVERSARY && anniversary.getBgn().after(item.getBgn())) {
TodoItem t = anniversary;
anniversary = item;
item = t;
return false;
}
List<GenericPair<Calendar, Calendar>> list = calculateRepeatArray(item);
@ -221,13 +222,15 @@ public class TodoItemUtil {
}
}
public static boolean isIn(@NotNull TodoItem i1, @NotNull TodoItem i2) {
if (i1.getType() == ANNIVERSARY) {
return isInAnniversary(i1, i2);
} else if (i2.getType() == ANNIVERSARY) {
return isInAnniversary(i2, i1);
public static boolean isIn(@NotNull TodoItem outItem, @NotNull TodoItem inItem) {
if (outItem.getType() == ANNIVERSARY) {
return isInAnniversary(outItem, inItem);
} else if (inItem.getType() == ANNIVERSARY) {
return false;
} else {
return isIn(calculateRepeatArray(i1), calculateRepeatArray(i2));
List<GenericPair<Calendar, Calendar>> ints1 = calculateRepeatArray(outItem);
List<GenericPair<Calendar, Calendar>> ints2 = calculateRepeatArray(inItem);
return isIn(ints1, ints2);
}
}
@ -236,7 +239,8 @@ public class TodoItemUtil {
int pType = parent.getType();
int cType = child.getType();
return pType != cType && arrayContains(PARENT_CHILDREN_CONFLICT, pType)
return pType != cType
&& arrayContains(PARENT_CHILDREN_CONFLICT, pType)
&& arrayContains(PARENT_CHILDREN_CONFLICT, cType)
&& isIn(parent, child);
}
@ -254,6 +258,10 @@ public class TodoItemUtil {
return result;
}
public static boolean haveParent(@NotNull TodoItem item) {
return getParentId(item) != item.getId();
}
public static long getParentId(@NotNull TodoItem item) {
String id = item.getStringProperty(PARENT_ID);
return id == null ? item.getId() : Long.parseLong(id);
@ -274,6 +282,7 @@ public class TodoItemUtil {
return builder.toString();
}
public static TodoItem[] bind(@NotNull TodoItem parent, @NotNull TodoItem child) {
TodoItemFactory fParent = new TodoItemFactory().copy(parent);
TodoItemFactory fChild = new TodoItemFactory().copy(child);
@ -315,6 +324,7 @@ public class TodoItemUtil {
return new TodoItem[]{newP, newC};
}
public static TodoItem finishSingleTodoItem(@NotNull TodoItem item) {
TodoItemFactory factory = new TodoItemFactory();
return factory.copy(item).stringProperties(FINISH, "finish").buildId(item.getId());
@ -328,4 +338,38 @@ public class TodoItemUtil {
.build();
}
public static boolean isFinished(@NotNull TodoItem item) {
if (item.getStringProperty(FINISH) != null) {
return true;
} else {
List<Long> ids = getAllChildrenIds(item);
if (ids.isEmpty()) { // leaf
return false;
} else {
for (long id : ids) {
TodoItem childItem = TodoItemManager.getInstance().get(id);
if (childItem != null && !isFinished(childItem)) {
return false;
}
}
return true;
}
}
}
public static boolean isBeforeStart(@NotNull TodoItem item) {
Calendar now = Calendar.getInstance();
return now.before(item.getBgn());
}
public static boolean isEnded(@NotNull TodoItem item) {
Calendar now = Calendar.getInstance();
return now.after(item.getEnd());
}
public static boolean isRunning(@NotNull TodoItem item) {
return !isBeforeStart(item) && !isEnded(item);
}
}