Finished implementing the TaskCommentsFragment (untested)

pull/14/head
Sam Bosley 12 years ago
parent 48eb144cff
commit 2a2ab57ece

@ -16,6 +16,7 @@ import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuInflater;
@ -37,12 +38,16 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.actfm.ActFmCameraModule.ClearImageCallback;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.StatisticsService;
public abstract class CommentsFragment extends ListFragment {
@ -64,6 +69,8 @@ public abstract class CommentsFragment extends ListFragment {
protected final ImageDiskCache imageCache;
@Autowired ActFmSyncService actFmSyncService;
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired UpdateDao updateDao;
@ -77,11 +84,13 @@ public abstract class CommentsFragment extends ListFragment {
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.tag_updates_fragment, container, false);
View v = inflater.inflate(getLayout(), container, false);
return v;
}
protected abstract int getLayout();
protected abstract void loadModelFromIntent(Intent intent);
protected abstract boolean hasModel();
@ -94,11 +103,13 @@ public abstract class CommentsFragment extends ListFragment {
protected abstract void addHeaderToListView(ListView listView);
protected abstract void refreshActivity(boolean manual);
protected abstract void populateListHeader(ViewGroup header);
protected abstract void addComment();
protected abstract Update createUpdate();
protected abstract String commentAddStatistic();
protected abstract void performFetch(boolean manual, Runnable done);
@Override
public void onActivityCreated(Bundle savedInstanceState) {
@ -245,6 +256,34 @@ public abstract class CommentsFragment extends ListFragment {
//
}
protected void refreshActivity(boolean manual) {
if (actFmPreferenceService.isLoggedIn()) {
final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback(
getActivity(), this, R.id.comments_progressBar, new Runnable() {
@Override
public void run() {
refreshUpdatesList();
}
});
callback.started();
callback.incrementMax(100);
Runnable doneRunnable = new Runnable() {
@Override
public void run() {
callback.incrementProgress(50);
callback.finished();
}
};
if (hasModel()) {
performFetch(manual, doneRunnable);
} else {
actFmSyncService.fetchPersonalUpdates(manual, doneRunnable);
}
callback.incrementProgress(50);
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if(menu.size() > 0)
@ -281,6 +320,41 @@ public abstract class CommentsFragment extends ListFragment {
}
}
protected void addComment() {
Update update = createUpdate();
if (picture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
try {
String updateString = getPictureHashForUpdate(update);
imageCache.put(updateString, picture);
update.setValue(Update.PICTURE, updateString);
}
catch (Exception e) {
Log.e("CommentFragment", "Failed to put image to disk...", e); //$NON-NLS-1$//$NON-NLS-2$
}
}
update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = picture;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
}
}.start();
addCommentField.setText(""); //$NON-NLS-1$
picture = null;
resetPictureButton();
refreshUpdatesList();
StatisticsService.reportEvent(commentAddStatistic());
}
protected String getPictureHashForUpdate(Update u) {
String s = u.getValue(Update.TASK).toString() + u.getValue(Update.CREATION_DATE);
return s;

@ -8,9 +8,7 @@ package com.todoroo.astrid.actfm;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
@ -20,16 +18,12 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.utility.AstridPreferences;
@ -41,14 +35,20 @@ public class TagUpdatesFragment extends CommentsFragment {
@Autowired
private TagDataService tagDataService;
@Autowired
private ActFmSyncService actFmSyncService;
public TagUpdatesFragment() {
super();
}
public TagUpdatesFragment(TagData tagData) {
super();
this.tagData = tagData;
}
@Override
protected int getLayout() {
return R.layout.tag_updates_fragment;
}
@Override
protected void loadModelFromIntent(Intent intent) {
if (tagData == null)
@ -107,37 +107,13 @@ public class TagUpdatesFragment extends CommentsFragment {
}
@Override
protected void refreshActivity(boolean manual) {
if (actFmPreferenceService.isLoggedIn()) {
final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback(
getActivity(), this, R.id.comments_progressBar, new Runnable() {
@Override
public void run() {
refreshUpdatesList();
}
});
callback.started();
callback.incrementMax(100);
Runnable doneRunnable = new Runnable() {
@Override
public void run() {
callback.incrementProgress(50);
callback.finished();
}
};
if (tagData != null) {
actFmSyncService.fetchUpdatesForTag(tagData, manual, doneRunnable);
} else {
actFmSyncService.fetchPersonalUpdates(manual, doneRunnable);
}
callback.incrementProgress(50);
}
protected void performFetch(boolean manual, Runnable done) {
actFmSyncService.fetchUpdatesForTag(tagData, manual, done);
}
@SuppressWarnings("nls")
@Override
protected void addComment() {
@SuppressWarnings("nls")
protected Update createUpdate() {
Update update = new Update();
update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, "tag_comment");
@ -146,35 +122,11 @@ public class TagUpdatesFragment extends CommentsFragment {
update.setValue(Update.TAGS_LOCAL, "," + tagData.getId() + ",");
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, tagData.getValue(TagData.NAME));
if (picture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
try {
String updateString = getPictureHashForUpdate(update);
imageCache.put(updateString, picture);
update.setValue(Update.PICTURE, updateString);
}
catch (Exception e) {
Log.e("TagUpdatesFragment", "Failed to put image to disk...");
}
}
update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = picture;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
}
}.start();
addCommentField.setText(""); //$NON-NLS-1$
picture = null;
resetPictureButton();
refreshUpdatesList();
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TAG_COMMENT);
return update;
}
protected String commentAddStatistic() {
return StatisticsConstants.ACTFM_TAG_COMMENT;
}
@Override
@ -187,4 +139,5 @@ public class TagUpdatesFragment extends CommentsFragment {
}
}
}

@ -5,11 +5,14 @@ import android.database.Cursor;
import android.view.ViewGroup;
import android.widget.ListView;
import com.timsu.astrid.R;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.service.StatisticsConstants;
public class TaskCommentsFragment extends CommentsFragment {
@ -28,6 +31,11 @@ public class TaskCommentsFragment extends CommentsFragment {
return task != null;
}
@Override
protected int getLayout() {
return R.layout.tag_updates_fragment;
}
@Override
protected String getModelName() {
return task.getValue(Task.TITLE);
@ -58,14 +66,27 @@ public class TaskCommentsFragment extends CommentsFragment {
}
@Override
protected void refreshActivity(boolean manual) {
// TODO Auto-generated method stub
protected void performFetch(boolean manual, Runnable done) {
actFmSyncService.fetchUpdatesForTask(task, manual, done);
}
@Override
protected Update createUpdate() {
Update update = new Update();
update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, UpdateAdapter.UPDATE_TASK_COMMENT);
update.setValue(Update.USER_ID, 0L);
if (task.containsNonNullValue(Task.REMOTE_ID))
update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID));
update.setValue(Update.TASK_LOCAL, task.getId());
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, task.getValue(Task.TITLE));
return update;
}
@Override
protected void addComment() {
// TODO Auto-generated method stub
protected String commentAddStatistic() {
return StatisticsConstants.ACTFM_TASK_COMMENT;
}
}

Loading…
Cancel
Save