Move min height computation out of task adapter

pull/493/head
Alex Baker 8 years ago
parent 5ae39c2345
commit 0072bb1c77

@ -33,6 +33,7 @@ import com.todoroo.astrid.ui.DraggableListView.SwipeListener;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.Preferences;
import org.tasks.tasklist.ManualSortHelper;
import org.tasks.tasklist.ViewHolder;
import org.tasks.themes.ThemeCache;
import org.tasks.ui.CheckBoxes;
@ -91,17 +92,14 @@ class OrderedMetadataListFragmentHelper {
return fragment.getListView();
}
private DraggableListView getTouchListView() {
return (DraggableListView) fragment.getListView();
}
void setUpUiComponents() {
TypedValue tv = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.colorAccent, tv, false);
getTouchListView().setDragndropBackgroundColor(tv.data);
getTouchListView().setDropListener(dropListener);
getTouchListView().setClickListener(rowClickListener);
getTouchListView().setSwipeListener(swipeListener);
DraggableListView draggableListView = (DraggableListView) fragment.getListView();
draggableListView.setDragndropBackgroundColor(tv.data);
draggableListView.setDropListener(dropListener);
draggableListView.setClickListener(rowClickListener);
draggableListView.setSwipeListener(swipeListener);
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
@ -191,11 +189,14 @@ class OrderedMetadataListFragmentHelper {
private final class DraggableTaskAdapter extends TaskAdapter {
private final ManualSortHelper manualSortHelper;
private DraggableTaskAdapter(Context context, Preferences preferences, TaskListFragment activity,
Cursor c, AtomicReference<String> query, DialogBuilder dialogBuilder,
CheckBoxes checkBoxes, TagService tagService, ThemeCache themeCache) {
super(context, preferences, taskAttachmentDao, taskDao, activity, c, query,
dialogBuilder, checkBoxes, tagService, themeCache);
manualSortHelper = new ManualSortHelper(context);
}
@Override
@ -203,6 +204,7 @@ class OrderedMetadataListFragmentHelper {
super.setFieldContentsAndVisibility(view);
ViewHolder vh = (ViewHolder) view.getTag();
vh.setMinimumHeight(manualSortHelper.getMinRowHeight());
int indent = vh.task.getValue(GtasksMetadata.INDENT);
vh.rowBody.setPadding(Math.round(indent * 20 * metrics.density), 0, 0, 0);
}

@ -19,7 +19,6 @@ import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@ -140,10 +139,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
private final AtomicReference<String> query;
// measure utilities
private final DisplayMetrics displayMetrics;
private final int minRowHeight;
private final float tagCharacters;
private final Map<String, TagData> tagMap = new HashMap<>();
@ -176,30 +171,14 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
tagCharacters = typedValue.getFloat();
fontSize = preferences.getIntegerFromString(R.string.p_fontSize, 18);
displayMetrics = new DisplayMetrics();
fragment.getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
textColorSecondary = getData(context, android.R.attr.textColorSecondary);
textColorHint = getData(context, android.R.attr.textColorTertiary);
textColorOverdue = getColor(context, R.color.overdue);
updateTagMap();
this.minRowHeight = computeMinRowHeight();
}
private int computeMinRowHeight() {
DisplayMetrics metrics = resources.getDisplayMetrics();
return (int) (metrics.density * 40);
}
public int computeFullRowHeight() {
DisplayMetrics metrics = resources.getDisplayMetrics();
if (fontSize < 16) {
return (int) (39 * metrics.density);
} else {
return minRowHeight + (int) (10 * metrics.density);
}
}
/* ======================================================================
* =========================================================== filterable
@ -261,7 +240,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
boolean showFullTaskTitle = preferences.getBoolean(R.string.p_fullTaskTitle, false);
// create view holder
new ViewHolder(view, showFullTaskTitle);
new ViewHolder(view, showFullTaskTitle, fontSize);
// add UI component listeners
addListeners(view);
@ -297,13 +276,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
public synchronized void setFieldContentsAndVisibility(View view) {
ViewHolder viewHolder = (ViewHolder)view.getTag();
Task task = viewHolder.task;
if (fontSize < 16) {
viewHolder.rowBody.setMinimumHeight(0);
viewHolder.completeBox.setMinimumHeight(0);
} else {
viewHolder.rowBody.setMinimumHeight(minRowHeight);
viewHolder.completeBox.setMinimumHeight(minRowHeight);
}
// name
final TextView nameView = viewHolder.nameView; {
@ -422,7 +394,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
fontSize = preferences.getIntegerFromString(R.string.p_fontSize, 18);
updateTagMap();
}
@ -633,5 +604,4 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
};
}
}
}

@ -31,6 +31,7 @@ import com.todoroo.astrid.ui.DraggableListView.SwipeListener;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.Preferences;
import org.tasks.tasklist.ManualSortHelper;
import org.tasks.tasklist.ViewHolder;
import org.tasks.themes.ThemeCache;
import org.tasks.ui.CheckBoxes;
@ -98,8 +99,6 @@ class AstridOrderedListFragmentHelper {
draggableListView.setClickListener(rowClickListener);
draggableListView.setSwipeListener(swipeListener);
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
draggableListView.setItemHightNormal(taskAdapter.computeFullRowHeight());
}
void beforeSetUpTaskList(Filter filter) {
@ -191,10 +190,14 @@ class AstridOrderedListFragmentHelper {
private final class DraggableTaskAdapter extends TaskAdapter {
private final ManualSortHelper manualSortHelper;
private DraggableTaskAdapter(Context context, Preferences preferences, TaskListFragment activity,
Cursor c, AtomicReference<String> query, DialogBuilder dialogBuilder,
CheckBoxes checkBoxes, TagService tagService, ThemeCache themeCache) {
super(context, preferences, taskAttachmentDao, taskDao, activity, c, query, dialogBuilder, checkBoxes, tagService, themeCache);
manualSortHelper = new ManualSortHelper(context);
}
@Override
@ -202,6 +205,7 @@ class AstridOrderedListFragmentHelper {
super.setFieldContentsAndVisibility(view);
ViewHolder vh = (ViewHolder) view.getTag();
vh.setMinimumHeight(manualSortHelper.getMinRowHeight());
int indent = updater.getIndentForTask(vh.task.getUuid());
vh.rowBody.setPadding(Math.round(indent * 20 * metrics.density), 0, 0, 0);
}

@ -0,0 +1,30 @@
package org.tasks.tasklist;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import org.tasks.injection.ForApplication;
import javax.inject.Inject;
public class ManualSortHelper {
private final Resources resources;
private final int minRowHeight;
@Inject
public ManualSortHelper(@ForApplication Context context) {
resources = context.getResources();
minRowHeight = computeMinRowHeight();
}
private int computeMinRowHeight() {
DisplayMetrics metrics = resources.getDisplayMetrics();
return (int) (metrics.density * 40);
}
public int getMinRowHeight() {
return minRowHeight;
}
}

@ -21,7 +21,6 @@ import butterknife.ButterKnife;
* @author Tim Su <tim@todoroo.com>
*/
public class ViewHolder {
public Task task;
@BindView(R.id.rowBody) public ViewGroup rowBody;
@BindView(R.id.title) public TextView nameView;
@BindView(R.id.completeBox) public CheckableImageView completeBox;
@ -30,11 +29,14 @@ public class ViewHolder {
@BindView(R.id.taskActionContainer) public View taskActionContainer;
@BindView(R.id.taskActionIcon) public ImageView taskActionIcon;
public Task task;
public String tagsString; // From join query, not part of the task model
public boolean hasFiles; // From join query, not part of the task model
public boolean hasNotes;
private final int fontSize;
public ViewHolder(ViewGroup view, boolean showFullTaskTitle) {
public ViewHolder(ViewGroup view, boolean showFullTaskTitle, int fontSize) {
this.fontSize = fontSize;
ButterKnife.bind(this, view);
task = new Task();
@ -59,4 +61,14 @@ public class ViewHolder {
// TODO: see if this is a performance issue
task = new Task(cursor);
}
public void setMinimumHeight(int minRowHeight) {
if (fontSize < 16) {
rowBody.setMinimumHeight(0);
completeBox.setMinimumHeight(0);
} else {
rowBody.setMinimumHeight(minRowHeight);
completeBox.setMinimumHeight(minRowHeight);
}
}
}

Loading…
Cancel
Save