Example #1
0
 public boolean handleOptionsMenuItemSelected(int id, Intent intent) {
   switch (id) {
     case MENU_ADDONS_ID:
       StatisticsService.reportEvent(StatisticsConstants.TLA_MENU_ADDONS);
       intent = new Intent(getActivity(), AddOnActivity.class);
       startActivityForResult(intent, ACTIVITY_ADDONS);
       return true;
     case MENU_SORT_ID:
       StatisticsService.reportEvent(StatisticsConstants.TLA_MENU_SORT);
       AlertDialog dialog =
           SortSelectionActivity.createDialog(
               getActivity(), hasDraggableOption(), this, sortFlags, sortSort);
       dialog.show();
       return true;
     case MENU_SYNC_ID:
       StatisticsService.reportEvent(StatisticsConstants.TLA_MENU_SYNC);
       syncActionHelper.performSyncAction();
       return true;
     case MENU_ADDON_INTENT_ID:
       AndroidUtilities.startExternalIntent(getActivity(), intent, ACTIVITY_MENU_EXTERNAL);
       return true;
     case MENU_NEW_FILTER_ID:
       intent = new Intent(getActivity(), CustomFilterActivity.class);
       getActivity().startActivityForResult(intent, ACTIVITY_REQUEST_NEW_FILTER);
       return true;
   }
   return false;
 }
  private void write(GtasksTaskContainer task) throws IOException {
    //  merge astrid dates with google dates
    if (!task.task.isSaved() && actFmPreferenceService.isLoggedIn()) titleMatchWithActFm(task.task);

    if (task.task.isSaved()) {
      Task local =
          PluginServices.getTaskService()
              .fetchById(task.task.getId(), Task.DUE_DATE, Task.COMPLETION_DATE);
      if (local == null) {
        task.task.clearValue(Task.ID);
      } else {
        mergeDates(task.task, local);
        if (task.task.isCompleted() && !local.isCompleted())
          StatisticsService.reportEvent(StatisticsConstants.GTASKS_TASK_COMPLETED);
      }
    } else { // Set default importance and reminders for remotely created tasks
      task.task.setValue(
          Task.IMPORTANCE,
          Preferences.getIntegerFromString(
              R.string.p_default_importance_key, Task.IMPORTANCE_SHOULD_DO));
      TaskDao.setDefaultReminders(task.task);
    }
    if (!TextUtils.isEmpty(task.task.getValue(Task.TITLE))) {
      task.task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
      gtasksMetadataService.saveTaskAndMetadata(task);
    }
  }
Example #3
0
 private static void accept(Activity activity) {
   if (activity instanceof EulaCallback) {
     ((EulaCallback) activity).eulaAccepted();
   }
   Preferences.setBoolean(PREFERENCE_EULA_ACCEPTED, true);
   StatisticsService.reportEvent(StatisticsConstants.EULA_ACCEPTED);
 }
Example #4
0
  /**
   * Loads action item from the given intent
   *
   * @param intent
   */
  @SuppressWarnings("nls")
  protected void loadItem(Intent intent) {
    if (model != null) {
      // came from bundle
      isNewTask = (model.getValue(Task.TITLE).length() == 0);
      return;
    }

    long idParam = intent.getLongExtra(TOKEN_ID, -1L);

    database.openForReading();
    if (idParam > -1L) {
      model = taskService.fetchById(idParam, Task.PROPERTIES);
    }

    // not found by id or was never passed an id
    if (model == null) {
      String valuesAsString = intent.getStringExtra(TOKEN_VALUES);
      ContentValues values = null;
      try {
        if (valuesAsString != null)
          values = AndroidUtilities.contentValuesFromSerializedString(valuesAsString);
      } catch (Exception e) {
        // oops, can't serialize
      }
      model = TaskListActivity.createWithValues(values, null, taskService, metadataService);
    }

    if (model.getValue(Task.TITLE).length() == 0) {
      StatisticsService.reportEvent("create-task");
      isNewTask = true;

      // set deletion date until task gets a title
      model.setValue(Task.DELETION_DATE, DateUtilities.now());
    } else {
      StatisticsService.reportEvent("edit-task");
    }

    if (model == null) {
      exceptionService.reportError("task-edit-no-task", new NullPointerException("model"));
      finish();
      return;
    }

    // clear notification
    Notifications.cancelNotifications(model.getId());
  }
