Merge EditText and EditTitle control sets

pull/14/head
Sam Bosley 13 years ago
parent ef58bb1cda
commit 5c5ba0b618

@ -450,7 +450,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
// populate control set
EditTitleControlSet editTitle = new EditTitleControlSet(getActivity(),
R.layout.control_set_title, Task.TITLE, R.id.title);
R.layout.control_set_title, R.id.title);
title = (EditText) editTitle.getView().findViewById(R.id.title);
controls.add(editTitle);
titleControls.addView(editTitle.getDisplayView(), 0, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));

@ -1,72 +0,0 @@
package com.todoroo.astrid.ui;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.EditText;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.service.TaskService;
/**
* Control set for mapping a Property to an EditText
* @author Tim Su <tim@todoroo.com>
*
*/
public class EditTextControlSet extends TaskEditControlSet {
private EditText editText;
private final StringProperty property;
protected CheckableImageView completeBox;
private final int editTextId;
@Autowired
private TaskService taskService;
public EditTextControlSet(Activity activity, int layout, StringProperty property, int editText) {
super(activity, layout);
this.property = property;
this.editTextId = editText;
DependencyInjectionService.getInstance().inject(this);
}
@Override
protected void afterInflate() {
this.editText = (EditText) getView().findViewById(editTextId);
this.completeBox = (CheckableImageView) getView().findViewById(R.id.completeBox);
}
@Override
protected void readFromTaskOnInitialize() {
editText.setTextKeepState(model.getValue(property));
completeBox.setChecked(model.isCompleted());
completeBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1.5f, 1.0f, 1.5f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(100);
// set check box to actual action item state
completeBox.startAnimation(scaleAnimation);
}
});
}
@Override
protected String writeToModelAfterInitialized(Task task) {
task.setValue(property, editText.getText().toString());
boolean newState = completeBox.isChecked();
if (newState != task.isCompleted()) {
taskService.setComplete(task, newState);
}
return null;
}
}

@ -2,21 +2,75 @@ package com.todoroo.astrid.ui;
import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.EditText;
import com.todoroo.andlib.data.Property.StringProperty;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.repeats.RepeatControlSet.RepeatChangedListener;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.ui.ImportanceControlSet.ImportanceChangedListener;
public class EditTitleControlSet extends EditTextControlSet implements ImportanceChangedListener, RepeatChangedListener {
/**
* Control set for mapping a Property to an EditText
* @author Tim Su <tim@todoroo.com>
*
*/
public class EditTitleControlSet extends TaskEditControlSet implements ImportanceChangedListener, RepeatChangedListener {
private EditText editText;
protected CheckableImageView completeBox;
private final int editTextId;
private boolean isRepeating;
private int importanceValue;
public EditTitleControlSet(Activity activity, int layout, StringProperty property, int editText) {
super(activity, layout, property, editText);
@Autowired
private TaskService taskService;
public EditTitleControlSet(Activity activity, int layout, int editText) {
super(activity, layout);
this.editTextId = editText;
DependencyInjectionService.getInstance().inject(this);
}
@Override
protected void afterInflate() {
this.editText = (EditText) getView().findViewById(editTextId);
this.completeBox = (CheckableImageView) getView().findViewById(R.id.completeBox);
}
@Override
protected void readFromTaskOnInitialize() {
editText.setTextKeepState(model.getValue(Task.TITLE));
completeBox.setChecked(model.isCompleted());
completeBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1.5f, 1.0f, 1.5f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(100);
// set check box to actual action item state
completeBox.startAnimation(scaleAnimation);
}
});
}
@Override
protected String writeToModelAfterInitialized(Task task) {
task.setValue(Task.TITLE, editText.getText().toString());
boolean newState = completeBox.isChecked();
if (newState != task.isCompleted()) {
taskService.setComplete(task, newState);
}
return null;
}
@Override
@ -54,5 +108,4 @@ public class EditTitleControlSet extends EditTextControlSet implements Importanc
}
}
}

Loading…
Cancel
Save