Created EditNoteActivity for viewing and adding task comments and notes.

pull/14/head
Tim Su 15 years ago
parent 948731dc61
commit e9db48b229

@ -43,11 +43,11 @@ public class Update extends RemoteModel {
public static final LongProperty REMOTE_ID = new LongProperty(
TABLE, REMOTE_ID_PROPERTY_NAME);
/** Associated Task (if any) */
/** Associated Task remote-id (if any) */
public static final LongProperty TASK = new LongProperty(
TABLE, "task");
/** Associated Project (if any) */
/** Associated Tag local-id (if any) */
public static final LongProperty TAG = new LongProperty(
TABLE, "tag");

@ -168,7 +168,7 @@
<!-- ======================================================== Services = -->
<service android:name="com.todoroo.astrid.widget.TasksWidget$UpdateService" />
<service android:name="com.todoroo.astrid.widget.TasksWidget$WidgetUpdateService" />
<!-- ======================================================= Providers = -->
@ -395,7 +395,23 @@
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
</intent-filter>
</receiver>
<!-- notes -->
<receiver android:name="com.todoroo.astrid.notes.NotesDetailExposer">
<intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_DETAILS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name="com.todoroo.astrid.notes.EditNoteActivity" />
<receiver android:name="com.todoroo.astrid.notes.EditNoteExposer">
<intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_ACTIONS" />
<action android:name="com.todoroo.astrid.EDIT_NOTES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<!-- actfm -->
<activity android:name="com.todoroo.astrid.actfm.ActFmLoginActivity">
</activity>
@ -467,16 +483,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<!-- notes -->
<receiver android:name="com.todoroo.astrid.notes.NotesDetailExposer">
<intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_DETAILS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name="com.todoroo.astrid.notes.NoteViewingActivity"
android:theme="@style/Theme.Dialog" />
<!-- reminders -->
<activity android:name="com.todoroo.astrid.reminders.ReminderPreferences"

@ -612,6 +612,7 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TAG, tagData.getId());
update.setValue(Update.CREATION_DATE, DateUtilities.now());
Flags.checkAndClear(Flags.SUPPRESS_SYNC);
updateDao.createNew(update);
addCommentField.setText(""); //$NON-NLS-1$

