Skip to content

Commit

Permalink
Fix editing comments from two-pane view: start edit activity from
Browse files Browse the repository at this point in the history
fragment rather than from activity
  • Loading branch information
jeisfeld committed May 19, 2014
1 parent cbbf270 commit b25cdc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,4 @@ protected DisplayOneFragment createFragment() {
return fragment;
}

private DisplayOneOverlayFragment getFragment() {
return (DisplayOneOverlayFragment) fragment;
}

/**
* When getting the response from the comment update, update the name field in the display.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case EditCommentActivity.REQUEST_CODE:
if (resultCode == RESULT_OK) {
CharSequence comment = EditCommentActivity.getResult(resultCode, data);
getFragment().storeComment(comment.toString());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.eisfeldj.augendiagnose.activities;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import de.eisfeldj.augendiagnose.R;
Expand All @@ -18,15 +20,16 @@ public class EditCommentActivity extends Activity implements EditCommentCallback
private static final String FRAGMENT_TAG = "FRAGMENT_TAG";

/**
* Static helper method to start the activity, passing the old value of the text
* Static helper method to start the activity from a fragment, passing the old value of the text
*
* @param context
* @param fragment
* @param resource
*/
public static void startActivity(Activity activity, String text) {
Intent intent = new Intent(activity, EditCommentActivity.class);
public static void startActivity(Context context, Fragment fragment, String text) {
Intent intent = new Intent(context, EditCommentActivity.class);
intent.putExtra(STRING_EXTRA_TEXT, text);
activity.startActivityForResult(intent, REQUEST_CODE);
fragment.startActivityForResult(intent, REQUEST_CODE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.eisfeldj.augendiagnose.fragments;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
Expand Down Expand Up @@ -211,7 +213,7 @@ public boolean onContextItemSelected(MenuItem item) {
updateDefaultShowUtilities(newShowUtilities);
return true;
case R.id.action_edit_comment:
EditCommentActivity.startActivity(getActivity(), imageView.getMetadata().comment);
EditCommentActivity.startActivity(getActivity(), this, imageView.getMetadata().comment);
return true;
case R.id.action_store_brightness:
imageView.storeBrightnessContrast(false);
Expand Down Expand Up @@ -326,6 +328,20 @@ public void onSaveInstanceState(Bundle outState) {
outState.putBoolean("showUtilities", showUtilities);
}

/**
* When getting the response from the comment update, update the name field in the display.
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case EditCommentActivity.REQUEST_CODE:
if (resultCode == Activity.RESULT_OK) {
CharSequence comment = EditCommentActivity.getResult(resultCode, data);
storeComment(comment.toString());
}
}
}

// Implementation of GuiElementUpdater

@Override
Expand Down

0 comments on commit b25cdc0

Please sign in to comment.