Added an 'add new' button to lists, which creates a list

pull/14/head
Tim Su 14 years ago
parent 5fa80b89f7
commit d443ff8502

@ -3,11 +3,14 @@ package com.todoroo.astrid.api;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.activity.TaskListActivity;
public class FilterWithCustomIntent extends Filter { public class FilterWithCustomIntent extends Filter {
@ -35,6 +38,14 @@ public class FilterWithCustomIntent extends Filter {
super(listingTitle, title, sqlQuery, valuesForNewTasks); super(listingTitle, title, sqlQuery, valuesForNewTasks);
} }
public void start(Context context) {
Intent intent = new Intent();
intent.putExtra(TaskListActivity.TOKEN_FILTER, this);
intent.setComponent(customTaskList);
if(customExtras != null)
intent.putExtras(customExtras);
context.startActivity(intent);
}
// --- parcelable // --- parcelable

@ -66,7 +66,7 @@ public class TagFilterExposer extends BroadcastReceiver {
/** Create filter from new tag object */ /** Create filter from new tag object */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static Filter filterFromTag(Context context, Tag tag, Criterion criterion, boolean useTagViewActivity) { public static FilterWithCustomIntent filterFromTag(Context context, Tag tag, Criterion criterion, boolean useTagViewActivity) {
String listTitle = tag.tag + " (" + tag.count + ")"; String listTitle = tag.tag + " (" + tag.count + ")";
String title = context.getString(R.string.tag_FEx_name, tag.tag); String title = context.getString(R.string.tag_FEx_name, tag.tag);
QueryTemplate tagTemplate = tag.queryTemplate(criterion); QueryTemplate tagTemplate = tag.queryTemplate(criterion);
@ -139,8 +139,6 @@ public class TagFilterExposer extends BroadcastReceiver {
addTags(list); addTags(list);
// transmit filter list // transmit filter list
if(list.size() <= 2)
return;
FilterListItem[] listAsArray = list.toArray(new FilterListItem[list.size()]); FilterListItem[] listAsArray = list.toArray(new FilterListItem[list.size()]);
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_FILTERS); Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_FILTERS);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, listAsArray); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, listAsArray);

@ -1,16 +1,33 @@
package com.todoroo.astrid.tags; package com.todoroo.astrid.tags;
import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.widget.EditText;
import android.widget.FrameLayout;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.api.Addon; import com.todoroo.astrid.api.Addon;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.tags.TagService.Tag;
public class TagsPlugin extends BroadcastReceiver { public class TagsPlugin extends BroadcastReceiver {
static final String IDENTIFIER = "tags"; //$NON-NLS-1$ static final String IDENTIFIER = "tags"; //$NON-NLS-1$
@Autowired TagDataService tagDataService;
@Autowired ActFmPreferenceService actFmPreferenceService;
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -22,4 +39,30 @@ public class TagsPlugin extends BroadcastReceiver {
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ); context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
} }
/**
* Create new tag data
* @param activity
*/
public void showNewTagDialog(final Activity activity) {
DependencyInjectionService.getInstance().inject(this);
FrameLayout frame = new FrameLayout(activity);
final EditText editText = new EditText(activity);
frame.addView(editText);
frame.setPadding(10, 0, 10, 0);
DialogUtilities.viewDialog(activity,
activity.getString(R.string.tag_new_list),
frame, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Tag tag = new Tag(editText.getText().toString(), 0, 0);
FilterWithCustomIntent filter = TagFilterExposer.filterFromTag(activity,
tag, TaskCriteria.isActive(), actFmPreferenceService.isLoggedIn());
filter.start(activity);
}
}, null);
}
} }

@ -29,7 +29,7 @@
<string name="actfm_picture_gallery">Pick from Gallery</string> <string name="actfm_picture_gallery">Pick from Gallery</string>
<!-- filter list activity: refresh tags --> <!-- filter list activity: refresh tags -->
<string name="actfm_FLA_menu_refresh">Refresh Tags</string> <string name="actfm_FLA_menu_refresh">Refresh Lists</string>
<!-- ================================================== TagViewActivity == --> <!-- ================================================== TagViewActivity == -->

@ -25,8 +25,14 @@
<!-- Context Item: show tag --> <!-- Context Item: show tag -->
<string name="TAd_contextFilterByTag">Show List</string> <string name="TAd_contextFilterByTag">Show List</string>
<!-- Dialog: new list -->
<string name="tag_new_list">New List Name:</string>
<!-- ========================================================== Filters == --> <!-- ========================================================== Filters == -->
<!-- filter button to add tag -->
<string name="tag_FEx_add_new">New</string>
<!-- filter header for tags --> <!-- filter header for tags -->
<string name="tag_FEx_header">Lists</string> <string name="tag_FEx_header">Lists</string>