Example #5
0
  public void showSettings() {
    Activity activity = getActivity();
    if (activity == null) return;

    StatisticsService.reportEvent(StatisticsConstants.TLA_MENU_SETTINGS);
    Intent intent = new Intent(activity, EditPreferences.class);
    startActivityForResult(intent, ACTIVITY_SETTINGS);
  }
Example #6
0
  private void userRetentionMetrics() {
    if (Preferences.getBoolean(AstridPreferences.P_FIRST_TASK, true)) {
      StatisticsService.reportEvent(StatisticsConstants.USER_FIRST_TASK);
      Preferences.setBoolean(AstridPreferences.P_FIRST_TASK, false);
    }

    long firstLaunchTime = Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, 0);
    long now = DateUtilities.now();
    long timeSinceFirst = now - firstLaunchTime;
    if (timeSinceFirst < DateUtilities.ONE_WEEK
        && !Preferences.getBoolean(StatisticsConstants.TASK_ONE_WEEK, false)) {
      StatisticsService.reportEvent(StatisticsConstants.TASK_ONE_WEEK);
      Preferences.setBoolean(StatisticsConstants.TASK_ONE_WEEK, true);
    } else if (timeSinceFirst < 2 * DateUtilities.ONE_WEEK
        && !Preferences.getBoolean(StatisticsConstants.TASK_TWO_WEEKS, false)) {
      StatisticsService.reportEvent(StatisticsConstants.TASK_TWO_WEEKS);
      Preferences.setBoolean(StatisticsConstants.TASK_TWO_WEEKS, true);
    } else if (timeSinceFirst < 3 * DateUtilities.ONE_WEEK
        && !Preferences.getBoolean(StatisticsConstants.TASK_THREE_WEEKS, false)) {
      StatisticsService.reportEvent(StatisticsConstants.TASK_THREE_WEEKS);
      Preferences.setBoolean(StatisticsConstants.TASK_THREE_WEEKS, true);
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    ContextManager.setContext(context);
    DependencyInjectionService.getInstance().inject(this);
    long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
    if (taskId == -1) return;

    Task task = PluginServices.getTaskService().fetchById(taskId, Task.PROPERTIES);
    if (task == null || !task.isCompleted()) return;

    String recurrence = task.getValue(Task.RECURRENCE);
    if (recurrence != null && recurrence.length() > 0) {
      long newDueDate;
      try {
        newDueDate = computeNextDueDate(task, recurrence);
        if (newDueDate == -1) return;
      } catch (ParseException e) {
        PluginServices.getExceptionService().reportError("repeat-parse", e); // $NON-NLS-1$
        return;
      }

      StatisticsService.reportEvent(StatisticsConstants.V2_TASK_REPEAT);

      long oldDueDate = task.getValue(Task.DUE_DATE);
      long repeatUntil = task.getValue(Task.REPEAT_UNTIL);

      boolean repeatFinished = repeatUntil > 0 && newDueDate >= repeatUntil;
      if (repeatFinished) {
        Intent repeatFinishedIntent =
            new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEAT_FINISHED);
        repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
        repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
        repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
        context.sendOrderedBroadcast(repeatFinishedIntent, null);
        return;
      }

      rescheduleTask(task, newDueDate);

      // send a broadcast
      Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
      context.sendOrderedBroadcast(broadcastIntent, null);
      Flags.set(Flags.REFRESH);
      return;
    }
  }
Example #8
0
  @Override
  public boolean persist(Metadata item) {
    if (!item.containsValue(Metadata.CREATION_DATE))
      item.setValue(Metadata.CREATION_DATE, DateUtilities.now());

    boolean state = super.persist(item);
    if (Preferences.getBoolean(AstridPreferences.P_FIRST_LIST, true)) {
      if (state && item.getValue(Metadata.KEY).equals(TagService.KEY)) {
        StatisticsService.reportEvent(StatisticsConstants.USER_FIRST_LIST);
        Preferences.setBoolean(AstridPreferences.P_FIRST_LIST, false);
      }
    }
    Astrid2TaskProvider.notifyDatabaseModification();
    return state;
  }
