Beispiel #1
0
  /**
   * Deal with a synchronization exception. If requested, will show an error to the user (unless
   * synchronization is happening in background)
   *
   * @param context
   * @param tag error tag
   * @param e exception
   * @param showError whether to display a dialog
   */
  protected void handleException(String tag, Exception e, boolean displayError) {
    // TODO: When Crittercism supports it, report error to them
    final Context context = ContextManager.getContext();
    getUtilities().setLastError(e.toString());

    String message = null;

    // occurs when application was closed
    if (e instanceof IllegalStateException) {
      exceptionService.reportError(tag + "-caught", e); // $NON-NLS-1$
    }

    // occurs when network error
    else if (e instanceof IOException) {
      exceptionService.reportError(tag + "-io", e); // $NON-NLS-1$
      message = context.getString(R.string.SyP_ioerror);
    }

    // unhandled error
    else {
      message = context.getString(R.string.DLG_error, e.toString());
      exceptionService.reportError(tag + "-unhandled", e); // $NON-NLS-1$
    }

    if (displayError && context instanceof Activity && message != null) {
      DialogUtilities.okDialog((Activity) context, message, null);
    }
  }
 private void handleActivityNotFound(String fileType) {
   if (fileType.startsWith(FileMetadata.FILE_TYPE_AUDIO)) {
     searchMarket(
         "com.clov4r.android.nil",
         R.string.search_market_audio_title,
         R.string.search_market_audio); // $NON-NLS-1$
   } else if (fileType.equals(FileMetadata.FILE_TYPE_PDF)) {
     searchMarket(
         "com.adobe.reader",
         R.string.search_market_pdf_title,
         R.string.search_market_pdf); // $NON-NLS-1$
   } else if (AndroidUtilities.indexOf(FileMetadata.MS_FILETYPES, fileType) >= 0) {
     searchMarket(
         "com.dataviz.docstogo",
         R.string.search_market_ms_title,
         R.string.search_market_ms); // $NON-NLS-1$
   } else {
     DialogUtilities.okDialog(
         activity,
         activity.getString(R.string.file_type_unhandled_title),
         0,
         activity.getString(R.string.file_type_unhandled),
         null);
   }
 }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setTheme(android.R.style.Theme_Dialog);

      final long id = getIntent().getLongExtra(TOKEN_FILTER_ID, -1);
      if (id == -1) {
        finish();
        return;
      }
      final String name = getIntent().getStringExtra(TOKEN_FILTER_NAME);

      DependencyInjectionService.getInstance().inject(this);
      DialogUtilities.okCancelDialog(
          this,
          getString(R.string.DLG_delete_this_item_question, name),
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              PluginServices.getStoreObjectDao().delete(id);
              setResult(RESULT_OK);
              finish();
            }
          },
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              setResult(RESULT_CANCELED);
              finish();
            }
          });
    }
 @Override
 protected void showDialog() {
   DialogUtilities.okCancelDialog(
       this,
       getString(R.string.DLG_delete_this_tag_question, tag),
       getOkListener(),
       getCancelListener());
 }
 @Override
 protected void showDialog() {
   editor = new EditText(this);
   DialogUtilities.viewDialog(
       this,
       getString(R.string.DLG_rename_this_tag_header, tag),
       editor,
       getOkListener(),
       getCancelListener());
 }
Beispiel #6
0
 public static void handleSQLiteError(Context context, final SQLiteException e) {
   if (context instanceof Activity) {
     Activity activity = (Activity) context;
     DialogUtilities.okDialog(
         activity,
         activity.getString(R.string.DB_corrupted_title),
         0,
         activity.getString(R.string.DB_corrupted_body));
   }
   e.printStackTrace();
 }
Beispiel #7
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();
  }
  private void onVoiceInputStatusChanged(final Preference preference, boolean newValue) {
    if (!newValue) return;

    final Resources r = getResources();
    if (!VoiceRecognizer.voiceInputAvailable(this)) {
      if (AndroidUtilities.getSdkVersion() > 6) {
        DialogUtilities.okCancelDialog(
            this,
            r.getString(R.string.EPr_voiceInputInstall_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                voiceInputAssistant.showVoiceInputMarketSearch(
                    new OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog1, int which1) {
                        ((CheckBoxPreference) preference).setChecked(false);
                      }
                    });
              }
            },
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      } else {
        DialogUtilities.okDialog(
            this,
            r.getString(R.string.EPr_voiceInputUnavailable_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog1, int which1) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      }
    }
  }
  private void showSubtasksHelp() {
    String body =
        String.format(
            "<h3>%s</h3><img src='%s'>" + "<br>%s<br><br><br><img src='%s'><br>%s",
            getActivity().getString(R.string.subtasks_help_1),
            "subtasks_vertical.png",
            getActivity().getString(R.string.subtasks_help_2),
            "subtasks_horizontal.png",
            getActivity().getString(R.string.subtasks_help_3));

    String color = ThemeService.getDialogTextColorString();
    String html =
        String.format(
            "<html><body style='text-align:center;color:%s'>%s</body></html>", color, body);

    DialogUtilities.htmlDialog(getActivity(), html, R.string.subtasks_help_title);
    Preferences.setInt(AstridPreferences.P_SUBTASKS_HELP, 1);
  }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setTheme(android.R.style.Theme_Dialog);

      tag = getIntent().getStringExtra(TAG);
      if (tag == null) {
        finish();
        return;
      }
      DependencyInjectionService.getInstance().inject(this);

      TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT);
      if (tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0) {
        DialogUtilities.okDialog(
            this, getString(R.string.actfm_tag_operation_disabled), getCancelListener());
        return;
      }
      showDialog();
    }
 private void searchMarket(final String packageName, int title, int body) {
   DialogUtilities.okCancelDialog(
       activity,
       activity.getString(title),
       activity.getString(body),
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface d, int which) {
           Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(packageName);
           try {
             if (marketIntent == null)
               throw new ActivityNotFoundException("No market link supplied"); // $NON-NLS-1$
             activity.startActivity(marketIntent);
           } catch (ActivityNotFoundException anf) {
             DialogUtilities.okDialog(
                 activity, activity.getString(R.string.EPr_marketUnavailable_dlg), null);
           }
         }
       },
       null);
 }
Beispiel #12
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();
  }
Beispiel #13
0
  public void showVoiceInputMarketSearch(DialogInterface.OnClickListener onFail) {
    String packageName;
    if (AndroidUtilities.getSdkVersion() <= 7) {
      packageName = "com.google.android.voicesearch.x";
    } else {
      packageName = "com.google.android.voicesearch";
    }

    // User wants to install voice search, take them to the market
    Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(packageName);
    if (activity != null) {
      try {
        if (marketIntent == null) {
          throw new ActivityNotFoundException("No market link supplied"); // $NON-NLS-1$
        }
        activity.startActivity(marketIntent);
      } catch (ActivityNotFoundException ane) {
        DialogUtilities.okDialog(
            activity, activity.getString(R.string.EPr_marketUnavailable_dlg), onFail);
      }
    }
  }
