mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Create GroupDissolvedEvent and react to it
Also react to incoming group invitations
This commit is contained in:
@@ -4,6 +4,7 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.android.threaded.ThreadListController.ThreadListListener;
|
||||
import org.briarproject.android.threaded.ThreadListControllerImpl;
|
||||
import org.briarproject.api.clients.MessageTracker.GroupCount;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
@@ -32,7 +33,7 @@ import static java.lang.Math.max;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public class ForumControllerImpl
|
||||
extends ThreadListControllerImpl<Forum, ForumItem, ForumPostHeader, ForumPost>
|
||||
extends ThreadListControllerImpl<Forum, ForumItem, ForumPostHeader, ForumPost, ThreadListListener<ForumPostHeader>>
|
||||
implements ForumController {
|
||||
|
||||
private static final Logger LOG =
|
||||
|
||||
@@ -18,8 +18,9 @@ import android.view.MenuItem;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.controller.handler.UiResultExceptionHandler;
|
||||
import org.briarproject.android.privategroup.memberlist.GroupMemberListActivity;
|
||||
import org.briarproject.android.privategroup.conversation.GroupController.GroupListener;
|
||||
import org.briarproject.android.privategroup.creation.GroupInviteActivity;
|
||||
import org.briarproject.android.privategroup.memberlist.GroupMemberListActivity;
|
||||
import org.briarproject.android.threaded.ThreadListActivity;
|
||||
import org.briarproject.android.threaded.ThreadListController;
|
||||
import org.briarproject.api.db.DbException;
|
||||
@@ -29,11 +30,12 @@ import org.briarproject.api.privategroup.PrivateGroup;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
|
||||
import static android.view.View.GONE;
|
||||
import static org.briarproject.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
|
||||
|
||||
public class GroupActivity extends
|
||||
ThreadListActivity<PrivateGroup, GroupMessageItem, GroupMessageHeader>
|
||||
implements OnClickListener {
|
||||
implements GroupListener, OnClickListener {
|
||||
|
||||
private final static int REQUEST_INVITE = 2;
|
||||
|
||||
@@ -200,6 +202,12 @@ public class GroupActivity extends
|
||||
if (writeMenuItem != null) writeMenuItem.setVisible(enabled);
|
||||
textInput.setSendButtonEnabled(enabled);
|
||||
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
|
||||
|
||||
if (!enabled) {
|
||||
textInput.setVisibility(GONE);
|
||||
if (textInput.isKeyboardOpen()) textInput.hideSoftKeyboard();
|
||||
if (textInput.isEmojiDrawerOpen()) textInput.hideEmojiDrawer();
|
||||
}
|
||||
}
|
||||
|
||||
private void showMenuItems() {
|
||||
@@ -254,4 +262,15 @@ public class GroupActivity extends
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupDissolved() {
|
||||
setGroupEnabled(false);
|
||||
AlertDialog.Builder builder =
|
||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||
builder.setTitle(getString(R.string.groups_dissolved_dialog_title));
|
||||
builder.setMessage(getString(R.string.groups_dissolved_dialog_message));
|
||||
builder.setNeutralButton(R.string.ok, null);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.briarproject.android.privategroup.conversation;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.android.threaded.ThreadListController;
|
||||
import org.briarproject.api.db.DbException;
|
||||
@@ -16,4 +18,9 @@ public interface GroupController
|
||||
void isDissolved(
|
||||
ResultExceptionHandler<Boolean, DbException> handler);
|
||||
|
||||
interface GroupListener extends ThreadListListener<GroupMessageHeader> {
|
||||
@UiThread
|
||||
void onGroupDissolved();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.android.privategroup.conversation.GroupController.GroupListener;
|
||||
import org.briarproject.android.threaded.ThreadListControllerImpl;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.GroupDissolvedEvent;
|
||||
import org.briarproject.api.event.GroupMessageAddedEvent;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
@@ -34,7 +36,7 @@ import static java.lang.Math.max;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public class GroupControllerImpl extends
|
||||
ThreadListControllerImpl<PrivateGroup, GroupMessageItem, GroupMessageHeader, GroupMessage>
|
||||
ThreadListControllerImpl<PrivateGroup, GroupMessageItem, GroupMessageHeader, GroupMessage, GroupListener>
|
||||
implements GroupController {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -78,6 +80,16 @@ public class GroupControllerImpl extends
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (e instanceof GroupDissolvedEvent) {
|
||||
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
||||
if (getGroupId().equals(g.getGroupId())) {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onGroupDissolved();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +70,8 @@ class GroupItem {
|
||||
return dissolved;
|
||||
}
|
||||
|
||||
void setDissolved() {
|
||||
dissolved = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,11 +38,18 @@ public interface GroupListController extends DbController {
|
||||
@UiThread
|
||||
void onGroupMessageAdded(GroupMessageHeader header);
|
||||
|
||||
@UiThread
|
||||
void onGroupInvitationReceived();
|
||||
|
||||
@UiThread
|
||||
void onGroupAdded(GroupId groupId);
|
||||
|
||||
@UiThread
|
||||
void onGroupRemoved(GroupId groupId);
|
||||
|
||||
@UiThread
|
||||
void onGroupDissolved(GroupId groupId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.GroupAddedEvent;
|
||||
import org.briarproject.api.event.GroupDissolvedEvent;
|
||||
import org.briarproject.api.event.GroupInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.GroupMessageAddedEvent;
|
||||
import org.briarproject.api.event.GroupRemovedEvent;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
@@ -89,6 +91,10 @@ public class GroupListControllerImpl extends DbControllerImpl
|
||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||
LOG.info("Private group message added");
|
||||
onGroupMessageAdded(g.getHeader());
|
||||
} else if (e instanceof GroupInvitationReceivedEvent) {
|
||||
GroupInvitationReceivedEvent g = (GroupInvitationReceivedEvent) e;
|
||||
LOG.info("Private group invitation received");
|
||||
onGroupInvitationReceived();
|
||||
} else if (e instanceof GroupAddedEvent) {
|
||||
GroupAddedEvent g = (GroupAddedEvent) e;
|
||||
ClientId id = g.getGroup().getClientId();
|
||||
@@ -103,6 +109,10 @@ public class GroupListControllerImpl extends DbControllerImpl
|
||||
LOG.info("Private group removed");
|
||||
onGroupRemoved(g.getGroup().getId());
|
||||
}
|
||||
} else if (e instanceof GroupDissolvedEvent) {
|
||||
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
||||
LOG.info("Private group dissolved");
|
||||
onGroupDissolved(g.getGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +125,15 @@ public class GroupListControllerImpl extends DbControllerImpl
|
||||
});
|
||||
}
|
||||
|
||||
private void onGroupInvitationReceived() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onGroupInvitationReceived();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onGroupAdded(final GroupId g) {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
@@ -133,6 +152,15 @@ public class GroupListControllerImpl extends DbControllerImpl
|
||||
});
|
||||
}
|
||||
|
||||
private void onGroupDissolved(final GroupId g) {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onGroupDissolved(g);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadGroups(
|
||||
final ResultExceptionHandler<Collection<GroupItem>, DbException> handler) {
|
||||
|
||||
@@ -151,6 +151,11 @@ public class GroupListFragment extends BaseFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupInvitationReceived() {
|
||||
loadAvailableGroups();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void onGroupAdded(GroupId groupId) {
|
||||
@@ -164,6 +169,17 @@ public class GroupListFragment extends BaseFragment implements
|
||||
adapter.removeItem(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupDissolved(GroupId groupId) {
|
||||
adapter.incrementRevision();
|
||||
int position = adapter.findItemPosition(groupId);
|
||||
GroupItem item = adapter.getItemAt(position);
|
||||
if (item != null) {
|
||||
item.setDissolved();
|
||||
adapter.updateItemAt(position, item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.support.annotation.CallSuper;
|
||||
import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.controller.DbControllerImpl;
|
||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.android.threaded.ThreadListController.ThreadListListener;
|
||||
import org.briarproject.api.clients.ThreadedMessage;
|
||||
import org.briarproject.api.clients.NamedGroup;
|
||||
import org.briarproject.api.clients.PostHeader;
|
||||
@@ -34,7 +35,7 @@ import java.util.logging.Logger;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends ThreadItem, H extends PostHeader, M extends ThreadedMessage>
|
||||
public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends ThreadItem, H extends PostHeader, M extends ThreadedMessage, L extends ThreadListListener<H>>
|
||||
extends DbControllerImpl
|
||||
implements ThreadListController<G, I, H>, EventListener {
|
||||
|
||||
@@ -49,7 +50,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
protected final AndroidNotificationManager notificationManager;
|
||||
protected final Executor cryptoExecutor;
|
||||
protected final Clock clock;
|
||||
protected volatile ThreadListListener<H> listener;
|
||||
protected volatile L listener;
|
||||
|
||||
protected ThreadListControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||
@@ -72,7 +73,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onActivityCreate(Activity activity) {
|
||||
listener = (ThreadListListener<H>) activity;
|
||||
listener = (L) activity;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
|
||||
Reference in New Issue
Block a user