Example #9
0
  @Override
  public void onCreate(Bundle icicle) {
    ThemeService.applyTheme(this);
    ThemeService.setForceFilterInvert(true);
    super.onCreate(icicle);

    // Set the result to CANCELED.  This will cause the widget host to cancel
    // out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);

    // Set the view layout resource to use.
    setContentView(R.layout.widget_config_activity);

    setTitle(R.string.WCA_title);

    // Find the widget id from the intent.
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
      mAppWidgetId =
          extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // If they gave us an intent without the widget id, just bail.
    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
      finish();
    }

    // set up ui
    adapter = new FilterAdapter(this, getListView(), R.layout.filter_adapter_row, true, true);
    adapter.filterStyle = R.style.TextAppearance_FLA_Filter_Widget;
    setListAdapter(adapter);

    Button button = (Button) findViewById(R.id.ok);
    button.setOnClickListener(mOnClickListener);

    StatisticsService.reportEvent(StatisticsConstants.WIDGET_CONFIG);
  }
Example #10
0
  @SuppressWarnings("nls")
  private void addComment(
      String message, String actionCode, String uuid, String title, boolean usePicture) {
    // Allow for users to just add picture
    if (TextUtils.isEmpty(message) && usePicture) {
      message = " ";
    }
    UserActivity userActivity = new UserActivity();
    userActivity.setValue(UserActivity.MESSAGE, message);
    userActivity.setValue(UserActivity.ACTION, actionCode);
    userActivity.setValue(UserActivity.USER_UUID, Task.USER_ID_SELF);
    userActivity.setValue(UserActivity.TARGET_ID, uuid);
    userActivity.setValue(UserActivity.TARGET_NAME, title);
    userActivity.setValue(UserActivity.CREATED_AT, DateUtilities.now());
    if (usePicture && pendingCommentPicture != null) {
      JSONObject pictureJson =
          RemoteModel.PictureHelper.savePictureJson(activity, pendingCommentPicture);
      if (pictureJson != null) userActivity.setValue(UserActivity.PICTURE, pictureJson.toString());
    }

    userActivityDao.createNew(userActivity);
    if (commentField != null) commentField.setText(""); // $NON-NLS-1$

    pendingCommentPicture = usePicture ? null : pendingCommentPicture;
    if (usePicture) {
      if (activity != null)
        activity.getIntent().removeExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
    }
    if (pictureButton != null) pictureButton.setImageResource(cameraButton);
    StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMMENT);

    setUpListAdapter();
    for (UpdatesChangedListener l : listeners) {
      l.commentAdded();
    }
  }
Example #11
0
 @Override
 protected void onStop() {
   StatisticsService.sessionStop(this);
   super.onStop();
 }
Example #12
0
 @Override
 protected void onResume() {
   super.onResume();
   StatisticsService.sessionStart(this);
 }
Example #13
0
 @Override
 protected void onPause() {
   StatisticsService.sessionPause();
   super.onPause();
 }
Example #14
0
 private void showForums() {
   StatisticsService.reportEvent(StatisticsConstants.TLA_MENU_HELP);
   Intent intent = new Intent(this, NewFeedbackSpringboardActivity.class);
   startActivity(intent);
 }
Example #15
0
 @Override
 protected void onResume() {
   super.onResume();
   StatisticsService.sessionStart(this);
   adapter.registerRecevier();
 }
Example #16
0
 @Override
 protected void onPause() {
   super.onPause();
   StatisticsService.sessionPause();
   adapter.unregisterRecevier();
 }
Example #17
0
 /**
  * A task was completed from the task adapter
  *
  * @param item task that was completed
  */
 protected void onTaskCompleted(Task item) {
   if (isInbox) StatisticsService.reportEvent(StatisticsConstants.TASK_COMPLETED_INBOX);
   else StatisticsService.reportEvent(StatisticsConstants.TASK_COMPLETED_FILTER);
 }
Example #18
0
 @Override
 protected void onStop() {
   super.onStop();
   StatisticsService.sessionStop(this);
   ThemeService.setForceFilterInvert(false);
 }