diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 3599e3f82..bc2eaf10f 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -361,15 +361,6 @@ android:name="com.todoroo.astrid.tags.TagFilterExposer$RenameTagActivity" android:theme="@style/Theme.FullTransparent"/> - - - - - - - - - diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java deleted file mode 100644 index 3f893b586..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java +++ /dev/null @@ -1,866 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.actfm; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.res.Resources; -import android.database.Cursor; -import android.graphics.Color; -import android.net.Uri; -import android.provider.ContactsContract; -import android.support.v4.app.Fragment; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.CheckedTextView; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; - -import com.commonsware.cwac.merge.MergeAdapter; -import com.timsu.astrid.R; -import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.service.Autowired; -import com.todoroo.andlib.service.DependencyInjectionService; -import com.todoroo.andlib.service.ExceptionService; -import com.todoroo.andlib.sql.Criterion; -import com.todoroo.andlib.sql.Order; -import com.todoroo.andlib.sql.Query; -import com.todoroo.andlib.utility.DialogUtilities; -import com.todoroo.andlib.utility.Preferences; -import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; -import com.todoroo.astrid.actfm.sync.ActFmSyncService; -import com.todoroo.astrid.activity.TaskEditFragment; -import com.todoroo.astrid.core.PluginServices; -import com.todoroo.astrid.dao.UserDao; -import com.todoroo.astrid.data.TagData; -import com.todoroo.astrid.data.TagMetadata; -import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.data.User; -import com.todoroo.astrid.helper.AsyncImageView; -import com.todoroo.astrid.service.AstridDependencyInjector; -import com.todoroo.astrid.service.MetadataService; -import com.todoroo.astrid.service.TagDataService; -import com.todoroo.astrid.service.TaskService; -import com.todoroo.astrid.service.ThemeService; -import com.todoroo.astrid.tags.TagMemberMetadata; -import com.todoroo.astrid.tags.TagService; -import com.todoroo.astrid.ui.PeopleContainer; -import com.todoroo.astrid.ui.PeopleContainer.ParseSharedException; -import com.todoroo.astrid.ui.PopupControlSet; -import com.todoroo.astrid.utility.ResourceDrawableCache; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; - -public class EditPeopleControlSet extends PopupControlSet { - - public static final String EXTRA_TASK_ID = "task"; //$NON-NLS-1$ - - private static final String CONTACT_CHOOSER_USER = "the_contact_user"; //$NON-NLS-1$ - - private Task task; - - @Autowired - ActFmPreferenceService actFmPreferenceService; - - @Autowired - ActFmSyncService actFmSyncService; - - @Autowired - TaskService taskService; - - @Autowired - UserDao userDao; - - @Autowired - MetadataService metadataService; - - @Autowired - ExceptionService exceptionService; - - @Autowired - TagDataService tagDataService; - - private final Fragment fragment; - - private final ListView assignedList; - - private final TextView assignedDisplay; - - private final EditText assignedCustom; - - private final View assignedClear; - - private final ImageView image; - - private final int loginRequestCode; - - private boolean assignedToMe = false; - - private AssignedToUser contactPickerUser = null; - - private boolean loadedUI = false; - - private boolean dontClearAssignedCustom = false; - - private final Resources resources; - - private int selected = 0; // remember last selected state - - static { - AstridDependencyInjector.initialize(); - } - - // --- UI initialization - - public EditPeopleControlSet(Activity activity, Fragment fragment, int viewLayout, int displayViewLayout, int title, int loginRequestCode) { - super(activity, viewLayout, displayViewLayout, title); - DependencyInjectionService.getInstance().inject(this); - this.resources = activity.getResources(); - this.loginRequestCode = loginRequestCode; - this.fragment = fragment; - - assignedCustom = (EditText) getView().findViewById(R.id.assigned_custom); - assignedList = (ListView) getView().findViewById(R.id.assigned_list); - assignedList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - assignedList.setItemsCanFocus(false); - assignedClear = getView().findViewById(R.id.assigned_clear); - - assignedDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit); - image = (ImageView) getDisplayView().findViewById(R.id.display_row_icon); - setUpListeners(); - } - - @Override - protected void setupOkButton(View v) { - // - } - - @Override - public void readFromTask(Task sourceTask) { - setTask(sourceTask); - if (!dontClearAssignedCustom) { - assignedCustom.setText(""); //$NON-NLS-1$ - } - dontClearAssignedCustom = false; - setUpData(task, null); - } - - public void setTask(Task task) { - this.task = task; - } - - public void setUpData(final Task task, final TagData includeTag) { - new Thread(new Runnable() { - @Override - public void run() { - ArrayList sharedPeople = new ArrayList(); - TodorooCursor tags = TagService.getInstance().getTagDataForTask(task.getId(), TagData.NAME, TagData.MEMBER_COUNT, TagData.MEMBERS, TagData.USER); - try { - TagData tagData = new TagData(); - for (tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { - tagData.readFromCursor(tags); - addMembersFromTagData(tagData, sharedPeople); - } - - if (includeTag != null && tags.getCount() == 0) { - addMembersFromTagData(includeTag, sharedPeople); - } - - buildAssignedToSpinner(task, sharedPeople); - } finally { - tags.close(); - loadedUI = true; - } - } - }).start(); - } - - private static void addMembersFromTagData(TagData tagData, ArrayList sharedPeople) { - try { - JSONArray members = new JSONArray(tagData.getValue(TagData.MEMBERS)); - for (int i = 0; i < members.length(); i++) { - JSONObject user = members.getJSONObject(i); - sharedPeople.add(user); - } - if (!TextUtils.isEmpty(tagData.getValue(TagData.USER))) { - JSONObject user = new JSONObject(tagData.getValue(TagData.USER)); - sharedPeople.add(user); - } - } catch (JSONException e) { - TodorooCursor users = PluginServices.getUserDao().query(Query.select(User.PROPERTIES).where(Criterion.or(User.UUID.in( - Query.select(TagMemberMetadata.USER_UUID).from(TagMetadata.TABLE).where(TagMetadata.TAG_UUID.eq(tagData.getUuid()))), User.UUID.eq(tagData.getValue(TagData.USER_ID))))); - User user = new User(); - for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) { - user.clear(); - user.readFromCursor(users); - JSONObject userJson = new JSONObject(); - try { - ActFmSyncService.JsonHelper.jsonFromUser(userJson, user); - sharedPeople.add(userJson); - } catch (JSONException e2) { - // - } - } - } - } - - public static class AssignedToUser { - public String label; - public JSONObject user; - - public AssignedToUser(String label, JSONObject user) { - this.label = label; - this.user = user; - } - - @Override - public String toString() { - return label; - } - } - - - private void buildAssignedToSpinner(Task t, ArrayList sharedWith) { - HashSet userIds = new HashSet(); - HashSet emails = new HashSet(); - HashMap names = new HashMap(); - - ArrayList coreUsers = new ArrayList(); - ArrayList listUsers = new ArrayList(); - ArrayList astridUsers = new ArrayList(); - - int assignedIndex = 0; - try { - ArrayList coreUsersJson = new ArrayList(); - JSONObject myself = new JSONObject(); - myself.put("id", Task.USER_ID_SELF); - myself.put("picture", ActFmPreferenceService.thisUser().optString("picture")); - coreUsersJson.add(myself); - - boolean hasTags = t.getTransitory("tags") != null && - ((HashSet) t.getTransitory("tags")).size() > 0; - boolean addUnassigned = actFmPreferenceService.isLoggedIn() && hasTags; - if (addUnassigned) { - JSONObject unassigned = new JSONObject(); - unassigned.put("id", Task.USER_ID_UNASSIGNED); - unassigned.put("default_picture", R.drawable.icn_anyone); - coreUsersJson.add(unassigned); - } - - if (Task.isRealUserId(t.getValue(Task.USER_ID))) { - try { - JSONObject user = new JSONObject(t.getValue(Task.USER)); - coreUsersJson.add(0, user); - } catch (JSONException e) { - User user = userDao.fetch(t.getValue(Task.USER_ID), User.PROPERTIES); - if (user != null) { - try { - JSONObject assignedUser = new JSONObject(); - ActFmSyncService.JsonHelper.jsonFromUser(assignedUser, user); - coreUsersJson.add(0, assignedUser); - } catch (JSONException e2) { - // - } - } - } - } - - ArrayList astridFriends = getAstridFriends(); - - // de-duplicate by user id and/or email - coreUsers = convertJsonUsersToAssignedUsers(coreUsersJson, userIds, emails, names); - listUsers = convertJsonUsersToAssignedUsers(sharedWith, userIds, emails, names); - astridUsers = convertJsonUsersToAssignedUsers(astridFriends, userIds, emails, names); - - contactPickerUser = new AssignedToUser(activity.getString(R.string.actfm_EPA_choose_contact), - new JSONObject().put("default_picture", R.drawable.icn_friends) - .put(CONTACT_CHOOSER_USER, true)); - int contactsIndex = addUnassigned ? 2 : 1; - boolean addContactPicker = Preferences.getBoolean(R.string.p_use_contact_picker, true) && contactPickerAvailable(); - if (addContactPicker) { - coreUsers.add(contactsIndex, contactPickerUser); - } - - if (assignedIndex == 0) { - assignedIndex = findAssignedIndex(t, coreUsers, listUsers, astridUsers); - } - - } catch (JSONException e) { - exceptionService.reportError("json-reading-data", e); - } - - selected = assignedIndex; - - final MergeAdapter mergeAdapter = new MergeAdapter(); - AssignedUserAdapter coreUserAdapter = new AssignedUserAdapter(activity, coreUsers, 0); - AssignedUserAdapter listUserAdapter = new AssignedUserAdapter(activity, listUsers, coreUserAdapter.getCount() + 1); - int offsetForAstridUsers = listUserAdapter.getCount() > 0 ? 2 : 1; - AssignedUserAdapter astridUserAdapter = new AssignedUserAdapter(activity, astridUsers, coreUserAdapter.getCount() + listUserAdapter.getCount() + offsetForAstridUsers); - - LayoutInflater inflater = activity.getLayoutInflater(); - TextView header1 = (TextView) inflater.inflate(R.layout.list_header, null); - header1.setText(R.string.actfm_EPA_assign_header_members); - TextView header2 = (TextView) inflater.inflate(R.layout.list_header, null); - header2.setText(R.string.actfm_EPA_assign_header_friends); - - mergeAdapter.addAdapter(coreUserAdapter); - if (listUserAdapter.getCount() > 0) { - mergeAdapter.addView(header1); - mergeAdapter.addAdapter(listUserAdapter); - } - if (astridUserAdapter.getCount() > 0) { - mergeAdapter.addView(header2); - mergeAdapter.addAdapter(astridUserAdapter); - } - - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - assignedList.setAdapter(mergeAdapter); - assignedList.setItemChecked(selected, true); - refreshDisplayView(); - } - }); - } - - private String getLongOrStringId(JSONObject obj, String defaultValue) { - try { - long value = obj.getLong("id"); //$NON-NLS-1$ - return Long.toString(value); - } catch (JSONException e) { - String value = obj.optString("id"); //$NON-NLS-1$ - if (TextUtils.isEmpty(value)) { - value = defaultValue; - } - return value; - } - } - - - private ArrayList convertJsonUsersToAssignedUsers(ArrayList jsonUsers, - HashSet userIds, HashSet emails, HashMap names) { - ArrayList users = new ArrayList(); - for (JSONObject person : jsonUsers) { - if (person == null) { - continue; - } - String id = getLongOrStringId(person, Task.USER_ID_EMAIL); - if (ActFmPreferenceService.userId().equals(id) || (Task.USER_ID_UNASSIGNED.equals(id) || Task.isRealUserId(id)) && userIds.contains(id)) { - continue; - } - userIds.add(id); - - String email = person.optString("email"); - if (!TextUtils.isEmpty(email) && emails.contains(email)) { - continue; - } - emails.add(email); - - String name = person.optString("name"); - if (Task.USER_ID_SELF.equals(id)) { - name = activity.getString(R.string.actfm_EPA_assign_me); - } - if (Task.USER_ID_UNASSIGNED.equals(id)) { - name = activity.getString(R.string.actfm_EPA_unassigned); - } - - AssignedToUser atu = new AssignedToUser(name, person); - users.add(atu); - if (names.containsKey(name)) { - AssignedToUser user = names.get(name); - if (user != null && user.user.has("email")) { - user.label += " (" + user.user.optString("email") + ")"; - names.put(name, null); - } - if (!TextUtils.isEmpty(email)) { - atu.label += " (" + email + ")"; - } - } else if (TextUtils.isEmpty(name) || "null".equals(name)) { - if (!TextUtils.isEmpty(email)) { - atu.label = email; - } else { - users.remove(atu); - } - } else { - names.put(name, atu); - } - } - return users; - } - - - private int findAssignedIndex(Task t, ArrayList... userLists) { - String assignedStr = t.getValue(Task.USER); - String assignedId = Task.USER_ID_IGNORE; - String assignedEmail = t.getValue(Task.USER_ID); - try { - JSONObject assigned = new JSONObject(assignedStr); - assignedId = getLongOrStringId(assigned, Task.USER_ID_EMAIL); - assignedEmail = assigned.optString("email"); - } catch (JSONException e) { - User assignedUser = userDao.fetch(t.getValue(Task.USER_ID), User.PROPERTIES); - JSONObject assigned = new JSONObject(); - try { - if (assignedUser != null) { - ActFmSyncService.JsonHelper.jsonFromUser(assigned, assignedUser); - try { - assignedId = assigned.getString("id"); - } catch (JSONException e2) { - assignedId = getLongOrStringId(assigned, Task.USER_ID_EMAIL); - } - assignedEmail = assigned.optString("email"); - } else if (!t.getValue(Task.USER_ID).contains("@")) { - assignedId = t.getValue(Task.USER_ID); - } - } catch (JSONException e2) { - // - } - } - - int index = 0; - for (ArrayList userList : userLists) { - for (AssignedToUser anUserList : userList) { - JSONObject user = anUserList.user; - if (user != null) { - if (user.optBoolean(CONTACT_CHOOSER_USER)) { - index++; - continue; - } - if (getLongOrStringId(user, Task.USER_ID_EMAIL).equals(assignedId) || - user.optString("email").equals(assignedEmail) && - !TextUtils.isEmpty(assignedEmail)) { - return index; - } - } - index++; - } - index++; // Add one for headers separating user lists - } - return 0; - } - - private ArrayList getAstridFriends() { - ArrayList astridFriends = new ArrayList(); - TodorooCursor users = userDao.query(Query.select(User.PROPERTIES) - .orderBy(Order.asc(User.FIRST_NAME), Order.asc(User.LAST_NAME), Order.asc(User.NAME), Order.asc(User.EMAIL))); - try { - User user = new User(); - for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) { - user.readFromCursor(users); - JSONObject userJson = new JSONObject(); - try { - ActFmSyncService.JsonHelper.jsonFromUser(userJson, user); - astridFriends.add(userJson); - } catch (JSONException e) { - // Ignored - } - } - } finally { - users.close(); - } - return astridFriends; - } - - - private class AssignedUserAdapter extends ArrayAdapter { - - private final int positionOffset; - - public AssignedUserAdapter(Context context, ArrayList people, int positionOffset) { - super(context, R.layout.assigned_adapter_row, people); - this.positionOffset = positionOffset; - } - - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - if (convertView == null) { - convertView = activity.getLayoutInflater().inflate(R.layout.assigned_adapter_row, parent, false); - } - CheckedTextView ctv = (CheckedTextView) convertView.findViewById(android.R.id.text1); - super.getView(position, ctv, parent); - if (assignedList.getCheckedItemPosition() == position + positionOffset) { - ctv.setChecked(true); - } else { - ctv.setChecked(false); - } - AsyncImageView image = (AsyncImageView) convertView.findViewById(R.id.person_image); - image.setDefaultImageDrawable(ResourceDrawableCache.getImageDrawableFromId(resources, R.drawable.icn_default_person_image)); - image.setUrl(getItem(position).user.optString("picture")); - if (getItem(position).user.optInt("default_picture", 0) > 0) { - image.setDefaultImageResource(getItem(position).user.optInt("default_picture")); - } - return convertView; - } - } - - public void assignToMe() { - if (assignedList != null && assignedList.getChildAt(0) != null) { - assignedList.performItemClick(assignedList.getChildAt(0), 0, 0); - refreshDisplayView(); - } - } - - private void setUpListeners() { - - assignedList.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(AdapterView arg0, View arg1, int position, - long id) { - AssignedToUser user = (AssignedToUser) assignedList.getAdapter().getItem(position); - - if (user.user.has(CONTACT_CHOOSER_USER)) { - Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); - fragment.startActivityForResult(intent, TaskEditFragment.REQUEST_CODE_CONTACT); - return; - } - - assignedDisplay.setText(user.toString()); - assignedCustom.setText(""); //$NON-NLS-1$ - selected = position; - refreshDisplayView(); - DialogUtilities.dismissDialog(activity, dialog); - } - - }); - - assignedClear.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - assignedCustom.setText(""); //$NON-NLS-1$ - selected = 0; - assignedList.setItemChecked(selected, true); - } - }); - -// sharedWithContainer.setOnAddNewPerson(new OnAddNewPersonListener() { -// @Override -// public void textChanged(String text) { -// getSharedWithView().findViewById(R.id.share_additional).setVisibility(View.VISIBLE); -// if(text.indexOf('@') > -1) { -//// getSharedWithView().findViewById(R.id.tag_label).setVisibility(View.VISIBLE); -//// getSharedWithView().findViewById(R.id.tag_name).setVisibility(View.VISIBLE); -// } -// } -// }); -// -// sharedWithRow.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// sharedWithDialog.show(); -// } -// }); - } - - private boolean contactPickerAvailable() { - Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); - return activity.getPackageManager().queryIntentActivities(intent, 0).size() > 0; - } - - // --- events - - @Override - protected void readFromTaskOnInitialize() { - // Nothing, we don't lazy load this control set yet - } - - @Override - public String writeToModel(Task t) { - if (initialized && dialog != null) { - dialog.dismiss(); - } - // do nothing else, we use a separate method - return null; - } - - @Override - protected String writeToModelAfterInitialized(Task t) { - // Nothing, we don't lazy load this control set yet - return null; - } - - @Override - protected void afterInflate() { - // Nothing, we don't lazy load this control set yet - } - - public boolean hasLoadedUI() { - return loadedUI; - } - - /** - * Save sharing settings - * - * @param toast toast to show after saving is finished - * @return false if login is required & save should be halted - */ - - public boolean saveSharingSettings(String toast) { - if (task == null) { - return false; - } - - boolean dirty = false; - try { - JSONObject userJson = null; - TextView assignedView = null; - if (!TextUtils.isEmpty(assignedCustom.getText())) { - userJson = PeopleContainer.createUserJson(assignedCustom); - assignedView = assignedCustom; - } else { - if (!loadedUI || assignedList.getCheckedItemPosition() == ListView.INVALID_POSITION) { - return true; - } - AssignedToUser item = (AssignedToUser) assignedList.getAdapter().getItem(assignedList.getCheckedItemPosition()); - if (item != null) { - if (item.equals(contactPickerUser)) { //don't want to ever set the user as the fake contact picker user - return true; - } - userJson = item.user; - } - } - - if (userJson != null) { - String email = userJson.optString("email"); - if (!TextUtils.isEmpty(email) && email.indexOf('@') == -1) { - throw new ParseSharedException(assignedView, - activity.getString(R.string.actfm_EPA_invalid_email, userJson.optString("email"))); - } - } - - if (userJson == null || Task.USER_ID_SELF.equals(getLongOrStringId(userJson, Task.USER_ID_EMAIL))) { - dirty = Task.USER_ID_SELF.equals(task.getValue(Task.USER_ID)) ? dirty : true; - task.setValue(Task.USER_ID, Task.USER_ID_SELF); - task.setValue(Task.USER, ""); - assignedToMe = true; - } else if (Task.USER_ID_UNASSIGNED.equals(getLongOrStringId(userJson, Task.USER_ID_SELF))) { - dirty = Task.USER_ID_UNASSIGNED.equals(task.getValue(Task.USER_ID)) ? dirty : true; - task.setValue(Task.USER_ID, Task.USER_ID_UNASSIGNED); - task.setValue(Task.USER, ""); - } else { - String taskUserId = Task.USER_ID_EMAIL; - String taskUserEmail = ""; - try { - // For backwards compatibility - JSONObject taskUser = new JSONObject(task.getValue(Task.USER)); - taskUserId = getLongOrStringId(taskUser, Task.USER_ID_EMAIL); - taskUserEmail = taskUser.optString("email"); - } catch (JSONException e) { - // sad times - taskUserId = task.getValue(Task.USER_ID); - if (Task.userIdIsEmail(taskUserId)) { - taskUserEmail = taskUserId; - } - } - String userId = getLongOrStringId(userJson, Task.USER_ID_EMAIL); - String userEmail = userJson.optString("email"); - - boolean match = userId.equals(taskUserId); - match = match || userEmail.equals(taskUserEmail) && !TextUtils.isEmpty(userEmail); - - dirty = match ? dirty : true; - String willAssignToId = getLongOrStringId(userJson, Task.USER_ID_EMAIL); - task.setValue(Task.USER_ID, willAssignToId); - if (Task.USER_ID_EMAIL.equals(task.getValue(Task.USER_ID))) { - task.setValue(Task.USER_ID, userEmail); - } - task.setValue(Task.USER, ""); - } - - if (dirty && !actFmPreferenceService.isLoggedIn()) { - makePrivateTask(); - task.setValue(Task.USER_ID, Task.USER_ID_SELF); - return false; - } - - task.putTransitory(TaskService.TRANS_ASSIGNED, true); - - if (assignedView == assignedCustom) { - } else if (task.getValue(Task.USER_ID) != Task.USER_ID_SELF) { - } - - return true; - } catch (ParseSharedException e) { - if (e.view != null) { - e.view.setTextColor(Color.RED); - e.view.requestFocus(); - } - DialogUtilities.okDialog(activity, e.message, null); - } - return false; - } - - private void makePrivateTask() { - assignToMe(); - } - - /** - * Warning - only valid after a call to saveSharingSettings - * - * @return - */ - public boolean isAssignedToMe() { - return assignedToMe; - } - - /** - * Check if task will be assigned to current user when save setting is called - */ - public boolean willBeAssignedToMe() { - JSONObject userJson = null; - if (!TextUtils.isEmpty(assignedCustom.getText())) { - userJson = PeopleContainer.createUserJson(assignedCustom); - } else { - if (!hasLoadedUI() || assignedList.getCheckedItemPosition() == ListView.INVALID_POSITION) { - if (task != null) { - return task.getValue(Task.USER_ID) == Task.USER_ID_SELF; - } else { - return true; - } - } - AssignedToUser item = (AssignedToUser) assignedList.getAdapter().getItem(assignedList.getCheckedItemPosition()); - if (item != null) { - userJson = item.user; - } - } - - if (userJson == null || Task.USER_ID_SELF.equals(getLongOrStringId(userJson, Task.USER_ID_EMAIL))) { - return true; - } - - return false; - } - - public String getAssignedToString() { - return assignedDisplay.getText().toString(); - } - - /** - * Resume save - * - * @param data - */ - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == loginRequestCode && resultCode == Activity.RESULT_OK) { - // clear user values & reset them to trigger a save - task.clearValue(Task.USER_ID); - task.clearValue(Task.USER); - } else if (requestCode == loginRequestCode) { - makePrivateTask(); - } else if (requestCode == TaskEditFragment.REQUEST_CODE_CONTACT && resultCode == Activity.RESULT_OK) { - Uri contactData = data.getData(); - String contactId = contactData.getLastPathSegment(); - String[] args = {contactId}; - String[] projection = {ContactsContract.CommonDataKinds.Email.DATA}; - String selection = ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?"; //$NON-NLS-1$ - Cursor emailCursor = activity.managedQuery(ContactsContract.CommonDataKinds.Email.CONTENT_URI, projection, selection, args, null); - if (emailCursor.getCount() > 0) { - emailCursor.moveToFirst(); - int emailIndex = emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA); - String email = emailCursor.getString(emailIndex); - if (!TextUtils.isEmpty(email)) { - String[] nameProjection = {ContactsContract.Contacts.DISPLAY_NAME}; - Cursor nameCursor = activity.managedQuery(contactData, nameProjection, null, null, null); - if (nameCursor.getCount() > 0) { - nameCursor.moveToFirst(); - int nameIndex = nameCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); - String name = nameCursor.getString(nameIndex); - if (!TextUtils.isEmpty(name)) { - StringBuilder fullName = new StringBuilder(); - fullName.append(name).append(" <").append(email).append('>'); //$NON-NLS-1$ - email = fullName.toString(); - } - } - assignedCustom.setText(email); - dontClearAssignedCustom = true; - refreshDisplayView(); - if (dialog != null) { - dialog.dismiss(); - } - } else { - DialogUtilities.okDialog(activity, activity.getString(R.string.TEA_contact_error), null); - } - } else { - DialogUtilities.okDialog(activity, activity.getString(R.string.TEA_contact_error), null); - } - } - } - - @Override - protected void refreshDisplayView() { - String displayString; - boolean unassigned = false; - if (!TextUtils.isEmpty(assignedCustom.getText())) { - displayString = activity.getString(R.string.TEA_assigned_to, assignedCustom.getText()); - } else { - AssignedToUser user = (AssignedToUser) assignedList.getAdapter().getItem(assignedList.getCheckedItemPosition()); - if (user == null) { - user = (AssignedToUser) assignedList.getAdapter().getItem(0); - } - - String id = getLongOrStringId(user.user, Task.USER_ID_IGNORE); - if (Task.USER_ID_UNASSIGNED.equals(id)) { - unassigned = true; - displayString = activity.getString(R.string.actfm_EPA_unassigned); - } else { - String userString = user.toString(); - if (Task.USER_ID_SELF.equals(id)) { - userString = userString.toLowerCase(); - } - displayString = activity.getString(R.string.TEA_assigned_to, userString); - } - - - } - - assignedDisplay.setTextColor(unassigned ? unsetColor : themeColor); - assignedDisplay.setText(displayString); - if (unassigned) { - image.setImageResource(R.drawable.tea_icn_assign_gray); - } else { - image.setImageResource(ThemeService.getTaskEditDrawable(R.drawable.tea_icn_assign, R.drawable.tea_icn_assign_lightblue)); - } - } - - @Override - protected boolean onOkClick() { - if (!TextUtils.isEmpty(assignedCustom.getText())) { - JSONObject assigned = PeopleContainer.createUserJson(assignedCustom); - String email = assigned.optString("email"); //$NON-NLS-1$ - if (!TextUtils.isEmpty(email) && email.indexOf('@') == -1) { - assignedCustom.requestFocus(); - DialogUtilities.okDialog(activity, activity.getString(R.string.actfm_EPA_invalid_email, - assigned.optString("email")), null); //$NON-NLS-1$ - return false; - } - } - return super.onOkClick(); - } - - @Override - protected void additionalDialogSetup() { - super.additionalDialogSetup(); - dialog.getWindow() - .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN - | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - } -} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java index 43ac38b84..7277f193d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java @@ -60,8 +60,6 @@ import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.tags.TagMemberMetadata; import com.todoroo.astrid.tags.TagService; -import com.todoroo.astrid.ui.PeopleContainer; -import com.todoroo.astrid.ui.PeopleContainer.ParseSharedException; import com.todoroo.astrid.utility.AstridPreferences; import com.todoroo.astrid.utility.ResourceDrawableCache; import com.todoroo.astrid.welcome.HelpInfoPopover; @@ -111,7 +109,6 @@ public class TagSettingsActivity extends SherlockFragmentActivity { @Autowired TagMetadataDao tagMetadataDao; - private PeopleContainer tagMembers; private AsyncImageView picture; private EditText tagName; private EditText tagDescription; @@ -179,8 +176,6 @@ public class TagSettingsActivity extends SherlockFragmentActivity { } }).start(); } - showCollaboratorsPopover(); - } private void setupForDialogOrFullscreen() { @@ -205,14 +200,6 @@ public class TagSettingsActivity extends SherlockFragmentActivity { } } - private void showCollaboratorsPopover() { - if (!Preferences.getBoolean(R.string.p_showed_collaborators_help, false)) { - View members = findViewById(R.id.members_container); - HelpInfoPopover.showPopover(this, members, R.string.help_popover_collaborators, null); - Preferences.setBoolean(R.string.p_showed_collaborators_help, true); - } - } - protected void setUpSettingsPage() { if (isDialog) { findViewById(R.id.save_and_cancel).setVisibility(View.VISIBLE); @@ -230,7 +217,6 @@ public class TagSettingsActivity extends SherlockFragmentActivity { }); } - tagMembers = (PeopleContainer) findViewById(R.id.members_container); tagName = (EditText) findViewById(R.id.tag_name); tagDescription = (EditText) findViewById(R.id.tag_description); picture = (AsyncImageView) findViewById(R.id.picture); @@ -330,30 +316,11 @@ public class TagSettingsActivity extends SherlockFragmentActivity { } } - JSONArray members; - try { - members = tagMembers.parseSharedWithAndTags(this, true).optJSONArray("p"); - } catch (JSONException e) { - exceptionService.displayAndReportError(this, "save-people", e); - return; - } catch (ParseSharedException e) { - if (e.view != null) { - e.view.setTextColor(Color.RED); - e.view.requestFocus(); - } - DialogUtilities.okDialog(this, e.message, null); - return; - } - if (members == null) { - members = new JSONArray(); - } - + JSONArray members = new JSONArray(); if (members.length() > 0 && !actFmPreferenceService.isLoggedIn()) { if (newName.length() > 0 && oldName.length() == 0) { tagDataService.save(tagData); } - tagMembers.removeAllViews(); - tagMembers.addPerson("", "", false); //$NON-NLS-1$ return; } @@ -450,7 +417,6 @@ public class TagSettingsActivity extends SherlockFragmentActivity { private void updateMembers(String peopleJson, String tagUuid) { - tagMembers.removeAllViews(); JSONArray people = null; try { people = new JSONArray(peopleJson); @@ -513,25 +479,6 @@ public class TagSettingsActivity extends SherlockFragmentActivity { } } - - if (people != null) { - try { - tagMembers.fromJSONArray(people); - } catch (JSONException e) { - Log.e("tag-settings", "Error parsing tag members: " + people, e); - } - } - - tagMembers.addPerson("", "", false); //$NON-NLS-1$ - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - if (tagMembers.getChildCount() > 1) { - JSONArray members = tagMembers.toJSONArray(); - outState.putString(MEMBERS_IN_PROGRESS, members.toString()); - } } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterAdapter.java b/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterAdapter.java deleted file mode 100644 index 6c9dc4958..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterAdapter.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.people; - -import android.app.Activity; -import android.content.Intent; -import android.content.IntentFilter; -import android.widget.ListView; - -import com.todoroo.astrid.adapter.FilterAdapter; -import com.todoroo.astrid.utility.Constants; - -public class PeopleFilterAdapter extends FilterAdapter { - - public static final String BROADCAST_REQUEST_PEOPLE_FILTERS = Constants.PACKAGE + ".REQUEST_PEOPLE_FILTERS"; //$NON-NLS-1$ - public static final String BROADCAST_SEND_PEOPLE_FILTERS = Constants.PACKAGE + ".SEND_PEOPLE_FILTERS"; //$NON-NLS-1$ - - public PeopleFilterAdapter(Activity activity, ListView listView, - int rowLayout, boolean skipIntentFilters) { - super(activity, listView, rowLayout, skipIntentFilters); - } - - @Override - public void getLists() { - Intent broadcastIntent = new Intent(BROADCAST_REQUEST_PEOPLE_FILTERS); - activity.sendBroadcast(broadcastIntent); - } - - @Override - public void registerRecevier() { - IntentFilter peopleFilter = new IntentFilter(BROADCAST_SEND_PEOPLE_FILTERS); - activity.registerReceiver(filterReceiver, peopleFilter); - getLists(); - } - - @Override - public void unregisterRecevier() { - activity.unregisterReceiver(filterReceiver); - } - - @Override - protected boolean shouldDirectlyPopulateFilters() { - return false; - } -} diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterExposer.java deleted file mode 100644 index 51bc8dd82..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterExposer.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.people; - -import android.content.BroadcastReceiver; -import android.content.ComponentName; -import android.content.ContentValues; -import android.content.Context; -import android.content.Intent; -import android.graphics.drawable.BitmapDrawable; -import android.os.Bundle; -import android.text.TextUtils; - -import com.timsu.astrid.R; -import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.service.ContextManager; -import com.todoroo.andlib.sql.Criterion; -import com.todoroo.andlib.sql.Field; -import com.todoroo.andlib.sql.Join; -import com.todoroo.andlib.sql.Order; -import com.todoroo.andlib.sql.Query; -import com.todoroo.andlib.sql.QueryTemplate; -import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; -import com.todoroo.astrid.api.AstridApiConstants; -import com.todoroo.astrid.api.Filter; -import com.todoroo.astrid.api.FilterListItem; -import com.todoroo.astrid.api.FilterWithCustomIntent; -import com.todoroo.astrid.api.FilterWithUpdate; -import com.todoroo.astrid.core.PluginServices; -import com.todoroo.astrid.dao.TaskDao.TaskCriteria; -import com.todoroo.astrid.data.Metadata; -import com.todoroo.astrid.data.RemoteModel; -import com.todoroo.astrid.data.TagData; -import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.data.User; -import com.todoroo.astrid.service.ThemeService; -import com.todoroo.astrid.tags.TaskToTagMetadata; -import com.todoroo.astrid.utility.AstridPreferences; - -import java.util.ArrayList; -import java.util.List; - -public class PeopleFilterExposer extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - FilterListItem[] listAsArray = prepareFilters(context); - - Intent broadcastIntent = new Intent(PeopleFilterAdapter.BROADCAST_SEND_PEOPLE_FILTERS); - broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, listAsArray); - broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, "people"); //$NON-NLS-1$ - context.sendBroadcast(broadcastIntent); - } - - private FilterListItem[] prepareFilters(Context context) { - TodorooCursor users = PluginServices.getUserDao().query(Query.select(User.PROPERTIES) - .where(Criterion.not(Criterion.or(User.STATUS.eq(User.STATUS_BLOCKED), - User.STATUS.eq(User.STATUS_IGNORED), User.STATUS.eq(User.STATUS_RENOUNCE), User.STATUS.eq(User.STATUS_IGNORE)))) - .orderBy(Order.asc(User.FIRST_NAME), Order.asc(User.LAST_NAME), Order.asc(User.NAME))); - try { - List items = new ArrayList(); - items.add(mySharedTasks(context)); - User user = new User(); - for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) { - user.readFromCursor(users); - if (ActFmPreferenceService.userId().equals(user.getValue(User.UUID))) { - continue; - } - Filter currFilter = filterFromUserData(user); - if (currFilter != null) { - items.add(currFilter); - } - } - return items.toArray(new FilterListItem[items.size()]); - } finally { - users.close(); - } - } - - - private static FilterWithCustomIntent filterFromUserData(User user) { - String title = user.getDisplayName(); - if (TextUtils.isEmpty(title) || "null".equals(title)) { - return null; - } - - String email = user.getValue(User.EMAIL); - Criterion criterion; - if (TextUtils.isEmpty(email) || "null".equals(email)) { - criterion = Task.USER_ID.eq(user.getValue(User.UUID)); - } else { - criterion = Criterion.or(Task.USER_ID.eq(user.getValue(User.UUID)), - Task.USER.like("%" + email + "%")); // Deprecated field OK for backwards compatibility - } - - criterion = Criterion.and(TaskCriteria.activeAndVisible(), criterion); - - QueryTemplate userTemplate = new QueryTemplate().where(criterion); - - FilterWithUpdate filter = new FilterWithUpdate(title, title, userTemplate, null); - - filter.customTaskList = new ComponentName(ContextManager.getContext(), PersonViewFragment.class); - - ContentValues values = new ContentValues(); - values.put(Task.USER_ID.name, user.getValue(User.UUID)); - filter.valuesForNewTasks = values; - - String imageUrl = user.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_THUMB); //user.getValue(User.PICTURE); - filter.imageUrl = imageUrl; - - Bundle extras = new Bundle(); - extras.putLong(PersonViewFragment.EXTRA_USER_ID_LOCAL, user.getId()); - filter.customExtras = extras; - - return filter; - } - - - public static FilterWithCustomIntent mySharedTasks(Context context) { - TodorooCursor tagsWithMembers = PluginServices.getTagDataService() - .query(Query.select(TagData.NAME).where(TagData.MEMBER_COUNT.gt(0))); - String[] names; - try { - if (tagsWithMembers.getCount() == 0) { - names = new String[1]; - names[0] = "\"\""; - } else { - names = new String[tagsWithMembers.getCount()]; - TagData curr = new TagData(); - int i = 0; - for (tagsWithMembers.moveToFirst(); !tagsWithMembers.isAfterLast(); tagsWithMembers.moveToNext()) { - curr.readFromCursor(tagsWithMembers); - names[i] = "\"" + curr.getValue(TagData.NAME) + "\""; - i++; - } - } - } finally { - tagsWithMembers.close(); - } - - boolean isTablet = AstridPreferences.useTabletLayout(context); - int themeFlags = isTablet ? ThemeService.FLAG_FORCE_LIGHT : 0; - - String title = context.getString(R.string.actfm_my_shared_tasks_title); - QueryTemplate template = new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), - Criterion.and(Task.ID.eq(Field.field("mtags." + Metadata.TASK.name)), - Field.field("mtags." + Metadata.KEY.name).eq(TaskToTagMetadata.KEY), - Field.field("mtags." + TaskToTagMetadata.TAG_NAME.name).in(names), - TaskCriteria.activeVisibleMine()))); - - FilterWithCustomIntent filter = new FilterWithCustomIntent(title, title, template, null); - - filter.customTaskList = new ComponentName(ContextManager.getContext(), PersonViewFragment.class); - - Bundle extras = new Bundle(); - extras.putBoolean(PersonViewFragment.EXTRA_HIDE_QUICK_ADD, true); - filter.customExtras = extras; - - filter.listingIcon = ((BitmapDrawable) context.getResources().getDrawable( - ThemeService.getDrawable(R.drawable.icn_menu_friends, themeFlags))).getBitmap(); - - return filter; - } -} diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterMode.java b/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterMode.java deleted file mode 100644 index 92a86ec1f..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterMode.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.todoroo.astrid.people; - -import android.content.Context; - -import com.timsu.astrid.R; -import com.todoroo.astrid.activity.FilterListFragment; -import com.todoroo.astrid.activity.FilterModeSpec; -import com.todoroo.astrid.activity.TaskListFragment; -import com.todoroo.astrid.api.Filter; -import com.todoroo.astrid.api.FilterListItem; -import com.todoroo.astrid.ui.MainMenuPopover; - -public class PeopleFilterMode implements FilterModeSpec { - - @Override - public Filter getDefaultFilter(Context context) { - Filter defaultFilter = PeopleFilterExposer.mySharedTasks(context); - return defaultFilter; - } - - @Override - public Class getFilterListClass() { - return PeopleListFragment.class; - } - - @Override - public void onFilterItemClickedCallback(FilterListItem item) {/**/} - - @Override - public int[] getForbiddenMenuItems() { - return FORBIDDEN_MENU_ITEMS; - } - - @Override - public int getMainMenuIconAttr() { - return R.attr.asPeopleMenu; - } - - private static final int[] FORBIDDEN_MENU_ITEMS = { - TaskListFragment.MENU_NEW_FILTER_ID, - MainMenuPopover.MAIN_MENU_ITEM_FRIENDS - }; - - @Override - public boolean showComments() { - return false; - } -} diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PeopleListFragment.java b/astrid/plugin-src/com/todoroo/astrid/people/PeopleListFragment.java deleted file mode 100644 index a66223301..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/people/PeopleListFragment.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.people; - -import android.app.Activity; - -import com.timsu.astrid.R; -import com.todoroo.astrid.activity.FilterListFragment; -import com.todoroo.astrid.adapter.FilterAdapter; -import com.todoroo.astrid.utility.AstridPreferences; - -public class PeopleListFragment extends FilterListFragment { - - @Override - protected FilterAdapter instantiateAdapter() { - return new PeopleFilterAdapter(getActivity(), null, R.layout.filter_adapter_row, false); - } - - @Override - protected int getLayout(Activity activity) { - if (AstridPreferences.useTabletLayout(activity)) { - return R.layout.filter_list_fragment_alternative_3pane; - } else { - return R.layout.filter_list_fragment_alternative; - } - } -} diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java deleted file mode 100644 index abdf712fb..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.people; - -import android.app.Activity; -import android.content.ContentValues; -import android.content.Intent; -import android.text.TextUtils; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.actionbarsherlock.view.Menu; -import com.timsu.astrid.R; -import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.service.Autowired; -import com.todoroo.andlib.utility.DateUtilities; -import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; -import com.todoroo.astrid.actfm.sync.ActFmSyncService; -import com.todoroo.astrid.actfm.sync.ActFmSyncThread; -import com.todoroo.astrid.actfm.sync.ActFmSyncThread.SyncMessageCallback; -import com.todoroo.astrid.actfm.sync.messages.BriefMe; -import com.todoroo.astrid.activity.TaskListFragment; -import com.todoroo.astrid.dao.UserDao; -import com.todoroo.astrid.data.RemoteModel; -import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.data.User; -import com.todoroo.astrid.helper.AsyncImageView; -import com.todoroo.astrid.service.SyncV2Service; -import com.todoroo.astrid.service.ThemeService; -import com.todoroo.astrid.utility.ResourceDrawableCache; - -import org.json.JSONArray; - -import java.util.List; - -public class PersonViewFragment extends TaskListFragment { - - public static final String EXTRA_USER_ID_LOCAL = "user_local_id"; //$NON-NLS-1$ - - public static final String EXTRA_HIDE_QUICK_ADD = "hide_quickAdd"; //$NON-NLS-1$ - - protected static final int MENU_REFRESH_ID = MENU_SUPPORT_ID + 1; - - @Autowired - UserDao userDao; - - @Autowired - SyncV2Service syncService; - - @Autowired - ActFmPreferenceService actFmPreferenceService; - - @Autowired - ActFmSyncService actFmSyncService; - - private AsyncImageView userImage; - private TextView userSubtitle; - private TextView userStatusButton; - private TextView emptyView; - - private User user; - - @Override - protected void initializeData() { - super.initializeData(); - if (extras.containsKey(EXTRA_USER_ID_LOCAL)) { - user = userDao.fetch(extras.getLong(EXTRA_USER_ID_LOCAL), User.PROPERTIES); - } - emptyView = (TextView) getView().findViewById(android.R.id.empty); - emptyView.setText(getEmptyDisplayString()); - - setupUserHeader(); - } - - private void setupUserHeader() { - if (user != null) { - userImage.setDefaultImageDrawable(ResourceDrawableCache.getImageDrawableFromId(resources, R.drawable.icn_default_person_image)); - userImage.setUrl(user.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_MEDIUM)); - - userSubtitle.setText(getUserSubtitleText()); - setupUserStatusButton(); - } else { - getView().findViewById(R.id.user_header).setVisibility(View.GONE); - userStatusButton.setVisibility(View.GONE); - } - } - - @Override - protected void setupQuickAddBar() { - super.setupQuickAddBar(); - quickAddBar.setUsePeopleControl(false); - if (user != null) { - quickAddBar.getQuickAddBox().setHint(getString(R.string.TLA_quick_add_hint_assign, user.getDisplayName())); - } - - if (extras.containsKey(EXTRA_HIDE_QUICK_ADD)) { - quickAddBar.setVisibility(View.GONE); - } - - // set listener for astrid icon - emptyView.setOnClickListener(null); - - } - - private String getUserSubtitleText() { - String status = user.getValue(User.STATUS); - String userName = user.getDisplayName(); - if (User.STATUS_PENDING.equals(status) || User.STATUS_REQUEST.equals(status)) { - return getString(R.string.actfm_friendship_pending, userName); - } else if (User.STATUS_BLOCKED.equals(status) || User.STATUS_RENOUNCE.equals(status)) { - return getString(R.string.actfm_friendship_blocked, userName); - } else if (User.STATUS_FRIENDS.equals(status) || User.STATUS_CONFIRM.equals(status)) { - return getString(R.string.actfm_friendship_friends, userName); - } else if (User.STATUS_OTHER_PENDING.equals(status)) { - return getString(R.string.actfm_friendship_other_pending, userName); - } else if (User.STATUS_IGNORED.equals(status) || User.STATUS_IGNORE.equals(status)) { - return getString(R.string.actfm_friendship_ignored, userName); - } else { - return getString(R.string.actfm_friendship_no_status, userName); - } - - } - - private void setupUserStatusButton() { - String status = user.getValue(User.STATUS); - userStatusButton.setVisibility(View.VISIBLE); - if (User.STATUS_CONFIRM.equals(status) || User.STATUS_IGNORE.equals(status) || User.STATUS_RENOUNCE.equals(status) || User.STATUS_REQUEST.equals(user)) // All the pending status options - { - userStatusButton.setVisibility(View.GONE); - } else if (TextUtils.isEmpty(status) || "null".equals(status)) //$NON-NLS-1$ - { - userStatusButton.setText(getString(R.string.actfm_friendship_connect)); - } else if (User.STATUS_OTHER_PENDING.equals(status)) { - userStatusButton.setText(getString(R.string.actfm_friendship_accept)); - } else { - userStatusButton.setVisibility(View.GONE); - } - } - - @Override - protected void setUpUiComponents() { - super.setUpUiComponents(); - userImage = (AsyncImageView) getView().findViewById(R.id.user_image); - userSubtitle = (TextView) getView().findViewById(R.id.user_subtitle); - userStatusButton = (TextView) getActivity().findViewById(R.id.person_image); - } - - @Override - protected View getListBody(ViewGroup root) { - ViewGroup parent = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.task_list_body_user, root, false); - - View taskListView = super.getListBody(parent); - parent.addView(taskListView); - - return parent; - } - - public void handleStatusButtonClicked() { - if (user != null) { // Just in case - String status = user.getValue(User.STATUS); - if (TextUtils.isEmpty(status) || "null".equals(status)) { // Add friend case //$NON-NLS-1$ - user.setValue(User.STATUS, User.STATUS_REQUEST); - } else if (User.STATUS_OTHER_PENDING.equals(status)) { // Accept friend case - user.setValue(User.STATUS, User.STATUS_CONFIRM); - } - - ContentValues setValues = user.getSetValues(); - if (setValues != null && setValues.containsKey(User.STATUS.name)) { - userDao.saveExisting(user); - userStatusButton.setVisibility(View.GONE); - } - } - } - - @Override - protected void addSyncRefreshMenuItem(Menu menu, int themeFlags) { - if (actFmPreferenceService.isLoggedIn()) { - addMenuItem(menu, R.string.actfm_TVA_menu_refresh, - ThemeService.getDrawable(R.drawable.icn_menu_refresh, themeFlags), MENU_REFRESH_ID, true); - } else { - super.addSyncRefreshMenuItem(menu, themeFlags); - } - } - - @Override - public boolean handleOptionsMenuItemSelected(int id, Intent intent) { - switch (id) { - case MENU_REFRESH_ID: - refreshData(); - return true; - } - return super.handleOptionsMenuItemSelected(id, intent); - } - - @Override - protected void initiateAutomaticSyncImpl() { - if (!isCurrentTaskListFragment()) { - return; - } - if (user != null) { - long lastAutosync = user.getValue(User.LAST_AUTOSYNC); - - if (DateUtilities.now() - lastAutosync > AUTOSYNC_INTERVAL) { - refreshData(); - user.setValue(User.LAST_AUTOSYNC, DateUtilities.now()); - userDao.saveExisting(user); - } - } - } - - private void reloadUserData() { - user = userDao.fetch(extras.getLong(EXTRA_USER_ID_LOCAL), User.PROPERTIES); - } - - @Override - protected void refresh() { - super.refresh(); - setupUserHeader(); - } - - private void refreshData() { - if (user != null) { - emptyView.setText(R.string.DLG_loading); - SyncMessageCallback callback = new SyncMessageCallback() { - @Override - public void runOnSuccess() { - Activity activity = getActivity(); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - reloadUserData(); - refresh(); - emptyView.setText(getEmptyDisplayString()); - } - }); - } - } - - @Override - public void runOnErrors(List errors) {/**/} - }; - long pushedAt = user.getValue(User.TASKS_PUSHED_AT); - JSONArray existingTasks = new JSONArray(); - TodorooCursor tasksCursor = (TodorooCursor) taskAdapter.getCursor(); - for (tasksCursor.moveToFirst(); !tasksCursor.isAfterLast(); tasksCursor.moveToNext()) { - existingTasks.put(tasksCursor.get(Task.UUID)); - } - - BriefMe briefMe = new BriefMe(Task.class, null, pushedAt, BriefMe.USER_ID_KEY, user.getValue(User.UUID), "existing_task_ids", existingTasks); //$NON-NLS-1$ - ActFmSyncThread.getInstance().enqueueMessage(briefMe, callback); - } - } - - private String getEmptyDisplayString() { - String userName = user != null ? user.getDisplayName() : null; - return TextUtils.isEmpty(userName) ? getString(R.string.actfm_my_shared_tasks_empty) : getString(R.string.TLA_no_items_person, userName); - } - -} diff --git a/astrid/res/layout/control_set_collaborators.xml b/astrid/res/layout/control_set_collaborators.xml deleted file mode 100644 index 37990a60e..000000000 --- a/astrid/res/layout/control_set_collaborators.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/astrid/res/layout/tag_settings_activity.xml b/astrid/res/layout/tag_settings_activity.xml index 449496b0b..2cc3fd1a8 100644 --- a/astrid/res/layout/tag_settings_activity.xml +++ b/astrid/res/layout/tag_settings_activity.xml @@ -102,31 +102,6 @@ - - - - - - 1) { - removeView(tagItem); - } else { - textView.setText(""); //$NON-NLS-1$ - textView.setEnabled(true); - } - } - }); - } - - final AsyncImageView imageView = (AsyncImageView) tagItem. - findViewById(R.id.icon); - imageView.setUrl(image); - if (TextUtils.isEmpty(textView.getText())) { - imageView.setDefaultImageDrawable(ResourceDrawableCache.getImageDrawableFromId(resources, R.drawable.icn_add_contact)); - removeButton.setVisibility(View.GONE); - } else { - imageView.setDefaultImageDrawable(ResourceDrawableCache.getImageDrawableFromId(resources, R.drawable.icn_default_person_image)); - if (!hideRemove) { - removeButton.setVisibility(View.VISIBLE); - } - } - - - textView.addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable s) { - // - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - // - } - - - @Override - public void onTextChanged(CharSequence s, int start, int before, - int count) { - if (count > 0 && getLastTextView() == textView) { - addPerson("", "", false); - } - if (TextUtils.isEmpty(textView.getText())) { - imageView.setDefaultImageDrawable(ResourceDrawableCache.getImageDrawableFromId(resources, R.drawable.icn_add_contact)); - removeButton.setVisibility(View.GONE); - } else { - imageView.setDefaultImageDrawable(ResourceDrawableCache.getImageDrawableFromId(resources, R.drawable.icn_default_person_image)); - removeButton.setVisibility(View.VISIBLE); - } - - if (onAddNewPerson != null) { - onAddNewPerson.textChanged(s.toString()); - } - } - }); - - textView.setOnEditorActionListener(new OnEditorActionListener() { - - @Override - public boolean onEditorAction(TextView arg0, int actionId, KeyEvent arg2) { - if (actionId != EditorInfo.IME_NULL) { - return false; - } - if (getLastTextView().getText().length() != 0) { - addPerson("", "", false); - } - return true; - } - }); - - return textView; - } - - /** - * Get tags container last text view. might be null - * - * @return - */ - private TextView getLastTextView() { - for (int i = getChildCount() - 1; i >= 0; i--) { - View lastItem = getChildAt(i); - TextView lastText = (TextView) lastItem.findViewById(R.id.text1); - if (lastText.isEnabled()) { - return lastText; - } - } - return null; - } - - public TextView getTextView(int index) { - View item = getChildAt(index); - return (TextView) item.findViewById(R.id.text1); - } - - /** - * @return json array of people - */ - public JSONArray toJSONArray() { - JSONArray people = new JSONArray(); - for (int i = 0; i < getChildCount(); i++) { - TextView textView = getTextView(i); - JSONObject person = PeopleContainer.createUserJson(textView); - if (person != null) { - String email = person.optString("email"); //$NON-NLS-1$ - if (email.indexOf('@') != -1) { - people.put(person); - } - } - } - return people; - } - - - public JSONObject parseSharedWithAndTags(Activity activity, boolean peopleAsJSON) throws - JSONException, ParseSharedException { - JSONObject sharedWith = new JSONObject(); - - HashSet addedEmails = new HashSet(); - HashSet addedIds = new HashSet(); - JSONArray peopleList = new JSONArray(); - for (int i = 0; i < getChildCount(); i++) { - TextView textView = getTextView(i); - String text = textView.getText().toString(); - - if (text.length() == 0) { - continue; - } - - if (text.indexOf('@') == -1 && textView.isEnabled()) { - throw new ParseSharedException(textView, - activity.getString(R.string.actfm_EPA_invalid_email, text)); - } - if (peopleAsJSON) { - JSONObject person = PeopleContainer.createUserJson(textView); - if (person != null) { - if (person.optBoolean("owner")) //$NON-NLS-1$ - { - continue; - } - String email = person.optString("email"); - Long id = person.optLong("id", -1); - if (!TextUtils.isEmpty(email) && !addedEmails.contains(email)) { - addedEmails.add(email); - if (id > 0) { - addedIds.add(id); - } - peopleList.put(person); - } else if (id > 0 && !addedIds.contains(id)) { - addedIds.add(id); - peopleList.put(person); - } - } - } else if (!addedEmails.contains(text)) { - addedEmails.add(text); - peopleList.put(text); - } - } - if (peopleList.length() > 0) { - sharedWith.put("p", peopleList); - } - - return sharedWith; - } - - public static class ParseSharedException extends Exception { - private static final long serialVersionUID = -4135848250086302970L; - public TextView view; - public String message; - - public ParseSharedException(TextView view, String message) { - this.view = view; - this.message = message; - } - } - - /** - * Add people from JSON Array - * - * @param people - */ - - public void fromJSONArray(JSONArray people) throws JSONException { - for (int i = 0; i < people.length(); i++) { - JSONObject person = people.getJSONObject(i); - TextView textView = null; - String imageURL = person.optString("picture", ""); - boolean owner = person.optBoolean("owner"); - boolean hideRemove = owner; - String name = ""; - - if (person.has("id") && ActFmPreferenceService.userId().equals(person.getString("id"))) { - name = Preferences.getStringValue(ActFmPreferenceService.PREF_NAME); - hideRemove = true; - } else if (!TextUtils.isEmpty(person.optString("name")) && !"null".equals(person.optString("name"))) { - name = person.getString("name"); - } else if (!TextUtils.isEmpty(person.optString("email")) && !"null".equals(person.optString("email"))) { - name = person.getString("email"); - } - - if (owner) { - name = name + " " + ContextManager.getString(R.string.actfm_list_owner); - } - - textView = addPerson(name, imageURL, hideRemove); - - if (textView != null) { - textView.setTag(person); - textView.setEnabled(false); - } - } - } - - /** - * Warning: user json may not have a valid email address. - * - * @param textView - * @return - */ - - public static JSONObject createUserJson(TextView textView) { - if (textView.isEnabled() == false) { - return (JSONObject) textView.getTag(); - } - - String text = textView.getText().toString().trim(); - if (text.length() == 0) { - return null; - } - - JSONObject user = new JSONObject(); - int bracket = text.lastIndexOf('<'); - try { - if (bracket > -1) { - user.put("name", text.substring(0, bracket - 1).trim()); - user.put("email", text.substring(bracket + 1, text.length() - 1).trim()); - } else { - user.put("email", text); - } - } catch (JSONException e) { - throw new RuntimeException(e); - } - - return user; - } - -} diff --git a/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java b/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java index 3021ab27e..dd4bcc35b 100644 --- a/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java +++ b/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java @@ -34,7 +34,6 @@ import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.Preferences; -import com.todoroo.astrid.actfm.EditPeopleControlSet; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.activity.AstridActivity; import com.todoroo.astrid.activity.TaskEditFragment; @@ -77,8 +76,6 @@ public class QuickAddBar extends LinearLayout { private DeadlineControlSet deadlineControl; private RepeatControlSet repeatControl; private GCalControlSet gcalControl; - private EditPeopleControlSet peopleControl; - private boolean usePeopleControl = true; private String currentVoiceFile = null; @@ -217,11 +214,6 @@ public class QuickAddBar extends LinearLayout { setUpQuickAddControlSets(); } - public void setUsePeopleControl(boolean usePeopleControl) { - this.usePeopleControl = usePeopleControl; - peopleControl.getDisplayView().setVisibility(usePeopleControl ? View.VISIBLE : View.GONE); - } - private void setUpQuickAddControlSets() { repeatControl = new RepeatControlSet(activity, @@ -238,24 +230,14 @@ public class QuickAddBar extends LinearLayout { repeatControl.getDisplayView(), gcalControl.getDisplayView()); deadlineControl.setIsQuickadd(true); - peopleControl = new EditPeopleControlSet(activity, fragment, - R.layout.control_set_assigned, - R.layout.control_set_default_display, - R.string.actfm_EPA_assign_label_long, - TaskEditFragment.REQUEST_LOG_IN); - resetControlSets(); LayoutParams lp = new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1.0f); - View peopleDisplay = peopleControl.getDisplayView(); View deadlineDisplay = deadlineControl.getDisplayView(); - quickAddControls.addView(peopleDisplay, 0, lp); - quickAddControls.addView(deadlineDisplay, 2, lp); + quickAddControls.addView(deadlineDisplay, 0, lp); TextView tv = (TextView) deadlineDisplay.findViewById(R.id.display_row_edit); tv.setGravity(Gravity.LEFT); - tv = (TextView) peopleDisplay.findViewById(R.id.display_row_edit); - tv.setGravity(Gravity.LEFT); } private void resetControlSets() { @@ -270,9 +252,6 @@ public class QuickAddBar extends LinearLayout { gcalControl.readFromTask(empty); gcalControl.resetCalendarSelector(); deadlineControl.readFromTask(empty); - peopleControl.setUpData(empty, fragment.getActiveTagData()); - peopleControl.assignToMe(); - peopleControl.setTask(null); } @@ -297,12 +276,7 @@ public class QuickAddBar extends LinearLayout { if (title != null) { title = title.trim(); } - boolean assignedToMe = usePeopleControl ? peopleControl.willBeAssignedToMe() : true; - if (!assignedToMe && !actFmPreferenceService.isLoggedIn()) { - // Reset people control - peopleControl.assignToMe(); - return null; - } + boolean assignedToMe = true; Task task = new Task(); if (title != null) { @@ -318,20 +292,9 @@ public class QuickAddBar extends LinearLayout { TaskDao.createDefaultHideUntil(task); } gcalControl.writeToModel(task); - if (!assignedToMe) { - peopleControl.setTask(task); - peopleControl.saveSharingSettings(null); - } TaskService.createWithValues(task, fragment.getFilter().valuesForNewTasks, title); - String assignedTo = peopleControl.getAssignedToString(); - String assignedEmail = ""; - String assignedId = task.getValue(Task.USER_ID); - if (Task.userIdIsEmail(task.getValue(Task.USER_ID))) { - assignedEmail = task.getValue(Task.USER_ID); - } - resetControlSets(); addToCalendar(task, title); @@ -340,10 +303,6 @@ public class QuickAddBar extends LinearLayout { fragment.showTaskEditHelpPopover(); } - if (activity instanceof TaskListActivity && !assignedToMe) { - ((TaskListActivity) activity).taskAssignedTo(assignedTo, assignedEmail, assignedId); - } - TextView quickAdd = (TextView) findViewById(R.id.quickAddText); quickAdd.setText(""); //$NON-NLS-1$ @@ -450,9 +409,7 @@ public class QuickAddBar extends LinearLayout { return true; } else if (requestCode == TaskEditFragment.REQUEST_CODE_CONTACT) { if (resultCode == Activity.RESULT_OK) { - peopleControl.onActivityResult(requestCode, resultCode, data); } else { - peopleControl.assignToMe(); } return true; } diff --git a/tests-sync/src/com/todoroo/astrid/sync/repeats/RepeatTestsActFmSync.java b/tests-sync/src/com/todoroo/astrid/sync/repeats/RepeatTestsActFmSync.java index fb68b3de0..ad6280b18 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/repeats/RepeatTestsActFmSync.java +++ b/tests-sync/src/com/todoroo/astrid/sync/repeats/RepeatTestsActFmSync.java @@ -61,16 +61,6 @@ public class RepeatTestsActFmSync extends AbstractSyncRepeatTests { } private void clearTasks() throws Exception { -// JSONObject result = invoker.invoke("task_list", "active", 1); -// -// JSONArray taskList = result.getJSONArray("list"); -// for(int i = 0; i < taskList.length(); i++) { -// Task remote = new Task(); -// ActFmSyncService.JsonHelper.taskFromJson(taskList.getJSONObject(i), remote, new ArrayList()); -// -// remote.setValue(Task.DELETION_DATE, DateUtilities.now()); -// actFmSyncService.pushTaskOnSave(remote, remote.getSetValues()); -// } } private void authenticate(String email, String firstName, String lastName, String provider, String secret) { @@ -120,15 +110,6 @@ public class RepeatTestsActFmSync extends AbstractSyncRepeatTests { */ @Override protected Task assertTaskExistsRemotely(Task t, long expectedDueDate) { -// Task remote = new Task(); -// try { -// ActFmSyncService.JsonHelper.taskFromJson(invoker.invoke("task_show", "id", t.getValue(Task.UUID)), remote, -// new ArrayList()); -// assertTimesMatch(expectedDueDate, remote.getValue(Task.DUE_DATE).longValue()); -// } catch (Exception e) { -// e.printStackTrace(); -// fail("Error in ActFm invoker"); -// } return null; //remote; }