@ -158,10 +158,7 @@ public final class ActFmSyncService {
}
if(update.getValue(Update.TASK) > 0) {
Task task = taskService.fetchById(update.getValue(Update.TASK), Task.REMOTE_ID);
if(task == null || task.getValue(Task.REMOTE_ID) == 0)
return;
params.add("task"); params.add(task.getValue(Task.REMOTE_ID));
params.add("task_id"); params.add(update.getValue(Update.TASK));
}
if(!checkForToken())
return;
@ -460,6 +457,7 @@ public final class ActFmSyncService {
Flags.set(Flags.SUPPRESS_SYNC);
taskService.save(remote);
metadataService.synchronizeMetadata(remote.getId(), metadata, MetadataCriteria.withKey(TagService.KEY));
remote.clear();
}
if(manual) {
@ -479,7 +477,7 @@ public final class ActFmSyncService {
}
/**
* Fetch tasks for the given tagData asynchronously
* Fetch updates for the given tagData asynchronously
* @param tagData
* @param manual
* @param done
@ -499,6 +497,7 @@ public final class ActFmSyncService {
updateDao.createNew(remote);
else
updateDao.saveExisting(remote);
remote.clear();
}
}
@ -512,6 +511,42 @@ public final class ActFmSyncService {
}, done, "updates:" + tagData.getId(), "tag_id", tagData.getValue(TagData.REMOTE_ID));
}
/**
* Fetch updates for the given task asynchronously
* @param task
* @param manual
* @param runnable
*/
public void fetchUpdatesForTask(final Task task, boolean manual, Runnable done) {
invokeFetchList("activity", manual, new ListItemProcessor<Update>() {
@Override
protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException {
Update remote = new Update();
for(int i = 0; i < list.length(); i++) {
JSONObject item = list.getJSONObject(i);
readIds(locals, item, remote);
JsonHelper.updateFromJson(item, null, remote);
System.err.println("GOJI BERRY: (" + remote.getId() + ") - " + remote.getSetValues());
Flags.set(Flags.SUPPRESS_SYNC);
if(remote.getId() == AbstractModel.NO_ID)
updateDao.createNew(remote);
else
updateDao.saveExisting(remote);
remote.clear();
}
}
@Override
protected HashMap<Long, Long> getLocalModels() {
TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID,
Update.REMOTE_ID).where(Update.REMOTE_ID.in(remoteIds)).orderBy(
Order.asc(Update.REMOTE_ID)));
return cursorToMap(cursor, updateDao, Update.REMOTE_ID, Update.ID);
}
}, done, "comments:" + task.getId(), "task_id", task.getValue(Task.REMOTE_ID));
}
/**
* Update tag picture
* @param path
@ -659,7 +694,7 @@ public final class ActFmSyncService {
return item.optLong(key, 0) * 1000L;
}
public static void updateFromJson(JSONObject json, TagData tagData,
public static void updateFromJson(JSONObject json, TagData tag,
Update model) throws JSONException {
model.setValue(Update.REMOTE_ID, json.getLong("id"));
readUser(json.getJSONObject("user"), model, Update.USER_ID, Update.USER);
@ -672,7 +707,8 @@ public final class ActFmSyncService {
model.setValue(Update.MESSAGE, json.getString("message"));
model.setValue(Update.PICTURE, json.getString("picture"));
model.setValue(Update.CREATION_DATE, readDate(json, "created_at"));
model.setValue(Update.TAG, tagData.getId());
model.setValue(Update.TAG, tag == null ? 0L : tag.getId());
model.setValue(Update.TASK, json.optLong("task_id", 0));
}
public static void readUser(JSONObject user, AbstractModel model, LongProperty idProperty,

@ -0,0 +1,333 @@
package com.todoroo.astrid.notes;
import greendroid.widget.AsyncImageView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.json.JSONObject;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.utility.Flags;
public class EditNoteActivity extends ListActivity {
public static final String EXTRA_TASK_ID = "task"; //$NON-NLS-1$
private static final int MENU_REFRESH_ID = Menu.FIRST;
private static final String LAST_FETCH_KEY = "task-fetch-"; //$NON-NLS-1$
private Task task;
@Autowired ActFmSyncService actFmSyncService;
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired MetadataService metadataService;
@Autowired UpdateDao updateDao;
private final ArrayList<NoteOrUpdate> items = new ArrayList<NoteOrUpdate>();
private NoteAdapter adapter;
private EditText commentField;
@Override
protected void onCreate(Bundle savedInstanceState) {
DependencyInjectionService.getInstance().inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_note_activity);
long taskId = getIntent().getLongExtra(EXTRA_TASK_ID, -1);
task = PluginServices.getTaskService().fetchById(taskId, Task.NOTES, Task.ID, Task.REMOTE_ID, Task.TITLE);
if(task == null)
return;
setTitle(task.getValue(Task.TITLE));
setUpListAdapter();
setUpInterface();
if(actFmPreferenceService.isLoggedIn() && task.getValue(Task.REMOTE_ID) > 0) {
findViewById(R.id.add_comment).setVisibility(View.VISIBLE);
String fetchKey = LAST_FETCH_KEY + task.getId();
long lastFetchDate = Preferences.getLong(fetchKey, 0);
if(DateUtilities.now() > lastFetchDate + 300000L) {
refreshData(false);
Preferences.setLong(fetchKey, DateUtilities.now());
}
}
}
// --- UI preparation
private void setUpInterface() {
final View commentButton = findViewById(R.id.commentButton);
commentField = (EditText) findViewById(R.id.commentField);
commentField.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_NULL && commentField.getText().length() > 0) {
addComment();
return true;
}
return false;
}
});
commentField.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
commentButton.setVisibility((s.length() > 0) ? View.VISIBLE : View.GONE);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//
}
});
commentButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addComment();
}
});
if(!TextUtils.isEmpty(task.getValue(Task.NOTES))) {
TextView notes = new TextView(this);
notes.setGravity(Gravity.CENTER);
notes.setTextSize(20);
getListView().addHeaderView(notes);
notes.setText(task.getValue(Task.NOTES));
}
}
private void setUpListAdapter() {
items.clear();
TodorooCursor<Metadata> notes = metadataService.query(
Query.select(Metadata.PROPERTIES).where(
MetadataCriteria.byTaskAndwithKey(task.getId(),
NoteMetadata.METADATA_KEY)).orderBy(Order.desc(Metadata.CREATION_DATE)));
try {
Metadata metadata = new Metadata();
for(notes.moveToFirst(); !notes.isAfterLast(); notes.moveToNext()) {
metadata.readFromCursor(notes);
items.add(NoteOrUpdate.fromMetadata(metadata));
}
} finally {
notes.close();
}
TodorooCursor<Update> updates = updateDao.query(Query.select(Update.PROPERTIES).where(
Update.TASK.eq(task.getValue(Task.REMOTE_ID))).orderBy(Order.desc(Update.CREATION_DATE)));
try {
Update update = new Update();
for(updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) {
update.readFromCursor(updates);
items.add(NoteOrUpdate.fromUpdate(update));
}
} finally {
updates.close();
}
Collections.sort(items, new Comparator<NoteOrUpdate>() {
@Override
public int compare(NoteOrUpdate a, NoteOrUpdate b) {
return (int)(b.createdAt - a.createdAt);
}
});
adapter = new NoteAdapter(this, R.id.name, items);
setListAdapter(adapter);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(menu.size() > 0)
return true;
MenuItem item;
if(actFmPreferenceService.isLoggedIn()) {
item = menu.add(Menu.NONE, MENU_REFRESH_ID, Menu.NONE,
R.string.ENA_refresh_comments);
item.setIcon(R.drawable.ic_menu_refresh);
}
return true;
}
// --- events
private void refreshData(boolean manual) {
final ProgressDialog progressDialog;
if(manual)
progressDialog = DialogUtilities.progressDialog(this, getString(R.string.DLG_please_wait));
else
progressDialog = null;
actFmSyncService.fetchUpdatesForTask(task, manual, new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
setUpListAdapter();
DialogUtilities.dismissDialog(EditNoteActivity.this, progressDialog);
}
});
}
});
}
private void addComment() {
Update update = new Update();
update.setValue(Update.MESSAGE, commentField.getText().toString());
update.setValue(Update.ACTION_CODE, "task_comment"); //$NON-NLS-1$
update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID));
update.setValue(Update.CREATION_DATE, DateUtilities.now());
Flags.checkAndClear(Flags.SUPPRESS_SYNC);
updateDao.createNew(update);
commentField.setText(""); //$NON-NLS-1$
setUpListAdapter();
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// handle my own menus
switch (item.getItemId()) {
case MENU_REFRESH_ID: {
refreshData(true);
return true;
}
default: return false;
}
}
// --- adapter
private static class NoteOrUpdate {
private final String picture;
private final String title;
private final String body;
private final long createdAt;
public NoteOrUpdate(String picture, String title, String body,
long createdAt) {
super();
this.picture = picture;
this.title = title;
this.body = body;
this.createdAt = createdAt;
}
public static NoteOrUpdate fromMetadata(Metadata m) {
return new NoteOrUpdate(m.getValue(NoteMetadata.THUMBNAIL),
m.getValue(NoteMetadata.TITLE),
m.getValue(NoteMetadata.BODY),
m.getValue(Metadata.CREATION_DATE));
}
@SuppressWarnings("nls")
public static NoteOrUpdate fromUpdate(Update u) {
JSONObject user = ActFmPreferenceService.userFromModel(u);
String description = u.getValue(Update.ACTION);
String message = u.getValue(Update.MESSAGE);
if(u.getValue(Update.ACTION_CODE).equals("task_comment"))
description = message;
else if(!TextUtils.isEmpty(message))
description += " " + message;
return new NoteOrUpdate(user.optString("picture"),
user.optString("name", ""),
description,
u.getValue(Update.CREATION_DATE));
}
@Override
public String toString() {
return title + ": " + body; //$NON-NLS-1$
}
}
private class NoteAdapter extends ArrayAdapter<NoteOrUpdate> {
public NoteAdapter(Context context, int textViewResourceId, List<NoteOrUpdate> list) {
super(context, textViewResourceId, list);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.update_adapter_row, parent, false);
}
bindView(convertView, items.get(position));
return convertView;
}
/** Helper method to set the contents and visibility of each field */
public synchronized void bindView(View view, NoteOrUpdate item) {
// picture
final AsyncImageView pictureView = (AsyncImageView)view.findViewById(R.id.picture); {
pictureView.setUrl(item.picture);
}
// name
final TextView nameView = (TextView)view.findViewById(R.id.title); {
nameView.setText(item.title);
}
// description
final TextView descriptionView = (TextView)view.findViewById(R.id.description); {
descriptionView.setText(item.body);
}
// date
final TextView date = (TextView)view.findViewById(R.id.date); {
CharSequence dateString = DateUtils.getRelativeTimeSpanString(item.createdAt,
DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
date.setText(dateString);
}
}
}
}

