// Path: ExpenseTracker/app/src/main/java/com/pedrocarrillo/expensetracker/utils/ExpensesManager.java
// public class ExpensesManager {
// 
//     private List<Expense> mExpensesList = new ArrayList<>();
//     private SparseBooleanArray mSelectedExpensesItems = new SparseBooleanArray();
// 
//     private static ExpensesManager ourInstance = new ExpensesManager();
// 
//     public static ExpensesManager getInstance() {
//         return ourInstance;
//     }
// 
//     private ExpensesManager() {
//     }
// 
//     public void setExpensesList(Date dateFrom, Date dateTo, @IExpensesType int type,  Category category) {
//         mExpensesList = Expense.getExpensesList(dateFrom, dateTo, type, category);
//         resetSelectedItems();
//     }
// 
//     public void setExpensesListByDateMode(@IDateMode int mCurrentDateMode) {
//         switch (mCurrentDateMode) {
//             case IDateMode.MODE_TODAY:
//                 mExpensesList = Expense.getTodayExpenses();
//                 break;
//             case IDateMode.MODE_WEEK:
//                 mExpensesList = Expense.getWeekExpenses();
//                 break;
//             case IDateMode.MODE_MONTH:
//                 mExpensesList = Expense.getMonthExpenses();
//                 break;
//         }
//     }
// 
//     public List<Expense> getExpensesList() {
//         return mExpensesList;
//     }
// 
//     public SparseBooleanArray getSelectedExpensesItems() {
//         return mSelectedExpensesItems;
//     }
// 
//     public void resetSelectedItems() {
//         mSelectedExpensesItems.clear();
//     }
// 
//     public List<Integer> getSelectedExpensesIndex() {
//         List<Integer> items = new ArrayList<>(mSelectedExpensesItems.size());
//         for (int i = 0; i < mSelectedExpensesItems.size(); ++i) {
//             items.add(mSelectedExpensesItems.keyAt(i));
//         }
//         return items;
//     }
// 
//     public void eraseSelectedExpenses() {
//         boolean isToday = false;
//         List<Expense> expensesToDelete = new ArrayList<>();
//         for (int position : getSelectedExpensesIndex()) {
//             Expense expense = mExpensesList.get(position);
//             expensesToDelete.add(expense);
//             Date expenseDate = expense.getDate();
//             // update widget if the expense is created today
//             if (DateUtils.isToday(expenseDate)) {
//                 isToday = true;
//             }
//         }
//         if (isToday) {
//             Intent i = new Intent(ExpenseTrackerApp.getContext(), ExpensesWidgetProvider.class);
//             i.setAction(ExpensesWidgetService.UPDATE_WIDGET);
//             ExpenseTrackerApp.getContext().sendBroadcast(i);
//         }
//         RealmManager.getInstance().delete(expensesToDelete);
//     }
// 
//     public void setSelectedItems(SparseBooleanArray selectedItems) {
//         this.mSelectedExpensesItems = selectedItems;
//     }
// 
// }


import android.support.v7.widget.RecyclerView;
import android.util.SparseBooleanArray;
import com.pedrocarrillo.expensetracker.utils.ExpensesManager;
import java.util.ArrayList;
import java.util.List;
package com.pedrocarrillo.expensetracker.adapters;




/**
 * Created by pcarrillo on 21/10/2015.
 */
abstract class BaseExpenseRecyclerViewAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

    /**
     * Indicates if the item at position position is selected
     * @param position Position of the item to check
     * @return true if the item is selected, false otherwise
     */
    public boolean isSelected(int position) {
        return getSelectedItems().contains(position);
    }

    /**
     * Toggle the selection status of the item at a given position
     * @param position Position of the item to toggle the selection status for
     */
    public void toggleSelection(int position) {
// Path: ExpenseTracker/app/src/main/java/com/pedrocarrillo/expensetracker/utils/ExpensesManager.java
// public class ExpensesManager {
// 
//     private List<Expense> mExpensesList = new ArrayList<>();
//     private SparseBooleanArray mSelectedExpensesItems = new SparseBooleanArray();
// 
//     private static ExpensesManager ourInstance = new ExpensesManager();
// 
//     public static ExpensesManager getInstance() {
//         return ourInstance;
//     }
// 
//     private ExpensesManager() {
//     }
// 
//     public void setExpensesList(Date dateFrom, Date dateTo, @IExpensesType int type,  Category category) {
//         mExpensesList = Expense.getExpensesList(dateFrom, dateTo, type, category);
//         resetSelectedItems();
//     }
// 
//     public void setExpensesListByDateMode(@IDateMode int mCurrentDateMode) {
//         switch (mCurrentDateMode) {
//             case IDateMode.MODE_TODAY:
//                 mExpensesList = Expense.getTodayExpenses();
//                 break;
//             case IDateMode.MODE_WEEK:
//                 mExpensesList = Expense.getWeekExpenses();
//                 break;
//             case IDateMode.MODE_MONTH:
//                 mExpensesList = Expense.getMonthExpenses();
//                 break;
//         }
//     }
// 
//     public List<Expense> getExpensesList() {
//         return mExpensesList;
//     }
// 
//     public SparseBooleanArray getSelectedExpensesItems() {
//         return mSelectedExpensesItems;
//     }
// 
//     public void resetSelectedItems() {
//         mSelectedExpensesItems.clear();
//     }
// 
//     public List<Integer> getSelectedExpensesIndex() {
//         List<Integer> items = new ArrayList<>(mSelectedExpensesItems.size());
//         for (int i = 0; i < mSelectedExpensesItems.size(); ++i) {
//             items.add(mSelectedExpensesItems.keyAt(i));
//         }
//         return items;
//     }
// 
//     public void eraseSelectedExpenses() {
//         boolean isToday = false;
//         List<Expense> expensesToDelete = new ArrayList<>();
//         for (int position : getSelectedExpensesIndex()) {
//             Expense expense = mExpensesList.get(position);
//             expensesToDelete.add(expense);
//             Date expenseDate = expense.getDate();
//             // update widget if the expense is created today
//             if (DateUtils.isToday(expenseDate)) {
//                 isToday = true;
//             }
//         }
//         if (isToday) {
//             Intent i = new Intent(ExpenseTrackerApp.getContext(), ExpensesWidgetProvider.class);
//             i.setAction(ExpensesWidgetService.UPDATE_WIDGET);
//             ExpenseTrackerApp.getContext().sendBroadcast(i);
//         }
//         RealmManager.getInstance().delete(expensesToDelete);
//     }
// 
//     public void setSelectedItems(SparseBooleanArray selectedItems) {
//         this.mSelectedExpensesItems = selectedItems;
//     }
// 
// }


// Path: ExpenseTracker/app/src/main/java/com/pedrocarrillo/expensetracker/adapters/BaseExpenseRecyclerViewAdapter.java
import android.support.v7.widget.RecyclerView;
import android.util.SparseBooleanArray;
import com.pedrocarrillo.expensetracker.utils.ExpensesManager;
import java.util.ArrayList;
import java.util.List;

package com.pedrocarrillo.expensetracker.adapters;




/**
 * Created by pcarrillo on 21/10/2015.
 */
abstract class BaseExpenseRecyclerViewAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

    /**
     * Indicates if the item at position position is selected
     * @param position Position of the item to check
     * @return true if the item is selected, false otherwise
     */
    public boolean isSelected(int position) {
        return getSelectedItems().contains(position);
    }

    /**
     * Toggle the selection status of the item at a given position
     * @param position Position of the item to toggle the selection status for
     */
    public void toggleSelection(int position) {
        if (ExpensesManager.getInstance().getSelectedExpensesItems().get(position, false)) {