diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index f8d4d6376..7e0212130 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -123,7 +123,8 @@ public class TagViewFragment extends TaskListFragment { ((EditText) getView().findViewById(R.id.quickAddText)).setOnTouchListener(onTouch); View membersEdit = getView().findViewById(R.id.members_edit); - membersEdit.setOnClickListener(settingsListener); + if (membersEdit != null) + membersEdit.setOnClickListener(settingsListener); originalFilter = filter; } @@ -165,8 +166,9 @@ public class TagViewFragment extends TaskListFragment { if (!Preferences.getBoolean(R.string.p_showed_list_settings_help, false)) { Preferences.setBoolean(R.string.p_showed_list_settings_help, true); View tabView = getView().findViewById(R.id.members_edit); - HelpInfoPopover.showPopover(getActivity(), tabView, - R.string.help_popover_list_settings, null); + if (tabView != null) + HelpInfoPopover.showPopover(getActivity(), tabView, + R.string.help_popover_list_settings, null); } } @@ -214,10 +216,10 @@ public class TagViewFragment extends TaskListFragment { } postLoadTagData(); - setUpMembersGallery(); - super.initializeData(); + setUpMembersGallery(); + if (extras.getBoolean(TOKEN_START_ACTIVITY, false)) { extras.remove(TOKEN_START_ACTIVITY); activity.showComments(); @@ -334,12 +336,15 @@ public class TagViewFragment extends TaskListFragment { } catch (JSONException e) { e.printStackTrace(); } - getView().findViewById(R.id.filter_assigned).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - resetAssignedFilter(); - } - }); + + View filterAssigned = getView().findViewById(R.id.filter_assigned); + if (filterAssigned != null) + filterAssigned.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetAssignedFilter(); + } + }); } @SuppressWarnings("nls") @@ -395,11 +400,13 @@ public class TagViewFragment extends TaskListFragment { Criterion assigned = Criterion.and(TaskCriteria.activeAndVisible(), assignedCriterion); filter = TagFilterExposer.filterFromTag(getActivity(), new Tag(tagData), assigned); TextView filterByAssigned = (TextView) getView().findViewById(R.id.filter_assigned); - filterByAssigned.setVisibility(View.VISIBLE); - if (id == Task.USER_ID_UNASSIGNED) - filterByAssigned.setText(getString(R.string.actfm_TVA_filter_by_unassigned)); - else - filterByAssigned.setText(getString(R.string.actfm_TVA_filtered_by_assign, displayName)); + if (filterByAssigned != null) { + filterByAssigned.setVisibility(View.VISIBLE); + if (id == Task.USER_ID_UNASSIGNED) + filterByAssigned.setText(getString(R.string.actfm_TVA_filter_by_unassigned)); + else + filterByAssigned.setText(getString(R.string.actfm_TVA_filtered_by_assign, displayName)); + } setUpTaskList(); } } @@ -416,7 +423,9 @@ public class TagViewFragment extends TaskListFragment { private void resetAssignedFilter() { currentId = Task.USER_ID_IGNORE; filter = originalFilter; - getView().findViewById(R.id.filter_assigned).setVisibility(View.GONE); + View filterAssigned = getView().findViewById(R.id.filter_assigned); + if (filterAssigned != null) + filterAssigned.setVisibility(View.GONE); setUpTaskList(); } diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java index 58968b738..d7966bfda 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java @@ -2,8 +2,15 @@ package com.todoroo.astrid.tags.reusable; import android.app.Activity; import android.app.ProgressDialog; +import android.content.Intent; +import android.content.res.Resources; +import android.support.v4.view.Menu; +import android.support.v4.view.MenuItem; +import android.text.TextUtils; +import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.MenuInflater; import android.view.View; -import android.view.View.OnClickListener; import android.widget.TextView; import android.widget.Toast; @@ -16,6 +23,7 @@ import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.adapter.TaskAdapter; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.helper.AsyncImageView; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.utility.Flags; @@ -23,6 +31,8 @@ public class FeaturedTaskListFragment extends TagViewFragment { @Autowired private TagDataService tagDataService; + private static final int MENU_CLONE_LIST = R.string.actfm_feat_list_clone; + @Override protected TaskAdapter createTaskAdapter(TodorooCursor cursor) { return new ReusableTaskAdapter(this, R.layout.reusable_task_adapter_row, @@ -46,61 +56,104 @@ public class FeaturedTaskListFragment extends TagViewFragment { return R.layout.task_list_body_featured_list; } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + + MenuItem item = menu.add(Menu.NONE, MENU_CLONE_LIST, 0, R.string.actfm_feat_list_clone); + item.setIcon(R.drawable.ic_menu_list_copy); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + } + + @Override + public boolean handleOptionsMenuItemSelected(int id, Intent intent) { + if (id == MENU_CLONE_LIST) { + cloneList(); + return true; + } + return super.handleOptionsMenuItemSelected(id, intent); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) { + // Do nothing + } + @Override protected void setUpMembersGallery() { - // Repurposed this method to set up listener for clone list button - View clone = getView().findViewById(R.id.clone_list); - clone.setOnClickListener(new OnClickListener() { + // Repurposed this method to set up the description view + AsyncImageView imageView = (AsyncImageView) getView().findViewById(R.id.url_image); + String imageUrl = tagData.getValue(TagData.PICTURE); + if (!TextUtils.isEmpty(imageUrl)) { + imageView.setVisibility(View.VISIBLE); + imageView.setDefaultImageResource(R.drawable.default_list_0); + imageView.setUrl(imageUrl); + } else { + imageView.setVisibility(View.GONE); + } + + final String description = tagData.getValue(TagData.TAG_DESCRIPTION); + final Resources r = getActivity().getResources(); + TextView desc = (TextView) getView().findViewById(R.id.feat_list_desc); + desc.setText(description); + desc.setLines(4); + desc.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - // Clone list - if (taskAdapter == null || taskAdapter.getCount() == 0) { - Toast.makeText(getActivity(), R.string.actfm_feat_list_clone_empty, Toast.LENGTH_LONG).show(); - return; - } - final String localName = tagData.getValue(TagData.NAME) + " " + getString(R.string.actfm_feat_list_suffix); //$NON-NLS-1$ - long remoteId = 0; - TodorooCursor existing = tagDataService.query(Query.select(TagData.REMOTE_ID) - .where(TagData.NAME.eqCaseInsensitive(localName))); + DialogUtilities.okDialog(getActivity(), r.getString(R.string.DLG_information_title), + 0, description, null); + } + }); + } + + private void cloneList() { + // Clone list + if (taskAdapter == null || taskAdapter.getCount() == 0) { + Toast.makeText(getActivity(), R.string.actfm_feat_list_clone_empty, Toast.LENGTH_LONG).show(); + return; + } + final String localName = tagData.getValue(TagData.NAME) + " " + getString(R.string.actfm_feat_list_suffix); //$NON-NLS-1$ + long remoteId = 0; + TodorooCursor existing = tagDataService.query(Query.select(TagData.REMOTE_ID) + .where(TagData.NAME.eqCaseInsensitive(localName))); + try { + if (existing.getCount() > 0) { + existing.moveToFirst(); + TagData match = new TagData(existing); + remoteId = match.getValue(TagData.REMOTE_ID); + } + + } finally { + existing.close(); + } + + final ProgressDialog pd = DialogUtilities.progressDialog(getActivity(), getString(R.string.actfm_feat_list_cloning)); + + final long finalRemoteId = remoteId; + new Thread(new Runnable() { + @Override + public void run() { + TodorooCursor tasks = taskService.fetchFiltered(taskAdapter.getQuery(), null, Task.PROPERTIES); try { - if (existing.getCount() > 0) { - existing.moveToFirst(); - TagData match = new TagData(existing); - remoteId = match.getValue(TagData.REMOTE_ID); + Task t = new Task(); + for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) { + t.readFromCursor(tasks); + taskService.cloneReusableTask(t, + localName, finalRemoteId); + } + Activity activity = getActivity(); + if (activity != null) { + DialogUtilities.dismissDialog(activity, pd); + DialogUtilities.okDialog(activity, getString(R.string.actfm_feat_list_clone_success), null); } + Flags.set(Flags.REFRESH); } finally { - existing.close(); + tasks.close(); } - - final ProgressDialog pd = DialogUtilities.progressDialog(getActivity(), getString(R.string.actfm_feat_list_cloning)); - - final long finalRemoteId = remoteId; - new Thread(new Runnable() { - @Override - public void run() { - TodorooCursor tasks = taskService.fetchFiltered(taskAdapter.getQuery(), null, Task.PROPERTIES); - try { - Task t = new Task(); - for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) { - t.readFromCursor(tasks); - taskService.cloneReusableTask(t, - localName, finalRemoteId); - } - Activity activity = getActivity(); - if (activity != null) { - DialogUtilities.dismissDialog(activity, pd); - DialogUtilities.okDialog(activity, getString(R.string.actfm_feat_list_clone_success), null); - } - - Flags.set(Flags.REFRESH); - } finally { - tasks.close(); - } - } - }).start(); } - }); + }).start(); } @Override diff --git a/astrid/res/drawable-hdpi/ic_menu_list_copy.png b/astrid/res/drawable-hdpi/ic_menu_list_copy.png new file mode 100644 index 000000000..9b6faaee4 Binary files /dev/null and b/astrid/res/drawable-hdpi/ic_menu_list_copy.png differ diff --git a/astrid/res/drawable-xhdpi/ic_menu_list_copy.png b/astrid/res/drawable-xhdpi/ic_menu_list_copy.png new file mode 100644 index 000000000..9b9f0cdd0 Binary files /dev/null and b/astrid/res/drawable-xhdpi/ic_menu_list_copy.png differ diff --git a/astrid/res/drawable/ic_menu_list_copy.png b/astrid/res/drawable/ic_menu_list_copy.png new file mode 100644 index 000000000..409377cdf Binary files /dev/null and b/astrid/res/drawable/ic_menu_list_copy.png differ diff --git a/astrid/res/layout/task_list_body_featured_list.xml b/astrid/res/layout/task_list_body_featured_list.xml index 1c3093292..f0ed64af1 100644 --- a/astrid/res/layout/task_list_body_featured_list.xml +++ b/astrid/res/layout/task_list_body_featured_list.xml @@ -6,50 +6,34 @@ android:layout_height="wrap_content" android:layout_weight="100"> - - + android:background="?attr/asMembersHeaderBackground" + android:padding="15dip" + android:gravity="center_vertical"> + + - + android:singleLine="false" + android:lines="4" + android:ellipsize="end"/> + - - - - diff --git a/astrid/res/values/strings-actfm.xml b/astrid/res/values/strings-actfm.xml index 953e27224..5cc1d6f90 100644 --- a/astrid/res/values/strings-actfm.xml +++ b/astrid/res/values/strings-actfm.xml @@ -273,7 +273,7 @@ - Copy this list + Copy list (Copy)