Skip to content
Snippets Groups Projects
Commit 6b5229a3 authored by akwizgran's avatar akwizgran
Browse files

Don't try to load a group before subscribing to it.

parent 9e17db5d
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@
<string name="groups_title">Groups</string>
<plurals name="groups_available">
<item quantity="one">%1$d group available from contacts</item>
<item quantity="two">$1$d groups available from contacts</item>
<item quantity="other">$1$d groups available from contacts</item>
</plurals>
<string name="no_posts">No posts</string>
<string name="subscribe_to_this_group">Subscribe to this group</string>
......@@ -71,7 +71,7 @@
<string name="blogs_title">Blogs</string>
<plurals name="blogs_available">
<item quantity="one">%1$d blog available from contacts</item>
<item quantity="two">$1$d blogs available from contacts</item>
<item quantity="other">$1$d blogs available from contacts</item>
</plurals>
<string name="manage_subscriptions_title">Manage Subscriptions</string>
<string name="subscribed_all">Subscribed, shared with all contacts</string>
......
......@@ -26,6 +26,7 @@ import net.sf.briar.api.ContactId;
import net.sf.briar.api.android.DatabaseUiExecutor;
import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.DbException;
import net.sf.briar.api.messaging.Group;
import net.sf.briar.api.messaging.GroupId;
import android.content.Intent;
import android.os.Bundle;
......@@ -60,7 +61,7 @@ SelectContactsDialog.Listener {
// Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db;
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
private volatile GroupId groupId = null;
private volatile Group group = null;
private volatile Collection<ContactId> selected = Collections.emptyList();
@Override
......@@ -70,10 +71,13 @@ SelectContactsDialog.Listener {
Intent i = getIntent();
byte[] b = i.getByteArrayExtra("net.sf.briar.GROUP_ID");
if(b == null) throw new IllegalStateException();
groupId = new GroupId(b);
String groupName = i.getStringExtra("net.sf.briar.GROUP_NAME");
if(groupName == null) throw new IllegalArgumentException();
setTitle(groupName);
GroupId id = new GroupId(b);
String name = i.getStringExtra("net.sf.briar.GROUP_NAME");
if(name == null) throw new IllegalStateException();
setTitle(name);
byte[] publicKey = i.getByteArrayExtra("net.sf.briar.PUBLIC_KEY");
if(publicKey == null) throw new IllegalStateException();
group = new Group(id, name, publicKey);
wasSubscribed = i.getBooleanExtra("net.sf.briar.SUBSCRIBED", false);
boolean all = i.getBooleanExtra("net.sf.briar.VISIBLE_TO_ALL", false);
......@@ -90,17 +94,18 @@ SelectContactsDialog.Listener {
radioGroup = new RadioGroup(this);
radioGroup.setOrientation(VERTICAL);
radioGroup.setEnabled(wasSubscribed);
visibleToAll = new RadioButton(this);
visibleToAll.setId(1);
visibleToAll.setText(R.string.blog_visible_to_all);
visibleToAll.setEnabled(wasSubscribed);
visibleToAll.setOnClickListener(this);
radioGroup.addView(visibleToAll);
visibleToSome = new RadioButton(this);
visibleToSome.setId(2);
visibleToSome.setText(R.string.blog_visible_to_some);
visibleToSome.setEnabled(wasSubscribed);
visibleToSome.setOnClickListener(this);
radioGroup.addView(visibleToSome);
......@@ -135,7 +140,9 @@ SelectContactsDialog.Listener {
public void onClick(View view) {
if(view == subscribeCheckBox) {
radioGroup.setEnabled(subscribeCheckBox.isChecked());
boolean subscribe = subscribeCheckBox.isChecked();
visibleToAll.setEnabled(subscribe);
visibleToSome.setEnabled(subscribe);
} else if(view == visibleToSome) {
loadContacts();
} else if(view == doneButton) {
......@@ -203,11 +210,11 @@ SelectContactsDialog.Listener {
serviceConnection.waitForStartup();
long now = System.currentTimeMillis();
if(subscribe) {
if(!wasSubscribed) db.subscribe(db.getGroup(groupId));
db.setVisibleToAll(groupId, all);
if(!all) db.setVisibility(groupId, visible);
if(!wasSubscribed) db.subscribe(group);
db.setVisibleToAll(group.getId(), all);
if(!all) db.setVisibility(group.getId(), visible);
} else if(wasSubscribed) {
db.unsubscribe(db.getGroup(groupId));
db.unsubscribe(group);
}
long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO))
......
......@@ -14,8 +14,8 @@ import java.util.logging.Logger;
import net.sf.briar.android.BriarFragmentActivity;
import net.sf.briar.android.BriarService;
import net.sf.briar.android.ManageGroupsAdapter;
import net.sf.briar.android.BriarService.BriarServiceConnection;
import net.sf.briar.android.ManageGroupsAdapter;
import net.sf.briar.api.android.DatabaseUiExecutor;
import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.DbException;
......@@ -147,9 +147,11 @@ implements DatabaseListener, OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
GroupStatus item = adapter.getItem(position);
Group g = item.getGroup();
Intent i = new Intent(this, ConfigureBlogActivity.class);
i.putExtra("net.sf.briar.GROUP_ID", item.getGroup().getId().getBytes());
i.putExtra("net.sf.briar.GROUP_NAME", item.getGroup().getName());
i.putExtra("net.sf.briar.GROUP_ID", g.getId().getBytes());
i.putExtra("net.sf.briar.GROUP_NAME", g.getName());
i.putExtra("net.sf.briar.PUBLIC_KEY", g.getPublicKey());
i.putExtra("net.sf.briar.SUBSCRIBED", item.isSubscribed());
i.putExtra("net.sf.briar.VISIBLE_TO_ALL", item.isVisibleToAll());
startActivity(i);
......
......@@ -26,6 +26,7 @@ import net.sf.briar.api.ContactId;
import net.sf.briar.api.android.DatabaseUiExecutor;
import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.DbException;
import net.sf.briar.api.messaging.Group;
import net.sf.briar.api.messaging.GroupId;
import android.content.Intent;
import android.os.Bundle;
......@@ -60,7 +61,7 @@ SelectContactsDialog.Listener {
// Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db;
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
private volatile GroupId groupId = null;
private volatile Group group = null;
private volatile Collection<ContactId> selected = Collections.emptyList();
@Override
......@@ -70,10 +71,11 @@ SelectContactsDialog.Listener {
Intent i = getIntent();
byte[] b = i.getByteArrayExtra("net.sf.briar.GROUP_ID");
if(b == null) throw new IllegalStateException();
groupId = new GroupId(b);
String groupName = i.getStringExtra("net.sf.briar.GROUP_NAME");
if(groupName == null) throw new IllegalArgumentException();
setTitle(groupName);
GroupId id = new GroupId(b);
String name = i.getStringExtra("net.sf.briar.GROUP_NAME");
if(name == null) throw new IllegalStateException();
setTitle(name);
group = new Group(id, name, null);
wasSubscribed = i.getBooleanExtra("net.sf.briar.SUBSCRIBED", false);
boolean all = i.getBooleanExtra("net.sf.briar.VISIBLE_TO_ALL", false);
......@@ -90,17 +92,18 @@ SelectContactsDialog.Listener {
radioGroup = new RadioGroup(this);
radioGroup.setOrientation(VERTICAL);
radioGroup.setEnabled(wasSubscribed);
visibleToAll = new RadioButton(this);
visibleToAll.setId(1);
visibleToAll.setText(R.string.group_visible_to_all);
visibleToAll.setEnabled(wasSubscribed);
visibleToAll.setOnClickListener(this);
radioGroup.addView(visibleToAll);
visibleToSome = new RadioButton(this);
visibleToSome.setId(2);
visibleToSome.setText(R.string.group_visible_to_some);
visibleToSome.setEnabled(wasSubscribed);
visibleToSome.setOnClickListener(this);
radioGroup.addView(visibleToSome);
......@@ -135,7 +138,9 @@ SelectContactsDialog.Listener {
public void onClick(View view) {
if(view == subscribeCheckBox) {
radioGroup.setEnabled(subscribeCheckBox.isChecked());
boolean subscribe = subscribeCheckBox.isChecked();
visibleToAll.setEnabled(subscribe);
visibleToSome.setEnabled(subscribe);
} else if(view == visibleToSome) {
loadContacts();
} else if(view == doneButton) {
......@@ -203,11 +208,11 @@ SelectContactsDialog.Listener {
serviceConnection.waitForStartup();
long now = System.currentTimeMillis();
if(subscribe) {
if(!wasSubscribed) db.subscribe(db.getGroup(groupId));
db.setVisibleToAll(groupId, all);
if(!all) db.setVisibility(groupId, visible);
if(!wasSubscribed) db.subscribe(group);
db.setVisibleToAll(group.getId(), all);
if(!all) db.setVisibility(group.getId(), visible);
} else if(wasSubscribed) {
db.unsubscribe(db.getGroup(groupId));
db.unsubscribe(group);
}
long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO))
......
......@@ -147,9 +147,10 @@ implements DatabaseListener, OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
GroupStatus item = adapter.getItem(position);
Group g = item.getGroup();
Intent i = new Intent(this, ConfigureGroupActivity.class);
i.putExtra("net.sf.briar.GROUP_ID", item.getGroup().getId().getBytes());
i.putExtra("net.sf.briar.GROUP_NAME", item.getGroup().getName());
i.putExtra("net.sf.briar.GROUP_ID", g.getId().getBytes());
i.putExtra("net.sf.briar.GROUP_NAME", g.getName());
i.putExtra("net.sf.briar.SUBSCRIBED", item.isSubscribed());
i.putExtra("net.sf.briar.VISIBLE_TO_ALL", item.isVisibleToAll());
startActivity(i);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment