Hold on to comment pictures in intent so that they will persist if activity is shut down or across device rotation

pull/14/head
Sam Bosley 12 years ago
parent 05a2f57c4a
commit fbbe9bd9d5

@ -55,6 +55,7 @@ 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.TaskEditFragment;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
@ -251,6 +252,15 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
Linkify.addLinks(notes, Linkify.ALL);
}
Activity activity = fragment.getActivity();
if (activity != null) {
Bitmap bitmap = activity.getIntent().getParcelableExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
if (bitmap != null) {
pendingCommentPicture = bitmap;
pictureButton.setImageBitmap(pendingCommentPicture);
}
}
//TODO add loading text back in
// loadingText = (TextView) findViewById(R.id.loading);
loadingText = new TextView(getContext());
@ -461,6 +471,11 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
commentField.setText(""); //$NON-NLS-1$
pendingCommentPicture = usePicture ? null : pendingCommentPicture;
if (usePicture) {
Activity activity = fragment.getActivity();
if (activity != null)
activity.getIntent().removeExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
}
pictureButton.setImageResource(cameraButton);
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMMENT);
@ -554,6 +569,10 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
CameraResultCallback callback = new CameraResultCallback() {
@Override
public void handleCameraResult(Bitmap bitmap) {
Activity activity = fragment.getActivity();
if (activity != null) {
activity.getIntent().putExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS, bitmap);
}
pendingCommentPicture = bitmap;
pictureButton.setImageBitmap(pendingCommentPicture);
commentField.requestFocus();

@ -142,6 +142,10 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
*/
private static final String TASK_REMOTE_ID = "task_remote_id"; //$NON-NLS-1$
/**
* Token for saving a bitmap in the intent before it has been added with a comment
*/
public static final String TOKEN_PICTURE_IN_PROGRESS = "picture_in_progress"; //$NON-NLS-1$
/**
* Tab to start on
@ -876,7 +880,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
tla.refreshTaskList();
}
getActivity().getIntent().removeExtra(TaskListActivity.OPEN_TASK);
removeExtrasFromIntent(getActivity().getIntent());
shouldSaveState = false;
getActivity().onBackPressed();
@ -913,6 +917,17 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
}
}
/**
* Helper to remove task edit specific info from activity intent
* @param intent
*/
public static void removeExtrasFromIntent(Intent intent) {
if (intent != null) {
intent.removeExtra(TaskListActivity.OPEN_TASK);
intent.removeExtra(TOKEN_PICTURE_IN_PROGRESS);
}
}
/*
* ======================================================================
* ======================================================= event handlers
@ -962,7 +977,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
}
}
getActivity().getIntent().removeExtra(TaskListActivity.OPEN_TASK);
removeExtrasFromIntent(getActivity().getIntent());
showCancelToast();
getActivity().onBackPressed();
}

@ -379,7 +379,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
return true;
}
getIntent().removeExtra(OPEN_TASK);
TaskEditFragment.removeExtrasFromIntent(getIntent());
TaskEditFragment tef = getTaskEditFragment();
if (tef != null)
onBackPressed();

Loading…
Cancel
Save