@ -229,15 +229,14 @@ public class FilterListActivity extends ExpandableListActivity {
protected boolean onItemClicked(FilterListItem item) { protected boolean onItemClicked(FilterListItem item) {
if(item instanceof Filter) { if(item instanceof Filter) {
Filter filter = (Filter)item; Filter filter = (Filter)item;
Intent intent = new Intent(FilterListActivity.this, TaskListActivity.class);
intent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
if(filter instanceof FilterWithCustomIntent) { if(filter instanceof FilterWithCustomIntent) {
FilterWithCustomIntent customFilter = ((FilterWithCustomIntent)filter); FilterWithCustomIntent customFilter = ((FilterWithCustomIntent)filter);
intent.setComponent(customFilter.customTaskList); customFilter.start(this);
if(customFilter.customExtras != null) } else {
intent.putExtras(customFilter.customExtras); Intent intent = new Intent(FilterListActivity.this, TaskListActivity.class);
} intent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
startActivity(intent); startActivity(intent);
}
AndroidUtilities.callApiMethod(5, this, "overridePendingTransition", //$NON-NLS-1$ AndroidUtilities.callApiMethod(5, this, "overridePendingTransition", //$NON-NLS-1$
new Class<?>[] { Integer.TYPE, Integer.TYPE }, new Class<?>[] { Integer.TYPE, Integer.TYPE },
R.anim.slide_left_in, R.anim.slide_left_out); R.anim.slide_left_in, R.anim.slide_left_out);

@ -1124,6 +1124,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
} }
} }
@SuppressWarnings("nls")
private void showFilterListActivity() { private void showFilterListActivity() {
Intent intent = new Intent(TaskListActivity.this, Intent intent = new Intent(TaskListActivity.this,
FilterListActivity.class); FilterListActivity.class);

@ -21,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter; import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -35,6 +36,7 @@ import com.todoroo.astrid.api.FilterCategory;
import com.todoroo.astrid.api.FilterListHeader; import com.todoroo.astrid.api.FilterListHeader;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagsPlugin;
public class FilterAdapter extends BaseExpandableListAdapter { public class FilterAdapter extends BaseExpandableListAdapter {
@ -159,6 +161,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
viewHolder.icon = (ImageView)convertView.findViewById(R.id.icon); viewHolder.icon = (ImageView)convertView.findViewById(R.id.icon);
viewHolder.name = (TextView)convertView.findViewById(R.id.name); viewHolder.name = (TextView)convertView.findViewById(R.id.name);
viewHolder.selected = (ImageView)convertView.findViewById(R.id.selected); viewHolder.selected = (ImageView)convertView.findViewById(R.id.selected);
viewHolder.decoration = null;
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
} }
return convertView; return convertView;
@ -171,6 +174,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
public TextView name; public TextView name;
public ImageView selected; public ImageView selected;
public View view; public View view;
public View decoration;
} }
/* ====================================================================== /* ======================================================================
@ -390,6 +394,11 @@ public class FilterAdapter extends BaseExpandableListAdapter {
viewHolder.view.setBackgroundResource(0); viewHolder.view.setBackgroundResource(0);
viewHolder.expander.setVisibility(View.GONE); viewHolder.expander.setVisibility(View.GONE);
if(viewHolder.decoration != null) {
((ViewGroup)viewHolder.view).removeView(viewHolder.decoration);
viewHolder.decoration = null;
}
if(viewHolder.item instanceof FilterListHeader) { if(viewHolder.item instanceof FilterListHeader) {
viewHolder.name.setTextAppearance(activity, headerStyle); viewHolder.name.setTextAppearance(activity, headerStyle);
viewHolder.view.setBackgroundResource(R.drawable.edit_titlebar); viewHolder.view.setBackgroundResource(R.drawable.edit_titlebar);
@ -420,6 +429,28 @@ public class FilterAdapter extends BaseExpandableListAdapter {
viewHolder.view.setBackgroundColor(Color.rgb(128, 230, 0)); viewHolder.view.setBackgroundColor(Color.rgb(128, 230, 0));
} else } else
viewHolder.selected.setVisibility(View.GONE); viewHolder.selected.setVisibility(View.GONE);
updateForActFm(viewHolder);
}
private void updateForActFm(ViewHolder viewHolder) {
if(viewHolder.item instanceof FilterListHeader &&
viewHolder.item.listingTitle.equals(activity.getString(R.string.tag_FEx_header))) {
Button add = new Button(activity);
add.setText(R.string.tag_FEx_add_new);
add.setBackgroundColor(Color.TRANSPARENT);
add.setTextColor(Color.WHITE);
add.setCompoundDrawablesWithIntrinsicBounds(R.drawable.tango_add,0,0,0);
viewHolder.decoration = add;
((ViewGroup)viewHolder.view).addView(add);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new TagsPlugin().showNewTagDialog(activity);
}
});
}
} }
} }

Loading…
Cancel
Save