Inline title edit, show keyboard on new task

pull/253/head
Alex Baker 10 years ago
parent 7bc0e4860a
commit e1776cde8b

@ -5,8 +5,8 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.tasks"
android:versionName="4.7"
android:versionCode="334">
android:versionName="4.7.0"
android:versionCode="335">
<!-- widgets, alarms, and services will break if Astrid is installed on SD card -->
<!-- android:installLocation="internalOnly"> -->

@ -68,6 +68,7 @@ import com.todoroo.astrid.tags.TagsControlSet;
import com.todoroo.astrid.timers.TimerActionControlSet;
import com.todoroo.astrid.timers.TimerControlSet;
import com.todoroo.astrid.timers.TimerPlugin;
import com.todoroo.astrid.ui.CheckableImageView;
import com.todoroo.astrid.ui.DateChangedAlerts;
import com.todoroo.astrid.ui.DeadlineControlSet;
import com.todoroo.astrid.ui.DescriptionControlSet;
@ -193,8 +194,6 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
/** whether task should be saved when this activity exits */
private boolean shouldSaveState = true;
private EditText notesEditText;
private Dialog whenDialog;
private boolean overrideFinishAnim;
@ -332,9 +331,6 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
/** Initialize UI components */
private void setUpUIComponents() {
LinearLayout titleControls = (LinearLayout) getView().findViewById(
R.id.title_controls);
LinearLayout whenDialogView = (LinearLayout) LayoutInflater.from(
getActivity()).inflate(R.layout.task_edit_when_controls, null);
@ -343,10 +339,13 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
controlSetMap = new HashMap<>();
// populate control set
EditTitleControlSet editTitle = new EditTitleControlSet(taskService, getActivity());
title = (EditText) editTitle.getView().findViewById(R.id.title);
title = (EditText) getView().findViewById(R.id.title);
EditTitleControlSet editTitle = new EditTitleControlSet(
taskService,
getActivity(),
title,
(CheckableImageView) getView().findViewById(R.id.completeBox));
controls.add(editTitle);
titleControls.addView(editTitle.getDisplayView(), 0, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
timerAction = new TimerActionControlSet(notificationManager, taskService, getActivity(), getView());
controls.add(timerAction);
@ -383,7 +382,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
importanceControl);
notesControlSet = new DescriptionControlSet(preferences, getActivity());
notesEditText = (EditText) notesControlSet.getView().findViewById(
EditText notesEditText = (EditText) notesControlSet.getView().findViewById(
R.id.notes);
controls.add(notesControlSet);
controlSetMap.put(getString(R.string.TEA_ctrl_notes_pref),
@ -501,6 +500,12 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
if (getActivity() != null) {
// todo: is this necessary?
loadMoreContainer();
if (isNewTask) {
title.requestFocus();
title.setCursorVisible(true);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
}
}

@ -17,7 +17,7 @@ import com.todoroo.andlib.data.Callback;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.helper.TaskEditControlSetBase;
import com.todoroo.astrid.ui.DateAndTimeDialog;
import com.todoroo.astrid.ui.DateAndTimeDialog.DateAndTimeDialogListener;
import com.todoroo.astrid.ui.DateAndTimePicker;
@ -36,7 +36,7 @@ import static org.tasks.date.DateTimeUtils.newDate;
* @author Tim Su <tim@todoroo.com>
*
*/
public final class AlarmControlSet extends TaskEditControlSet {
public final class AlarmControlSet extends TaskEditControlSetBase {
private final ActivityPreferences preferences;
private final AlarmService alarmService;

@ -1,124 +1,15 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.helper;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.content.res.Resources.Theme;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.ui.EditDialogOkBackground;
import org.tasks.R;
public interface TaskEditControlSet {
View getView();
import static org.tasks.preferences.ResourceResolver.getData;
View getDisplayView();
// --- interface
void readFromTask(Task task);
/**
* Interface for working with controls that alter task data
*/
public abstract class TaskEditControlSet {
protected final Activity activity;
private final int viewLayout;
private View view;
protected Task model;
protected boolean initialized = false;
protected final int themeColor;
protected final int unsetColor;
public TaskEditControlSet(Activity activity, int viewLayout) {
this.activity = activity;
this.viewLayout = viewLayout;
if (viewLayout == -1) {
initialized = true;
}
themeColor = getData(activity, R.attr.task_edit_theme_color);
unsetColor = activity.getResources().getColor(R.color.task_edit_deadline_gray);
}
public View getView() {
if (view == null && !initialized) {
if (viewLayout != -1) {
view = LayoutInflater.from(activity).inflate(viewLayout, null);
afterInflate();
setupOkButton(view);
}
if (model != null) {
readFromTaskOnInitialize();
}
this.initialized = true;
}
return view;
}
public View getDisplayView() {
return getView();
}
/**
* Read data from model to update the control set
*/
public void readFromTask(Task task) {
this.model = task;
if (initialized) {
readFromTaskOnInitialize();
}
}
/**
* Called once to setup the ui with data from the task
*/
protected abstract void readFromTaskOnInitialize();
/**
* Write data from control set to model
*/
public void writeToModel(Task task) {
if (initialized) {
writeToModelAfterInitialized(task);
}
}
/**
* Write to model, if initialization logic has been called
*/
protected abstract void writeToModelAfterInitialized(Task task);
/**
* Called when views need to be inflated
*/
protected abstract void afterInflate();
/**
* Sets up ok button background. Subclasses can override to customize look and feel
*/
protected void setupOkButton(View view) {
Button ok = (Button) view.findViewById(R.id.edit_dlg_ok);
Theme theme = activity.getTheme();
TypedValue themeColor = new TypedValue();
theme.resolveAttribute(R.attr.asThemeTextColor, themeColor, false);
TypedValue inverseColor = new TypedValue();
theme.resolveAttribute(R.attr.asTextColorInverse, inverseColor, false);
if (ok != null) {
ok.setBackgroundDrawable(EditDialogOkBackground.getBg(activity.getResources().getColor(themeColor.data)));
int[][] states = new int[2][];
states[0] = new int[] { android.R.attr.state_pressed };
states[1] = new int[] { android.R.attr.state_enabled };
int[] colors = new int[] { inverseColor.data, activity.getResources().getColor(themeColor.data) };
ColorStateList csl = new ColorStateList(states, colors);
ok.setTextColor(csl);
}
}
void writeToModel(Task task);
}

@ -0,0 +1,128 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.helper;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.content.res.Resources.Theme;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.ui.EditDialogOkBackground;
import org.tasks.R;
import static org.tasks.preferences.ResourceResolver.getData;
// --- interface
/**
* Interface for working with controls that alter task data
*/
public abstract class TaskEditControlSetBase implements TaskEditControlSet {
protected final Activity activity;
private final int viewLayout;
private View view;
protected Task model;
protected boolean initialized = false;
protected final int themeColor;
protected final int unsetColor;
public TaskEditControlSetBase(Activity activity, int viewLayout) {
this.activity = activity;
this.viewLayout = viewLayout;
if (viewLayout == -1) {
initialized = true;
}
themeColor = getData(activity, R.attr.task_edit_theme_color);
unsetColor = activity.getResources().getColor(R.color.task_edit_deadline_gray);
}
@Override
public View getView() {
if (view == null && !initialized) {
if (viewLayout != -1) {
view = LayoutInflater.from(activity).inflate(viewLayout, null);
afterInflate();
setupOkButton(view);
}
if (model != null) {
readFromTaskOnInitialize();
}
this.initialized = true;
}
return view;
}
@Override
public View getDisplayView() {
return getView();
}
/**
* Read data from model to update the control set
*/
@Override
public void readFromTask(Task task) {
this.model = task;
if (initialized) {
readFromTaskOnInitialize();
}
}
/**
* Called once to setup the ui with data from the task
*/
protected abstract void readFromTaskOnInitialize();
/**
* Write data from control set to model
*/
@Override
public void writeToModel(Task task) {
if (initialized) {
writeToModelAfterInitialized(task);
}
}
/**
* Write to model, if initialization logic has been called
*/
protected abstract void writeToModelAfterInitialized(Task task);
/**
* Called when views need to be inflated
*/
protected abstract void afterInflate();
/**
* Sets up ok button background. Subclasses can override to customize look and feel
*/
protected void setupOkButton(View view) {
Button ok = (Button) view.findViewById(R.id.edit_dlg_ok);
Theme theme = activity.getTheme();
TypedValue themeColor = new TypedValue();
theme.resolveAttribute(R.attr.asThemeTextColor, themeColor, false);
TypedValue inverseColor = new TypedValue();
theme.resolveAttribute(R.attr.asTextColorInverse, inverseColor, false);
if (ok != null) {
ok.setBackgroundDrawable(EditDialogOkBackground.getBg(activity.getResources().getColor(themeColor.data)));
int[][] states = new int[2][];
states[0] = new int[] { android.R.attr.state_pressed };
states[1] = new int[] { android.R.attr.state_enabled };
int[] colors = new int[] { inverseColor.data, activity.getResources().getColor(themeColor.data) };
ColorStateList csl = new ColorStateList(states, colors);
ok.setTextColor(csl);
}
}
}

@ -17,7 +17,7 @@ import android.widget.LinearLayout;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.helper.TaskEditControlSetBase;
import com.todoroo.astrid.service.TaskService;
import org.tasks.R;
@ -26,7 +26,7 @@ import org.tasks.notifications.NotificationManager;
import java.util.LinkedList;
import java.util.List;
public class TimerActionControlSet extends TaskEditControlSet {
public class TimerActionControlSet extends TaskEditControlSetBase {
private final ImageView timerButton;
private final Chronometer chronometer;

@ -14,7 +14,7 @@ import android.widget.TextView;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.helper.TaskEditControlSetBase;
import com.todoroo.astrid.timers.TimerActionControlSet.TimerActionListener;
import com.todoroo.astrid.ui.PopupControlSet;
import com.todoroo.astrid.ui.TimeDurationControlSet;
@ -75,7 +75,7 @@ public class TimerControlSet extends PopupControlSet implements TimerActionListe
* @author Tim Su <tim@todoroo.com>
*
*/
public class TimeDurationTaskEditControlSet extends TaskEditControlSet {
public class TimeDurationTaskEditControlSet extends TaskEditControlSetBase {
private final TimeDurationControlSet controlSet;
private final IntegerProperty property;

@ -26,33 +26,26 @@ import com.todoroo.astrid.repeats.RepeatControlSet.RepeatChangedListener;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.ui.ImportanceControlSet.ImportanceChangedListener;
import org.tasks.R;
/**
* Control set for mapping a Property to an EditText
* @author Tim Su <tim@todoroo.com>
*
*/
public class EditTitleControlSet extends TaskEditControlSet implements ImportanceChangedListener, RepeatChangedListener {
private static final int editTextId = R.id.title;
public class EditTitleControlSet implements TaskEditControlSet, ImportanceChangedListener, RepeatChangedListener {
private EditText editText;
protected CheckableImageView completeBox;
private final EditText editText;
private CheckableImageView completeBox;
private boolean isRepeating;
private int importanceValue;
private Task model;
private final TaskService taskService;
public EditTitleControlSet(TaskService taskService, Activity activity) {
super(activity, R.layout.control_set_title);
public EditTitleControlSet(TaskService taskService, final Activity activity, final EditText editText, CheckableImageView completeBox) {
this.editText = editText;
this.completeBox = completeBox;
this.taskService = taskService;
}
@Override
protected void afterInflate() {
this.editText = (EditText) getView().findViewById(editTextId);
editText.setHorizontallyScrolling(false);
editText.setMaxLines(Integer.MAX_VALUE);
editText.setOnKeyListener(new OnKeyListener() {
@ -81,10 +74,8 @@ public class EditTitleControlSet extends TaskEditControlSet implements Importanc
return false;
}
});
this.completeBox = (CheckableImageView) getView().findViewById(R.id.completeBox);
}
@Override
protected void readFromTaskOnInitialize() {
editText.setTextKeepState(model.getTitle());
completeBox.setChecked(model.isCompleted());
@ -101,15 +92,6 @@ public class EditTitleControlSet extends TaskEditControlSet implements Importanc
});
}
@Override
protected void writeToModelAfterInitialized(Task task) {
task.setTitle(editText.getText().toString());
boolean newState = completeBox.isChecked();
if (newState != task.isCompleted()) {
taskService.setComplete(task, newState);
}
}
@Override
public void importanceChanged(int i) {
importanceValue = i;
@ -121,17 +103,16 @@ public class EditTitleControlSet extends TaskEditControlSet implements Importanc
public void repeatChanged(boolean repeat) {
isRepeating = repeat;
updateCompleteBox();
}
@Override
public void readFromTask(Task task) {
super.readFromTask(task);
this.model = task;
readFromTaskOnInitialize();
isRepeating = !TextUtils.isEmpty(task.getRecurrence());
importanceValue = model.getImportance();
}
private void updateCompleteBox() {
boolean checked = completeBox.isChecked();
int[] resourceArray = isRepeating ? (checked ? TaskAdapter.IMPORTANCE_REPEAT_RESOURCES_CHECKED : TaskAdapter.IMPORTANCE_REPEAT_RESOURCES)
@ -155,4 +136,22 @@ public class EditTitleControlSet extends TaskEditControlSet implements Importanc
}
}
@Override
public void writeToModel(Task task) {
task.setTitle(editText.getText().toString());
boolean newState = completeBox.isChecked();
if (newState != task.isCompleted()) {
taskService.setComplete(task, newState);
}
}
@Override
public View getView() {
throw new RuntimeException();
}
@Override
public View getDisplayView() {
throw new RuntimeException();
}
}

@ -14,7 +14,7 @@ import android.widget.LinearLayout;
import android.widget.ToggleButton;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.helper.TaskEditControlSetBase;
import org.tasks.R;
@ -29,7 +29,7 @@ import static org.tasks.preferences.ResourceResolver.getResource;
* @author Tim Su <tim@todoroo.com>
*
*/
public class ImportanceControlSet extends TaskEditControlSet {
public class ImportanceControlSet extends TaskEditControlSetBase {
private final List<CompoundButton> buttons = new LinkedList<>();
private final int[] colors;
private final List<ImportanceChangedListener> listeners = new LinkedList<>();

@ -18,12 +18,12 @@ import android.widget.Button;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.helper.TaskEditControlSetBase;
import org.tasks.R;
import org.tasks.preferences.ActivityPreferences;
public abstract class PopupControlSet extends TaskEditControlSet {
public abstract class PopupControlSet extends TaskEditControlSetBase {
protected final View displayView;
protected final ActivityPreferences preferences;

@ -15,7 +15,7 @@ import android.widget.Spinner;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.helper.TaskEditControlSetBase;
import org.tasks.R;
@ -25,7 +25,7 @@ import org.tasks.R;
* @author Tim Su <tim@todoroo.com>
*
*/
public class RandomReminderControlSet extends TaskEditControlSet {
public class RandomReminderControlSet extends TaskEditControlSetBase {
private final CheckBox settingCheckbox;
private final Spinner periodSpinner;

@ -25,17 +25,7 @@
android:gravity="center_horizontal"
android:padding="10dip" >
<LinearLayout
android:id="@+id/title_controls"
android:background="?attr/asEditRowBackground"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dip"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingRight="6dip" >
</LinearLayout>
<include layout="@layout/control_set_title"/>
<LinearLayout
android:id="@+id/basic_controls"

Loading…
Cancel
Save