Fix quick add assignment when not logged in

pull/14/head
Sam Bosley 13 years ago
parent 2bf26ee51e
commit c08e008be6

@ -16,6 +16,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
@ -76,6 +77,8 @@ public class EditPeopleControlSet extends PopupControlSet {
@Autowired TagDataService tagDataService;
private final Fragment fragment;
private final PeopleContainer sharedWithContainer;
private final CheckBox cbFacebook;
@ -108,10 +111,11 @@ public class EditPeopleControlSet extends PopupControlSet {
// --- UI initialization
public EditPeopleControlSet(Activity activity, int viewLayout, int displayViewLayout, int title, int loginRequestCode) {
public EditPeopleControlSet(Activity activity, Fragment fragment, int viewLayout, int displayViewLayout, int title, int loginRequestCode) {
super(activity, viewLayout, displayViewLayout, title);
DependencyInjectionService.getInstance().inject(this);
this.loginRequestCode = loginRequestCode;
this.fragment = fragment;
displayText.setText(activity.getString(R.string.TEA_control_who));
sharedWithRow = LayoutInflater.from(activity).inflate(R.layout.control_set_default_display, null);
@ -413,8 +417,9 @@ public class EditPeopleControlSet extends PopupControlSet {
}
}
private void assignToMe() {
assignedClear.performClick();
public void assignToMe() {
assignedList.performItemClick(assignedList.getChildAt(0), 0, 0);
refreshDisplayView();
}
private void setUpListeners() {
@ -546,7 +551,7 @@ public class EditPeopleControlSet extends PopupControlSet {
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
activity.startActivityForResult(new Intent(activity, ActFmLoginActivity.class),
fragment.startActivityForResult(new Intent(activity, ActFmLoginActivity.class),
loginRequestCode);
}
};
@ -592,10 +597,9 @@ public class EditPeopleControlSet extends PopupControlSet {
}
private void makePrivateTask() {
assignToMe();
sharedWithContainer.removeAllViews();
sharedWithContainer.addPerson(""); //$NON-NLS-1$
refreshDisplayView();
assignToMe();
}
private void showSaveToast(String saveToast) {
@ -704,6 +708,26 @@ public class EditPeopleControlSet extends PopupControlSet {
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 {
AssignedToUser item = (AssignedToUser) assignedList.getAdapter().getItem(assignedList.getCheckedItemPosition());
if (item != null)
userJson = item.user;
}
if(userJson == null || userJson.optLong("id", Task.USER_ID_EMAIL) == Task.USER_ID_SELF) { //$NON-NLS-1$
return true;
}
return false;
}
public String getAssignedToString() {
return assignedDisplay.getText().toString();
}

@ -505,7 +505,7 @@ public final class TaskEditFragment extends Fragment implements
// EditPeopleControlSet relies on the "tags" transitory created by the
// TagsControlSet, so we put the tags control before the people control
controls.add(peopleControlSet = new EditPeopleControlSet(getActivity(),
controls.add(peopleControlSet = new EditPeopleControlSet(getActivity(), this,
R.layout.control_set_assigned,
R.layout.control_set_default_display,
R.string.actfm_EPA_assign_label, REQUEST_LOG_IN));

@ -74,6 +74,7 @@ import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.andlib.widget.GestureService;
import com.todoroo.andlib.widget.GestureService.GestureInterface;
@ -81,6 +82,7 @@ import com.todoroo.astrid.actfm.ActFmLoginActivity;
import com.todoroo.astrid.actfm.EditPeopleControlSet;
import com.todoroo.astrid.actfm.TagUpdatesActivity;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.adapter.TaskAdapter.OnCompletedTaskListener;
@ -205,6 +207,9 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
@Autowired
TagDataService tagDataService;
@Autowired
ActFmPreferenceService actFmPreferenceService;
private final TaskContextActionExposer[] contextItemExposers = new TaskContextActionExposer[] {
new ReminderDebugContextActions.MakeNotification(),
new ReminderDebugContextActions.WhenReminder(), };
@ -624,7 +629,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
repeatControl.getDisplayView(), gcalControl.getDisplayView());
deadlineControl.setUseNewlineForDisplaySeparator(true);
peopleControl = new EditPeopleControlSet(getActivity(),
peopleControl = new EditPeopleControlSet(getActivity(), this,
R.layout.control_set_assigned,
R.layout.control_set_default_display,
R.string.actfm_EPA_assign_label, TaskEditFragment.REQUEST_LOG_IN);
@ -643,6 +648,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
gcalControl.readFromTask(empty);
deadlineControl.readFromTask(empty);
peopleControl.setUpData(empty);
peopleControl.assignToMe();
peopleControl.setTask(null);
}
@ -1127,17 +1133,38 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
try {
if (title != null)
title = title.trim();
if (!peopleControl.willBeAssignedToMe() && !actFmPreferenceService.isLoggedIn()) {
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
startActivity(new Intent(getActivity(), ActFmLoginActivity.class));
}
};
DialogInterface.OnClickListener cancelListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
// Reset people control
peopleControl.assignToMe();
}
};
DialogUtilities.okCancelCustomDialog(getActivity(), getActivity().getString(R.string.actfm_EPA_login_button),
getActivity().getString(R.string.actfm_EPA_login_to_share), R.string.actfm_EPA_login_button,
R.string.actfm_EPA_dont_share_button, android.R.drawable.ic_dialog_alert,
okListener, cancelListener);
return null;
}
Task task = createWithValues(filter.valuesForNewTasks, title,
taskService, metadataService);
//TODO: fix assigned
if (repeatControl.isRecurrenceSet())
repeatControl.writeToModel(task);
if (deadlineControl.isDeadlineSet())
deadlineControl.writeToModel(task);
gcalControl.writeToModel(task);
//peopleControl.setTask(task);
//peopleControl.saveSharingSettings("");
peopleControl.setTask(task);
peopleControl.saveSharingSettings(null);
taskService.save(task);
resetControlSets();

Loading…
Cancel
Save