Beispiel #14
0
  /**
   * Return a change log string. Releases occur often enough that we don't expect change sets to be
   * localized.
   *
   * @param from
   * @param to
   * @return
   */
  @SuppressWarnings("nls")
  public void showChangeLog(Context context, int from) {
    if (!(context instanceof Activity) || from == 0) return;

    Preferences.clear(TagCaseMigrator.PREF_SHOW_MIGRATION_ALERT);

    Preferences.clear(AstridPreferences.P_UPGRADE_FROM);
    StringBuilder changeLog = new StringBuilder();

    if (from >= V4_2_0 && from < V4_2_1) {
      newVersionString(
          changeLog,
          "4.2.1 (6/08/12)",
          new String[] {
            "Fix for MyTouch 4G Lists",
            "Fixed a crash when adding tasks with due times to Google Calendar",
            "Better syncing of the people list",
            "Minor UI polish and bugfixes"
          });
    }

    if (from < V4_2_0) {
      newVersionString(
          changeLog,
          "4.2.0 (6/05/12)",
          new String[] {
            "Support for the Nook", "Fixed crash on large image attachments", "Minor bugfixes"
          });
    }

    if (from >= V4_1_3 && from < V4_1_3_1) {
      newVersionString(changeLog, "4.1.3.1 (5/18/12)", new String[] {"Fixed reminders for ICS"});
    }

    if (from >= V4_1_2 && from < V4_1_3) {
      newVersionString(
          changeLog,
          "4.1.3 (5/17/12)",
          new String[] {
            "Added ability to see shared tasks sorted by friend! Enable or disable "
                + "in Settings > Astrid Labs",
            "Fixed desktop shortcuts",
            "Fixed adding tasks from the Power Pack widget",
            "Fixed selecting photos on the Kindle Fire",
            "Various other minor bug and crash fixes"
          });
    }

    if (from >= V4_1_1 && from < V4_1_2) {
      newVersionString(
          changeLog, "4.1.2 (5/05/12)", new String[] {"Fixed some crashes and minor bugs"});
    }

    if (from < V4_1_1) {
      newVersionString(
          changeLog,
          "4.1.1 (5/04/12)",
          new String[] {
            "Respond to or set reminders for missed calls. This feature requires a new permission to read "
                + "the phone state.",
          });
    }

    if (from < V4_1_0) {
      newVersionString(
          changeLog,
          "4.1.0 (5/03/12)",
          new String[] {
            "Swipe between lists! Swipe left and right to move through your lists. Enable or adjust "
                + "in Settings > Astrid Labs",
            "Assign tasks to contacts without typing",
            "Links to tasks in comments",
            "Astrid.com sync improvements",
            "Other minor bugfixes",
          });
    }

    if (from >= V4_0_6 && from < V4_0_6_2) {
      newVersionString(
          changeLog,
          "4.0.6.2 (4/03/12)",
          new String[] {
            "Minor fix to backup migration fix to handle deleted tasks as well as completed tasks."
          });
    }

    if (from >= V4_0_6 && from < V4_0_6_1) {
      newVersionString(
          changeLog,
          "4.0.6.1 (4/03/12)",
          new String[] {
            "Fixed a bug where old tasks could become uncompleted. Sorry to those of you"
                + " who were affected by this! To recover, you can import your old tasks"
                + " from any backup file created before April 3 by clicking Menu -> Settings ->"
                + " Backups -> Manage Backups -> Import Tasks. Backup files from April 3 will start"
                + " with 'auto.120403'."
          });
    }

    if (from < V4_0_6) {
      newVersionString(
          changeLog,
          "4.0.6 (4/02/12)",
          new String[] {
            "Fixes and performance improvements to Astrid.com and Google Tasks sync",
            "Google TV support! (Beta)",
            "Fixed a bug that could put duetimes on tasks when changing timezones",
            "Fixed a rare crash when starting a task timer"
          });
    }

    if (from >= V4_0_0 && from < V4_0_5) {
      newVersionString(
          changeLog,
          "4.0.5 (3/22/12)",
          new String[] {
            "Better conflict resolution for Astrid.com sync",
            "Fixes and improvements to Gtasks sync",
            "Added option to report sync errors in sync preference screen"
          });
    }

    if (from >= V4_0_0 && from < V4_0_4) {
      newVersionString(
          changeLog,
          "4.0.4 (3/7/12)",
          new String[] {
            "Fixed crashes related to error reporting",
            "Fixed a crash when creating a task from the widget",
            "Fixed a bug where a manual sync wouldn't always start"
          });
    }

    if (from >= V4_0_0 && from < V4_0_3) {
      newVersionString(
          changeLog,
          "4.0.3 (3/6/12)",
          new String[] {
            "Fix some issues with Google Tasks sync. We're sorry to "
                + "everyone who's been having trouble with it!",
            "Updated translations for Portuguese, Chinese, German, Russian, and Dutch",
            "Centralize Android's menu key with in-app navigation",
            "Fixed crashes & improve crash logging",
          });
    }

    if (from >= V4_0_0 && from < V4_0_2) {
      newVersionString(
          changeLog,
          "4.0.2 (2/29/12)",
          new String[] {
            "Removed GPS permission - no longer needed",
            "Fixes for some subtasks issues",
            "No longer need to run the Crittercism service in the background",
            "Fixed a crash that could occur when cloning tasks",
            "Fixed a bug that prevented certain comments from syncing correctly",
            "Fixed issues where voice add wouldn't work correctly",
          });
    }

    if (from >= V4_0_0 && from < V4_0_1) {
      newVersionString(
          changeLog,
          "4.0.1 (2/23/12)",
          new String[] {
            "Fixed a database issue affecting Android 2.1 users",
            "Fixed a crash when using drag and drop in Google Tasks lists",
            "Other small bugfixes"
          });
    }

    if (from < V4_0_0) {
      newVersionString(
          changeLog,
          "4.0.0 (2/23/12)",
          new String[] {
            "Welcome to Astrid 4.0! Here's what's new:",
            "<b>Subtasks!!!</b><br>Press the Menu key and select 'Sort' to access",
            "<b>New Look!</b><br>Customize how Astrid looks from the Settings menu",
            "<b>Task Rabbit!</b><br>Outsource your tasks with the help of trustworthy people",
            "<b>More Reliable Sync</b><br>Including fixes to Astrid.com and Google Tasks sync",
            "<b>Tablet version</b><br>Enjoy Astrid on your luxurious Android tablet",
            "Many bug and usability fixes"
          });
    }

    // --- old messages

    if (from >= V3_0_0 && from < V3_9_0) {
      newVersionString(
          changeLog,
          "3.9 (12/09/11)",
          new String[] {
            "Cleaner design (especially the task edit page)!",
            "Customize the edit page (\"Beast Mode\" in preferences)",
            "Make shared lists with tasks open to anyone (perfect for potlucks, road trips etc)",
            "Fixes for some ICS crashes (full support coming soon)",
            "Google Tasks sync improvement - Note: If you have been experiencing \"Sync with errors\", try logging out and logging back in to Google Tasks.",
            "Other minor bug fixes",
            "Feedback welcomed!"
          });
    }

    if (from >= V3_0_0 && from < V3_8_0) {
      newVersionString(
          changeLog,
          "3.8.0 (7/15/11)",
          new String[] {
            "Astrid.com: sync & share tasks / lists with others!",
            "GTasks Sync using Google's official task API! Gtasks users "
                + "will need to perform a manual sync to set everything up.",
            "Renamed \"Tags\" to \"Lists\" (see blog.astrid.com for details)",
            "New style for \"Task Edit\" page!",
            "Purge completed or deleted tasks from settings menu!",
          });
      gtasksPreferenceService.setToken(null);
    }

    if (from >= V3_0_0 && from < V3_7_0) {
      newVersionString(
          changeLog,
          "3.7.0 (2/7/11)",
          new String[] {
            "Improved UI for displaying task actions. Tap a task to "
                + "bring up actions, tap again to dismiss.",
            "Task notes can be viewed by tapping the note icon to " + "the right of the task.",
            "Added Astrid as 'Send-To' choice in Android Browser and " + "other apps.",
            "Add tags and importance in quick-add, e.g. " + "\"call mom #family @phone !4\"",
            "Fixed bug with custom filters & tasks being hidden.",
          });
      upgrade3To3_7();
      if (gtasksPreferenceService.isLoggedIn()) taskService.clearDetails(Criterion.all);
      Preferences.setBoolean(Eula.PREFERENCE_EULA_ACCEPTED, true);
    }
    if (from >= V3_0_0 && from < V3_6_0) {
      newVersionString(
          changeLog,
          "3.6.0 (11/13/10)",
          new String[] {
            "Astrid Power Pack is now launched to the Android Market. "
                + "New Power Pack features include 4x2 and 4x4 widgets and voice "
                + "task reminders and creation. Go to the add-ons page to find out more!",
            "Fix for Google Tasks: due times got lost on sync, repeating tasks not repeated",
            "Fix for task alarms not always firing if multiple set",
            "Fix for various force closes",
          });
      upgrade3To3_6(context);
    }
    if (from >= V3_0_0 && from < V3_5_0)
      newVersionString(
          changeLog,
          "3.5.0 (10/25/10)",
          new String[] {
            "Google Tasks Sync (beta!)",
            "Bug fix with RMilk & new tasks not getting synced",
            "Fixed Force Closes and other bugs",
          });
    if (from >= V3_0_0 && from < V3_4_0) {
      newVersionString(
          changeLog,
          "3.4.0 (10/08/10)",
          new String[] {
            "End User License Agreement",
            "Option to disable usage statistics",
            "Bug fixes with Producteev",
          });
    }
    if (from >= V3_0_0 && from < V3_3_0)
      newVersionString(
          changeLog,
          "3.3.0 (9/17/10)",
          new String[] {
            "Fixed some RTM duplicated tasks issues",
            "UI updates based on your feedback",
            "Snooze now overrides other alarms",
            "Added preference option for selecting snooze style",
            "Hide until: now allows you to pick a specific time",
          });
    if (from >= V3_0_0 && from < V3_2_0)
      newVersionString(
          changeLog,
          "3.2.0 (8/16/10)",
          new String[] {
            "Build your own custom filters from the Filter page",
            "Easy task sorting (in the task list menu)",
            "Create widgets from any of your filters",
            "Synchronize with Producteev! (producteev.com)",
            "Select tags by drop-down box",
            "Cosmetic improvements, calendar & sync bug fixes",
          });
    if (from >= V3_0_0 && from < V3_1_0)
      newVersionString(
          changeLog,
          "3.1.0 (8/9/10)",
          new String[] {
            "Linkify phone numbers, e-mails, and web pages",
            "Swipe L => R to go from tasks to filters",
            "Moved task priority bar to left side",
            "Added ability to create fixed alerts for a task",
            "Restored tag hiding when tag begins with underscore (_)",
            "FROYO: disabled moving app to SD card, it would break alarms and widget",
            "Also gone: a couple force closes, bugs with repeating tasks",
          });

    if (changeLog.length() == 0) return;

    changeLog.append("Have a spectacular day!</body></html>");
    String color = ThemeService.getDialogTextColor();
    String changeLogHtml = "<html><body style='color: " + color + "'>" + changeLog;

    DialogUtilities.htmlDialog(context, changeLogHtml, R.string.UpS_changelog_title);
  }
