Comment pictures show up in taskeditactivity now YAAA

pull/14/head
Andrew Shaw 13 years ago
parent ed10a08cbe
commit 89aa3a00c9

@ -14,6 +14,7 @@ import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Environment; import android.os.Environment;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import com.timsu.astrid.R; import com.timsu.astrid.R;
@ -70,6 +71,47 @@ public class ActFmCameraModule {
.show().setOwnerActivity(activity); .show().setOwnerActivity(activity);
} }
public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) {
ArrayList<String> options = new ArrayList<String>();
options.add(fragment.getString(R.string.actfm_picture_camera));
options.add(fragment.getString(R.string.actfm_picture_gallery));
if (clearImageOption != null) {
options.add(fragment.getString(R.string.actfm_picture_clear));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(fragment.getActivity(),
android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@SuppressWarnings("nls")
@Override
public void onClick(DialogInterface d, int which) {
if(which == 0) {
lastTempFile = getTempFile(fragment.getActivity());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (lastTempFile != null) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
}
fragment.startActivityForResult(intent, REQUEST_CODE_CAMERA);
} else if (which == 1) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
fragment.startActivityForResult(Intent.createChooser(intent,
fragment.getString(R.string.actfm_TVA_tag_picture)), REQUEST_CODE_PICTURE);
} else {
if (clearImageOption != null)
clearImageOption.clearImage();
}
}
};
// show a menu of available options
new AlertDialog.Builder(fragment.getActivity())
.setAdapter(adapter, listener)
.show().setOwnerActivity(fragment.getActivity());
}
@SuppressWarnings("nls") @SuppressWarnings("nls")
private static File getTempFile(Activity activity) { private static File getTempFile(Activity activity) {
try { try {

@ -15,6 +15,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -84,6 +85,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
private int commentItems = 10; private int commentItems = 10;
private ImageButton pictureButton; private ImageButton pictureButton;
private Bitmap picture = null; private Bitmap picture = null;
private final Fragment fragment;
private final List<UpdatesChangedListener> listeners = new LinkedList<UpdatesChangedListener>(); private final List<UpdatesChangedListener> listeners = new LinkedList<UpdatesChangedListener>();
@ -92,8 +94,11 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
public void commentAdded(); public void commentAdded();
} }
public EditNoteActivity(Activity activity, View parent, long t) { public EditNoteActivity(Fragment fragment, View parent, long t) {
super(activity); super(fragment.getActivity());
Log.d("EditnoteActivity", "Contructor being called");
this.fragment = fragment;
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
setOrientation(VERTICAL); setOrientation(VERTICAL);
@ -191,6 +196,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
final ClearImageCallback clearImage = new ClearImageCallback() { final ClearImageCallback clearImage = new ClearImageCallback() {
@Override @Override
public void clearImage() { public void clearImage() {
Log.e("Errrr EditNOtes activity", "Picture clear image called");
picture = null; picture = null;
pictureButton.setImageResource(R.drawable.camera_button); pictureButton.setImageResource(R.drawable.camera_button);
} }
@ -200,9 +206,9 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (picture != null) if (picture != null)
ActFmCameraModule.showPictureLauncher((Activity)getContext(), clearImage); ActFmCameraModule.showPictureLauncher(fragment, clearImage);
else else
ActFmCameraModule.showPictureLauncher((Activity)getContext(), null); ActFmCameraModule.showPictureLauncher(fragment, null);
} }
}); });
if(!TextUtils.isEmpty(task.getValue(Task.NOTES))) { if(!TextUtils.isEmpty(task.getValue(Task.NOTES))) {
@ -217,6 +223,10 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
// loadingText = (TextView) findViewById(R.id.loading); // loadingText = (TextView) findViewById(R.id.loading);
loadingText = new TextView(getContext()); loadingText = new TextView(getContext());
for (UpdatesChangedListener l : listeners) {
l.updatesChanged();
}
} }
private void setUpListAdapter() { private void setUpListAdapter() {
@ -334,6 +344,16 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
DateUtils.FORMAT_ABBREV_RELATIVE); DateUtils.FORMAT_ABBREV_RELATIVE);
date.setText(dateString); date.setText(dateString);
} }
// picture
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); {
if(TextUtils.isEmpty(item.commentPicture))
commentPictureView.setVisibility(View.GONE);
else {
commentPictureView.setVisibility(View.VISIBLE);
commentPictureView.setUrl(item.commentPicture);
}
}
} }
public void refreshData(boolean manual, SyncResultCallback existingCallback) { public void refreshData(boolean manual, SyncResultCallback existingCallback) {
@ -390,10 +410,11 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID)); update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID));
update.setValue(Update.CREATION_DATE, DateUtilities.now()); update.setValue(Update.CREATION_DATE, DateUtilities.now());
Log.d("Add comment", "The picture is: " + picture);
if (picture != null) { if (picture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING); update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
} }
Flags.checkAndClear(Flags.ACTFM_SUPPRESS_SYNC); Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
updateDao.createNew(update); updateDao.createNew(update);
final long updateId = update.getId(); final long updateId = update.getId();
@ -402,6 +423,8 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
@Override @Override
public void run() { public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture); actFmSyncService.pushUpdate(updateId, tempPicture);
Log.d("Run thread", "The picture is: " + picture);
} }
}.start(); }.start();
commentField.setText(""); //$NON-NLS-1$ commentField.setText(""); //$NON-NLS-1$
@ -424,14 +447,16 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
private final String picture; private final String picture;
private final String title; private final String title;
private final String body; private final String body;
private final String commentPicture;
private final long createdAt; private final long createdAt;
public NoteOrUpdate(String picture, String title, String body, public NoteOrUpdate(String picture, String title, String body, String commentPicture,
long createdAt) { long createdAt) {
super(); super();
this.picture = picture; this.picture = picture;
this.title = title; this.title = title;
this.body = body; this.body = body;
this.commentPicture = commentPicture;
this.createdAt = createdAt; this.createdAt = createdAt;
} }
@ -442,6 +467,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
return new NoteOrUpdate(m.getValue(NoteMetadata.THUMBNAIL), return new NoteOrUpdate(m.getValue(NoteMetadata.THUMBNAIL),
m.getValue(NoteMetadata.TITLE), m.getValue(NoteMetadata.TITLE),
m.getValue(NoteMetadata.BODY), m.getValue(NoteMetadata.BODY),
m.getValue(NoteMetadata.COMMENTPICTURE),
m.getValue(Metadata.CREATION_DATE)); m.getValue(Metadata.CREATION_DATE));
} }
@ -455,10 +481,12 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
description = message; description = message;
else if(!TextUtils.isEmpty(message)) else if(!TextUtils.isEmpty(message))
description += " " + message; description += " " + message;
String commentPicture = u.getValue(Update.PICTURE);
return new NoteOrUpdate(user.optString("picture"), return new NoteOrUpdate(user.optString("picture"),
user.optString("name", ""), user.optString("name", ""),
description, description,
commentPicture,
u.getValue(Update.CREATION_DATE)); u.getValue(Update.CREATION_DATE));
} }
@ -504,6 +532,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
public void handleCameraResult(Bitmap bitmap) { public void handleCameraResult(Bitmap bitmap) {
picture = bitmap; picture = bitmap;
pictureButton.setImageBitmap(picture); pictureButton.setImageBitmap(picture);
Log.d("Picture", "Picture = " + picture);
} }
}; };

