Esempio n. 1
0
  @Override
  public void addDesire(String content, String consumeScore) {
    DesireBean bean = new DesireBean();
    bean.setStatue(DESIRE_STATUE_RUNNING);
    bean.setCreatetime(DateHelper.formatCurToDatabase());
    bean.setType(DESIRE_TYPE_NORMAL);
    bean.setContent(content);
    bean.setConsumescore(consumeScore);

    ArrayList<DesireBean> desires =
        json2DesireBeans(SPHelper.findJson(context, Constant.SP_TAG_DESIRE));
    desires.add(0, bean);
    String json = desireBeans2Json(desires);
    SPHelper.saveJson(context, Constant.SP_TAG_DESIRE, json);

    CuteLog.dLog("added task:" + bean.getContent() + "|" + bean.getConsumescore());
  }
Esempio n. 2
0
  @Override
  public void finishDesire(String content, String consumeScore) {
    DesireBean finishedDesire = null;
    ArrayList<DesireBean> tasks =
        json2DesireBeans(SPHelper.findJson(context, Constant.SP_TAG_DESIRE));
    int index = -1;
    for (int i = 0; i < tasks.size(); i++) {
      if (content.equals(tasks.get(i).getContent())
          && consumeScore.equals(tasks.get(i).getConsumescore())) {
        index = i;
        break;
      }
    }
    // 未找到对应的任务
    if (index == -1) {
      CuteLog.eLog("None task finished!");
    }
    // 找到对应任务,移除任务列表,减去积分
    if (index > -1) {
      CuteLog.dLog("finish task:" + tasks.get(index));
      finishedDesire = tasks.remove(index);
      SPHelper.saveJson(context, Constant.SP_TAG_DESIRE, desireBeans2Json(tasks));
      // 计分
      String str = SPHelper.findJson(context, Constant.SP_TAG_SCORE);
      int score = 0;
      if (str != null) {
        score = new Integer(str);
      }
      score -= new Integer(consumeScore);
      SPHelper.saveJson(context, Constant.SP_TAG_SCORE, score + "");
    }

    // 将移除的任务添加到已完成列表
    if (finishedDesire != null) {
      finishedDesire.setFinishtime(DateHelper.formatCurToDatabase());
      finishedDesire.setStatue(DESIRE_STATUE_FINISH);
      ArrayList<DesireBean> finishDesires =
          json2DesireBeans(SPHelper.findJson(context, Constant.SP_TAG_FINISHDESIRE));
      finishDesires.add(finishedDesire);
      SPHelper.saveJson(context, Constant.SP_TAG_FINISHDESIRE, desireBeans2Json(finishDesires));
    }
  }