Example #1
0
 public static SpecialList firstSpecialSafe(final Context ctx) {
   SpecialList s = SpecialList.firstSpecial();
   if (s == null) {
     s =
         SpecialList.newSpecialList(
             ctx.getString(R.string.list_all),
             new HashMap<String, SpecialListsBaseProperty>(),
             true,
             ctx);
     if (ListMirakel.count() == 0) {
       ListMirakel.safeFirst(ctx);
     }
     s.save(false);
   }
   return s;
 }
Example #2
0
  public static SpecialList newSpecialList(
      final String name,
      final Map<String, SpecialListsBaseProperty> whereQuery,
      final boolean active,
      final Context context) {
    final int listId = ListMirakel.safeFirst(context).getId();
    database.beginTransaction();

    final ContentValues values = new ContentValues();
    values.put(DatabaseHelper.NAME, name);
    values.put(WHERE_QUERY, serializeWhere(whereQuery));
    values.put(ACTIVE, active);
    values.put(DEFAULT_LIST, listId);
    final long insertId = database.insert(TABLE, null, values);
    final Cursor cursor =
        database.query(TABLE, allColumns, "_id = " + insertId, null, null, null, null);
    cursor.moveToFirst();
    database.execSQL(
        "update "
            + TABLE
            + " SET "
            + LFT
            + "=(SELECT MAX("
            + RGT
            + ") from "
            + TABLE
            + ")+1, "
            + RGT
            + "=(SELECT MAX("
            + RGT
            + ") from "
            + TABLE
            + ")+2 where "
            + DatabaseHelper.ID
            + "="
            + insertId);
    database.setTransactionSuccessful();
    database.endTransaction();
    final SpecialList newSList = cursorToSList(cursor);
    cursor.close();
    return newSList;
  }
Example #3
0
 /**
  * Create a List from a Cursor
  *
  * @param cursor
  * @return
  */
 private static SpecialList cursorToSList(final Cursor cursor) {
   int i = 0;
   Integer defDate = cursor.getInt(5);
   if (cursor.isNull(5)) {
     defDate = null;
   }
   final SpecialList slist =
       new SpecialList(
           cursor.getInt(i++),
           cursor.getString(i++),
           deserializeWhere(cursor.getString(i++)),
           cursor.getInt(i++) == 1,
           ListMirakel.getList(cursor.getInt(i++)),
           defDate,
           (short) cursor.getInt(++i),
           SYNC_STATE.parseInt(cursor.getInt(++i)),
           cursor.getInt(++i),
           cursor.getInt(++i),
           cursor.getInt(++i));
   return slist;
 }
Example #4
0
 public ListMirakel getDefaultList() {
   if (this.defaultList == null) {
     return ListMirakel.first();
   }
   return this.defaultList;
 }