Пример #1
0
  /**
   * Perform upgrade from one version to the next. Needs to be called on the UI thread so it can
   * display a progress bar and then show users a change log.
   *
   * @param from
   * @param to
   */
  public void performUpgrade(final Context context, final int from) {
    if (from == 135) AddOnService.recordOem();

    if (from > 0 && from < V3_8_2) {
      if (Preferences.getBoolean(R.string.p_transparent_deprecated, false))
        Preferences.setString(R.string.p_theme, "transparent"); // $NON-NLS-1$
      else Preferences.setString(R.string.p_theme, "black"); // $NON-NLS-1$
    }

    if (from <= V3_9_1_1) {
      actFmPreferenceService.clearLastSyncDate();
    }

    // long running tasks: pop up a progress dialog
    final ProgressDialog dialog;
    if (from < V4_0_6 && context instanceof Activity)
      dialog = DialogUtilities.progressDialog(context, context.getString(R.string.DLG_upgrading));
    else dialog = null;

    final String lastSetVersionName = AstridPreferences.getCurrentVersionName();

    Preferences.setInt(AstridPreferences.P_UPGRADE_FROM, from);

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  // NOTE: This line should be uncommented whenever any new version requires a data
                  // migration
                  // TasksXmlExporter.exportTasks(context,
                  // TasksXmlExporter.ExportType.EXPORT_TYPE_ON_UPGRADE, null, null,
                  // lastSetVersionName);

                  if (from < V3_0_0) new Astrid2To3UpgradeHelper().upgrade2To3(context, from);

                  if (from < V3_1_0) new Astrid2To3UpgradeHelper().upgrade3To3_1(context, from);

                  if (from < V3_8_3_1) new TagCaseMigrator().performTagCaseMigration(context);

                  if (from < V3_8_4 && Preferences.getBoolean(R.string.p_showNotes, false))
                    taskService.clearDetails(Task.NOTES.neq("")); // $NON-NLS-1$

                  if (from < V4_0_6) new DueDateTimeMigrator().migrateDueTimes();

                } finally {
                  DialogUtilities.dismissDialog((Activity) context, dialog);
                  context.sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
                }
              }
            })
        .start();
  }
Пример #2
0
  /**
   * Perform upgrade from one version to the next. Needs to be called on the UI thread so it can
   * display a progress bar and then show users a change log.
   *
   * @param from
   * @param to
   */
  public void performUpgrade(final Context context, final int from) {
    if (from == 135) AddOnService.recordOem();

    // pop up a progress dialog
    final ProgressDialog dialog;
    if (context instanceof Activity)
      dialog = DialogUtilities.progressDialog(context, context.getString(R.string.DLG_upgrading));
    else dialog = null;

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  if (from < V3_0_0) new Astrid2To3UpgradeHelper().upgrade2To3(context, from);

                  if (from < V3_1_0) new Astrid2To3UpgradeHelper().upgrade3To3_1(context, from);

                  if (from < V3_3_0) upgrade3To3_3(context);

                } finally {
                  if (context instanceof Activity) {
                    ((Activity) context)
                        .runOnUiThread(
                            new Runnable() {
                              public void run() {
                                if (dialog != null) dialog.dismiss();

                                // display changelog
                                showChangeLog(context, from);
                                if (context instanceof TaskListActivity)
                                  ((TaskListActivity) context).loadTaskListContent(true);
                              }
                            });
                  }
                }
              }
            })
        .start();
  }
