Ejemplo n.º 1
0
 // saveRecord///////////////////////////////////////////////////////////////////////////////////////
 public static long saveRecord(final CoCoinRecord coCoinRecord) {
   long insertId = -1;
   // this is a new coCoinRecord, which is not uploaded
   coCoinRecord.setIsUploaded(false);
   //        User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
   //        if (user != null) coCoinRecord.setUserId(user.getObjectId());
   //        else coCoinRecord.setUserId(null);
   if (BuildConfig.DEBUG)
     if (BuildConfig.DEBUG)
       Log.d("CoCoin", "recordManager.saveRecord: Save " + coCoinRecord.toString() + " S");
   insertId = db.saveRecord(coCoinRecord);
   if (insertId == -1) {
     if (BuildConfig.DEBUG)
       if (BuildConfig.DEBUG)
         Log.d("CoCoin", "recordManager.saveRecord: Save the above coCoinRecord FAIL!");
     CoCoinToast.getInstance().showToast(R.string.save_failed_locale, SuperToast.Background.RED);
   } else {
     if (BuildConfig.DEBUG)
       if (BuildConfig.DEBUG)
         Log.d("CoCoin", "recordManager.saveRecord: Save the above coCoinRecord SUCCESSFULLY!");
     RECORDS.add(coCoinRecord);
     SUM += (int) coCoinRecord.getMoney();
     //            if (user != null) {
     //                // already login
     //                coCoinRecord.save(CoCoinApplication.getAppContext(), new SaveListener() {
     //                    @Override
     //                    public void onSuccess() {
     //                        if (BuildConfig.DEBUG)
     //                            if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.saveRecord: Save online " + coCoinRecord.toString() + " S");
     //                        coCoinRecord.setIsUploaded(true);
     //                        coCoinRecord.setLocalObjectId(coCoinRecord.getObjectId());
     //                        db.updateRecord(coCoinRecord);
     //                        CoCoinToast.getInstance()
     //                                .showToast(R.string.save_successfully_online,
     // SuperToast.Background.BLUE);
     //                    }
     //                    @Override
     //                    public void onFailure(int code, String msg) {
     //                        if (BuildConfig.DEBUG)
     //                            if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.saveRecord: Save online " + coCoinRecord.toString() + " F");
     //                        if (BuildConfig.DEBUG)
     //                            if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.saveRecord: Save online msg: " + msg + " code " + code);
     //                        CoCoinToast.getInstance()
     //                                .showToast(R.string.save_failed_online,
     // SuperToast.Background.RED);
     //                    }
     //                });
     //            } else {
     //                CoCoinToast.getInstance()
     //                        .showToast(R.string.save_successfully_locale,
     // SuperToast.Background.BLUE);
     //            }
     CoCoinToast.getInstance()
         .showToast(R.string.save_successfully_locale, SuperToast.Background.BLUE);
   }
   return insertId;
 }
Ejemplo n.º 2
0
 public static long updateRecord(final CoCoinRecord coCoinRecord) {
   long updateNumber = db.updateRecord(coCoinRecord);
   if (updateNumber <= 0) {
     if (BuildConfig.DEBUG) {
       if (BuildConfig.DEBUG)
         Log.d("CoCoin", "recordManager.updateRecord " + coCoinRecord.toString() + " F");
     }
     CoCoinToast.getInstance().showToast(R.string.update_failed_locale, SuperToast.Background.RED);
   } else {
     if (BuildConfig.DEBUG) {
       if (BuildConfig.DEBUG)
         Log.d("CoCoin", "recordManager.updateRecord " + coCoinRecord.toString() + " S");
     }
     p = RECORDS.size() - 1;
     for (; p >= 0; p--) {
       if (RECORDS.get(p).getId() == coCoinRecord.getId()) {
         SUM -= (int) RECORDS.get(p).getMoney();
         SUM += (int) coCoinRecord.getMoney();
         RECORDS.get(p).set(coCoinRecord);
         break;
       }
     }
     coCoinRecord.setIsUploaded(false);
     //            User user = BmobUser
     //                    .getCurrentUser(CoCoinApplication.getAppContext(), User.class);
     //            if (user != null) {
     //                // already login
     //                if (coCoinRecord.getLocalObjectId() != null) {
     //                    // this coCoinRecord has been push to the server
     //                    coCoinRecord.setUserId(user.getObjectId());
     //                    coCoinRecord.update(CoCoinApplication.getAppContext(),
     //                            coCoinRecord.getLocalObjectId(), new UpdateListener() {
     //                                @Override
     //                                public void onSuccess() {
     //                                    if (BuildConfig.DEBUG) {
     //                                        if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.updateRecord update online " + coCoinRecord.toString() + " S");
     //                                    }
     //                                    coCoinRecord.setIsUploaded(true);
     //                                    RECORDS.get(p).setIsUploaded(true);
     //                                    db.updateRecord(coCoinRecord);
     //
     // CoCoinToast.getInstance().showToast(R.string.update_successfully_online,
     // SuperToast.Background.BLUE);
     //                                }
     //
     //                                @Override
     //                                public void onFailure(int code, String msg) {
     //                                    if (BuildConfig.DEBUG) {
     //                                        if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.updateRecord update online " + coCoinRecord.toString() + " F");
     //                                    }
     //                                    if (BuildConfig.DEBUG) {
     //                                        if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.updateRecord update online code" + code + " msg " + msg );
     //                                    }
     //
     // CoCoinToast.getInstance().showToast(R.string.update_failed_online,
     // SuperToast.Background.RED);
     //                                }
     //                            });
     //                } else {
     //                    // this coCoinRecord has not been push to the server
     //                    coCoinRecord.setUserId(user.getObjectId());
     //                    coCoinRecord.save(CoCoinApplication.getAppContext(), new SaveListener()
     // {
     //                                @Override
     //                                public void onSuccess() {
     //                                    if (BuildConfig.DEBUG) {
     //                                        if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.updateRecord save online " + coCoinRecord.toString() + " S");
     //                                    }
     //                                    coCoinRecord.setIsUploaded(true);
     //
     // coCoinRecord.setLocalObjectId(coCoinRecord.getObjectId());
     //                                    RECORDS.get(p).setIsUploaded(true);
     //
     // RECORDS.get(p).setLocalObjectId(coCoinRecord.getObjectId());
     //                                    db.updateRecord(coCoinRecord);
     //
     // CoCoinToast.getInstance().showToast(R.string.update_successfully_online,
     // SuperToast.Background.BLUE);
     //                                }
     //                                @Override
     //                                public void onFailure(int code, String msg) {
     //                                    if (BuildConfig.DEBUG) {
     //                                        if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.updateRecord save online " + coCoinRecord.toString() + " F");
     //                                    }
     //                                    if (BuildConfig.DEBUG) {
     //                                        if (BuildConfig.DEBUG) Log.d("CoCoin",
     // "recordManager.updateRecord save online code" + code + " msg " + msg );
     //                                    }
     //
     // CoCoinToast.getInstance().showToast(R.string.update_failed_online,
     // SuperToast.Background.RED);
     //                                }
     //                            });
     //                }
     //            } else {
     //                // has not login
     //                db.updateRecord(coCoinRecord);
     //                CoCoinToast.getInstance().showToast(R.string.update_successfully_locale,
     // SuperToast.Background.BLUE);
     //            }
     db.updateRecord(coCoinRecord);
     CoCoinToast.getInstance()
         .showToast(R.string.update_successfully_locale, SuperToast.Background.BLUE);
   }
   return updateNumber;
 }
