private void getUpdatesFromServer() {
   Message message = new Message();
   message.what = INFO;
   Bundle bundle = new Bundle();
   for (String set : updatableSets) {
     Log.d("UPDATES", set);
     bundle.putString(SET, set);
     message.setData(bundle);
     handler.sendMessage(message);
     String jsonString = HTTPUtil.getUpdateFromServer(set);
     JsonParser.saveJsonToAsset(context, jsonString, set);
   }
 }
Пример #2
0
  /**
   * Do a smart update, i.e: Check out httprequest, and overwrite any of the back/next/cancel/finish
   * values with a corresponding http request parameter, *provided* the request parameter is !=null.
   */
  public void smartUpdate() {

    HTTPUtil hru = new HTTPUtil();

    String vBack = hru.getParameterSingleValue(getParamBack());
    if (vBack != null) {
      this.back = vBack;
    }

    String vNext = hru.getParameterSingleValue(getParamNext());
    if (vNext != null) {
      this.next = vNext;
    }

    String vCancel = hru.getParameterSingleValue(getParamCancel());
    if (vCancel != null) {
      this.cancel = vCancel;
    }

    String vFinish = hru.getParameterSingleValue(getParamFinish());
    if (vFinish != null) {
      this.finish = vFinish;
    }
  } // smartUpdate
  @Override
  public void run() {
    long start = System.currentTimeMillis();
    String list;
    try {
      list = HTTPUtil.getVersionFromServer(context);
    } catch (RuntimeException e) {
      e.printStackTrace();
      handler.sendEmptyMessage(DONE);
      Toast.makeText(
              context,
              context.getString(R.string.synchronization_problem_connecting),
              Toast.LENGTH_SHORT)
          .show();
      Log.d(
          "TIMER",
          "Can't retrieve version, it took " + (System.currentTimeMillis() - start) + " ms");
      return;
    }

    updatableSets = new ArrayList<String>();
    try {
      JSONObject jsonList = new JSONObject(list);
      Iterator<String> keys = jsonList.keys();
      while (keys.hasNext()) {
        String key = keys.next();
        checkForUpdates(key, jsonList.optInt(key, 1));
      }
    } catch (JSONException e) {
      Log.e("JSON", "Can't convert string to json, " + list);
    }
    Log.d("TIMER", "Retrieving version list took " + (System.currentTimeMillis() - start) + " ms");
    if (updatableSets.isEmpty()) {
      handler.sendEmptyMessage(DONE);
      return;
    } else {
      start = System.currentTimeMillis();
      handler.sendEmptyMessage(UPDATING);
      getUpdatesFromServer();
      Log.d("TIMER", "Updating all the sets took " + (System.currentTimeMillis() - start) + " ms");
      handler.sendEmptyMessage(DONE);
    }
  }