mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Introduce SharingStatus to report more fine-grained status
This commit is contained in:
@@ -12,7 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
@NotNullByDefault
|
||||
public abstract class BaseContactSelectorAdapter<I extends SelectableContactItem, H extends ContactItemViewHolder<I>>
|
||||
public abstract class BaseContactSelectorAdapter<I extends BaseSelectableContactItem, H extends ContactItemViewHolder<I>>
|
||||
extends BaseContactListAdapter<I, H> {
|
||||
|
||||
public BaseContactSelectorAdapter(Context context, Class<I> c,
|
||||
@@ -24,7 +24,7 @@ public abstract class BaseContactSelectorAdapter<I extends SelectableContactItem
|
||||
Collection<ContactId> selected = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
SelectableContactItem item = items.get(i);
|
||||
BaseSelectableContactItem item = items.get(i);
|
||||
if (item.isSelected()) selected.add(item.getContact().getId());
|
||||
}
|
||||
return selected;
|
||||
|
||||
@@ -33,7 +33,7 @@ import static org.briarproject.briar.android.contactselection.ContactSelectorAct
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public abstract class BaseContactSelectorFragment<I extends SelectableContactItem, A extends BaseContactSelectorAdapter<I, ? extends ContactItemViewHolder<I>>>
|
||||
public abstract class BaseContactSelectorFragment<I extends BaseSelectableContactItem, A extends BaseContactSelectorAdapter<I, ? extends ContactItemViewHolder<I>>>
|
||||
extends BaseFragment
|
||||
implements OnContactClickListener<I> {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import static org.briarproject.briar.android.util.UiUtils.GREY_OUT;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
public class BaseSelectableContactHolder<I extends SelectableContactItem>
|
||||
public abstract class BaseSelectableContactHolder<I extends BaseSelectableContactItem>
|
||||
extends ContactItemViewHolder<I> {
|
||||
|
||||
private final CheckBox checkBox;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.briarproject.briar.android.contactselection;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.briar.android.contact.ContactItem;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
public abstract class BaseSelectableContactItem extends ContactItem {
|
||||
|
||||
private boolean selected;
|
||||
|
||||
public BaseSelectableContactItem(Contact contact, AuthorInfo authorInfo,
|
||||
boolean selected) {
|
||||
super(contact, authorInfo);
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
void toggleSelected() {
|
||||
selected = !selected;
|
||||
}
|
||||
|
||||
public abstract boolean isDisabled();
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.briarproject.nullsafety.NotNullByDefault;
|
||||
import java.util.Collection;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface ContactSelectorController<I extends SelectableContactItem>
|
||||
public interface ContactSelectorController<I extends BaseSelectableContactItem>
|
||||
extends DbController {
|
||||
|
||||
void loadContacts(GroupId g, Collection<ContactId> selection,
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.briarproject.briar.android.controller.DbControllerImpl;
|
||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.briar.api.identity.AuthorManager;
|
||||
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -53,10 +54,8 @@ public abstract class ContactSelectorControllerImpl
|
||||
AuthorInfo authorInfo = authorManager.getAuthorInfo(c);
|
||||
// was this contact already selected?
|
||||
boolean selected = selection.contains(c.getId());
|
||||
// can this contact be selected?
|
||||
boolean disabled = isDisabled(g, c);
|
||||
contacts.add(new SelectableContactItem(c, authorInfo,
|
||||
selected, disabled));
|
||||
selected, getSharingStatus(g, c)));
|
||||
}
|
||||
handler.onResult(contacts);
|
||||
} catch (DbException e) {
|
||||
@@ -67,7 +66,7 @@ public abstract class ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
protected abstract boolean isDisabled(GroupId g, Contact c)
|
||||
protected abstract SharingStatus getSharingStatus(GroupId g, Contact c)
|
||||
throws DbException;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,20 @@ package org.briarproject.briar.android.contactselection;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.INVITED;
|
||||
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.NOT_SUPPORTED;
|
||||
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHARING;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
@@ -27,6 +32,15 @@ class SelectableContactHolder
|
||||
super.bind(item, listener);
|
||||
|
||||
if (item.isDisabled()) {
|
||||
@StringRes int strRes;
|
||||
if (item.getSharingStatus() == SHARING) {
|
||||
strRes = R.string.forum_invitation_already_sharing;
|
||||
} else if (item.getSharingStatus() == INVITED) {
|
||||
strRes = R.string.forum_invitation_already_invited;
|
||||
} else if (item.getSharingStatus() == NOT_SUPPORTED) {
|
||||
strRes = R.string.forum_invitation_not_supported;
|
||||
} else throw new AssertionError("Unhandled SharingStatus");
|
||||
info.setText(strRes);
|
||||
info.setVisibility(VISIBLE);
|
||||
} else {
|
||||
info.setVisibility(GONE);
|
||||
|
||||
@@ -1,36 +1,33 @@
|
||||
package org.briarproject.briar.android.contactselection;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.briar.android.contact.ContactItem;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
public class SelectableContactItem extends ContactItem {
|
||||
public class SelectableContactItem extends BaseSelectableContactItem {
|
||||
|
||||
private boolean selected;
|
||||
private final boolean disabled;
|
||||
private final SharingStatus sharingStatus;
|
||||
|
||||
public SelectableContactItem(Contact contact, AuthorInfo authorInfo,
|
||||
boolean selected, boolean disabled) {
|
||||
super(contact, authorInfo);
|
||||
this.selected = selected;
|
||||
this.disabled = disabled;
|
||||
boolean selected, SharingStatus sharingStatus) {
|
||||
super(contact, authorInfo, selected);
|
||||
this.sharingStatus = sharingStatus;
|
||||
}
|
||||
|
||||
boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
void toggleSelected() {
|
||||
selected = !selected;
|
||||
public SharingStatus getSharingStatus() {
|
||||
return sharingStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
return sharingStatus != SHAREABLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
||||
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -140,8 +141,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDisabled(GroupId g, Contact c) throws DbException {
|
||||
return !groupInvitationManager.isInvitationAllowed(c, g);
|
||||
protected SharingStatus getSharingStatus(GroupId g, Contact c) throws DbException {
|
||||
return groupInvitationManager.getSharingStatus(c, g);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -92,7 +92,7 @@ class RevealContactsControllerImpl extends DbControllerImpl
|
||||
boolean selected =
|
||||
disabled || selection.contains(c.getId());
|
||||
items.add(new RevealableContactItem(c, authorInfo, selected,
|
||||
disabled, m.getVisibility()));
|
||||
m.getVisibility()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
package org.briarproject.briar.android.privategroup.reveal;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.briar.android.contactselection.SelectableContactItem;
|
||||
import org.briarproject.briar.android.contactselection.BaseSelectableContactItem;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.briar.api.privategroup.Visibility;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
class RevealableContactItem extends SelectableContactItem {
|
||||
class RevealableContactItem extends BaseSelectableContactItem {
|
||||
|
||||
private final Visibility visibility;
|
||||
|
||||
RevealableContactItem(Contact contact, AuthorInfo authorInfo,
|
||||
boolean selected, boolean disabled, Visibility visibility) {
|
||||
super(contact, authorInfo, selected, disabled);
|
||||
boolean selected, Visibility visibility) {
|
||||
super(contact, authorInfo, selected);
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@@ -24,4 +26,8 @@ class RevealableContactItem extends SelectableContactItem {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled() {
|
||||
return visibility != INVISIBLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.briarproject.briar.android.contactselection.ContactSelectorController
|
||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||
import org.briarproject.briar.api.identity.AuthorManager;
|
||||
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -47,8 +48,9 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDisabled(GroupId g, Contact c) throws DbException {
|
||||
return !blogSharingManager.canBeShared(g, c);
|
||||
protected SharingStatus getSharingStatus(GroupId g, Contact c)
|
||||
throws DbException {
|
||||
return blogSharingManager.getSharingStatus(g, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.briarproject.briar.android.contactselection.ContactSelectorController
|
||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||
import org.briarproject.briar.api.identity.AuthorManager;
|
||||
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -47,8 +48,9 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDisabled(GroupId g, Contact c) throws DbException {
|
||||
return !forumSharingManager.canBeShared(g, c);
|
||||
protected SharingStatus getSharingStatus(GroupId g, Contact c)
|
||||
throws DbException {
|
||||
return forumSharingManager.getSharingStatus(g, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -461,6 +461,8 @@
|
||||
<string name="forum_declined_toast">Invitation declined</string>
|
||||
<string name="shared_by_format">Shared by %s</string>
|
||||
<string name="forum_invitation_already_sharing">Already sharing</string>
|
||||
<string name="forum_invitation_already_invited">Already invited</string>
|
||||
<string name="forum_invitation_not_supported">Not supported by this contact</string>
|
||||
<string name="forum_invitation_response_accepted_sent">You accepted the forum invitation from %s.</string>
|
||||
<string name="forum_invitation_response_declined_sent">You declined the forum invitation from %s.</string>
|
||||
<string name="forum_invitation_response_declined_auto">The forum invitation from %s was automatically declined.</string>
|
||||
|
||||
Reference in New Issue
Block a user