@ -0,0 +1,80 @@
/**
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.notes;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
/**
* Exposes {@link TaskDecoration} for timers
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class EditNoteExposer extends BroadcastReceiver {
private static final String ACTION = "com.todoroo.astrid.EDIT_NOTES"; //$NON-NLS-1$
@Autowired ActFmPreferenceService actFmPreferenceService;
@Override
public void onReceive(Context context, Intent intent) {
ContextManager.setContext(context);
DependencyInjectionService.getInstance().inject(this);
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
if(taskId == -1)
return;
if(AstridApiConstants.BROADCAST_REQUEST_ACTIONS.equals(intent.getAction())) {
String label;
Drawable drawable;
if(!actFmPreferenceService.isLoggedIn()) {
Task task = PluginServices.getTaskService().fetchById(taskId, Task.NOTES);
if(task == null || TextUtils.isEmpty(task.getValue(Task.NOTES)))
return;
label = context.getString(R.string.ENE_label);
drawable = context.getResources().getDrawable(R.drawable.tango_notes);
} else {
label = context.getString(R.string.ENE_label_comments);
drawable = context.getResources().getDrawable(R.drawable.tango_chat);
}
Intent newIntent = new Intent(ACTION);
newIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
Bitmap icon = ((BitmapDrawable)drawable).getBitmap();
TaskAction action = new TaskAction(label,
PendingIntent.getBroadcast(context, (int)taskId, newIntent, 0), icon);
// transmit
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_ACTIONS);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ActFmPreferenceService.IDENTIFIER);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, action);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
} else if(ACTION.equals(intent.getAction())) {
Intent launchIntent = new Intent(context, EditNoteActivity.class);
launchIntent.putExtra(EditNoteActivity.EXTRA_TASK_ID, taskId);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ContextManager.getContext().startActivity(launchIntent);
}
}
}

@ -1,93 +0,0 @@
package com.todoroo.astrid.notes;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
public class NoteViewingActivity extends Activity {
public static final String EXTRA_TASK = "task"; //$NON-NLS-1$
private Task task;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.empty_linear_layout);
getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
LinearLayout body = (LinearLayout) findViewById(R.id.body);
task = getIntent().getParcelableExtra(EXTRA_TASK);
setTitle(task.getValue(Task.TITLE));
ScrollView scrollView = new ScrollView(this);
LinearLayout scrollViewBody = new LinearLayout(this);
scrollViewBody.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(scrollViewBody);
body.addView(scrollView);
if(!TextUtils.isEmpty(task.getValue(Task.NOTES))) {
TextView note = new TextView(this);
note.setText(task.getValue(Task.NOTES));
Linkify.addLinks(note, Linkify.ALL);
note.setPadding(0, 0, 0, 10);
scrollViewBody.addView(note);
}
TodorooCursor<Metadata> cursor = PluginServices.getMetadataService().query(
Query.select(Metadata.PROPERTIES).where(
MetadataCriteria.byTaskAndwithKey(task.getId(),
NoteMetadata.METADATA_KEY)).orderBy(Order.desc(Metadata.CREATION_DATE)));
Metadata metadata = new Metadata();
try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor);
TextView title = new TextView(this);
title.setTypeface(Typeface.DEFAULT_BOLD);
title.setText(metadata.getValue(NoteMetadata.TITLE));
scrollViewBody.addView(title);
TextView note = new TextView(this);
note.setText(metadata.getValue(NoteMetadata.BODY));
Linkify.addLinks(note, Linkify.ALL);
note.setPadding(0, 0, 0, 10);
scrollViewBody.addView(note);
}
} finally {
cursor.close();
}
Button ok = new Button(this);
ok.setText(android.R.string.ok);
ok.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
body.addView(ok);
}
}

@ -47,8 +47,8 @@ public class NotesActionExposer extends BroadcastReceiver {
}
private void displayNote(Context context, Task task) {
Intent intent = new Intent(context, NoteViewingActivity.class);
intent.putExtra(NoteViewingActivity.EXTRA_TASK, task);
Intent intent = new Intent(context, EditNoteActivity.class);
intent.putExtra(EditNoteActivity.EXTRA_TASK_ID, task);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}

@ -1,54 +0,0 @@
/**
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.notes;
import android.app.PendingIntent;
import android.content.Intent;
import android.widget.RemoteViews;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.api.TaskDecorationExposer;
import com.todoroo.astrid.data.Task;
/**
* Exposes {@link TaskDecoration} for notes
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class NotesDecorationExposer implements TaskDecorationExposer {
@Override
public TaskDecoration expose(Task task) {
if(Preferences.getBoolean(R.string.p_showNotes, false))
return null;
if(task == null || !NotesPlugin.hasNotes(task))
return null;
TaskDecoration decoration;
RemoteViews remoteViews = new RemoteViews(ContextManager.getContext().getPackageName(),
R.layout.note_decoration);
decoration = new TaskDecoration(remoteViews, TaskDecoration.POSITION_RIGHT, 0);
Intent intent = new Intent(ContextManager.getContext(), NoteViewingActivity.class);
intent.putExtra(NoteViewingActivity.EXTRA_TASK, task);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(ContextManager.getContext(),
(int)task.getId(), intent, PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.icon, pendingIntent);
return decoration;
}
@Override
public String getAddon() {
return NotesPlugin.IDENTIFIER;
}
}

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background_gradient">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="100">
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100"
android:gravity="center"
android:visibility="gone"
android:text="@string/ENA_no_comments"
style="@style/TextAppearance.TLA_NoItems" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100" />
</FrameLayout>
<!-- Footer -->
<LinearLayout
android:id="@+id/add_comment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone"
android:orientation="horizontal">
<!-- Add Button -->
<ImageButton android:id="@+id/commentButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone"
android:src="@drawable/tango_chat"
android:scaleType="fitCenter"/>
<!-- Comment Field -->
<EditText android:id="@+id/commentField"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="100"
android:hint="@string/TVA_add_comment"
android:singleLine="true"
android:autoText="true"
android:capitalize="sentences"/>
</LinearLayout>
</LinearLayout>

@ -66,13 +66,18 @@
<!-- ============================================================= notes -->
<!-- Note screen: quick-add comment text -->
<string name="notes_quick_add_comment_hint">Add a comment...</string>
<!-- Note Exposer -->
<string name="ENE_label">Notes</string>
<!-- Note Exposer / Comments -->
<string name="ENE_label_comments">Comments</string>
<!-- EditNoteActivity - no comments -->
<string name="ENA_no_comments">No Comments</string>
<!-- EditNoteActivity - refresh comments -->
<string name="ENA_refresh_comments">Refresh Comments</string>
<!-- Note screen: blank notes -->
<string name="notes_blank">No notes!</string>
<!-- ================================================= TaskListActivity == -->
<!-- Task List: Displayed instead of list when no items present -->

@ -42,7 +42,7 @@ import com.timsu.astrid.data.sync.SyncDataController;
import com.timsu.astrid.data.task.AbstractTaskModel.RepeatInfo;
import com.timsu.astrid.data.task.AbstractTaskModel.TaskModelDatabaseHelper;
import com.todoroo.astrid.provider.Astrid2TaskProvider;
import com.todoroo.astrid.widget.TasksWidget.UpdateService;
import com.todoroo.astrid.widget.TasksWidget.WidgetUpdateService;
/**
* Controller for task-related operations
@ -277,7 +277,7 @@ public class TaskController extends AbstractController {
// notify widget that something changed
if(saveSucessful) {
Intent intent = new Intent(context, UpdateService.class);
Intent intent = new Intent(context, WidgetUpdateService.class);
context.startService(intent);
}

@ -68,28 +68,28 @@ import com.todoroo.astrid.service.ThemeService;
public class FilterListActivity extends ExpandableListActivity {
// --- menu codes
private static final int MENU_SEARCH_ID = Menu.FIRST + 0;
private static final int MENU_HELP_ID = Menu.FIRST + 1;
private static final int MENU_REFRESH_ID = Menu.FIRST + 2;
private static final int CONTEXT_MENU_SHORTCUT = Menu.FIRST + 3;
private static final int CONTEXT_MENU_INTENT = Menu.FIRST + 4;
private static final int REQUEST_CUSTOM_INTENT = 1;
// --- instance variables
@Autowired ExceptionService exceptionService;
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired ActFmSyncService actFmSyncService;
FilterAdapter adapter = null;
/* ======================================================================
* ======================================================= initialization
* ====================================================================== */
public FilterListActivity() {
DependencyInjectionService.getInstance().inject(this);
}
@ -144,23 +144,23 @@ public class FilterListActivity extends ExpandableListActivity {
public boolean onPrepareOptionsMenu(Menu menu) {
if(menu.size() > 0)
return true;
MenuItem item;
item = menu.add(Menu.NONE, MENU_SEARCH_ID, Menu.NONE,
R.string.FLA_menu_search);
item.setIcon(android.R.drawable.ic_menu_search);
if(actFmPreferenceService.isLoggedIn()) {
item = menu.add(Menu.NONE, MENU_REFRESH_ID, Menu.NONE,
R.string.actfm_FLA_menu_refresh);
item.setIcon(R.drawable.ic_menu_refresh);
}
item = menu.add(Menu.NONE, MENU_HELP_ID, Menu.NONE,
R.string.FLA_menu_help);
item.setIcon(android.R.drawable.ic_menu_help);
return true;
}
@ -346,44 +346,44 @@ public class FilterListActivity extends ExpandableListActivity {
@Override
public boolean onMenuItemSelected(int featureId, final MenuItem item) {
// handle my own menus
switch (item.getItemId()) {
case MENU_SEARCH_ID: {
onSearchRequested();
return true;
}
case MENU_REFRESH_ID: {
onRefreshRequested();
return true;
}
case MENU_HELP_ID: {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://weloveastrid.com/help-user-guide-astrid-v3/filters/")); //$NON-NLS-1$
startActivity(intent);
return true;
}
case CONTEXT_MENU_SHORTCUT: {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo)item.getMenuInfo();
final Intent shortcutIntent = item.getIntent();
FilterListItem filter = ((FilterAdapter.ViewHolder)info.targetView.getTag()).item;
if(filter instanceof Filter)
showCreateShortcutDialog(shortcutIntent, (Filter)filter);
return true;
}
case CONTEXT_MENU_INTENT: {
Intent intent = item.getIntent();
startActivityForResult(intent, REQUEST_CUSTOM_INTENT);
return true;
}
}
return false;
}

@ -1095,7 +1095,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
editor.putInt(SortHelper.PREF_SORT_SORT, sort);
editor.commit();
ContextManager.getContext().startService(new Intent(ContextManager.getContext(),
TasksWidget.UpdateService.class));
TasksWidget.WidgetUpdateService.class));
}
setUpTaskList();

