Exemplo n.º 1
0
  @Override
  public void readFromTask(Task task) {
    this.myTask = task;
    Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(myTask.getId());
    if (metadata == null) metadata = ProducteevTask.newMetadata();

    // Fill the dashboard-spinner and set the current dashboard
    long dashboardId = ProducteevUtilities.INSTANCE.getDefaultDashboard();
    if (metadata.containsNonNullValue(ProducteevTask.DASHBOARD_ID))
      dashboardId = metadata.getValue(ProducteevTask.DASHBOARD_ID);

    StoreObject[] dashboardsData = ProducteevDataService.getInstance().getDashboards();
    dashboards = new ArrayList<ProducteevDashboard>(dashboardsData.length);
    ProducteevDashboard ownerDashboard = null;
    int dashboardSpinnerIndex = -1;

    int i = 0;
    for (i = 0; i < dashboardsData.length; i++) {
      ProducteevDashboard dashboard = new ProducteevDashboard(dashboardsData[i]);
      dashboards.add(dashboard);
      if (dashboard.getId() == dashboardId) {
        ownerDashboard = dashboard;
        dashboardSpinnerIndex = i;
      }
    }

    // dashboard to not sync as first spinner-entry
    dashboards.add(
        0,
        new ProducteevDashboard(
            ProducteevUtilities.DASHBOARD_NO_SYNC,
            activity.getString(R.string.producteev_no_dashboard),
            null));
    // dummy entry for adding a new dashboard
    dashboards.add(
        new ProducteevDashboard(
            ProducteevUtilities.DASHBOARD_CREATE,
            activity.getString(R.string.producteev_create_dashboard),
            null));

    ArrayAdapter<ProducteevDashboard> dashAdapter =
        new ArrayAdapter<ProducteevDashboard>(
            activity, android.R.layout.simple_spinner_item, dashboards);
    dashAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dashboardSelector.setAdapter(dashAdapter);
    dashboardSelector.setSelection(dashboardSpinnerIndex + 1);

    if (ownerDashboard == null
        || ownerDashboard.getId() == ProducteevUtilities.DASHBOARD_NO_SYNC
        || ownerDashboard.getId() == ProducteevUtilities.DASHBOARD_CREATE) {
      responsibleSelector.setEnabled(false);
      responsibleSelector.setAdapter(null);
      view.findViewById(R.id.producteev_TEA_task_assign_label).setVisibility(View.GONE);
      return;
    }

    refreshResponsibleSpinner(ownerDashboard.getUsers());
  }
Exemplo n.º 2
0
  @Override
  public void onReceive(Context context, Intent intent) {
    ContextManager.setContext(context);
    // if we aren't logged in, don't expose features
    if (!ProducteevUtilities.INSTANCE.isLoggedIn()) return;

    StoreObject[] dashboards = ProducteevDataService.getInstance().getDashboards();

    // If user does not have any dashboards, don't show this section at all
    if (dashboards.length == 0) return;

    FilterListHeader producteevHeader =
        new FilterListHeader(context.getString(R.string.producteev_FEx_header));

    long currentUserId = Preferences.getLong(ProducteevUtilities.PREF_USER_ID, -1);

    // load dashboards
    Filter[] dashboardFilters = new Filter[dashboards.length];
    for (int i = 0; i < dashboards.length; i++)
      dashboardFilters[i] =
          filterFromList(context, new ProducteevDashboard(dashboards[i]), currentUserId);
    FilterCategory producteevDashboards =
        new FilterCategory(context.getString(R.string.producteev_FEx_dashboard), dashboardFilters);

    // load responsible people, assigned by me
    TreeSet<ProducteevUser> people = loadResponsiblePeople(dashboards);
    Filter[] peopleByMeFilters = new Filter[people.size()];
    int index = 0;
    for (ProducteevUser person : people)
      peopleByMeFilters[index++] = filterUserAssignedByMe(context, person, currentUserId);
    FilterCategory producteevUsersByMeCategory =
        new FilterCategory(
            context.getString(R.string.producteev_FEx_responsible_byme), peopleByMeFilters);

    // load responsible people, assigned by others
    Filter[] peopleByOthersFilters = new Filter[people.size()];
    index = 0;
    for (ProducteevUser person : people)
      peopleByOthersFilters[index++] = filterUserAssignedByOthers(context, person, currentUserId);
    FilterCategory producteevUsersByOthersCategory =
        new FilterCategory(
            context.getString(R.string.producteev_FEx_responsible_byothers), peopleByOthersFilters);

    // transmit filter list
    FilterListItem[] list = new FilterListItem[4];
    list[0] = producteevHeader;
    list[1] = producteevDashboards;
    list[2] = producteevUsersByMeCategory;
    list[3] = producteevUsersByOthersCategory;
    Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_FILTERS);
    broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ProducteevUtilities.IDENTIFIER);
    broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, list);
    context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    // if we aren't logged in, don't expose sync action
    if (!ProducteevUtilities.INSTANCE.isLoggedIn()) return;

    Intent syncIntent =
        new Intent(
            ProducteevBackgroundService.SYNC_ACTION,
            null,
            context,
            ProducteevBackgroundService.class);
    PendingIntent pendingIntent =
        PendingIntent.getService(context, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    SyncAction syncAction =
        new SyncAction(context.getString(R.string.producteev_PPr_header), pendingIntent);

    Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS);
    broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ProducteevUtilities.IDENTIFIER);
    broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, syncAction);
    context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
  }