Пример #1
0
 /**
  * Get list name
  *
  * @return NOT_FOUND if no list by this id exists, otherwise list name
  */
 public String getListName(String listId) {
   StoreObject list = getList(listId);
   if (list != LIST_NOT_FOUND_OBJECT) {
     return list.getValue(GtasksList.NAME);
   }
   return LIST_NOT_FOUND;
 }
Пример #2
0
  @Override
  public void synchronizeList(
      Object list, final boolean manual, final SyncResultCallback callback) {
    if (!(list instanceof StoreObject)) return;
    final StoreObject gtasksList = (StoreObject) list;
    if (!GtasksList.TYPE.equals(gtasksList.getValue(StoreObject.TYPE))) return;

    callback.started();
    callback.incrementMax(100);

    new Thread(
            new Runnable() {
              public void run() {
                callback.incrementProgress(50);
                try {
                  String authToken = getValidatedAuthToken();
                  callback.incrementProgress(12);
                  gtasksSyncService.waitUntilEmpty();
                  callback.incrementProgress(13);
                  final GtasksInvoker service = new GtasksInvoker(authToken);
                  synchronizeListHelper(gtasksList, service, manual, null, callback);
                } finally {
                  callback.incrementProgress(25);
                  callback.finished();
                }
              }
            })
        .start();
  }
Пример #3
0
  private synchronized void synchronizeListHelper(
      StoreObject list,
      GtasksInvoker invoker,
      boolean manual,
      SyncExceptionHandler errorHandler,
      SyncResultCallback callback) {
    String listId = list.getValue(GtasksList.REMOTE_ID);
    long lastSyncDate;
    if (!manual && list.containsNonNullValue(GtasksList.LAST_SYNC)) {
      lastSyncDate = list.getValue(GtasksList.LAST_SYNC);
    } else {
      lastSyncDate = 0;
    }
    boolean includeDeletedAndHidden = lastSyncDate != 0;
    try {
      Tasks taskList =
          invoker.getAllGtasksFromListId(
              listId, includeDeletedAndHidden, includeDeletedAndHidden, lastSyncDate);
      List<com.google.api.services.tasks.model.Task> tasks = taskList.getItems();
      if (tasks != null) {
        callback.incrementMax(tasks.size() * 10);
        HashSet<Long> localIds = new HashSet<Long>(tasks.size());
        for (com.google.api.services.tasks.model.Task t : tasks) {
          GtasksTaskContainer container = parseRemoteTask(t, listId);
          gtasksMetadataService.findLocalMatch(container);
          container.gtaskMetadata.setValue(
              GtasksMetadata.GTASKS_ORDER, Long.parseLong(t.getPosition()));
          container.gtaskMetadata.setValue(
              GtasksMetadata.PARENT_TASK, gtasksMetadataService.localIdForGtasksId(t.getParent()));
          container.gtaskMetadata.setValue(GtasksMetadata.LAST_SYNC, DateUtilities.now() + 1000L);
          write(container);
          localIds.add(container.task.getId());
          callback.incrementProgress(10);
        }
        list.setValue(GtasksList.LAST_SYNC, DateUtilities.now());
        storeObjectDao.persist(list);

        if (lastSyncDate == 0) {
          Long[] localIdArray = localIds.toArray(new Long[localIds.size()]);
          Criterion delete =
              Criterion.and(
                  Metadata.KEY.eq(GtasksMetadata.METADATA_KEY),
                  GtasksMetadata.LIST_ID.eq(listId),
                  Criterion.not(Metadata.TASK.in(localIdArray)));
          taskService.deleteWhere(
              Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).where(delete)));
          metadataService.deleteWhere(delete);
        }

        gtasksTaskListUpdater.correctOrderAndIndentForList(listId);
      }
    } catch (GoogleTasksException e) {
      if (errorHandler != null)
        errorHandler.handleException("gtasks-sync-io", e, e.getType()); // $NON-NLS-1$
    } catch (IOException e) {
      if (errorHandler != null)
        errorHandler.handleException("gtasks-sync-io", e, e.toString()); // $NON-NLS-1$
    }
  }
