public void separateIncomeAndExpense() { CategoryTree<Category> newCategories = new CategoryTree<Category>(); Category income = new Category(); income.id = INCOME_CATEGORY_ID; income.makeThisCategoryIncome(); income.title = "<INCOME>"; Category expense = new Category(); expense.id = EXPENSE_CATEGORY_ID; expense.makeThisCategoryExpense(); expense.title = "<EXPENSE>"; for (Category category : categories) { if (category.id <= 0) { newCategories.add(category); } else { if (category.isIncome()) { income.addChild(category); } else { expense.addChild(category); } } } if (income.hasChildren()) { newCategories.add(income); } if (expense.hasChildren()) { newCategories.add(expense); } categories = newCategories; }
public void tagCategories(Category parent) { if (categories.size() > 0 && categories.getAt(0).id != parent.id) { Category copy = new Category(); copy.id = parent.id; copy.title = parent.title; if (parent.isIncome()) { copy.makeThisCategoryIncome(); } categories.insertAtTop(copy); } StringBuilder sb = new StringBuilder(); for (Category c : categories) { if (c.tag == null && c.hasChildren()) { sb.setLength(0); CategoryTree<Category> children = c.children; for (Category child : children) { if (sb.length() > 0) { sb.append(","); } sb.append(child.title); } c.tag = sb.toString(); } } }
public boolean navigateTo(long categoryId) { Category selectedCategory = findCategory(categoryId); if (selectedCategory != null) { selectedCategoryId = selectedCategory.id; if (selectedCategory.hasChildren()) { categoriesStack.push(categories); categories = selectedCategory.children; tagCategories(selectedCategory); return true; } } return false; }