@ -65,8 +65,7 @@ import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.api.TaskDecorationExposer;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskAdapterAddOnManager;
import com.todoroo.astrid.notes.NoteViewingActivity;
import com.todoroo.astrid.notes.NotesDecorationExposer;
import com.todoroo.astrid.notes.EditNoteActivity;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.timers.TimerDecorationExposer;
import com.todoroo.astrid.utility.Constants;
@ -592,7 +591,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
private final TaskDecorationExposer[] exposers = new TaskDecorationExposer[] {
new TimerDecorationExposer(),
new NotesDecorationExposer(),
};
/**
@ -851,8 +849,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
long taskId = viewHolder.task.getId();
if(isIntroTask(viewHolder.task)) {
Intent intent = new Intent(ContextManager.getContext(), NoteViewingActivity.class);
intent.putExtra(NoteViewingActivity.EXTRA_TASK, viewHolder.task);
Intent intent = new Intent(ContextManager.getContext(), EditNoteActivity.class);
intent.putExtra(EditNoteActivity.EXTRA_TASK_ID, viewHolder.task);
activity.startActivity(intent);
return;
}

@ -56,10 +56,10 @@ public class UpdateAdapter extends CursorAdapter {
OnCompletedTaskListener onCompletedTaskListener) {
super(activity, c, autoRequery);
DependencyInjectionService.getInstance().inject(this);
inflater = (LayoutInflater) activity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
this.resource = resource;
this.activity = activity;
}

@ -43,7 +43,7 @@ import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.reminders.ReminderStartupReceiver;
import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.widget.TasksWidget.UpdateService;
import com.todoroo.astrid.widget.TasksWidget.WidgetUpdateService;
/**
* Service which handles jobs that need to be run when Astrid starts up.
@ -150,7 +150,7 @@ public class StartupService {
public void run() {
// start widget updating alarm
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, UpdateService.class);
Intent intent = new Intent(context, WidgetUpdateService.class);
PendingIntent pendingIntent = PendingIntent.getService(context,
0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setInexactRepeating(AlarmManager.RTC, 0,

@ -68,7 +68,7 @@ public class TasksWidget extends AppWidgetProvider {
*/
public static void updateWidgets(Context context) {
context.startService(new Intent(context,
TasksWidget.UpdateService.class));
TasksWidget.WidgetUpdateService.class));
}
/**
@ -77,8 +77,8 @@ public class TasksWidget extends AppWidgetProvider {
*/
public static void updateWidget(Context context, int id) {
Intent intent = new Intent(ContextManager.getContext(),
TasksWidget.UpdateService.class);
intent.putExtra(UpdateService.EXTRA_WIDGET_ID, id);
TasksWidget.WidgetUpdateService.class);
intent.putExtra(WidgetUpdateService.EXTRA_WIDGET_ID, id);
context.startService(intent);
}
@ -89,7 +89,7 @@ public class TasksWidget extends AppWidgetProvider {
}
}
public static class UpdateService extends Service {
public static class WidgetUpdateService extends Service {
public static String EXTRA_WIDGET_ID = "widget_id"; //$NON-NLS-1$

Loading…
Cancel
Save