mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Merge branch '810-fix-sharing-status-screens' into 'master'
Fix Sharing Status screens * Remove distinction between "shared with" and "shared by" * Show all contacts a blog is shared with * Show online status of contacts in sharing screen  Closes #810 See merge request !445
This commit is contained in:
@@ -10,13 +10,27 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
public class ContactItem {
|
||||
|
||||
private final Contact contact;
|
||||
private boolean connected;
|
||||
|
||||
public ContactItem(Contact contact) {
|
||||
this(contact, false);
|
||||
}
|
||||
|
||||
public ContactItem(Contact contact, boolean connected) {
|
||||
this.contact = contact;
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
public Contact getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
void setConnected(boolean connected) {
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.briar.android.contact;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
@@ -12,8 +13,6 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import im.delight.android.identicons.IdenticonDrawable;
|
||||
|
||||
@UiThread
|
||||
@@ -24,6 +23,8 @@ public class ContactItemViewHolder<I extends ContactItem>
|
||||
protected final ViewGroup layout;
|
||||
protected final ImageView avatar;
|
||||
protected final TextView name;
|
||||
@Nullable
|
||||
protected final ImageView bulb;
|
||||
|
||||
public ContactItemViewHolder(View v) {
|
||||
super(v);
|
||||
@@ -31,6 +32,8 @@ public class ContactItemViewHolder<I extends ContactItem>
|
||||
layout = (ViewGroup) v;
|
||||
avatar = (ImageView) v.findViewById(R.id.avatarView);
|
||||
name = (TextView) v.findViewById(R.id.nameView);
|
||||
// this can be null as not all layouts that use this ViewHolder have it
|
||||
bulb = (ImageView) v.findViewById(R.id.bulbView);
|
||||
}
|
||||
|
||||
protected void bind(final I item,
|
||||
@@ -41,6 +44,15 @@ public class ContactItemViewHolder<I extends ContactItem>
|
||||
String contactName = author.getName();
|
||||
name.setText(contactName);
|
||||
|
||||
if (bulb != null) {
|
||||
// online/offline
|
||||
if (item.isConnected()) {
|
||||
bulb.setImageResource(R.drawable.contact_connected);
|
||||
} else {
|
||||
bulb.setImageResource(R.drawable.contact_disconnected);
|
||||
}
|
||||
}
|
||||
|
||||
layout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@@ -10,14 +10,13 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
@NotNullByDefault
|
||||
public class ContactListItem extends ContactItem {
|
||||
|
||||
private boolean connected, empty;
|
||||
private boolean empty;
|
||||
private long timestamp;
|
||||
private int unread;
|
||||
|
||||
public ContactListItem(Contact contact, boolean connected,
|
||||
GroupCount count) {
|
||||
super(contact);
|
||||
this.connected = connected;
|
||||
super(contact, connected);
|
||||
this.empty = count.getMsgCount() == 0;
|
||||
this.unread = count.getUnreadCount();
|
||||
this.timestamp = count.getLatestMsgTime();
|
||||
@@ -30,14 +29,6 @@ public class ContactListItem extends ContactItem {
|
||||
unread++;
|
||||
}
|
||||
|
||||
boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
void setConnected(boolean connected) {
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return empty;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.contact;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
@@ -20,13 +19,11 @@ import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
||||
@NotNullByDefault
|
||||
class ContactListItemViewHolder extends ContactItemViewHolder<ContactListItem> {
|
||||
|
||||
protected final ImageView bulb;
|
||||
private final TextView unread;
|
||||
private final TextView date;
|
||||
|
||||
ContactListItemViewHolder(View v) {
|
||||
super(v);
|
||||
bulb = (ImageView) v.findViewById(R.id.bulbView);
|
||||
unread = (TextView) v.findViewById(R.id.unreadCountView);
|
||||
date = (TextView) v.findViewById(R.id.dateView);
|
||||
}
|
||||
@@ -53,13 +50,6 @@ class ContactListItemViewHolder extends ContactItemViewHolder<ContactListItem> {
|
||||
date.setText(formatDate(date.getContext(), timestamp));
|
||||
}
|
||||
|
||||
// online/offline
|
||||
if (item.isConnected()) {
|
||||
bulb.setImageResource(R.drawable.contact_connected);
|
||||
} else {
|
||||
bulb.setImageResource(R.drawable.contact_disconnected);
|
||||
}
|
||||
|
||||
ContactId c = item.getContact().getId();
|
||||
setTransitionName(avatar, UiUtils.getAvatarTransitionName(c));
|
||||
setTransitionName(bulb, UiUtils.getBulbTransitionName(c));
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.briarproject.briar.android.sharing;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||
|
||||
@@ -10,6 +12,8 @@ import java.util.Collection;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class BlogSharingStatusActivity extends SharingStatusActivity {
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@@ -21,16 +25,10 @@ public class BlogSharingStatusActivity extends SharingStatusActivity {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
@Override
|
||||
@DatabaseExecutor
|
||||
protected Collection<Contact> getSharedWith() throws DbException {
|
||||
return blogSharingManager.getSharedWith(getGroupId());
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
@Override
|
||||
protected Collection<Contact> getSharedBy() throws DbException {
|
||||
return blogSharingManager.getSharedBy(getGroupId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,18 @@ package org.briarproject.briar.android.sharing;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class ForumSharingStatusActivity extends SharingStatusActivity {
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@@ -21,16 +26,10 @@ public class ForumSharingStatusActivity extends SharingStatusActivity {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
@Override
|
||||
@DatabaseExecutor
|
||||
protected Collection<Contact> getSharedWith() throws DbException {
|
||||
return forumSharingManager.getSharedWith(getGroupId());
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
@Override
|
||||
protected Collection<Contact> getSharedBy() throws DbException {
|
||||
return forumSharingManager.getSharedBy(getGroupId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,16 @@ package org.briarproject.briar.android.sharing;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionRegistry;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
@@ -18,55 +23,53 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
abstract class SharingStatusActivity extends BriarActivity {
|
||||
|
||||
@Inject
|
||||
ConnectionRegistry connectionRegistry;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SharingStatusActivity.class.getName());
|
||||
|
||||
private GroupId groupId;
|
||||
private BriarRecyclerView sharedByList, sharedWithList;
|
||||
private SharingStatusAdapter sharedByAdapter, sharedWithAdapter;
|
||||
private BriarRecyclerView list;
|
||||
private SharingStatusAdapter adapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_sharing_status);
|
||||
setContentView(R.layout.list);
|
||||
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||
if (b == null) throw new IllegalStateException("No GroupId");
|
||||
groupId = new GroupId(b);
|
||||
|
||||
sharedByList = (BriarRecyclerView) findViewById(R.id.sharedByView);
|
||||
sharedByAdapter = new SharingStatusAdapter(this);
|
||||
sharedByList.setLayoutManager(new LinearLayoutManager(this));
|
||||
sharedByList.setAdapter(sharedByAdapter);
|
||||
sharedByList.setEmptyText(getString(R.string.nobody));
|
||||
|
||||
sharedWithList = (BriarRecyclerView) findViewById(R.id.sharedWithView);
|
||||
sharedWithAdapter = new SharingStatusAdapter(this);
|
||||
sharedWithList.setLayoutManager(new LinearLayoutManager(this));
|
||||
sharedWithList.setAdapter(sharedWithAdapter);
|
||||
sharedWithList.setEmptyText(getString(R.string.nobody));
|
||||
list = (BriarRecyclerView) findViewById(R.id.list);
|
||||
adapter = new SharingStatusAdapter(this);
|
||||
list.setLayoutManager(new LinearLayoutManager(this));
|
||||
list.setAdapter(adapter);
|
||||
list.setEmptyText(getString(R.string.nobody));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
loadSharedBy();
|
||||
loadSharedWith();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
sharedByAdapter.clear();
|
||||
sharedByList.showProgressBar();
|
||||
sharedWithAdapter.clear();
|
||||
sharedWithList.showProgressBar();
|
||||
adapter.clear();
|
||||
list.showProgressBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,49 +84,13 @@ abstract class SharingStatusActivity extends BriarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This must only be called from the DbThread
|
||||
*/
|
||||
@DatabaseExecutor
|
||||
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() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<ContactItem> contactItems = new ArrayList<>();
|
||||
for (Contact c : getSharedBy()) {
|
||||
ContactItem item = new ContactItem(c);
|
||||
contactItems.add(item);
|
||||
}
|
||||
displaySharedBy(contactItems);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displaySharedBy(final List<ContactItem> contacts) {
|
||||
runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (contacts.isEmpty()) sharedByList.showData();
|
||||
else sharedByAdapter.addAll(contacts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadSharedWith() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
@@ -131,7 +98,9 @@ abstract class SharingStatusActivity extends BriarActivity {
|
||||
try {
|
||||
List<ContactItem> contactItems = new ArrayList<>();
|
||||
for (Contact c : getSharedWith()) {
|
||||
ContactItem item = new ContactItem(c);
|
||||
boolean online =
|
||||
connectionRegistry.isConnected(c.getId());
|
||||
ContactItem item = new ContactItem(c, online);
|
||||
contactItems.add(item);
|
||||
}
|
||||
displaySharedWith(contactItems);
|
||||
@@ -147,8 +116,8 @@ abstract class SharingStatusActivity extends BriarActivity {
|
||||
runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (contacts.isEmpty()) sharedWithList.showData();
|
||||
else sharedWithAdapter.addAll(contacts);
|
||||
if (contacts.isEmpty()) list.showData();
|
||||
else adapter.addAll(contacts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/default_separator_inverted"
|
||||
android:padding="@dimen/margin_medium"
|
||||
android:text="@string/forum_shared_by"
|
||||
android:textSize="@dimen/text_size_large"/>
|
||||
|
||||
<View style="@style/Divider.ForumList"/>
|
||||
|
||||
<org.briarproject.briar.android.view.BriarRecyclerView
|
||||
android:id="@+id/sharedByView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/margin_medium"
|
||||
android:paddingTop="@dimen/margin_medium"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/default_separator_inverted"
|
||||
android:padding="@dimen/margin_medium"
|
||||
android:text="@string/forum_shared_with"
|
||||
android:textSize="@dimen/text_size_large"/>
|
||||
|
||||
<View style="@style/Divider.ForumList"/>
|
||||
|
||||
<org.briarproject.briar.android.view.BriarRecyclerView
|
||||
android:id="@+id/sharedWithView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/margin_medium"
|
||||
android:paddingTop="@dimen/margin_medium"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
@@ -5,28 +5,38 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="@dimen/margin_small"
|
||||
android:paddingTop="@dimen/margin_small">
|
||||
android:paddingBottom="@dimen/margin_medium"
|
||||
android:paddingTop="@dimen/margin_medium">
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/avatarView"
|
||||
style="@style/BriarAvatar"
|
||||
android:layout_width="@dimen/listitem_picture_size_small"
|
||||
android:layout_height="@dimen/listitem_picture_size_small"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="@dimen/listitem_horizontal_margin"
|
||||
android:layout_marginStart="@dimen/listitem_horizontal_margin"
|
||||
tools:src="@drawable/ic_launcher"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/nameView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="@dimen/listitem_horizontal_margin"
|
||||
android:layout_marginStart="@dimen/listitem_horizontal_margin"
|
||||
android:layout_marginLeft="@dimen/margin_medium"
|
||||
android:layout_marginStart="@dimen/margin_medium"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="2"
|
||||
android:textColor="@color/briar_text_primary"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
tools:text="This is a name of a contact"/>
|
||||
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/bulbView"
|
||||
android:layout_width="@dimen/listitem_horizontal_margin"
|
||||
android:layout_height="@dimen/listitem_horizontal_margin"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="@dimen/listitem_horizontal_margin"
|
||||
tools:src="@drawable/contact_connected"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -263,8 +263,6 @@
|
||||
<item quantity="one">%d forum shared by contacts</item>
|
||||
<item quantity="other">%d forums shared by contacts</item>
|
||||
</plurals>
|
||||
<string name="forum_shared_by">Shared by</string>
|
||||
<string name="forum_shared_with">Shared with</string>
|
||||
<string name="nobody">Nobody</string>
|
||||
|
||||
<!-- Blogs -->
|
||||
|
||||
Reference in New Issue
Block a user