Exemplo n.º 1
0
  @SuppressWarnings("nls")
  private void refreshMembersPage() {
    tagName.setText(tagData.getValue(TagData.NAME));
    picture.setUrl(tagData.getValue(TagData.PICTURE));

    TextView ownerLabel = (TextView) findViewById(R.id.tag_owner);
    try {
      if (tagData.getFlag(TagData.FLAGS, TagData.FLAG_EMERGENT)) {
        ownerLabel.setText(String.format("<%s>", getString(R.string.actfm_TVA_tag_owner_none)));
      } else if (tagData.getValue(TagData.USER_ID) == 0) {
        ownerLabel.setText(Preferences.getStringValue(ActFmPreferenceService.PREF_NAME));
      } else {
        JSONObject owner = new JSONObject(tagData.getValue(TagData.USER));
        ownerLabel.setText(owner.getString("name"));
      }
    } catch (JSONException e) {
      Log.e("tag-view-activity", "json error refresh owner", e);
      ownerLabel.setText("<error>");
      System.err.println(tagData.getValue(TagData.USER));
    }

    tagMembers.removeAllViews();
    String peopleJson = tagData.getValue(TagData.MEMBERS);
    if (!TextUtils.isEmpty(peopleJson)) {
      try {
        JSONArray people = new JSONArray(peopleJson);
        for (int i = 0; i < people.length(); i++) {
          JSONObject person = people.getJSONObject(i);
          TextView textView = null;

          if (person.has("id") && person.getLong("id") == ActFmPreferenceService.userId())
            textView =
                tagMembers.addPerson(Preferences.getStringValue(ActFmPreferenceService.PREF_NAME));
          else if (!TextUtils.isEmpty(person.optString("name")))
            textView = tagMembers.addPerson(person.getString("name"));
          else if (!TextUtils.isEmpty(person.optString("email")))
            textView = tagMembers.addPerson(person.getString("email"));

          if (textView != null) {
            textView.setTag(person);
            textView.setEnabled(false);
          }
        }
      } catch (JSONException e) {
        System.err.println(peopleJson);
        Log.e("tag-view-activity", "json error refresh members", e);
      }
    }

    tagMembers.addPerson(""); // $NON-NLS-1$
  }
Exemplo n.º 2
0
  @SuppressWarnings("nls")
  private JSONObject parseSharedWithAndTags() throws JSONException, ParseSharedException {
    JSONObject sharedWith = new JSONObject();
    if (cbFacebook.isChecked()) sharedWith.put("fb", true);
    if (cbTwitter.isChecked()) sharedWith.put("tw", true);

    JSONArray peopleList = new JSONArray();
    for (int i = 0; i < sharedWithContainer.getChildCount(); i++) {
      TextView textView = sharedWithContainer.getTextView(i);
      textView.setTextAppearance(activity, android.R.style.TextAppearance_Medium_Inverse);
      String text = textView.getText().toString();

      if (text.length() == 0) continue;

      if (text.indexOf('@') == -1)
        throw new ParseSharedException(
            textView, activity.getString(R.string.actfm_EPA_invalid_email, text));
      peopleList.put(text);
    }
    if (peopleList.length() > 0) sharedWith.put("p", peopleList);

    return sharedWith;
  }
Exemplo n.º 3
0
  public EditPeopleControlSet(Activity activity, int loginRequestCode) {
    DependencyInjectionService.getInstance().inject(this);
    this.activity = activity;
    this.loginRequestCode = loginRequestCode;

    sharedWithContainer = (PeopleContainer) activity.findViewById(R.id.share_container);
    assignedCustom = (EditText) activity.findViewById(R.id.assigned_custom);
    assignedSpinner = (Spinner) activity.findViewById(R.id.assigned_spinner);
    cbFacebook = (CheckBox) activity.findViewById(R.id.checkbox_facebook);
    cbTwitter = (CheckBox) activity.findViewById(R.id.checkbox_twitter);

    sharedWithContainer.addPerson(""); // $NON-NLS-1$
    setUpListeners();
  }
