Distinguish request and result codes of different activities.

This commit is contained in:
akwizgran
2014-02-05 15:03:28 +00:00
parent 8d850b290c
commit 843ad55163
8 changed files with 53 additions and 43 deletions

View File

@@ -6,8 +6,7 @@ import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.groups.ReadGroupPostActivity.RESULT_NEXT;
import static org.briarproject.android.groups.ReadGroupPostActivity.RESULT_PREV;
import static org.briarproject.android.groups.ReadGroupPostActivity.RESULT_PREV_NEXT;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
@@ -49,6 +48,7 @@ import android.widget.ListView;
public class GroupActivity extends RoboActivity implements EventListener,
OnClickListener, OnItemClickListener {
private static final int REQUEST_READ_POST = 2;
private static final Logger LOG =
Logger.getLogger(GroupActivity.class.getName());
@@ -170,12 +170,10 @@ OnClickListener, OnItemClickListener {
@Override
public void onActivityResult(int request, int result, Intent data) {
if(result == RESULT_PREV) {
int position = request - 1;
if(position >= 0 && position < adapter.getCount())
displayMessage(position);
} else if(result == RESULT_NEXT) {
int position = request + 1;
super.onActivityResult(request, result, data);
if(request == REQUEST_READ_POST && result == RESULT_PREV_NEXT) {
int position = data.getIntExtra("briar.POSITION", -1);
if(position == -1) throw new IllegalStateException();
if(position >= 0 && position < adapter.getCount())
displayMessage(position);
}
@@ -227,13 +225,11 @@ OnClickListener, OnItemClickListener {
i.putExtra("briar.GROUP_NAME", groupName);
i.putExtra("briar.MESSAGE_ID", item.getId().getBytes());
Author author = item.getAuthor();
if(author != null) {
i.putExtra("briar.AUTHOR_ID", author.getId().getBytes());
i.putExtra("briar.AUTHOR_NAME", author.getName());
}
if(author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
i.putExtra("briar.AUTHOR_STATUS", item.getAuthorStatus().name());
i.putExtra("briar.CONTENT_TYPE", item.getContentType());
i.putExtra("briar.TIMESTAMP", item.getTimestamp());
startActivityForResult(i, position);
i.putExtra("briar.POSITION", position);
startActivityForResult(i, REQUEST_READ_POST);
}
}

View File

@@ -47,8 +47,7 @@ public class ReadGroupPostActivity extends RoboActivity
implements OnClickListener {
static final int RESULT_REPLY = RESULT_FIRST_USER;
static final int RESULT_PREV = RESULT_FIRST_USER + 1;
static final int RESULT_NEXT = RESULT_FIRST_USER + 2;
static final int RESULT_PREV_NEXT = RESULT_FIRST_USER + 1;
private static final Logger LOG =
Logger.getLogger(ReadGroupPostActivity.class.getName());
@@ -58,6 +57,7 @@ implements OnClickListener {
private ImageButton readButton = null, prevButton = null, nextButton = null;
private ImageButton replyButton = null;
private TextView content = null;
private int position = -1;
// Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db;
@@ -84,6 +84,8 @@ implements OnClickListener {
if(contentType == null) throw new IllegalStateException();
timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
if(timestamp == -1) throw new IllegalStateException();
position = i.getIntExtra("briar.POSITION", -1);
if(position == -1) throw new IllegalStateException();
String authorName = i.getStringExtra("briar.AUTHOR_NAME");
String s = i.getStringExtra("briar.AUTHOR_STATUS");
if(s == null) throw new IllegalStateException();
@@ -258,10 +260,14 @@ implements OnClickListener {
if(view == readButton) {
setReadInDatabase(!read);
} else if(view == prevButton) {
setResult(RESULT_PREV);
Intent i = new Intent();
i.putExtra("briar.POSITION", position - 1);
setResult(RESULT_PREV_NEXT, i);
finish();
} else if(view == nextButton) {
setResult(RESULT_NEXT);
Intent i = new Intent();
i.putExtra("briar.POSITION", position + 1);
setResult(RESULT_PREV_NEXT, i);
finish();
} else if(view == replyButton) {
Intent i = new Intent(this, WriteGroupPostActivity.class);

View File

@@ -61,6 +61,7 @@ import android.widget.Toast;
public class WriteGroupPostActivity extends RoboActivity
implements OnItemSelectedListener, OnClickListener {
private static final int REQUEST_CREATE_IDENTITY = 2;
private static final Logger LOG =
Logger.getLogger(WriteGroupPostActivity.class.getName());
@@ -219,12 +220,13 @@ implements OnItemSelectedListener, OnClickListener {
@Override
protected void onActivityResult(int request, int result, Intent data) {
// This is the result of CreateIdentityActivity
if(result == RESULT_CANCELED) return;
byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
if(b == null) throw new IllegalStateException();
localAuthorId = new AuthorId(b);
loadAuthorsAndGroup();
super.onActivityResult(request, result, data);
if(request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
if(b == null) throw new IllegalStateException();
localAuthorId = new AuthorId(b);
loadAuthorsAndGroup();
}
}
public void onItemSelected(AdapterView<?> parent, View view, int position,
@@ -237,7 +239,7 @@ implements OnItemSelectedListener, OnClickListener {
localAuthor = null;
localAuthorId = null;
Intent i = new Intent(this, CreateIdentityActivity.class);
startActivityForResult(i, 0);
startActivityForResult(i, REQUEST_CREATE_IDENTITY);
} else {
localAuthor = item.getLocalAuthor();
localAuthorId = localAuthor.getId();