@ -23,10 +23,14 @@ public class NoteMetadata {
/** note thumbnail URL */ /** note thumbnail URL */
public static final StringProperty THUMBNAIL = Metadata.VALUE3; public static final StringProperty THUMBNAIL = Metadata.VALUE3;
/** note external id (use for your own purposes) */
public static final StringProperty COMMENTPICTURE = Metadata.VALUE6;
/** note external provider (use for your own purposes) */ /** note external provider (use for your own purposes) */
public static final StringProperty EXT_PROVIDER = Metadata.VALUE4; public static final StringProperty EXT_PROVIDER = Metadata.VALUE4;
/** note external id (use for your own purposes) */ /** note external id (use for your own purposes) */
public static final StringProperty EXT_ID = Metadata.VALUE5; public static final StringProperty EXT_ID = Metadata.VALUE5;
} }

@ -47,6 +47,17 @@
android:paddingLeft="50dip" android:paddingLeft="50dip"
android:textSize="14sp" /> android:textSize="14sp" />
<!-- picture -->
<greendroid.widget.AsyncImageView android:id="@+id/comment_picture"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_below="@id/description"
android:paddingTop="5dip"
astrid:defaultSrc="@drawable/icn_default_person_image"
android:scaleType="fitCenter"
android:visibility="gone" />
<!-- activity date --> <!-- activity date -->
<TextView android:id="@+id/date" <TextView android:id="@+id/date"
android:layout_width="75dip" android:layout_width="75dip"

@ -370,26 +370,24 @@ public final class TaskEditActivity extends Fragment implements
long idParam = getActivity().getIntent().getLongExtra(TOKEN_ID, long idParam = getActivity().getIntent().getLongExtra(TOKEN_ID,
-1L); -1L);
if (remoteId > 0 && idParam > -1L) { if (remoteId > 0 && idParam > -1L) {
// if (editNotes == null) { if (editNotes == null) {
editNotes = new EditNoteActivity(getActivity(), getView(), editNotes = new EditNoteActivity(this, getView(),
idParam); idParam);
editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
editNotes.addListener(this);
if (timerAction != null) { if (timerAction != null) {
timerAction.addListener(editNotes); timerAction.addListener(editNotes);
} }
}
else { else {
Log.d("Did not add timerAction", "did not add timer action"); editNotes.loadViewForTaskID(idParam);
} }
// }
// else {
// editNotes.loadViewForTaskID(idParam);
// }
if (mAdapter == null) { if (mAdapter == null) {
mAdapter = new TaskEditViewPager(getActivity()); mAdapter = new TaskEditViewPager(getActivity());
mAdapter.parent = this; mAdapter.parent = this;
editNotes = new EditNoteActivity(getActivity(), getView(), editNotes = new EditNoteActivity(this, getView(),
idParam); idParam);
editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
@ -1087,6 +1085,7 @@ public final class TaskEditActivity extends Fragment implements
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("Activity !!!", "Called on camera for request code: " + requestCode + "EditNOtes: " + editNotes.toString());
if (editNotes.activityResult(requestCode, resultCode, data)) { if (editNotes.activityResult(requestCode, resultCode, data)) {
return; return;
} }

Loading…
Cancel
Save