mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Make final copies of non-volatile fields when passing to other threads.
This commit is contained in:
@@ -88,6 +88,7 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
|
||||
|
||||
// Add some fake contacts to the database in a background thread
|
||||
// FIXME: Remove this
|
||||
final DatabaseComponent db = this.db;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
@@ -137,6 +138,7 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
|
||||
}
|
||||
|
||||
private void reloadContactList() {
|
||||
final DatabaseComponent db = this.db;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
@@ -217,6 +217,7 @@ implements InvitationListener {
|
||||
}
|
||||
|
||||
void addContactAndFinish(final String nickname) {
|
||||
final DatabaseComponent db = this.db;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
@@ -121,6 +121,7 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
||||
}
|
||||
|
||||
private void reloadMessageHeaders() {
|
||||
final DatabaseComponent db = this.db;
|
||||
final ContactId contactId = this.contactId;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
@@ -93,6 +93,8 @@ implements OnClickListener, DatabaseListener {
|
||||
|
||||
// Add some fake messages to the database in a background thread
|
||||
// FIXME: Remove this
|
||||
final DatabaseComponent db = this.db;
|
||||
final MessageFactory messageFactory = this.messageFactory;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
@@ -183,6 +185,7 @@ implements OnClickListener, DatabaseListener {
|
||||
}
|
||||
|
||||
private void reloadMessageHeaders() {
|
||||
final DatabaseComponent db = this.db;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
@@ -89,27 +89,7 @@ implements OnClickListener {
|
||||
} else {
|
||||
starred = i.getBooleanExtra("net.sf.briar.STARRED", false);
|
||||
read = false;
|
||||
final MessageId id = messageId;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
serviceConnection.waitForStartup();
|
||||
db.setReadFlag(id, true);
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
setRead(true);
|
||||
}
|
||||
});
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Interrupted while waiting for service");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
setReadInDatabase(true);
|
||||
}
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
@@ -204,9 +184,40 @@ implements OnClickListener {
|
||||
serviceConnection, 0);
|
||||
}
|
||||
|
||||
private void loadMessageBody() {
|
||||
private void setReadInDatabase(final boolean read) {
|
||||
final DatabaseComponent db = this.db;
|
||||
final MessageId messageId = this.messageId;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
serviceConnection.waitForStartup();
|
||||
db.setReadFlag(messageId, read);
|
||||
setReadInUi(read);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Interrupted while waiting for service");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setReadInUi(final boolean read) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ReadMessageActivity.this.read = read;
|
||||
if(read) readButton.setImageResource(R.drawable.content_unread);
|
||||
else readButton.setImageResource(R.drawable.content_read);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadMessageBody() {
|
||||
final DatabaseComponent db = this.db;
|
||||
final MessageId messageId = this.messageId;
|
||||
final TextView content = this.content;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
@@ -247,28 +258,7 @@ implements OnClickListener {
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == readButton) {
|
||||
final MessageId messageId = this.messageId;
|
||||
final boolean read = !this.read;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
serviceConnection.waitForStartup();
|
||||
db.setReadFlag(messageId, read);
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
setRead(read);
|
||||
}
|
||||
});
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Interrupted while waiting for service");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
setReadInDatabase(!read);
|
||||
} else if(view == prevButton) {
|
||||
setResult(RESULT_PREV);
|
||||
finish();
|
||||
@@ -284,10 +274,4 @@ implements OnClickListener {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void setRead(boolean read) {
|
||||
this.read = read;
|
||||
if(read) readButton.setImageResource(R.drawable.content_unread);
|
||||
else readButton.setImageResource(R.drawable.content_read);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ implements OnClickListener, OnItemSelectedListener {
|
||||
private ContactId contactId = null;
|
||||
private MessageId parentId = null;
|
||||
private ContactNameSpinnerAdapter adapter = null;
|
||||
private Spinner spinner = null;
|
||||
private ImageButton sendButton = null;
|
||||
private EditText content = null;
|
||||
|
||||
@@ -88,32 +89,10 @@ implements OnClickListener, OnItemSelectedListener {
|
||||
actionBar.addView(to);
|
||||
|
||||
adapter = new ContactNameSpinnerAdapter(this);
|
||||
final Spinner spinner = new Spinner(this);
|
||||
spinner = new Spinner(this);
|
||||
spinner.setAdapter(adapter);
|
||||
spinner.setOnItemSelectedListener(this);
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
serviceConnection.waitForStartup();
|
||||
final Collection<Contact> contacts = db.getContacts();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
for(Contact c : contacts) {
|
||||
if(c.getId().equals(contactId))
|
||||
spinner.setSelection(adapter.getCount());
|
||||
adapter.add(c);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
LOG.info("Interrupted while waiting for service");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
loadContactNames();
|
||||
actionBar.addView(spinner);
|
||||
|
||||
actionBar.addView(new HorizontalSpace(this));
|
||||
@@ -141,6 +120,33 @@ implements OnClickListener, OnItemSelectedListener {
|
||||
serviceConnection, 0);
|
||||
}
|
||||
|
||||
private void loadContactNames() {
|
||||
final DatabaseComponent db = this.db;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
serviceConnection.waitForStartup();
|
||||
final Collection<Contact> contacts = db.getContacts();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
for(Contact c : contacts) {
|
||||
if(c.getId().equals(contactId))
|
||||
spinner.setSelection(adapter.getCount());
|
||||
adapter.add(c);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
LOG.info("Interrupted while waiting for service");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle state) {
|
||||
Parcelable p = content.onSaveInstanceState();
|
||||
@@ -156,16 +162,20 @@ implements OnClickListener, OnItemSelectedListener {
|
||||
|
||||
public void onClick(View view) {
|
||||
if(contactId == null) throw new IllegalStateException();
|
||||
final Message m;
|
||||
try {
|
||||
byte[] body = content.getText().toString().getBytes("UTF-8");
|
||||
m = messageFactory.createPrivateMessage(parentId, "text/plain",
|
||||
body);
|
||||
storeMessage(messageFactory.createPrivateMessage(parentId,
|
||||
"text/plain", body));
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch(GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void storeMessage(final Message m) {
|
||||
final DatabaseComponent db = this.db;
|
||||
final ContactId contactId = this.contactId;
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
@@ -182,7 +192,6 @@ implements OnClickListener, OnItemSelectedListener {
|
||||
}
|
||||
}
|
||||
});
|
||||
finish();
|
||||
}
|
||||
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||
|
||||
Reference in New Issue
Block a user