Ejemplo n.º 1
0
  public static ListMirakel getList(Context context, int widgetId) {

    int listId = getSettings(context).getInt(getKey(widgetId, "list_id"), 0);
    ListMirakel list = ListMirakel.getList(listId);
    if (list == null) {
      list = SpecialList.firstSpecial();
      if (list == null) {
        list = ListMirakel.first();
        if (list == null) {
          Toast.makeText(context, "You have no Lists!", Toast.LENGTH_SHORT).show();
          return null;
        }
      }
    }
    return list;
  }
Ejemplo n.º 2
0
 public static void logCreate(ListMirakel newList, Context ctx) {
   updateLog(LIST, newList.getId() + "", ctx);
 }
Ejemplo n.º 3
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();
  }
Ejemplo n.º 4
0
 public static void updateLog(ListMirakel listMirakel, Context ctx) {
   if (listMirakel != null) {
     updateLog(LIST, listMirakel.toJson(), ctx);
   }
 }