Ejemplo n.º 3
0
  // delete a
  // coCoinRecord//////////////////////////////////////////////////////////////////////////////////
  public static long deleteRecord(final CoCoinRecord coCoinRecord, boolean deleteInList) {
    long deletedNumber = db.deleteRecord(coCoinRecord.getId());
    if (deletedNumber > 0) {
      if (BuildConfig.DEBUG)
        Log.d("CoCoin", "recordManager.deleteRecord: Delete " + coCoinRecord.toString() + " S");
      User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
      // if we can delete the coCoinRecord from server
      //            if (user != null && coCoinRecord.getLocalObjectId() != null) {
      //                coCoinRecord.delete(CoCoinApplication.getAppContext(), new DeleteListener()
      // {
      //                    @Override
      //                    public void onSuccess() {
      //                        if (BuildConfig.DEBUG) {
      //                            if (BuildConfig.DEBUG) Log.d("CoCoin",
      //                                    "recordManager.deleteRecord: Delete online " +
      // coCoinRecord.toString() + " S");
      //                        }
      //                        CoCoinToast.getInstance()
      //                                .showToast(R.string.delete_successfully_online,
      // SuperToast.Background.BLUE);
      //                    }
      //                    @Override
      //                    public void onFailure(int code, String msg) {
      //                        if (BuildConfig.DEBUG) {
      //                            if (BuildConfig.DEBUG) Log.d("CoCoin",
      //                                    "recordManager.deleteRecord: Delete online " +
      // coCoinRecord.toString() + " F");
      //                        }
      //                        CoCoinToast.getInstance()
      //                                .showToast(R.string.delete_failed_online,
      // SuperToast.Background.RED);
      //                    }
      //                });
      //            } else {
      //                CoCoinToast.getInstance()
      //                        .showToast(R.string.delete_successfully_locale,
      // SuperToast.Background.BLUE);
      //            }
      CoCoinToast.getInstance()
          .showToast(R.string.delete_successfully_locale, SuperToast.Background.BLUE);
      // update RECORDS list and SUM
      SUM -= (int) coCoinRecord.getMoney();
      if (deleteInList) {
        int size = RECORDS.size();
        for (int i = 0; i < RECORDS.size(); i++) {
          if (RECORDS.get(i).getId() == coCoinRecord.getId()) {
            RECORDS.remove(i);
            if (BuildConfig.DEBUG)
              Log.d(
                  "CoCoin",
                  "recordManager.deleteRecord: Delete in RECORD " + coCoinRecord.toString() + " S");
            break;
          }
        }
      }
    } else {
      if (BuildConfig.DEBUG)
        Log.d("CoCoin", "recordManager.deleteRecord: Delete " + coCoinRecord.toString() + " F");
      CoCoinToast.getInstance().showToast(R.string.delete_failed_locale, SuperToast.Background.RED);
    }

    return coCoinRecord.getId();
  }