Search in sources :

Example 6 with Item

use of com.thevarunshah.classes.Item in project SimpleBucketList-material by thevarunshah.

the class Utility method moveToArchive.

/**
 * moves a single item at index position from the bucket list to the archive list
 *
 * @param position the index of the item to be moved
 */
public static void moveToArchive(int position) {
    Item bi = bucketList.get(position);
    archiveList.add(bi);
    bucketList.remove(position);
}
Also used : Item(com.thevarunshah.classes.Item)

Example 7 with Item

use of com.thevarunshah.classes.Item in project SimpleBucketList-material by thevarunshah.

the class Utility method transferCompletedToArchive.

/**
 * transfers all completed items in the bucket list to the archive list
 *
 * @return indices of the items moved to archive
 */
public static ArrayList<Integer> transferCompletedToArchive() {
    // add items to the archive list and store their indices for deletion
    ArrayList<Integer> removeIndices = new ArrayList<>();
    for (int i = 0; i < bucketList.size(); i++) {
        Item bi = bucketList.get(i);
        if (bi.isDone()) {
            archiveList.add(bi);
            removeIndices.add(i);
        }
    }
    // remove items from the bucket list
    // index offset
    int numRemoved = 0;
    for (Integer i : removeIndices) {
        bucketList.remove(i - numRemoved);
        numRemoved++;
    }
    return removeIndices;
}
Also used : Item(com.thevarunshah.classes.Item) ArrayList(java.util.ArrayList)

Example 8 with Item

use of com.thevarunshah.classes.Item in project SimpleBucketList-material by thevarunshah.

the class Utility method readData.

/**
 * reads from serialized file in internal memory
 *
 * @param context the application context
 */
public static void readData(Context context) {
    FileInputStream fis = null;
    ObjectInputStream ois = null;
    try {
        // open file and read the bucket and archive lists from it
        fis = context.openFileInput("bucket_list.ser");
        ois = new ObjectInputStream(fis);
        ArrayList<Item> bucketItems = (ArrayList<Item>) ois.readObject();
        ArrayList<Item> archiveItems = (ArrayList<Item>) ois.readObject();
        if (bucketItems != null) {
            bucketList.clear();
            bucketList.addAll(bucketItems);
        }
        if (archiveItems != null) {
            archiveList.clear();
            archiveList.addAll(archiveItems);
        }
        updateWidget(context);
    } catch (Exception e) {
        Log.i(TAG, "could not read from file");
        e.printStackTrace();
    } finally {
        try {
            if (ois != null)
                ois.close();
            if (fis != null)
                fis.close();
        } catch (Exception e) {
            Log.i(TAG, "could not close the file");
            e.printStackTrace();
        }
    }
}
Also used : Item(com.thevarunshah.classes.Item) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Item (com.thevarunshah.classes.Item)8 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 DialogInterface (android.content.DialogInterface)2 Snackbar (android.support.design.widget.Snackbar)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2 OnClickListener (android.view.View.OnClickListener)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Toolbar (android.support.v7.widget.Toolbar)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 MenuItem (android.view.MenuItem)1 MotionEvent (android.view.MotionEvent)1 Button (android.widget.Button)1