Back to project page ShoppingList.
The source code is released under:
GNU General Public License
If you think the Android project ShoppingList listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.sledzdev.shoppinglist.manager; /*from w w w .ja va 2s . c om*/ import android.content.ContentValues; import android.database.Cursor; import com.google.common.collect.ImmutableList; import net.sledzdev.shoppinglist.content.ItemsTable; import net.sledzdev.shoppinglist.model.ShoppingItem; import net.sledzdev.shoppinglist.model.ShoppingItemBuilder; import java.util.ArrayList; import java.util.List; /** * Created by Mariusz on 27.12.13. */ public class ItemContentTransformer implements ContentTransformer<ShoppingItem> { @Override public List<ShoppingItem> transformCursor(Cursor cursor) { List<ShoppingItem> items = new ArrayList<ShoppingItem>(); while (cursor.moveToNext()) { items.add(getShoppingItem(cursor)); } return ImmutableList.copyOf(items); } protected ShoppingItem getShoppingItem(Cursor cursor) { ShoppingItemBuilder builder = new ShoppingItemBuilder(); builder.setId(cursor.getLong(cursor.getColumnIndexOrThrow(ItemsTable.C_ID))) .setList_id(cursor.getLong(cursor.getColumnIndexOrThrow(ItemsTable.C_LIST_ID))) .setName(cursor.getString(cursor.getColumnIndexOrThrow(ItemsTable.C_NAME))) .setPrice(cursor.getDouble(cursor.getColumnIndexOrThrow(ItemsTable.C_PRICE))) .setChecked(cursor.getInt(cursor.getColumnIndexOrThrow(ItemsTable.C_CHECKED))); return builder.createShoppingItem(); } @Override public ContentValues transformValue(ShoppingItem item) { ContentValues values = new ContentValues(); values.put(ItemsTable.C_NAME, item.name); values.put(ItemsTable.C_PRICE, item.price); values.put(ItemsTable.C_CHECKED, item.checked ? 1 : 0); values.put(ItemsTable.C_LIST_ID, item.list.getId()); return values; } }