Exemplo n.º 4
0
  private void setUpListeners() {
    final View assignedClear = activity.findViewById(R.id.assigned_clear);

    assignedSpinner.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View v, int index, long id) {
            if (index == spinnerValues.size() - 1) {
              assignedCustom.setVisibility(View.VISIBLE);
              assignedClear.setVisibility(View.VISIBLE);
              assignedSpinner.setVisibility(View.GONE);
              assignedCustom.requestFocus();
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {
            //
          }
        });

    assignedClear.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            assignedCustom.setVisibility(View.GONE);
            assignedClear.setVisibility(View.GONE);
            assignedCustom.setText(""); // $NON-NLS-1$
            assignedSpinner.setVisibility(View.VISIBLE);
            assignedSpinner.setSelection(0);
          }
        });

    sharedWithContainer.setOnAddNewPerson(
        new OnAddNewPersonListener() {
          @Override
          public void textChanged(String text) {
            activity.findViewById(R.id.share_additional).setVisibility(View.VISIBLE);
            if (text.indexOf('@') > -1) {
              activity.findViewById(R.id.tag_label).setVisibility(View.VISIBLE);
              activity.findViewById(R.id.tag_name).setVisibility(View.VISIBLE);
            }
          }
        });
  }
Exemplo n.º 5
0
  private void saveSettings() {
    String oldName = tagData.getValue(TagData.NAME);
    String newName = tagName.getText().toString();

    if (!oldName.equals(newName)) {
      tagData.setValue(TagData.NAME, newName);
      TagService.getInstance().rename(oldName, newName);
      tagData.setFlag(TagData.FLAGS, TagData.FLAG_EMERGENT, false);
    }

    JSONArray members = tagMembers.toJSONArray();
    tagData.setValue(TagData.MEMBERS, members.toString());
    tagData.setValue(TagData.MEMBER_COUNT, members.length());
    Flags.set(Flags.TOAST_ON_SAVE);
    tagDataService.save(tagData);

    refreshMembersPage();
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
  @SuppressWarnings("nls")
  private void setUpData() {
    try {
      JSONObject sharedWith;
      if (task.getValue(Task.SHARED_WITH).length() > 0)
        sharedWith = new JSONObject(task.getValue(Task.SHARED_WITH));
      else sharedWith = new JSONObject();

      cbFacebook.setChecked(sharedWith.optBoolean("fb", false));
      cbTwitter.setChecked(sharedWith.optBoolean("tw", false));

      final ArrayList<JSONObject> sharedPeople = new ArrayList<JSONObject>();
      JSONArray people = sharedWith.optJSONArray("p");
      if (people != null) {
        for (int i = 0; i < people.length(); i++) {
          String person = people.getString(i);
          TextView textView = sharedWithContainer.addPerson(person);
          textView.setEnabled(false);
          sharedPeople.add(PeopleContainer.createUserJson(textView));
        }
      }

      new Thread(
              new Runnable() {
                @Override
                public void run() {
                  ArrayList<JSONObject> collaborators = new ArrayList<JSONObject>();
                  TodorooCursor<Metadata> tags = TagService.getInstance().getTags(task.getId());
                  try {
                    Metadata metadata = new Metadata();
                    for (tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) {
                      metadata.readFromCursor(tags);
                      final String tag = metadata.getValue(TagService.TAG);
                      TagData tagData =
                          tagDataService.getTag(
                              tag, TagData.MEMBER_COUNT, TagData.MEMBERS, TagData.USER);
                      if (tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0) {
                        JSONArray members = new JSONArray(tagData.getValue(TagData.MEMBERS));
                        for (int i = 0; i < members.length(); i++) {
                          JSONObject user = members.getJSONObject(i);
                          user.put("tag", tag);
                          sharedPeople.add(user);
                          collaborators.add(user);
                        }
                        if (!TextUtils.isEmpty(tagData.getValue(TagData.USER))) {
                          JSONObject user = new JSONObject(tagData.getValue(TagData.USER));
                          user.put("tag", tag);
                          sharedPeople.add(user);
                          collaborators.add(user);
                        }
                      } else {
                        nonSharedTags.add((Metadata) metadata.clone());
                      }
                    }

                    if (collaborators.size() > 0) buildCollaborators(collaborators);
                    buildAssignedToSpinner(sharedPeople);
                  } catch (JSONException e) {
                    exceptionService.reportError("json-reading-data", e);
                  } finally {
                    tags.close();
                  }
                }
              })
          .start();

    } catch (JSONException e) {
      exceptionService.reportError("json-reading-data", e);
    }
  }