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);
}
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;
}
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();
}
}
}
Aggregations