Sort of apply material list guidelines to task row

pull/493/head
Alex Baker 9 years ago
parent df85ac4648
commit 1eb5d7ee80

@ -25,4 +25,8 @@ public class SyncAdapterHelper {
public boolean isEnabled() {
return false;
}
public void requestSynchronization() {
}
}

@ -25,4 +25,8 @@ public class SyncAdapterHelper {
public boolean isEnabled() {
return false;
}
public void requestSynchronization() {
}
}

@ -97,7 +97,7 @@ public class CommentsController {
if (items.size() > commentItems) {
Button loadMore = new Button(activity);
loadMore.setText(R.string.TEA_load_more);
loadMore.setTextColor(getColor(activity, R.color.task_edit_deadline_gray));
loadMore.setTextColor(getColor(activity, R.color.text_secondary));
loadMore.setBackgroundColor(Color.alpha(0));
loadMore.setOnClickListener(v -> {
// Perform action on click

@ -20,7 +20,6 @@ import com.bignerdranch.android.multiselector.MultiSelectorBindingHolder;
import com.google.common.collect.Lists;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Pair;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.core.LinkActionExposer;
@ -38,16 +37,13 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnLongClick;
import timber.log.Timber;
import static com.google.common.collect.Lists.newArrayList;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
/**
* View Holder saves a lot of findViewById lookups.
*
* @author Tim Su <tim@todoroo.com>
*/
class ViewHolder extends MultiSelectorBindingHolder {
@Override
@ -72,7 +68,7 @@ class ViewHolder extends MultiSelectorBindingHolder {
updateBackground();
}
void updateBackground() {
private void updateBackground() {
if (selected || moving) {
rowBody.setBackgroundColor(selectedColor);
} else if (selectable) {
@ -102,7 +98,6 @@ class ViewHolder extends MultiSelectorBindingHolder {
@BindView(R.id.completeBox) CheckableImageView completeBox;
@BindView(R.id.due_date) public TextView dueDate;
@BindView(R.id.tag_block) TextView tagBlock;
@BindView(R.id.taskActionContainer) View taskActionContainer;
@BindView(R.id.taskActionIcon) ImageView taskActionIcon;
public Task task;
@ -111,7 +106,6 @@ class ViewHolder extends MultiSelectorBindingHolder {
private boolean hasFiles; // From join query, not part of the task model
private boolean hasNotes;
private final Context context;
private final int fontSize;
private final CheckBoxes checkBoxes;
private final TagFormatter tagFormatter;
private final int textColorSecondary;
@ -123,7 +117,6 @@ class ViewHolder extends MultiSelectorBindingHolder {
private final int background;
private final int selectedColor;
private final int textColorOverdue;
private Pair<Float, Float> lastTouchYRawY = new Pair<>(0f, 0f);
private int indent;
private boolean selectable = false;
private boolean selected;
@ -132,11 +125,10 @@ class ViewHolder extends MultiSelectorBindingHolder {
ViewHolder(Context context, ViewGroup view, boolean showFullTaskTitle, int fontSize,
CheckBoxes checkBoxes, TagFormatter tagFormatter,
int textColorOverdue, int textColorSecondary, int textColorHint, TaskDao taskDao,
DialogBuilder dialogBuilder, ViewHolderCallbacks callback, int minRowHeight,
DialogBuilder dialogBuilder, ViewHolderCallbacks callback,
DisplayMetrics metrics, int background, int selectedColor, MultiSelector multiSelector) {
super(view, multiSelector);
this.context = context;
this.fontSize = fontSize;
this.checkBoxes = checkBoxes;
this.tagFormatter = tagFormatter;
this.textColorOverdue = textColorOverdue;
@ -158,14 +150,21 @@ class ViewHolder extends MultiSelectorBindingHolder {
nameView.setEllipsize(null);
}
if (fontSize < 16) {
// developer.android.com/guide/practices/screens_support.html#dips-pels
int fontSizeInDP = (int) (fontSize * metrics.density + 0.5f);
rowBody.setPadding(0, fontSizeInDP, 0, fontSizeInDP);
}
nameView.setTextSize(fontSize);
int fontSizeDetails = Math.max(10, fontSize - 2);
dueDate.setTextSize(fontSizeDetails);
tagBlock.setTextSize(fontSizeDetails);
view.setTag(this);
for(int i = 0; i < view.getChildCount(); i++) {
view.getChildAt(i).setTag(this);
}
setMinimumHeight(minRowHeight);
addListeners();
}
@SuppressLint("NewApi")
@ -176,7 +175,7 @@ class ViewHolder extends MultiSelectorBindingHolder {
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) row.getLayoutParams();
layoutParams.setMarginStart(indentSize);
} else {
rowBody.setPadding(indentSize, row.getPaddingTop(), 0, row.getPaddingBottom());
rowBody.setPadding(indentSize, rowBody.getPaddingTop(), 0, rowBody.getPaddingBottom());
}
}
@ -204,16 +203,6 @@ class ViewHolder extends MultiSelectorBindingHolder {
setTaskAppearance();
}
private void setMinimumHeight(int minRowHeight) {
if (fontSize < 16) {
rowBody.setMinimumHeight(0);
completeBox.setMinimumHeight(0);
} else {
rowBody.setMinimumHeight(minRowHeight);
completeBox.setMinimumHeight(minRowHeight);
}
}
/** Helper method to set the contents and visibility of each field */
private synchronized void setFieldContentsAndVisibility() {
String nameValue = task.getTitle();
@ -227,17 +216,14 @@ class ViewHolder extends MultiSelectorBindingHolder {
setupDueDateAndTags();
// Task action
ImageView taskAction = taskActionIcon;
if (taskAction != null) {
TaskAction action = getTaskAction(task, hasFiles, hasNotes);
if (action != null) {
taskActionContainer.setVisibility(View.VISIBLE);
taskAction.setImageResource(action.icon);
taskAction.setTag(action);
} else {
taskActionContainer.setVisibility(View.GONE);
taskAction.setTag(null);
}
TaskAction action = getTaskAction(task, hasFiles, hasNotes);
if (action != null) {
taskActionIcon.setVisibility(View.VISIBLE);
taskActionIcon.setImageResource(action.icon);
taskActionIcon.setTag(action);
} else {
taskActionIcon.setVisibility(View.GONE);
taskActionIcon.setTag(null);
}
}
@ -259,16 +245,9 @@ class ViewHolder extends MultiSelectorBindingHolder {
name.setEnabled(true);
name.setPaintFlags(name.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
name.setTextSize(fontSize);
setupDueDateAndTags();
float detailTextSize = Math.max(10, fontSize * 14 / 20);
if(dueDate != null) {
dueDate.setTextSize(detailTextSize);
dueDate.setTypeface(null, 0);
}
setupCompleteBox();
}
@ -326,39 +305,47 @@ class ViewHolder extends MultiSelectorBindingHolder {
}
}
/**
* Set listeners for this view. This is called once per view when it is
* created.
*/
private void addListeners() {
// check box listener
View.OnTouchListener otl = (v, event) -> {
lastTouchYRawY = new Pair<>(event.getY(), event.getRawY());
return false;
};
completeBox.setOnTouchListener(otl);
completeBox.setOnClickListener(completeBoxListener);
rowBody.setOnClickListener(view -> callback.onClick(this));
rowBody.setOnLongClickListener(view -> callback.onLongPress(this));
if (taskActionContainer != null) {
taskActionContainer.setOnClickListener(v -> {
TaskAction action = (TaskAction) taskActionIcon.getTag();
if (action instanceof NotesAction) {
showEditNotesDialog(task);
} else if (action instanceof FilesAction) {
showFilesDialog(task);
} else if (action != null) {
try {
action.intent.send();
} catch (PendingIntent.CanceledException e) {
// Oh well
Timber.e(e, e.getMessage());
}
}
});
@OnClick(R.id.rowBody)
void onRowBodyClick() {
callback.onClick(this);
}
@OnLongClick(R.id.rowBody)
boolean onRowBodyLongClick() {
return callback.onLongPress(this);
}
@OnClick(R.id.completeBox)
void onCompleteBoxClick(View v) {
if(task == null) {
return;
}
boolean newState = completeBox.isChecked();
if (newState != task.isCompleted()) {
callback.onCompletedTask(task, newState);
taskDao.setComplete(task, newState);
}
// set check box to actual action item state
setTaskAppearance();
}
@OnClick(R.id.taskActionIcon)
void onTaskActionClick() {
TaskAction action = (TaskAction) taskActionIcon.getTag();
if (action instanceof NotesAction) {
showEditNotesDialog(task);
} else if (action instanceof FilesAction) {
showFilesDialog(task);
} else if (action != null) {
try {
action.intent.send();
} catch (PendingIntent.CanceledException e) {
// Oh well
Timber.e(e, e.getMessage());
}
}
}
@ -386,37 +373,4 @@ class ViewHolder extends MultiSelectorBindingHolder {
// filesControlSet.readFromTask(task);
// filesControlSet.getView().performClick();
}
private final View.OnClickListener completeBoxListener = v -> {
int[] location = new int[2];
v.getLocationOnScreen(location);
if(Math.abs(location[1] + lastTouchYRawY.getLeft() - lastTouchYRawY.getRight()) > 10) {
completeBox.setChecked(!completeBox.isChecked());
return;
}
completeTask(task, completeBox.isChecked());
// set check box to actual action item state
setTaskAppearance();
};
/**
* This method is called when user completes a task via check box or other
* means
*
* @param newState
* state that this task should be set to
*/
private void completeTask(final Task task, final boolean newState) {
if(task == null) {
return;
}
if (newState != task.isCompleted()) {
callback.onCompletedTask(task, newState);
taskDao.setComplete(task, newState);
}
}
}

@ -31,7 +31,6 @@ public class ViewHolderFactory {
private final int fontSize;
private final TaskDao taskDao;
private final DialogBuilder dialogBuilder;
private final int minRowHeight;
private final DisplayMetrics metrics;
private final int background;
private final int selectedColor;
@ -51,14 +50,13 @@ public class ViewHolderFactory {
background = getResourceId(context, R.attr.selectableItemBackground);
selectedColor = getData(context, R.attr.colorControlHighlight);
showFullTaskTitle = preferences.getBoolean(R.string.p_fullTaskTitle, false);
fontSize = preferences.getIntegerFromString(R.string.p_fontSize, 18);
fontSize = preferences.getIntegerFromString(R.string.p_fontSize, 16);
metrics = context.getResources().getDisplayMetrics();
minRowHeight = (int) (metrics.density * 40);
}
ViewHolder newViewHolder(ViewGroup viewGroup, ViewHolder.ViewHolderCallbacks callbacks, MultiSelector multiSelector) {
return new ViewHolder(context, viewGroup, showFullTaskTitle, fontSize, checkBoxes,
tagFormatter, textColorOverdue, textColorSecondary, textColorHint, taskDao,
dialogBuilder, callbacks, minRowHeight, metrics, background, selectedColor, multiSelector);
dialogBuilder, callbacks, metrics, background, selectedColor, multiSelector);
}
}

@ -55,7 +55,8 @@ public class ThemeCache {
widgetThemes.add(new WidgetTheme(
widgetBackgroundNames[i],
getColor(context, WidgetTheme.BACKGROUNDS[i]),
getColor(context, i == 0 ? R.color.black_87 : R.color.white_100)));
getColor(context, i == 0 ? R.color.black_87 : R.color.white_100),
getColor(context, i == 0 ? R.color.black_54 : R.color.white_70)));
}
String []ledNames = resources.getStringArray(R.array.led);
for (int i = 0 ; i < LEDColor.LED_COLORS.length ; i++) {

@ -10,20 +10,26 @@ public class WidgetTheme {
};
private final String name;
private final int backgroundColor;
private final int textColor;
private final int textColorPrimary;
private final int textColorSecondary;
public WidgetTheme(String name, int backgroundColor, int textColor) {
public WidgetTheme(String name, int backgroundColor, int textColorPrimary, int textColorSecondary) {
this.name = name;
this.backgroundColor = backgroundColor;
this.textColor = textColor;
this.textColorPrimary = textColorPrimary;
this.textColorSecondary = textColorSecondary;
}
public int getBackgroundColor() {
return backgroundColor;
}
public int getTextColor() {
return textColor;
public int getTextColorPrimary() {
return textColorPrimary;
}
public int getTextColorSecondary() {
return textColorSecondary;
}
public String getName() {

@ -52,11 +52,12 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
private float textSize;
private float dueDateTextSize;
private String filterId;
private int themeTextColor;
private int textColorPrimary;
private int textColorSecondary;
private TodorooCursor<Task> cursor;
public ScrollableViewsFactory(
ScrollableViewsFactory(
SubtasksHelper subtasksHelper,
Preferences preferences,
Context context,
@ -145,30 +146,30 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
return null;
}
String textContent;
int textColor = themeTextColor;
int textColorTitle = textColorPrimary;
textContent = task.getTitle();
RemoteViews row = new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_row);
if (task.isCompleted()) {
textColor = getColor(context, R.color.task_list_done);
textColorTitle = textColorSecondary;
row.setInt(R.id.widget_text, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
} else {
row.setInt(R.id.widget_text, "setPaintFlags", Paint.ANTI_ALIAS_FLAG);
}
row.setFloat(R.id.widget_text, "setTextSize", textSize);
if (showDueDates) {
formatDueDate(row, task, textColor);
formatDueDate(row, task);
} else {
row.setViewVisibility(R.id.widget_due_date, View.GONE);
if (task.hasDueDate() && task.isOverdue()) {
textColor = getColor(context, R.color.overdue);
textColorTitle = getColor(context, R.color.overdue);
}
}
row.setTextViewText(R.id.widget_text, textContent);
row.setTextColor(R.id.widget_text, textColor);
row.setTextColor(R.id.widget_text, textColorTitle);
row.setImageViewBitmap(R.id.widget_complete_box, getCheckbox(task));
long taskId = task.getId();
@ -230,7 +231,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
return subtasksHelper.applySubtasksToWidgetFilter(filter, query);
}
private void formatDueDate(RemoteViews row, Task task, int textColor) {
private void formatDueDate(RemoteViews row, Task task) {
if (task.hasDueDate()) {
Resources resources = context.getResources();
row.setViewVisibility(R.id.widget_due_date, View.VISIBLE);
@ -238,7 +239,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
? resources.getString(R.string.TAd_completed, DateUtilities.getRelativeDateStringWithTime(context, task.getCompletionDate()))
: DateUtilities.getRelativeDateStringWithTime(context, task.getDueDate()));
//noinspection ResourceAsColor
row.setTextColor(R.id.widget_due_date, task.isOverdue() ? getColor(context, R.color.overdue) : textColor);
row.setTextColor(R.id.widget_due_date, task.isOverdue() ? getColor(context, R.color.overdue) : textColorSecondary);
row.setFloat(R.id.widget_due_date, "setTextSize", dueDateTextSize);
} else {
row.setViewVisibility(R.id.widget_due_date, View.GONE);
@ -247,11 +248,12 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
private void updateSettings() {
WidgetTheme widgetTheme = themeCache.getWidgetTheme(widgetPreferences.getThemeIndex());
themeTextColor = widgetTheme.getTextColor();
textColorPrimary = widgetTheme.getTextColorPrimary();
textColorSecondary = widgetTheme.getTextColorSecondary();
showDueDates = widgetPreferences.showDueDate();
showCheckboxes = widgetPreferences.showCheckboxes();
textSize = widgetPreferences.getFontSize();
dueDateTextSize = Math.max(10, textSize * 14 / 20);
dueDateTextSize = Math.max(10, textSize - 2);
filterId = widgetPreferences.getFilterId();
}
}

@ -1,123 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rowBody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:paddingBottom="5dp"
android:paddingTop="5dp">
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<com.todoroo.astrid.ui.CheckableImageView
android:id="@+id/completeBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:paddingEnd="@dimen/keyline_second"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_second"
android:paddingStart="@dimen/keyline_first"
android:scaleType="center" />
<LinearLayout
android:id="@+id/task_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/completeBox"
android:layout_toRightOf="@id/completeBox"
android:gravity="center_vertical"
android:orientation="vertical">
<!-- row 1 -->
<!-- row 1 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
<com.todoroo.astrid.ui.CheckableImageView
android:id="@+id/completeBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingEnd="@dimen/keyline_second"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_second"
android:paddingStart="@dimen/keyline_first"
android:scaleType="center" />
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorPrimary" />
<ImageView
android:id="@+id/taskActionIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:alpha="?attr/alpha_secondary"
android:gravity="end|center_vertical"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:scaleType="center"
android:tint="?attr/icon_tint" />
<LinearLayout
android:id="@+id/taskActionContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end|center_vertical"
android:orientation="vertical"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:visibility="gone">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/completeBox"
android:layout_toLeftOf="@id/taskActionIcon"
android:layout_toRightOf="@id/completeBox"
android:layout_toStartOf="@id/taskActionIcon"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp" />
<ImageView
android:id="@+id/taskActionIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:alpha="?attr/alpha_secondary"
android:scaleType="center"
android:tint="?attr/icon_tint" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<!-- row 2 -->
<!-- row 2 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingEnd="0dp"
android:paddingLeft="@dimen/keyline_content_inset"
android:paddingRight="0dp"
android:paddingStart="@dimen/keyline_content_inset">
<RelativeLayout
android:layout_width="match_parent"
<TextView
android:id="@+id/tag_block"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tag_block"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:ellipsize="none"
android:maxLines="1"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:singleLine="true" />
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:ellipsize="none"
android:maxLines="1"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:singleLine="true"
android:textSize="14sp" />
<TextView
android:id="@+id/due_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/tag_block"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignStart="@id/tag_block"
android:ellipsize="end"
android:gravity="center_vertical"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:singleLine="true" />
</RelativeLayout>
<TextView
android:id="@+id/due_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/tag_block"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignStart="@id/tag_block"
android:ellipsize="end"
android:gravity="center_vertical"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="0dp"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="0dp"
android:singleLine="true"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>

@ -92,10 +92,6 @@
<color name="led_purple">#800080</color>
<color name="led_white">#ffffff</color>
<color name="overdue">@color/red_500</color>
<color name="task_list_done">#ff777777</color>
<color name="task_edit_deadline_gray">#888888</color>
<color name="black_87">#de000000</color>
<color name="black_54">#8a000000</color>
<color name="black_38">#61000000</color>
@ -106,6 +102,8 @@
<color name="white_50">#80ffffff</color>
<color name="white_12">#1fffffff</color>
<color name="overdue">@color/red_500</color>
<color name="md_background_dark">#303030</color>
<color name="widget_background_black">#000000</color>
<color name="icon_tint_light">@android:color/black</color>

Loading…
Cancel
Save