Exemplo n.º 1
0
 public static int getSpecialListCount(final boolean respectEnable) {
   String where = "";
   if (respectEnable) {
     where = " WHERE " + ACTIVE + "=1";
   }
   final Cursor c =
       MirakelContentProvider.getReadableDatabase()
           .rawQuery("Select count(" + DatabaseHelper.ID + ") from " + TABLE + where, null);
   c.moveToFirst();
   int r = 0;
   if (c.getCount() > 0) {
     r = c.getInt(0);
   }
   c.close();
   return r;
 }
Exemplo n.º 2
0
  public static void undoLast() {
    String last = MirakelCommonPreferences.getFromLog(0);
    if (last != null && !last.equals("")) {
      short type = Short.parseShort(last.charAt(0) + "");
      if (last.charAt(1) != '{') {
        try {
          long id = Long.parseLong(last.substring(1));
          switch (type) {
            case TASK:
              Task.get(id).destroy(true);
              break;
            case LIST:
              ListMirakel.getList((int) id).destroy(true);
              break;
            default:
              Log.wtf(TAG, "unkown Type");
              break;
          }
        } catch (Exception e) {
          Log.e(TAG, "cannot parse String");
        }

      } else {
        JsonObject json = new JsonParser().parse(last.substring(1)).getAsJsonObject();
        switch (type) {
          case TASK:
            Task t = Task.parse_json(json, AccountMirakel.getLocal(), false);
            if (Task.get(t.getId()) != null) {
              t.safeSave(false);
            } else {
              try {
                MirakelContentProvider.getWritableDatabase()
                    .insert(Task.TABLE, null, t.getContentValues());
              } catch (Exception e) {
                Log.e(TAG, "cannot restore Task");
              }
            }
            break;
          case LIST:
            ListMirakel l = ListMirakel.parseJson(json);
            if (ListMirakel.getList(l.getId()) != null) {
              l.save(false);
            } else {
              try {
                MirakelContentProvider.getWritableDatabase()
                    .insert(ListMirakel.TABLE, null, l.getContentValues());
              } catch (Exception e) {
                Log.e(TAG, "cannot restore List");
              }
            }
            break;
          default:
            Log.wtf(TAG, "unkown Type");
            break;
        }
      }
    }
    SharedPreferences.Editor editor = MirakelCommonPreferences.getEditor();
    for (int i = 0; i < MirakelCommonPreferences.getUndoNumber(); i++) {
      String old = MirakelCommonPreferences.getFromLog(i + 1);
      editor.putString(UNDO + i, old);
    }
    editor.putString(UNDO + 10, "");
    editor.commit();
  }