mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Use Inheritence for shared Forum and Blog Sharing Code
This commit is contained in:
@@ -6,14 +6,11 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.contact.ContactListItem;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.api.blogs.BlogSharingManager;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
@@ -26,11 +23,8 @@ import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.sharing.ShareActivity.BLOG;
|
||||
import static org.briarproject.android.sharing.ShareActivity.FORUM;
|
||||
import static org.briarproject.android.sharing.ShareActivity.SHAREABLE;
|
||||
|
||||
public class SharingStatusActivity extends BriarActivity {
|
||||
abstract class SharingStatusActivity extends BriarActivity {
|
||||
|
||||
private GroupId groupId;
|
||||
private BriarRecyclerView sharedByList, sharedWithList;
|
||||
@@ -38,28 +32,21 @@ public class SharingStatusActivity extends BriarActivity {
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile BlogSharingManager blogSharingManager;
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
|
||||
public final static String TAG = "ForumSharingStatusActivity";
|
||||
public final static String TAG = SharingStatusActivity.class.getName();
|
||||
private static final Logger LOG = Logger.getLogger(TAG);
|
||||
private int shareable;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_forum_sharing_status);
|
||||
setContentView(R.layout.activity_sharing_status);
|
||||
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||
if (b == null) throw new IllegalStateException("No GroupId");
|
||||
groupId = new GroupId(b);
|
||||
shareable = i.getIntExtra(SHAREABLE, 0);
|
||||
if (shareable == 0) throw new IllegalStateException("No Shareable");
|
||||
|
||||
sharedByList = (BriarRecyclerView) findViewById(R.id.sharedByView);
|
||||
sharedByAdapter = new SharingStatusAdapter(this);
|
||||
@@ -94,9 +81,18 @@ public class SharingStatusActivity extends BriarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectActivity(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
/**
|
||||
* This must only be called from the DbThread
|
||||
*/
|
||||
abstract protected Collection<Contact> getSharedWith() throws DbException;
|
||||
|
||||
/**
|
||||
* This must only be called from the DbThread
|
||||
*/
|
||||
abstract protected Collection<Contact> getSharedBy() throws DbException;
|
||||
|
||||
protected GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
private void loadSharedBy() {
|
||||
@@ -158,36 +154,6 @@ public class SharingStatusActivity extends BriarActivity {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This must only be called from the DbThread
|
||||
*/
|
||||
private Collection<Contact> getSharedWith() throws DbException {
|
||||
Collection<Contact> contacts;
|
||||
if (shareable == FORUM) {
|
||||
contacts = forumSharingManager.getSharedWith(groupId);
|
||||
} else if (shareable == BLOG) {
|
||||
contacts = blogSharingManager.getSharedWith(groupId);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown Shareable");
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* This must only be called from the DbThread
|
||||
*/
|
||||
private Collection<Contact> getSharedBy() throws DbException {
|
||||
Collection<Contact> contacts;
|
||||
if (shareable == FORUM) {
|
||||
contacts = forumSharingManager.getSharedBy(groupId);
|
||||
} else if (shareable == BLOG) {
|
||||
contacts = blogSharingManager.getSharedBy(groupId);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown Shareable");
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private void displaySharedWith(final List<ContactListItem> contacts) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user