Beispiel #15
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();
  }
Beispiel #16
0
  /**
   * Save sharing settings
   *
   * @param toast toast to show after saving is finished
   * @return false if login is required & save should be halted
   */
  @SuppressWarnings("nls")
  public boolean saveSharingSettings(String toast) {
    if (task == null) return false;

    saveToast = toast;
    boolean dirty = false;
    try {
      JSONObject userJson = null;
      TextView assignedView = null;
      if (assignedCustom.getVisibility() == View.VISIBLE) {
        userJson = PeopleContainer.createUserJson(assignedCustom);
        assignedView = assignedCustom;
      } else if (assignedSpinner.getSelectedItem() != null) {
        userJson = ((AssignedToUser) assignedSpinner.getSelectedItem()).user;
      }

      if (userJson != null && userJson.optString("email").indexOf('@') == -1) {
        throw new ParseSharedException(
            assignedView,
            activity.getString(R.string.actfm_EPA_invalid_email, userJson.optString("email")));
      }

      if (userJson == null || userJson.optLong("id", -1) == 0) {
        dirty = task.getValue(Task.USER_ID) == 0L ? dirty : true;
        task.setValue(Task.USER_ID, 0L);
        if (!TextUtils.isEmpty(task.getValue(Task.USER))) task.setValue(Task.USER, "{}");
      } else {
        String user = userJson.toString();

        long taskUserId = -1;
        String taskUserEmail = "";
        try {
          JSONObject taskUser = new JSONObject(task.getValue(Task.USER));
          taskUserId = taskUser.optLong("id", -1);
          taskUserEmail = taskUser.optString("email");
        } catch (JSONException e) {
          // sad times
        }
        long userId = userJson.optLong("id", -1);
        String userEmail = userJson.optString("email");

        boolean match = (userId == taskUserId && userId != -1);
        match = match || (userEmail.equals(taskUserEmail) && !TextUtils.isEmpty(userEmail));

        dirty = match ? dirty : true;
        task.setValue(Task.USER_ID, userJson.optLong("id", -1));
        task.setValue(Task.USER, user);
      }

      JSONObject sharedWith = parseSharedWithAndTags();
      dirty = dirty || sharedWith.has("p");
      if (!TextUtils.isEmpty(task.getValue(Task.SHARED_WITH)) || sharedWith.length() != 0)
        task.setValue(Task.SHARED_WITH, sharedWith.toString());

      if (dirty) taskService.save(task);

      if (dirty && !actFmPreferenceService.isLoggedIn()) {
        activity.startActivityForResult(
            new Intent(activity, ActFmLoginActivity.class), loginRequestCode);
        return false;
      }

      if (dirty) shareTask(sharedWith);
      else showSaveToast();

      return true;
    } catch (JSONException e) {
      exceptionService.displayAndReportError(activity, "save-people", e);
    } catch (ParseSharedException e) {
      if (e.view != null) {
        e.view.setTextColor(Color.RED);
        e.view.requestFocus();
      }
      DialogUtilities.okDialog(activity, e.message, null);
    }
    return false;
  }
Beispiel #17
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);
                  }
                });
          }
        });
  }