Пример #4
0
  private Filter[] buildSavedFilters(Context context, Resources r) {
    int themeFlags = ThemeService.getFilterThemeFlags();

    StoreObjectDao dao = PluginServices.getStoreObjectDao();
    TodorooCursor<StoreObject> cursor =
        dao.query(
            Query.select(StoreObject.PROPERTIES)
                .where(StoreObject.TYPE.eq(SavedFilter.TYPE))
                .orderBy(Order.asc(SavedFilter.NAME)));
    try {
      ArrayList<Filter> list = new ArrayList<>();

      // stock filters
      if (Preferences.getBoolean(R.string.p_show_recently_modified_filter, true)) {
        Filter recent =
            new Filter(
                r.getString(R.string.BFE_Recent),
                r.getString(R.string.BFE_Recent),
                new QueryTemplate()
                    .where(TaskCriteria.ownedByMe())
                    .orderBy(Order.desc(Task.MODIFICATION_DATE))
                    .limit(15),
                null);
        recent.listingIcon =
            ((BitmapDrawable)
                    r.getDrawable(ThemeService.getDrawable(R.drawable.filter_pencil, themeFlags)))
                .getBitmap();

        list.add(recent);
      }

      if (cursor != null) {
        StoreObject savedFilter = new StoreObject();
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
          savedFilter.readFromCursor(cursor);
          Filter f = SavedFilter.load(savedFilter);

          Intent deleteIntent = new Intent(context, DeleteActivity.class);
          deleteIntent.putExtra(TOKEN_FILTER_ID, savedFilter.getId());
          deleteIntent.putExtra(TOKEN_FILTER_NAME, f.title);
          f.contextMenuLabels = new String[] {context.getString(R.string.BFE_Saved_delete)};
          f.contextMenuIntents = new Intent[] {deleteIntent};
          f.listingIcon =
              ((BitmapDrawable)
                      r.getDrawable(
                          ThemeService.getDrawable(R.drawable.filter_sliders, themeFlags)))
                  .getBitmap();
          list.add(f);
        }
      }

      return list.toArray(new Filter[list.size()]);
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
Пример #5
0
 public StoreObject getList(String listId) {
   readLists();
   for (StoreObject list : lists) {
     if (list != null && list.getValue(GtasksList.REMOTE_ID).equals(listId)) {
       return list;
     }
   }
   return LIST_NOT_FOUND_OBJECT;
 }
Пример #6
0
  void saveAndView() {
    String title = filterName.getText().toString().trim();

    if (isEmpty(title)) {
      return;
    }

    StringBuilder sql = new StringBuilder(" WHERE ");
    ContentValues values = new ContentValues();
    for (int i = 0; i < adapter.getCount(); i++) {
      CriterionInstance instance = adapter.getItem(i);
      String value = instance.getValueFromCriterion();
      if (value == null && instance.criterion.sql != null && instance.criterion.sql.contains("?")) {
        value = "";
      }

      switch (instance.type) {
        case CriterionInstance.TYPE_ADD:
          sql.append("OR ");
          break;
        case CriterionInstance.TYPE_SUBTRACT:
          sql.append("AND NOT ");
          break;
        case CriterionInstance.TYPE_INTERSECT:
          sql.append("AND ");
          break;
        case CriterionInstance.TYPE_UNIVERSE:
      }

      // special code for all tasks universe
      if (instance.criterion.sql == null) {
        sql.append(TaskCriteria.activeAndVisible()).append(' ');
      } else {
        String subSql = instance.criterion.sql.replace("?", UnaryCriterion.sanitize(value));
        sql.append(Task.ID).append(" IN (").append(subSql).append(") ");
      }

      if (instance.criterion.valuesForNewTasks != null
          && instance.type == CriterionInstance.TYPE_INTERSECT) {
        for (Entry<String, Object> entry : instance.criterion.valuesForNewTasks.valueSet()) {
          values.put(
              entry.getKey().replace("?", value), entry.getValue().toString().replace("?", value));
        }
      }
    }

    StoreObject storeObject =
        SavedFilter.persist(storeObjectDao, adapter, title, sql.toString(), values);
    Filter filter = new CustomFilter(title, sql.toString(), values, storeObject.getId());
    setResult(RESULT_OK, new Intent().putExtra(TagSettingsActivity.TOKEN_NEW_FILTER, filter));
    finish();
  }
Пример #7
0
  public void migrateListIds(TaskLists remoteLists) {
    readLists();

    List<TaskList> items = remoteLists.getItems();
    for (TaskList remote : items) {
      for (StoreObject list : lists) {
        if (list.getValue(GtasksList.NAME).equals(remote.getTitle())) {
          list.setValue(GtasksList.REMOTE_ID, remote.getId());
          storeObjectDao.persist(list);
          break;
        }
      }
    }
  }
Пример #8
0
 @Override
 protected void initiateAutomaticSyncImpl() {
   if (!isCurrentTaskListFragment()) return;
   if (list != null
       && DateUtilities.now() - list.getValue(GtasksList.LAST_SYNC) > DateUtilities.ONE_HOUR) {
     refreshData(false);
   }
 }
Пример #9
0
  public StoreObject addNewList(com.google.api.services.tasks.model.TaskList newList) {
    readLists();

    if (lists != null) {
      for (StoreObject list : lists) {
        if (list.getValue(GtasksList.REMOTE_ID)
            .equals(newList.getId())) // Sanity check--make sure it's actually a new list
        {
          return null;
        }
      }
    }
    StoreObject local = new StoreObject();

    local.setValue(StoreObject.TYPE, GtasksList.TYPE);
    local.setValue(GtasksList.REMOTE_ID, newList.getId());
    local.setValue(GtasksList.NAME, newList.getTitle());

    int order = lists == null ? 0 : lists.length;
    local.setValue(GtasksList.ORDER, order);

    storeObjectDao.persist(local);

    clearListCache();
    return local;
  }
Пример #10
0
  /**
   * Reads in remote list information and updates local list objects.
   *
   * @param remoteLists remote information about your lists
   */
  public synchronized void updateLists(TaskLists remoteLists) {
    readLists();

    HashSet<Long> previousLists = new HashSet<Long>(lists.length);
    for (StoreObject list : lists) {
      previousLists.add(list.getId());
    }

    List<TaskList> items = remoteLists.getItems();
    StoreObject[] newLists = new StoreObject[items.size()];
    for (int i = 0; i < items.size(); i++) {
      com.google.api.services.tasks.model.TaskList remote = items.get(i);

      String id = remote.getId();
      StoreObject local = null;
      for (StoreObject list : lists) {
        if (list.getValue(GtasksList.REMOTE_ID).equals(id)) {
          local = list;
          break;
        }
      }

      if (local == null) {
        local = new StoreObject();
      }

      local.setValue(StoreObject.TYPE, GtasksList.TYPE);
      local.setValue(GtasksList.REMOTE_ID, id);
      local.setValue(GtasksList.NAME, remote.getTitle());
      local.setValue(GtasksList.ORDER, i);
      storeObjectDao.persist(local);
      previousLists.remove(local.getId());
      newLists[i] = local;
    }
    lists = newLists;

    // check for lists that aren't on remote server
    for (Long listId : previousLists) {
      storeObjectDao.delete(listId);
    }
  }
Пример #11
0
  private Filter[] buildSavedFilters(Context context, Resources r) {
    int themeFlags = ThemeService.getFilterThemeFlags();

    boolean useCustomFilters = Preferences.getBoolean(R.string.p_use_filters, true);
    StoreObjectDao dao = PluginServices.getStoreObjectDao();
    TodorooCursor<StoreObject> cursor = null;
    if (useCustomFilters)
      cursor =
          dao.query(
              Query.select(StoreObject.PROPERTIES)
                  .where(StoreObject.TYPE.eq(SavedFilter.TYPE))
                  .orderBy(Order.asc(SavedFilter.NAME)));
    try {
      Filter[] list;
      if (useCustomFilters && cursor != null) list = new Filter[cursor.getCount() + 3];
      else list = new Filter[3];

      // stock filters
      list[0] = getTodayFilter(r);

      list[1] =
          new Filter(
              r.getString(R.string.BFE_Recent),
              r.getString(R.string.BFE_Recent),
              new QueryTemplate()
                  .where(TaskCriteria.ownedByMe())
                  .orderBy(Order.desc(Task.MODIFICATION_DATE))
                  .limit(15),
              null);
      list[1].listingIcon =
          ((BitmapDrawable)
                  r.getDrawable(ThemeService.getDrawable(R.drawable.filter_pencil, themeFlags)))
              .getBitmap();

      list[2] = getAssignedByMeFilter(r);

      if (useCustomFilters && cursor != null) {
        StoreObject savedFilter = new StoreObject();
        for (int i = 3; i < list.length; i++) {
          cursor.moveToNext();
          savedFilter.readFromCursor(cursor);
          list[i] = SavedFilter.load(savedFilter);

          Intent deleteIntent = new Intent(context, DeleteActivity.class);
          deleteIntent.putExtra(TOKEN_FILTER_ID, savedFilter.getId());
          deleteIntent.putExtra(TOKEN_FILTER_NAME, list[i].title);
          list[i].contextMenuLabels = new String[] {context.getString(R.string.BFE_Saved_delete)};
          list[i].contextMenuIntents = new Intent[] {deleteIntent};
          list[i].listingIcon =
              ((BitmapDrawable)
                      r.getDrawable(
                          ThemeService.getDrawable(R.drawable.filter_sliders, themeFlags)))
                  .getBitmap();
        }
      }

      return list;
    } finally {
      if (cursor != null) cursor.close();
    }
  }