Made forward progress on being able to toggle drag and drop from sort dialog

pull/14/head
Tim Su 13 years ago
parent a7cae150c0
commit c83cdfba7a

@ -19,6 +19,7 @@ public class SortHelper {
public static final int FLAG_SHOW_COMPLETED = 1 << 1; public static final int FLAG_SHOW_COMPLETED = 1 << 1;
public static final int FLAG_SHOW_HIDDEN = 1 << 2; public static final int FLAG_SHOW_HIDDEN = 1 << 2;
public static final int FLAG_SHOW_DELETED = 1 << 3; public static final int FLAG_SHOW_DELETED = 1 << 3;
public static final int FLAG_DRAG_DROP = 1 << 4;
public static final int SORT_AUTO = 0; public static final int SORT_AUTO = 0;
public static final int SORT_ALPHA = 1; public static final int SORT_ALPHA = 1;
@ -66,7 +67,11 @@ public class SortHelper {
return originalSql; return originalSql;
} }
public static boolean isManualSort(int flags) {
return (flags & FLAG_DRAG_DROP) > 0;
}
@SuppressWarnings("nls")
public static Order orderForSortType(int sortType) { public static Order orderForSortType(int sortType) {
Order order; Order order;
switch(sortType) { switch(sortType) {

@ -46,8 +46,9 @@ public final class CoreFilterExposer extends BroadcastReceiver implements Astrid
private FilterListItem[] prepareFilters(Resources r) { private FilterListItem[] prepareFilters(Resources r) {
// core filters // core filters
Filter inbox = buildInboxFilter(r); Filter inbox = new Filter(r.getString(R.string.BFE_Active), r.getString(R.string.BFE_Active),
(String) null, null);
inbox.listingIcon = ((BitmapDrawable)r.getDrawable(R.drawable.filter_inbox)).getBitmap();
// transmit filter list // transmit filter list
FilterListItem[] list = new FilterListItem[1]; FilterListItem[] list = new FilterListItem[1];

@ -10,6 +10,7 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
@ -95,8 +96,11 @@ public class SubtasksUpdater extends OrderedListUpdater<String> {
if(!query.contains(subtaskJoin)) { if(!query.contains(subtaskJoin)) {
query = subtaskJoin + query; query = subtaskJoin + query;
query = query.replaceAll("ORDER BY .*", ""); query = query.replaceAll("ORDER BY .*", "");
query = query + String.format(" ORDER BY CAST(%s AS LONG) ASC, %s ASC", query = query + String.format(" ORDER BY %s, %s, CAST(%s AS LONG), %s",
Task.DELETION_DATE, Task.COMPLETION_DATE,
SubtasksMetadata.ORDER, Task.ID); SubtasksMetadata.ORDER, Task.ID);
query = query.replace(TaskCriteria.isVisible().toString(),
Criterion.all.toString());
filter.sqlQuery = query; filter.sqlQuery = query;
} }

@ -12,40 +12,18 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<!-- hidden task status -->
<CheckBox android:id="@+id/hidden"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SSD_hidden" />
<CheckBox android:id="@+id/completed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SSD_completed" />
<CheckBox android:id="@+id/deleted"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SSD_deleted" />
<!-- Sorting --> <!-- Sorting -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:gravity="center"
android:textSize="20sp"
android:textColor="#ffffff"
android:text="@string/SSD_sort_header"
android:background="@drawable/edit_titlebar"/>
<RadioGroup <RadioGroup
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<RadioButton android:id="@+id/sort_drag"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SSD_sort_drag" />
<RadioButton android:id="@+id/sort_smart" <RadioButton android:id="@+id/sort_smart"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -78,6 +56,33 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/SSD_sort_reverse" /> android:text="@string/SSD_sort_reverse" />
<!-- hidden task status -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:gravity="center"
android:textSize="20sp"
android:textColor="#ffffff"
android:text="@string/SSD_hidden_title"
android:background="@drawable/edit_titlebar"/>
<CheckBox android:id="@+id/hidden"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SSD_hidden" />
<CheckBox android:id="@+id/completed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SSD_completed" />
<CheckBox android:id="@+id/deleted"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SSD_deleted" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

@ -102,7 +102,7 @@
<string name="TLA_menu_addons">Add-ons</string> <string name="TLA_menu_addons">Add-ons</string>
<!-- Menu: Adjust Sort and Hidden Task Settings --> <!-- Menu: Adjust Sort and Hidden Task Settings -->
<string name="TLA_menu_sort">Sort &amp; Hidden</string> <string name="TLA_menu_sort">Sort &amp; Subtasks</string>
<!-- Menu: Sync Now --> <!-- Menu: Sync Now -->
<string name="TLA_menu_sync">Sync Now!</string> <string name="TLA_menu_sync">Sync Now!</string>
@ -214,7 +214,10 @@
<!-- ============================================== SortSelectionDialog == --> <!-- ============================================== SortSelectionDialog == -->
<!-- Sort Selection: dialog title --> <!-- Sort Selection: dialog title -->
<string name="SSD_title">Sorting and Hidden Tasks</string> <string name="SSD_title">Sort, Subtasks, and Hidden</string>
<!-- Hidden: title -->
<string name="SSD_hidden_title">Hidden Tasks</string>
<!-- Hidden Task Selection: show completed tasks --> <!-- Hidden Task Selection: show completed tasks -->
<string name="SSD_completed">Show Completed Tasks</string> <string name="SSD_completed">Show Completed Tasks</string>
@ -225,8 +228,8 @@
<!-- Hidden Task Selection: show deleted tasks --> <!-- Hidden Task Selection: show deleted tasks -->
<string name="SSD_deleted">Show Deleted Tasks</string> <string name="SSD_deleted">Show Deleted Tasks</string>
<!-- Sort Selection: sort options header --> <!-- Sort Selection: drag with subtasks -->
<string name="SSD_sort_header">Sort Options</string> <string name="SSD_sort_drag">Drag &amp; Drop with Subtasks</string>
<!-- Sort Selection: smart sort --> <!-- Sort Selection: smart sort -->
<string name="SSD_sort_auto">Astrid Smart Sort</string> <string name="SSD_sort_auto">Astrid Smart Sort</string>

@ -4,6 +4,7 @@ import android.app.PendingIntent.CanceledException;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -23,6 +24,7 @@ import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.IntentFilter; import com.todoroo.astrid.api.IntentFilter;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.core.SearchFilter; import com.todoroo.astrid.core.SearchFilter;
import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment; import com.todoroo.astrid.reminders.NotificationFragment;
@ -31,7 +33,9 @@ import com.todoroo.astrid.reminders.ReminderDialog;
import com.todoroo.astrid.service.StartupService; import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.subtasks.SubtasksListFragment;
import com.todoroo.astrid.ui.DateChangedAlerts; import com.todoroo.astrid.ui.DateChangedAlerts;
import com.todoroo.astrid.utility.AstridPreferences;
/** /**
* This wrapper activity contains all the glue-code to handle the callbacks between the different * This wrapper activity contains all the glue-code to handle the callbacks between the different
@ -189,7 +193,16 @@ public class AstridActivity extends FragmentActivity
} }
protected final void setupTasklistFragmentWithFilter(Filter filter) { protected final void setupTasklistFragmentWithFilter(Filter filter) {
setupTasklistFragmentWithFilterAndCustomTaskList(filter, TaskListFragment.class); Class<?> customTaskList = TaskListFragment.class;
if(filter == null || filter.sqlQuery == null) {
SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(this);
int sortFlags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0);
if(SortHelper.isManualSort(sortFlags))
customTaskList = SubtasksListFragment.class;
}
setupTasklistFragmentWithFilterAndCustomTaskList(filter, customTaskList);
} }
protected final void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Class<?> customTaskList) { protected final void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Class<?> customTaskList) {

@ -41,23 +41,34 @@ public class SortSelectionActivity {
if((flags & SortHelper.FLAG_SHOW_DELETED) > 0) if((flags & SortHelper.FLAG_SHOW_DELETED) > 0)
((CheckBox)body.findViewById(R.id.deleted)).setChecked(true); ((CheckBox)body.findViewById(R.id.deleted)).setChecked(true);
switch(sort) { if((flags & SortHelper.FLAG_DRAG_DROP) > 0)
case SortHelper.SORT_ALPHA: ((RadioButton)body.findViewById(R.id.sort_drag)).setChecked(true);
((RadioButton)body.findViewById(R.id.sort_alpha)).setChecked(true); else {
break; switch(sort) {
case SortHelper.SORT_DUE: case SortHelper.SORT_ALPHA:
((RadioButton)body.findViewById(R.id.sort_due)).setChecked(true); ((RadioButton)body.findViewById(R.id.sort_alpha)).setChecked(true);
break; break;
case SortHelper.SORT_IMPORTANCE: case SortHelper.SORT_DUE:
((RadioButton)body.findViewById(R.id.sort_importance)).setChecked(true); ((RadioButton)body.findViewById(R.id.sort_due)).setChecked(true);
break; break;
case SortHelper.SORT_MODIFIED: case SortHelper.SORT_IMPORTANCE:
((RadioButton)body.findViewById(R.id.sort_modified)).setChecked(true); ((RadioButton)body.findViewById(R.id.sort_importance)).setChecked(true);
break; break;
default: case SortHelper.SORT_MODIFIED:
((RadioButton)body.findViewById(R.id.sort_smart)).setChecked(true); ((RadioButton)body.findViewById(R.id.sort_modified)).setChecked(true);
break;
default:
((RadioButton)body.findViewById(R.id.sort_smart)).setChecked(true);
}
} }
body.findViewById(R.id.sort_drag).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// disable reverse
}
});
AlertDialog dialog = new AlertDialog.Builder(activity). AlertDialog dialog = new AlertDialog.Builder(activity).
setTitle(R.string.SSD_title). setTitle(R.string.SSD_title).
setIcon(android.R.drawable.ic_menu_sort_by_size). setIcon(android.R.drawable.ic_menu_sort_by_size).
@ -101,6 +112,8 @@ public class SortSelectionActivity {
flags |= SortHelper.FLAG_SHOW_HIDDEN; flags |= SortHelper.FLAG_SHOW_HIDDEN;
if(((CheckBox)body.findViewById(R.id.deleted)).isChecked()) if(((CheckBox)body.findViewById(R.id.deleted)).isChecked())
flags |= SortHelper.FLAG_SHOW_DELETED; flags |= SortHelper.FLAG_SHOW_DELETED;
if(((RadioButton)body.findViewById(R.id.sort_drag)).isChecked())
flags |= SortHelper.FLAG_DRAG_DROP;
if(((RadioButton)body.findViewById(R.id.sort_alpha)).isChecked()) if(((RadioButton)body.findViewById(R.id.sort_alpha)).isChecked())
sort = SortHelper.SORT_ALPHA; sort = SortHelper.SORT_ALPHA;

@ -142,6 +142,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
commentsButton.setOnClickListener(commentsButtonClickListener); commentsButton.setOnClickListener(commentsButtonClickListener);
Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER);
if (getIntent().getIntExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_DEFAULT) == if (getIntent().getIntExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_DEFAULT) ==
Constants.SOURCE_NOTIFICATION) Constants.SOURCE_NOTIFICATION)
setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, NotificationFragment.class); setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, NotificationFragment.class);
@ -435,7 +436,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
public void switchToAssignedFilter(final String assignedEmail) { public void switchToAssignedFilter(final String assignedEmail) {
TaskListFragment tlf = getTaskListFragment(); TaskListFragment tlf = getTaskListFragment();
if (tlf != null && !tlf.isFilter()) { if (tlf != null && tlf.isInbox()) {
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {

@ -181,7 +181,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
protected QuickAddBar quickAddBar; protected QuickAddBar quickAddBar;
private Timer backgroundTimer; private Timer backgroundTimer;
private boolean isFilter; private boolean isInbox;
private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader(); private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader();
@ -352,10 +352,15 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
return; return;
} else if (extras != null && extras.containsKey(TOKEN_FILTER)) { } else if (extras != null && extras.containsKey(TOKEN_FILTER)) {
filter = extras.getParcelable(TOKEN_FILTER); filter = extras.getParcelable(TOKEN_FILTER);
isFilter = true; if(filter.sqlQuery == null)
} else { filter = null;
else
isInbox = false;
}
if(filter == null) {
filter = CoreFilterExposer.buildInboxFilter(getResources()); filter = CoreFilterExposer.buildInboxFilter(getResources());
isFilter = false; isInbox = true;
} }
setUpTaskList(); setUpTaskList();
@ -496,7 +501,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
} }
}); });
// animation
SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(getActivity()); SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(getActivity());
sortFlags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0); sortFlags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0);
sortSort = publicPrefs.getInt(SortHelper.PREF_SORT_SORT, 0); sortSort = publicPrefs.getInt(SortHelper.PREF_SORT_SORT, 0);
@ -946,7 +950,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
* task that was completed * task that was completed
*/ */
protected void onTaskCompleted(Task item) { protected void onTaskCompleted(Task item) {
if (isFilter) if (isInbox)
StatisticsService.reportEvent(StatisticsConstants.TASK_COMPLETED_INBOX); StatisticsService.reportEvent(StatisticsConstants.TASK_COMPLETED_INBOX);
else else
StatisticsService.reportEvent(StatisticsConstants.TASK_COMPLETED_FILTER); StatisticsService.reportEvent(StatisticsConstants.TASK_COMPLETED_FILTER);
@ -1011,8 +1015,8 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
} }
} }
public boolean isFilter() { public boolean isInbox() {
return isFilter; return isInbox;
} }
/** Show a dialog box and delete the task specified */ /** Show a dialog box and delete the task specified */
@ -1175,6 +1179,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
TasksWidget.WidgetUpdateService.class)); TasksWidget.WidgetUpdateService.class));
} }
setUpTaskList(); ((AstridActivity)getActivity()).onFilterItemClicked(getFilter());
} }
} }

@ -204,7 +204,7 @@ public class DraggableListView extends ListView {
break; break;
} }
int height = mItemHeightNormal; int height = mItemHeightNormal;
int marginBottom = 0; int marginTop = 0;
int visibility = View.VISIBLE; int visibility = View.VISIBLE;
if (vv.equals(first)) { if (vv.equals(first)) {
// processing the item that is being dragged // processing the item that is being dragged
@ -217,7 +217,7 @@ public class DraggableListView extends ListView {
} }
} else if (i == childnum) { } else if (i == childnum) {
if (mDragPos < getCount() - 1) { if (mDragPos < getCount() - 1) {
marginBottom = mItemHeightNormal; marginTop = mItemHeightNormal;
// height = mItemHeightExpanded; // height = mItemHeightExpanded;
} }
} }
@ -227,7 +227,7 @@ public class DraggableListView extends ListView {
params.height = height; params.height = height;
vv.setLayoutParams(params); vv.setLayoutParams(params);
vv.setVisibility(visibility); vv.setVisibility(visibility);
vv.setPadding(0, 0, 0, marginBottom); vv.setPadding(0, marginTop, 0, 0);
} }
} }
// Request re-layout since we changed the items layout // Request re-layout since we changed the items layout

Loading…
Cancel
Save