예제 #1
0
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    fragmentPosition = FragmentPagerItem.getPosition(getArguments());
    button0 = (RadioButton) view.findViewById(R.id.button0);
    button1 = (RadioButton) view.findViewById(R.id.button1);
    button2 = (RadioButton) view.findViewById(R.id.button2);
    button3 = (RadioButton) view.findViewById(R.id.button3);
    ly = (LinearLayout) view.findViewById(R.id.buttonLy);
    passwordTip = (TextView) view.findViewById(R.id.password_tip);
    passwordTip.setTypeface(CoCoinUtil.GetTypeface());
    switch (fragmentPosition) {
      case 0:
        if (SettingManager.getInstance().getFirstTime()) {
          passwordTip.setText(
              CoCoinApplication.getAppContext()
                  .getResources()
                  .getString(R.string.first_time_set_password));
        } else {
          passwordTip.setText(
              CoCoinApplication.getAppContext().getResources().getString(R.string.password_tip_0));
        }
        break;
      case 1:
        if (SettingManager.getInstance().getFirstTime()) {
          passwordTip.setText(
              CoCoinApplication.getAppContext()
                  .getResources()
                  .getString(R.string.first_time_set_password_again));
        } else {
          passwordTip.setText(
              CoCoinApplication.getAppContext().getResources().getString(R.string.password_tip_1));
        }
        break;
      case 2:
        passwordTip.setText(
            CoCoinApplication.getAppContext().getResources().getString(R.string.password_tip_2));
        break;
      default:
        break;
    }
  }
예제 #2
0
  public static long updateOldRecordsToServer() {
    long counter = 0;
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
      // already
      // login////////////////////////////////////////////////////////////////////////////////////
      isLastOne = false;
      for (int i = 0; i < RECORDS.size(); i++) {
        if (i == RECORDS.size() - 1) isLastOne = true;
        final CoCoinRecord coCoinRecord = RECORDS.get(i);
        if (!coCoinRecord.getIsUploaded()) {
          // has been
          // changed/////////////////////////////////////////////////////////////////////////////////
          if (coCoinRecord.getLocalObjectId() != null) {
            // there is an old coCoinRecord in server, we should update this
            // coCoinRecord///////////////////////////////////
            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.updateOldRecordsToServer update online "
                                + coCoinRecord.toString()
                                + " S");
                    }
                    coCoinRecord.setIsUploaded(true);
                    coCoinRecord.setLocalObjectId(coCoinRecord.getObjectId());
                    db.updateRecord(coCoinRecord);
                    // after updating, get the old records from
                    // server//////////////////////////////////////////////////
                    if (isLastOne) getRecordsFromServer();
                  }

                  @Override
                  public void onFailure(int code, String msg) {
                    if (BuildConfig.DEBUG) {
                      if (BuildConfig.DEBUG)
                        Log.d(
                            "CoCoin",
                            "recordManager.updateOldRecordsToServer update online "
                                + coCoinRecord.toString()
                                + " F");
                    }
                    if (BuildConfig.DEBUG) {
                      if (BuildConfig.DEBUG)
                        Log.d(
                            "CoCoin",
                            "recordManager.updateOldRecordsToServer update online code"
                                + code
                                + " msg "
                                + msg);
                    }
                  }
                });
          } else {
            counter++;
            coCoinRecord.setUserId(user.getObjectId());
            coCoinRecord.save(
                CoCoinApplication.getAppContext(),
                new SaveListener() {
                  @Override
                  public void onSuccess() {
                    if (BuildConfig.DEBUG) {
                      if (BuildConfig.DEBUG)
                        Log.d(
                            "CoCoin",
                            "recordManager.updateOldRecordsToServer save online "
                                + coCoinRecord.toString()
                                + " S");
                    }
                    coCoinRecord.setIsUploaded(true);
                    coCoinRecord.setLocalObjectId(coCoinRecord.getObjectId());
                    db.updateRecord(coCoinRecord);
                    // after updating, get the old records from
                    // server//////////////////////////////////////////////////
                    if (isLastOne) getRecordsFromServer();
                  }

                  @Override
                  public void onFailure(int code, String msg) {
                    if (BuildConfig.DEBUG) {
                      if (BuildConfig.DEBUG)
                        Log.d(
                            "CoCoin",
                            "recordManager.updateOldRecordsToServer save online "
                                + coCoinRecord.toString()
                                + " F");
                    }
                    if (BuildConfig.DEBUG) {
                      if (BuildConfig.DEBUG)
                        Log.d(
                            "CoCoin",
                            "recordManager.updateOldRecordsToServer save online code"
                                + code
                                + " msg "
                                + msg);
                    }
                  }
                });
          }
        }
      }
    } else {

    }

    if (BuildConfig.DEBUG) {
      if (BuildConfig.DEBUG)
        Log.d(
            "CoCoin",
            "recordManager.updateOldRecordsToServer update " + counter + " records to server.");
    }

    if (RECORDS.size() == 0) getRecordsFromServer();

    return counter;
  }
예제 #3
0
  public static long getRecordsFromServer() {
    updateNum = 0;
    BmobQuery<CoCoinRecord> query = new BmobQuery<CoCoinRecord>();
    query.addWhereEqualTo(
        "userId",
        BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class).getObjectId());
    query.setLimit(Integer.MAX_VALUE);
    query.findObjects(
        CoCoinApplication.getAppContext(),
        new FindListener<CoCoinRecord>() {
          @Override
          public void onSuccess(List<CoCoinRecord> object) {
            if (BuildConfig.DEBUG) {
              if (BuildConfig.DEBUG)
                Log.d(
                    "CoCoin",
                    "recordManager.getRecordsFromServer get "
                        + object.size()
                        + " records from server");
            }
            updateNum = object.size();
            for (CoCoinRecord coCoinRecord : object) {
              boolean exist = false;
              for (int i = RECORDS.size() - 1; i >= 0; i--) {
                if (coCoinRecord.getObjectId().equals(RECORDS.get(i).getLocalObjectId())) {
                  exist = true;
                  break;
                }
              }
              if (!exist) {
                CoCoinRecord newCoCoinRecord = new CoCoinRecord();
                newCoCoinRecord.set(coCoinRecord);
                newCoCoinRecord.setId(-1);
                RECORDS.add(newCoCoinRecord);
              }
            }

            Collections.sort(
                RECORDS,
                new Comparator<CoCoinRecord>() {
                  @Override
                  public int compare(CoCoinRecord lhs, CoCoinRecord rhs) {
                    if (lhs.getCalendar().before(rhs.getCalendar())) {
                      return -1;
                    } else if (lhs.getCalendar().after(rhs.getCalendar())) {
                      return 1;
                    } else {
                      return 0;
                    }
                  }
                });

            db.deleteAllRecords();

            SUM = 0;
            for (int i = 0; i < RECORDS.size(); i++) {
              RECORDS.get(i).setLocalObjectId(RECORDS.get(i).getObjectId());
              RECORDS.get(i).setIsUploaded(true);
              db.saveRecord(RECORDS.get(i));
              SUM += (int) RECORDS.get(i).getMoney();
            }

            if (BuildConfig.DEBUG) {
              if (BuildConfig.DEBUG)
                Log.d(
                    "CoCoin",
                    "recordManager.getRecordsFromServer save " + RECORDS.size() + " records");
            }
          }

          @Override
          public void onError(int code, String msg) {
            if (BuildConfig.DEBUG) {
              if (BuildConfig.DEBUG)
                Log.d("CoCoin", "recordManager.getRecordsFromServer error " + msg);
            }
          }
        });

    return updateNum;
  }
예제 #4
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();
  }