improvements / fixes to note edite activity

pull/14/head
Tim Su 14 years ago
parent 80f64974b8
commit 7189020842

@ -17,7 +17,6 @@ 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;
@ -66,6 +65,7 @@ public class EditNoteActivity extends ListActivity {
private final ArrayList<NoteOrUpdate> items = new ArrayList<NoteOrUpdate>();
private NoteAdapter adapter;
private EditText commentField;
private TextView loadingText;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -75,13 +75,15 @@ public class EditNoteActivity extends ListActivity {
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)
if(task == null) {
finish();
return;
}
setTitle(task.getValue(Task.TITLE));
setUpListAdapter();
setUpInterface();
setUpListAdapter();
if(actFmPreferenceService.isLoggedIn() && task.getValue(Task.REMOTE_ID) > 0) {
findViewById(R.id.add_comment).setVisibility(View.VISIBLE);
@ -91,6 +93,10 @@ public class EditNoteActivity extends ListActivity {
if(DateUtilities.now() > lastFetchDate + 300000L) {
refreshData(false);
Preferences.setLong(fetchKey, DateUtilities.now());
} else {
loadingText.setText(R.string.ENA_no_comments);
if(items.size() == 0)
loadingText.setVisibility(View.VISIBLE);
}
}
}
@ -133,11 +139,13 @@ public class EditNoteActivity extends ListActivity {
if(!TextUtils.isEmpty(task.getValue(Task.NOTES))) {
TextView notes = new TextView(this);
notes.setGravity(Gravity.CENTER);
notes.setTextSize(20);
notes.setTextAppearance(this, R.style.TextAppearance_TAd_ItemTitle);
notes.setTextSize(18);
getListView().addHeaderView(notes);
notes.setText(task.getValue(Task.NOTES));
notes.setPadding(5, 10, 5, 10);
}
loadingText = (TextView) findViewById(R.id.loading);
}
private void setUpListAdapter() {
@ -207,6 +215,8 @@ public class EditNoteActivity extends ListActivity {
@Override
public void run() {
setUpListAdapter();
loadingText.setText(R.string.ENA_no_comments);
loadingText.setVisibility(items.size() == 0 ? View.VISIBLE : View.GONE);
DialogUtilities.dismissDialog(EditNoteActivity.this, progressDialog);
}
});

@ -1,74 +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.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.ContextManager;
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 NotesActionExposer extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ContextManager.setContext(context);
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
if(taskId == -1)
return;
Task task = PluginServices.getTaskService().fetchById(taskId, Task.ID, Task.TITLE, Task.NOTES);
if(!task.containsNonNullValue(Task.NOTES) || TextUtils.isEmpty(task.getValue(Task.NOTES)))
return;
if(AstridApiConstants.BROADCAST_REQUEST_ACTIONS.equals(intent.getAction())) {
sendNoteAction(context, taskId);
} else {
displayNote(context, task);
}
}
private void displayNote(Context context, 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);
}
private void sendNoteAction(Context context, long taskId) {
final String label = context.getString(R.string.TEA_note_label);
final Drawable drawable = context.getResources().getDrawable(R.drawable.tango_notes);
Bitmap icon = ((BitmapDrawable)drawable).getBitmap();
Intent newIntent = new Intent(context, getClass());
newIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
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, NotesPlugin.IDENTIFIER);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, action);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
}
}

@ -12,13 +12,13 @@
android:layout_weight="100">
<TextView
android:id="@android:id/empty"
android:id="@+id/loading"
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"
android:text="@string/ENA_loading"
style="@style/TextAppearance.TLA_NoItems" />
<ListView

@ -73,7 +73,10 @@
<string name="ENE_label_comments">Comments</string>
<!-- EditNoteActivity - no comments -->
<string name="ENA_no_comments">No Comments</string>
<string name="ENA_no_comments">Nothing To Show</string>
<!-- EditNoteActivity - loading -->
<string name="ENA_loading">Loading...</string>
<!-- EditNoteActivity - refresh comments -->
<string name="ENA_refresh_comments">Refresh Comments</string>

@ -850,7 +850,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
if(isIntroTask(viewHolder.task)) {
Intent intent = new Intent(ContextManager.getContext(), EditNoteActivity.class);
intent.putExtra(EditNoteActivity.EXTRA_TASK_ID, viewHolder.task);
intent.putExtra(EditNoteActivity.EXTRA_TASK_ID, viewHolder.task.getId());
activity.startActivity(intent);
return;
}

Loading…
Cancel
Save