Пример #3
0
  @SuppressWarnings("nls")
  private void shareTask(final JSONObject sharedWith) {
    final JSONArray emails = sharedWith.optJSONArray("p");

    final ProgressDialog pd =
        DialogUtilities.progressDialog(activity, activity.getString(R.string.DLG_please_wait));
    new Thread() {
      @Override
      public void run() {
        ActFmInvoker invoker = new ActFmInvoker(actFmPreferenceService.getToken());
        try {
          if (task.getValue(Task.REMOTE_ID) == 0) {
            actFmSyncService.pushTask(task.getId());
            task.setValue(
                Task.REMOTE_ID,
                taskService.fetchById(task.getId(), Task.REMOTE_ID).getValue(Task.REMOTE_ID));
          }
          if (task.getValue(Task.REMOTE_ID) == 0) {
            DialogUtilities.okDialog(
                activity,
                "We had an error saving "
                    + "this task to Astrid.com. Could you let us know why this happened?",
                null);
            return;
          }

          Object[] args = buildSharingArgs(emails);
          JSONObject result = invoker.invoke("task_share", args);

          sharedWith.remove("p");
          task.setValue(Task.SHARED_WITH, sharedWith.toString());
          task.setValue(Task.DETAILS_DATE, 0L);

          readTagData(result.getJSONArray("tags"));
          JsonHelper.readUser(result.getJSONObject("assignee"), task, Task.USER_ID, Task.USER);
          Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
          taskService.save(task);

          int count = result.optInt("shared", 0);
          if (count > 0) {
            saveToast +=
                "\n"
                    + activity.getString(
                        R.string.actfm_EPA_emailed_toast,
                        activity.getResources().getQuantityString(R.plurals.Npeople, count, count));
            StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_SHARED);
          }

          Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH);
          ContextManager.getContext()
              .sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);

          DialogUtilities.dismissDialog(activity, pd);
          activity.runOnUiThread(
              new Runnable() {
                public void run() {
                  showSaveToast();
                  activity.finish();
                }
              });
        } catch (IOException e) {
          DialogUtilities.okDialog(
              activity,
              activity.getString(R.string.SyP_ioerror),
              android.R.drawable.ic_dialog_alert,
              e.toString(),
              null);
        } catch (JSONException e) {
          DialogUtilities.okDialog(
              activity,
              activity.getString(R.string.SyP_ioerror),
              android.R.drawable.ic_dialog_alert,
              e.toString(),
              null);
        } finally {
          DialogUtilities.dismissDialog(activity, pd);
        }
      }
    }.start();
  }
Пример #4
0
  /** refresh the list with latest data from the web */
  private void refreshData(final boolean manual, boolean bypassTagShow) {
    final boolean noRemoteId = tagData.getValue(TagData.REMOTE_ID) == 0;

    final ProgressDialog progressDialog;
    if (manual && !noRemoteId)
      progressDialog = DialogUtilities.progressDialog(this, getString(R.string.DLG_please_wait));
    else progressDialog = null;

    Thread tagShowThread =
        new Thread(
            new Runnable() {
              @SuppressWarnings("nls")
              @Override
              public void run() {
                try {
                  String oldName = tagData.getValue(TagData.NAME);
                  actFmSyncService.fetchTag(tagData);
                  if (noRemoteId && tagData.getValue(TagData.REMOTE_ID) > 0) {
                    refreshData(manual, true);

                    runOnUiThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            refreshUpdatesList();
                            refreshMembersPage();
                          }
                        });
                  }

                  if (!oldName.equals(tagData.getValue(TagData.NAME))) {
                    TagService.getInstance().rename(oldName, tagData.getValue(TagData.NAME));
                  }

                } catch (IOException e) {
                  Log.e("tag-view-activity", "error-fetching-task-io", e);
                } catch (JSONException e) {
                  Log.e("tag-view-activity", "error-fetching-task", e);
                }
              }
            });
    if (!bypassTagShow) tagShowThread.start();

    if (noRemoteId) return;

    actFmSyncService.fetchTasksForTag(
        tagData,
        manual,
        new Runnable() {
          @Override
          public void run() {
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    loadTaskListContent(true);
                    DialogUtilities.dismissDialog(TagViewActivity.this, progressDialog);
                  }
                });
          }
        });

    actFmSyncService.fetchUpdatesForTag(
        tagData,
        manual,
        new Runnable() {
          @Override
          public void run() {
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    refreshUpdatesList();
                    DialogUtilities.dismissDialog(TagViewActivity.this, progressDialog);
                  }
                });
          }
        });
  }