mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Refactor existing adapters into a generic superclass
This commit also moves various blog classes into their own packages and makes the required visibility changes.
This commit is contained in:
@@ -3,14 +3,4 @@
|
|||||||
android:id="@+id/fragmentContainer"
|
android:id="@+id/fragmentContainer"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progressBar"
|
|
||||||
style="?android:attr/progressBarStyleLarge"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:visibility="invisible"/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
@@ -11,7 +11,7 @@ import org.briarproject.api.sync.MessageId;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface BaseController {
|
interface BaseController {
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
void onStart();
|
void onStart();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import static android.view.View.INVISIBLE;
|
|||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static org.briarproject.android.util.AndroidUtils.MIN_RESOLUTION;
|
import static org.briarproject.android.util.AndroidUtils.MIN_RESOLUTION;
|
||||||
|
|
||||||
public abstract class BasePostFragment extends BaseFragment {
|
abstract class BasePostFragment extends BaseFragment {
|
||||||
|
|
||||||
private final Logger LOG =
|
private final Logger LOG =
|
||||||
Logger.getLogger(BasePostFragment.class.getName());
|
Logger.getLogger(BasePostFragment.class.getName());
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ public class BlogActivity extends BriarActivity implements
|
|||||||
static final String BLOG_NAME = "briar.BLOG_NAME";
|
static final String BLOG_NAME = "briar.BLOG_NAME";
|
||||||
static final String IS_NEW_BLOG = "briar.IS_NEW_BLOG";
|
static final String IS_NEW_BLOG = "briar.IS_NEW_BLOG";
|
||||||
|
|
||||||
private ProgressBar progressBar;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BlogController blogController;
|
BlogController blogController;
|
||||||
|
|
||||||
@@ -45,7 +43,6 @@ public class BlogActivity extends BriarActivity implements
|
|||||||
boolean isNew = i.getBooleanExtra(IS_NEW_BLOG, false);
|
boolean isNew = i.getBooleanExtra(IS_NEW_BLOG, false);
|
||||||
|
|
||||||
setContentView(R.layout.activity_fragment_container);
|
setContentView(R.layout.activity_fragment_container);
|
||||||
progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
|
||||||
|
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
BlogFragment f = BlogFragment.newInstance(groupId, blogName, isNew);
|
BlogFragment f = BlogFragment.newInstance(groupId, blogName, isNew);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.briarproject.android.blogs;
|
package org.briarproject.android.blogs;
|
||||||
|
|
||||||
import android.support.annotation.UiThread;
|
|
||||||
|
|
||||||
import org.briarproject.api.blogs.BlogCommentHeader;
|
import org.briarproject.api.blogs.BlogCommentHeader;
|
||||||
import org.briarproject.api.blogs.BlogPostHeader;
|
import org.briarproject.api.blogs.BlogPostHeader;
|
||||||
|
|
||||||
@@ -10,7 +8,7 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@UiThread
|
// This class is not thread-safe
|
||||||
class BlogCommentItem extends BlogPostItem {
|
class BlogCommentItem extends BlogPostItem {
|
||||||
|
|
||||||
private static final BlogCommentComparator COMPARATOR =
|
private static final BlogCommentComparator COMPARATOR =
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package org.briarproject.android.blogs;
|
package org.briarproject.android.blogs;
|
||||||
|
|
||||||
import android.support.annotation.UiThread;
|
|
||||||
|
|
||||||
import org.briarproject.android.controller.ActivityLifecycleController;
|
|
||||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||||
import org.briarproject.api.blogs.BlogPostHeader;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.briarproject.android.blogs;
|
|||||||
import org.briarproject.android.controller.ActivityLifecycleController;
|
import org.briarproject.android.controller.ActivityLifecycleController;
|
||||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||||
import org.briarproject.api.blogs.Blog;
|
import org.briarproject.api.blogs.Blog;
|
||||||
import org.briarproject.api.blogs.BlogPostHeader;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.event.BlogPostAddedEvent;
|
import org.briarproject.api.event.BlogPostAddedEvent;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.api.event.Event;
|
||||||
@@ -14,7 +13,6 @@ import org.briarproject.api.sync.GroupId;
|
|||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -108,9 +106,7 @@ public class BlogControllerImpl extends BaseControllerImpl
|
|||||||
Blog b = blogManager.getBlog(groupId);
|
Blog b = blogManager.getBlog(groupId);
|
||||||
boolean ours = a.getId().equals(b.getAuthor().getId());
|
boolean ours = a.getId().equals(b.getAuthor().getId());
|
||||||
boolean removable = blogManager.canBeRemoved(groupId);
|
boolean removable = blogManager.canBeRemoved(groupId);
|
||||||
BlogItem blog = new BlogItem(b,
|
BlogItem blog = new BlogItem(b, ours, removable);
|
||||||
Collections.<BlogPostHeader>emptyList(),
|
|
||||||
ours, removable);
|
|
||||||
handler.onResult(blog);
|
handler.onResult(blog);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING))
|
||||||
@@ -119,7 +115,6 @@ public class BlogControllerImpl extends BaseControllerImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class BlogFragment extends BaseFragment implements
|
|||||||
private MenuItem writeButton, deleteButton;
|
private MenuItem writeButton, deleteButton;
|
||||||
private boolean isMyBlog = false, canDeleteBlog = false;
|
private boolean isMyBlog = false, canDeleteBlog = false;
|
||||||
|
|
||||||
static BlogFragment newInstance(GroupId groupId, String name,
|
static BlogFragment newInstance(GroupId groupId, @Nullable String name,
|
||||||
boolean isNew) {
|
boolean isNew) {
|
||||||
|
|
||||||
BlogFragment f = new BlogFragment();
|
BlogFragment f = new BlogFragment();
|
||||||
|
|||||||
@@ -1,40 +1,14 @@
|
|||||||
package org.briarproject.android.blogs;
|
package org.briarproject.android.blogs;
|
||||||
|
|
||||||
import org.briarproject.api.blogs.Blog;
|
import org.briarproject.api.blogs.Blog;
|
||||||
import org.briarproject.api.blogs.BlogPostHeader;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
class BlogItem {
|
class BlogItem {
|
||||||
|
|
||||||
private final Blog blog;
|
private final Blog blog;
|
||||||
private final int postCount;
|
|
||||||
private final long timestamp;
|
|
||||||
private final int unread;
|
|
||||||
private final boolean ours, removable;
|
private final boolean ours, removable;
|
||||||
|
|
||||||
BlogItem(Blog blog, Collection<BlogPostHeader> headers, boolean ours,
|
BlogItem(Blog blog, boolean ours, boolean removable) {
|
||||||
boolean removable) {
|
|
||||||
this.blog = blog;
|
this.blog = blog;
|
||||||
if (headers.isEmpty()) {
|
|
||||||
postCount = 0;
|
|
||||||
timestamp = 0;
|
|
||||||
unread = 0;
|
|
||||||
} else {
|
|
||||||
BlogPostHeader newest = null;
|
|
||||||
long timestamp = -1;
|
|
||||||
int unread = 0;
|
|
||||||
for (BlogPostHeader h : headers) {
|
|
||||||
if (h.getTimestamp() > timestamp) {
|
|
||||||
timestamp = h.getTimestamp();
|
|
||||||
newest = h;
|
|
||||||
}
|
|
||||||
if (!h.isRead()) unread++;
|
|
||||||
}
|
|
||||||
this.postCount = headers.size();
|
|
||||||
this.timestamp = newest.getTimestamp();
|
|
||||||
this.unread = unread;
|
|
||||||
}
|
|
||||||
this.ours = ours;
|
this.ours = ours;
|
||||||
this.removable = removable;
|
this.removable = removable;
|
||||||
}
|
}
|
||||||
@@ -47,22 +21,6 @@ class BlogItem {
|
|||||||
return blog.getName();
|
return blog.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isEmpty() {
|
|
||||||
return postCount == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getPostCount() {
|
|
||||||
return postCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
long getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getUnreadCount() {
|
|
||||||
return unread;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isOurs() {
|
boolean isOurs() {
|
||||||
return ours;
|
return ours;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +1,20 @@
|
|||||||
package org.briarproject.android.blogs;
|
package org.briarproject.android.blogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v7.util.SortedList;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
|
import org.briarproject.android.util.BriarAdapter;
|
||||||
|
|
||||||
import java.util.Collection;
|
class BlogPostAdapter
|
||||||
|
extends BriarAdapter<BlogPostItem, BlogPostViewHolder> {
|
||||||
|
|
||||||
class BlogPostAdapter extends RecyclerView.Adapter<BlogPostViewHolder> {
|
|
||||||
|
|
||||||
private SortedList<BlogPostItem> posts = new SortedList<>(
|
|
||||||
BlogPostItem.class, new SortedList.Callback<BlogPostItem>() {
|
|
||||||
@Override
|
|
||||||
public int compare(BlogPostItem a, BlogPostItem b) {
|
|
||||||
return a.compareTo(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInserted(int position, int count) {
|
|
||||||
notifyItemRangeInserted(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemoved(int position, int count) {
|
|
||||||
notifyItemRangeRemoved(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMoved(int fromPosition, int toPosition) {
|
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChanged(int position, int count) {
|
|
||||||
notifyItemRangeChanged(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(BlogPostItem a, BlogPostItem b) {
|
|
||||||
return a.isRead() == b.isRead();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(BlogPostItem a, BlogPostItem b) {
|
|
||||||
return a.getId().equals(b.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
private final Context ctx;
|
|
||||||
private final OnBlogPostClickListener listener;
|
private final OnBlogPostClickListener listener;
|
||||||
|
|
||||||
BlogPostAdapter(Context ctx, OnBlogPostClickListener listener) {
|
BlogPostAdapter(Context ctx, OnBlogPostClickListener listener) {
|
||||||
this.ctx = ctx;
|
super(ctx, BlogPostItem.class);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,36 +30,22 @@ class BlogPostAdapter extends RecyclerView.Adapter<BlogPostViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(BlogPostViewHolder ui, int position) {
|
public void onBindViewHolder(BlogPostViewHolder ui, int position) {
|
||||||
ui.bindItem(getItem(position));
|
ui.bindItem(getItemAt(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int compare(BlogPostItem a, BlogPostItem b) {
|
||||||
return posts.size();
|
return a.compareTo(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlogPostItem getItem(int position) {
|
@Override
|
||||||
return posts.get(position);
|
public boolean areContentsTheSame(BlogPostItem a, BlogPostItem b) {
|
||||||
|
return a.isRead() == b.isRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(BlogPostItem item) {
|
@Override
|
||||||
posts.add(item);
|
public boolean areItemsTheSame(BlogPostItem a, BlogPostItem b) {
|
||||||
}
|
return a.getId().equals(b.getId());
|
||||||
|
|
||||||
public void addAll(Collection<BlogPostItem> items) {
|
|
||||||
posts.addAll(items);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(BlogPostItem item) {
|
|
||||||
posts.remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
posts.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return posts.size() == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OnBlogPostClickListener {
|
interface OnBlogPostClickListener {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.android.blogs;
|
|||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.UiThread;
|
|
||||||
|
|
||||||
import org.briarproject.api.blogs.BlogPostHeader;
|
import org.briarproject.api.blogs.BlogPostHeader;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
@@ -10,8 +9,8 @@ import org.briarproject.api.identity.Author.Status;
|
|||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
@UiThread
|
// This class is not thread-safe
|
||||||
class BlogPostItem implements Comparable<BlogPostItem> {
|
public class BlogPostItem implements Comparable<BlogPostItem> {
|
||||||
|
|
||||||
private final BlogPostHeader header;
|
private final BlogPostHeader header;
|
||||||
protected String body;
|
protected String body;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
|
||||||
public class BlogPostPagerFragment extends BasePostPagerFragment {
|
public class BlogPostPagerFragment extends BasePostPagerFragment {
|
||||||
|
|
||||||
public final static String TAG = BlogPostPagerFragment.class.getName();
|
public final static String TAG = BlogPostPagerFragment.class.getName();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.briarproject.android.blogs;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.ActivityOptionsCompat;
|
import android.support.v4.app.ActivityOptionsCompat;
|
||||||
@@ -85,7 +86,9 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
return "blogPost" + id.hashCode();
|
return "blogPost" + id.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bindItem(final BlogPostItem item) {
|
void bindItem(@Nullable final BlogPostItem item) {
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
setTransitionName(item.getId());
|
setTransitionName(item.getId());
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
layout.setClickable(true);
|
layout.setClickable(true);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class FeedPostPagerFragment extends BasePostPagerFragment {
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
void loadBlogPosts(final MessageId select) {
|
void loadBlogPosts(final MessageId select) {
|
||||||
feedController.loadBlogPosts(
|
feedController.loadBlogPosts(
|
||||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
||||||
@@ -57,6 +57,7 @@ public class FeedPostPagerFragment extends BasePostPagerFragment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
void loadBlogPost(BlogPostHeader header) {
|
void loadBlogPost(BlogPostHeader header) {
|
||||||
feedController.loadBlogPost(header,
|
feedController.loadBlogPost(header,
|
||||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package org.briarproject.android.blogs;
|
package org.briarproject.android.blogs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.content.Context;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v7.util.SortedList;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -13,67 +11,18 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
|
import org.briarproject.android.util.BriarAdapter;
|
||||||
import org.briarproject.api.feed.Feed;
|
import org.briarproject.api.feed.Feed;
|
||||||
import org.briarproject.api.sync.GroupId;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
class RssFeedAdapter extends
|
class RssFeedAdapter extends BriarAdapter<Feed, RssFeedAdapter.FeedViewHolder> {
|
||||||
RecyclerView.Adapter<RssFeedAdapter.FeedViewHolder> {
|
|
||||||
|
|
||||||
private SortedList<Feed> feeds = new SortedList<>(
|
|
||||||
Feed.class, new SortedList.Callback<Feed>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Feed a, Feed b) {
|
|
||||||
if (a == b) return 0;
|
|
||||||
long aTime = a.getAdded(), bTime = b.getAdded();
|
|
||||||
if (aTime > bTime) return -1;
|
|
||||||
if (aTime < bTime) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInserted(int position, int count) {
|
|
||||||
notifyItemRangeInserted(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemoved(int position, int count) {
|
|
||||||
notifyItemRangeRemoved(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMoved(int fromPosition, int toPosition) {
|
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChanged(int position, int count) {
|
|
||||||
notifyItemRangeChanged(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(Feed a, Feed b) {
|
|
||||||
return a.getUpdated() == b.getUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(Feed a, Feed b) {
|
|
||||||
return a.getUrl().equals(b.getUrl()) &&
|
|
||||||
a.getBlogId().equals(b.getBlogId()) &&
|
|
||||||
a.getAdded() == b.getAdded();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
private final Activity ctx;
|
|
||||||
private final RssFeedListener listener;
|
private final RssFeedListener listener;
|
||||||
|
|
||||||
RssFeedAdapter(Activity ctx, RssFeedListener listener) {
|
RssFeedAdapter(Context ctx, RssFeedListener listener) {
|
||||||
this.ctx = ctx;
|
super(ctx, Feed.class);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +35,8 @@ class RssFeedAdapter extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(FeedViewHolder ui, int position) {
|
public void onBindViewHolder(FeedViewHolder ui, int position) {
|
||||||
final Feed item = getItem(position);
|
final Feed item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
// Feed Title
|
// Feed Title
|
||||||
if (item.getTitle() != null) {
|
if (item.getTitle() != null) {
|
||||||
@@ -128,39 +78,24 @@ class RssFeedAdapter extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int compare(Feed a, Feed b) {
|
||||||
return feeds.size();
|
if (a == b) return 0;
|
||||||
|
long aTime = a.getAdded(), bTime = b.getAdded();
|
||||||
|
if (aTime > bTime) return -1;
|
||||||
|
if (aTime < bTime) return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feed getItem(int position) {
|
@Override
|
||||||
return feeds.get(position);
|
public boolean areContentsTheSame(Feed a, Feed b) {
|
||||||
|
return a.getUpdated() == b.getUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Override
|
||||||
public Feed getItem(GroupId g) {
|
public boolean areItemsTheSame(Feed a, Feed b) {
|
||||||
for (int i = 0; i < feeds.size(); i++) {
|
return a.getUrl().equals(b.getUrl()) &&
|
||||||
Feed item = feeds.get(i);
|
a.getBlogId().equals(b.getBlogId()) &&
|
||||||
if (item.getBlogId().equals(g)) {
|
a.getAdded() == b.getAdded();
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAll(Collection<Feed> items) {
|
|
||||||
feeds.addAll(items);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(Feed item) {
|
|
||||||
feeds.remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
feeds.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return feeds.size() == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class FeedViewHolder extends RecyclerView.ViewHolder {
|
static class FeedViewHolder extends RecyclerView.ViewHolder {
|
||||||
@@ -172,7 +107,7 @@ class RssFeedAdapter extends
|
|||||||
private final TextView authorLabel;
|
private final TextView authorLabel;
|
||||||
private final TextView description;
|
private final TextView description;
|
||||||
|
|
||||||
FeedViewHolder(View v) {
|
private FeedViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
|
|
||||||
title = (TextView) v.findViewById(R.id.titleView);
|
title = (TextView) v.findViewById(R.id.titleView);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.briarproject.android.contact;
|
package org.briarproject.android.contact;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v7.util.SortedList;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -10,34 +10,32 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
|
import org.briarproject.android.util.BriarAdapter;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import im.delight.android.identicons.IdenticonDrawable;
|
import im.delight.android.identicons.IdenticonDrawable;
|
||||||
|
|
||||||
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
||||||
|
|
||||||
public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.BaseContactHolder>
|
public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.BaseContactHolder>
|
||||||
extends RecyclerView.Adapter<VH> {
|
extends BriarAdapter<ContactListItem, VH> {
|
||||||
|
|
||||||
protected final SortedList<ContactListItem> contacts;
|
@Nullable
|
||||||
protected final OnItemClickListener listener;
|
protected final OnItemClickListener listener;
|
||||||
protected Context ctx;
|
|
||||||
|
|
||||||
public BaseContactListAdapter(Context ctx, OnItemClickListener listener) {
|
public BaseContactListAdapter(Context ctx,
|
||||||
this.ctx = ctx;
|
@Nullable OnItemClickListener listener) {
|
||||||
|
super(ctx, ContactListItem.class);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.contacts = new SortedList<>(ContactListItem.class,
|
|
||||||
new SortedListCallBacks());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final VH ui, int position) {
|
public void onBindViewHolder(final VH ui, int position) {
|
||||||
final ContactListItem item = getItem(position);
|
final ContactListItem item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
Author author = item.getContact().getAuthor();
|
Author author = item.getContact().getAuthor();
|
||||||
ui.avatar.setImageDrawable(
|
ui.avatar.setImageDrawable(
|
||||||
@@ -59,30 +57,37 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int compare(ContactListItem c1, ContactListItem c2) {
|
||||||
return contacts.size();
|
return compareByName(c1, c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContactListItem getItem(int position) {
|
@Override
|
||||||
if (position == INVALID_POSITION || contacts.size() <= position) {
|
public boolean areItemsTheSame(ContactListItem c1, ContactListItem c2) {
|
||||||
return null; // Not found
|
return c1.getContact().getId().equals(c2.getContact().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areContentsTheSame(ContactListItem c1, ContactListItem c2) {
|
||||||
|
// check for all properties that influence visual
|
||||||
|
// representation of contact
|
||||||
|
if (c1.isConnected() != c2.isConnected()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return contacts.get(position);
|
if (c1.getUnreadCount() != c2.getUnreadCount()) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
void updateItem(int position, ContactListItem item) {
|
if (c1.getTimestamp() != c2.getTimestamp()) {
|
||||||
contacts.updateItemAt(position, item);
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
public int findItemPosition(ContactListItem c) {
|
|
||||||
return contacts.indexOf(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int findItemPosition(ContactId c) {
|
int findItemPosition(ContactId c) {
|
||||||
int count = getItemCount();
|
int count = getItemCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
ContactListItem item = getItem(i);
|
ContactListItem item = getItemAt(i);
|
||||||
if (item.getContact().getId().equals(c)) return i;
|
if (item != null && item.getContact().getId().equals(c))
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
return INVALID_POSITION; // Not found
|
return INVALID_POSITION; // Not found
|
||||||
}
|
}
|
||||||
@@ -90,28 +95,13 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
|||||||
int findItemPosition(GroupId g) {
|
int findItemPosition(GroupId g) {
|
||||||
int count = getItemCount();
|
int count = getItemCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
ContactListItem item = getItem(i);
|
ContactListItem item = getItemAt(i);
|
||||||
if (item.getGroupId().equals(g)) return i;
|
if (item != null && item.getGroupId().equals(g))
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
return INVALID_POSITION; // Not found
|
return INVALID_POSITION; // Not found
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(List<ContactListItem> contacts) {
|
|
||||||
this.contacts.addAll(contacts);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(ContactListItem contact) {
|
|
||||||
contacts.add(contact);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(ContactListItem contact) {
|
|
||||||
contacts.remove(contact);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
contacts.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class BaseContactHolder extends RecyclerView.ViewHolder {
|
public static class BaseContactHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
public final ViewGroup layout;
|
public final ViewGroup layout;
|
||||||
@@ -127,10 +117,6 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareContactListItems(ContactListItem c1, ContactListItem c2) {
|
|
||||||
return compareByName(c1, c2);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int compareByName(ContactListItem c1, ContactListItem c2) {
|
protected int compareByName(ContactListItem c1, ContactListItem c2) {
|
||||||
int authorCompare = c1.getLocalAuthor().getName()
|
int authorCompare = c1.getLocalAuthor().getName()
|
||||||
.compareTo(c2.getLocalAuthor().getName());
|
.compareTo(c2.getLocalAuthor().getName());
|
||||||
@@ -142,7 +128,7 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int compareByTime(ContactListItem c1, ContactListItem c2) {
|
protected int compareByTime(ContactListItem c1, ContactListItem c2) {
|
||||||
long time1 = c1.getTimestamp();
|
long time1 = c1.getTimestamp();
|
||||||
long time2 = c2.getTimestamp();
|
long time2 = c2.getTimestamp();
|
||||||
if (time1 < time2) return 1;
|
if (time1 < time2) return 1;
|
||||||
@@ -150,58 +136,8 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SortedListCallBacks
|
|
||||||
extends SortedList.Callback<ContactListItem> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInserted(int position, int count) {
|
|
||||||
notifyItemRangeInserted(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChanged(int position, int count) {
|
|
||||||
notifyItemRangeChanged(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMoved(int fromPosition, int toPosition) {
|
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemoved(int position, int count) {
|
|
||||||
notifyItemRangeRemoved(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(ContactListItem c1, ContactListItem c2) {
|
|
||||||
return compareContactListItems(c1, c2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(ContactListItem c1, ContactListItem c2) {
|
|
||||||
return c1.getContact().getId().equals(c2.getContact().getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(ContactListItem c1,
|
|
||||||
ContactListItem c2) {
|
|
||||||
// check for all properties that influence visual
|
|
||||||
// representation of contact
|
|
||||||
if (c1.isConnected() != c2.isConnected()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (c1.getUnreadCount() != c2.getUnreadCount()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (c1.getTimestamp() != c2.getTimestamp()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnItemClickListener {
|
public interface OnItemClickListener {
|
||||||
void onItemClick(View view, ContactListItem item);
|
void onItemClick(View view, ContactListItem item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ public class ContactListAdapter
|
|||||||
public void onBindViewHolder(ContactHolder ui, int position) {
|
public void onBindViewHolder(ContactHolder ui, int position) {
|
||||||
super.onBindViewHolder(ui, position);
|
super.onBindViewHolder(ui, position);
|
||||||
|
|
||||||
ContactListItem item = getItem(position);
|
ContactListItem item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
// unread count
|
// unread count
|
||||||
int unread = item.getUnreadCount();
|
int unread = item.getUnreadCount();
|
||||||
@@ -65,11 +66,11 @@ public class ContactListAdapter
|
|||||||
extends BaseContactListAdapter.BaseContactHolder {
|
extends BaseContactListAdapter.BaseContactHolder {
|
||||||
|
|
||||||
public final ImageView bulb;
|
public final ImageView bulb;
|
||||||
final TextView unread;
|
private final TextView unread;
|
||||||
public final TextView date;
|
public final TextView date;
|
||||||
public final TextView identity;
|
public final TextView identity;
|
||||||
|
|
||||||
ContactHolder(View v) {
|
private ContactHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
|
|
||||||
bulb = (ImageView) v.findViewById(R.id.bulbView);
|
bulb = (ImageView) v.findViewById(R.id.bulbView);
|
||||||
@@ -80,7 +81,7 @@ public class ContactListAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareContactListItems(ContactListItem c1, ContactListItem c2) {
|
public int compare(ContactListItem c1, ContactListItem c2) {
|
||||||
return compareByTime(c1, c2);
|
return compareByTime(c1, c2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
protected volatile BlogSharingManager blogSharingManager;
|
protected volatile BlogSharingManager blogSharingManager;
|
||||||
|
|
||||||
public static ContactListFragment newInstance() {
|
public static ContactListFragment newInstance() {
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
||||||
ContactListFragment fragment = new ContactListFragment();
|
ContactListFragment fragment = new ContactListFragment();
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
@@ -320,10 +320,10 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int position = adapter.findItemPosition(c);
|
int position = adapter.findItemPosition(c);
|
||||||
ContactListItem item = adapter.getItem(position);
|
ContactListItem item = adapter.getItemAt(position);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.setMessages(messages);
|
item.setMessages(messages);
|
||||||
adapter.updateItem(position, item);
|
adapter.updateItemAt(position, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -334,10 +334,10 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int position = adapter.findItemPosition(c);
|
int position = adapter.findItemPosition(c);
|
||||||
ContactListItem item = adapter.getItem(position);
|
ContactListItem item = adapter.getItemAt(position);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.addMessage(m);
|
item.addMessage(m);
|
||||||
adapter.updateItem(position, item);
|
adapter.updateItemAt(position, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -348,10 +348,10 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int position = adapter.findItemPosition(g);
|
int position = adapter.findItemPosition(g);
|
||||||
ContactListItem item = adapter.getItem(position);
|
ContactListItem item = adapter.getItemAt(position);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.addMessage(m);
|
item.addMessage(m);
|
||||||
adapter.updateItem(position, item);
|
adapter.updateItemAt(position, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -362,7 +362,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int position = adapter.findItemPosition(c);
|
int position = adapter.findItemPosition(c);
|
||||||
ContactListItem item = adapter.getItem(position);
|
ContactListItem item = adapter.getItemAt(position);
|
||||||
if (item != null) adapter.remove(item);
|
if (item != null) adapter.remove(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -373,7 +373,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int position = adapter.findItemPosition(c);
|
int position = adapter.findItemPosition(c);
|
||||||
ContactListItem item = adapter.getItem(position);
|
ContactListItem item = adapter.getItemAt(position);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.setConnected(connected);
|
item.setConnected(connected);
|
||||||
adapter.notifyItemChanged(position);
|
adapter.notifyItemChanged(position);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.briarproject.android.contact;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.util.SortedList;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -16,6 +16,7 @@ import org.briarproject.R;
|
|||||||
import org.briarproject.android.sharing.InvitationsBlogActivity;
|
import org.briarproject.android.sharing.InvitationsBlogActivity;
|
||||||
import org.briarproject.android.sharing.InvitationsForumActivity;
|
import org.briarproject.android.sharing.InvitationsForumActivity;
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
|
import org.briarproject.android.util.BriarAdapter;
|
||||||
import org.briarproject.api.blogs.BlogInvitationRequest;
|
import org.briarproject.api.blogs.BlogInvitationRequest;
|
||||||
import org.briarproject.api.clients.SessionId;
|
import org.briarproject.api.clients.SessionId;
|
||||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||||
@@ -24,9 +25,6 @@ import org.briarproject.api.messaging.PrivateMessageHeader;
|
|||||||
import org.briarproject.api.sharing.InvitationRequest;
|
import org.briarproject.api.sharing.InvitationRequest;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
|
||||||
import static android.support.v7.widget.RecyclerView.ViewHolder;
|
import static android.support.v7.widget.RecyclerView.ViewHolder;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
@@ -43,18 +41,13 @@ import static org.briarproject.android.contact.ConversationItem.NOTICE_IN;
|
|||||||
import static org.briarproject.android.contact.ConversationItem.NOTICE_OUT;
|
import static org.briarproject.android.contact.ConversationItem.NOTICE_OUT;
|
||||||
import static org.briarproject.android.contact.ConversationItem.OutgoingItem;
|
import static org.briarproject.android.contact.ConversationItem.OutgoingItem;
|
||||||
|
|
||||||
class ConversationAdapter extends RecyclerView.Adapter {
|
class ConversationAdapter extends BriarAdapter<ConversationItem, ViewHolder> {
|
||||||
|
|
||||||
private final SortedList<ConversationItem> items =
|
|
||||||
new SortedList<>(ConversationItem.class, new ListCallbacks());
|
|
||||||
|
|
||||||
private Context ctx;
|
|
||||||
private IntroductionHandler intro;
|
private IntroductionHandler intro;
|
||||||
private String contactName;
|
private String contactName;
|
||||||
|
|
||||||
ConversationAdapter(Context context,
|
ConversationAdapter(Context ctx, IntroductionHandler introductionHandler) {
|
||||||
IntroductionHandler introductionHandler) {
|
super(ctx, ConversationItem.class);
|
||||||
ctx = context;
|
|
||||||
intro = introductionHandler;
|
intro = introductionHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +58,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
return getItem(position).getType();
|
return items.get(position).getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,7 +107,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder ui, int position) {
|
public void onBindViewHolder(ViewHolder ui, int position) {
|
||||||
ConversationItem item = getItem(position);
|
ConversationItem item = getItemAt(position);
|
||||||
if (item instanceof ConversationMessageItem) {
|
if (item instanceof ConversationMessageItem) {
|
||||||
bindMessage((MessageHolder) ui, (ConversationMessageItem) item);
|
bindMessage((MessageHolder) ui, (ConversationMessageItem) item);
|
||||||
} else if (item instanceof ConversationIntroductionOutItem) {
|
} else if (item instanceof ConversationIntroductionOutItem) {
|
||||||
@@ -370,17 +363,28 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int compare(ConversationItem c1,
|
||||||
return items.size();
|
ConversationItem c2) {
|
||||||
|
long time1 = c1.getTime();
|
||||||
|
long time2 = c2.getTime();
|
||||||
|
if (time1 < time2) return -1;
|
||||||
|
if (time1 > time2) return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConversationItem getItem(int position) {
|
@Override
|
||||||
if (position == INVALID_POSITION || items.size() <= position) {
|
public boolean areItemsTheSame(ConversationItem c1,
|
||||||
return null; // Not found
|
ConversationItem c2) {
|
||||||
}
|
return c1.getId().equals(c2.getId());
|
||||||
return items.get(position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areContentsTheSame(ConversationItem c1,
|
||||||
|
ConversationItem c2) {
|
||||||
|
return c1.equals(c2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
ConversationItem getLastItem() {
|
ConversationItem getLastItem() {
|
||||||
if (items.size() > 0) {
|
if (items.size() > 0) {
|
||||||
return items.get(items.size() - 1);
|
return items.get(items.size() - 1);
|
||||||
@@ -425,23 +429,11 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(final ConversationItem message) {
|
|
||||||
this.items.add(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
items.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAll(List<ConversationItem> items) {
|
|
||||||
this.items.addAll(items);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MessageHolder extends RecyclerView.ViewHolder {
|
private static class MessageHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
public ViewGroup layout;
|
public ViewGroup layout;
|
||||||
public TextView body;
|
public TextView body;
|
||||||
public TextView date;
|
private TextView date;
|
||||||
public ImageView status;
|
public ImageView status;
|
||||||
|
|
||||||
private MessageHolder(View v, int type) {
|
private MessageHolder(View v, int type) {
|
||||||
@@ -532,51 +524,6 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ListCallbacks extends SortedList.Callback<ConversationItem> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInserted(int position, int count) {
|
|
||||||
notifyItemRangeInserted(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChanged(int position, int count) {
|
|
||||||
notifyItemRangeChanged(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMoved(int fromPosition, int toPosition) {
|
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemoved(int position, int count) {
|
|
||||||
notifyItemRangeRemoved(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(ConversationItem c1,
|
|
||||||
ConversationItem c2) {
|
|
||||||
long time1 = c1.getTime();
|
|
||||||
long time2 = c2.getTime();
|
|
||||||
if (time1 < time2) return -1;
|
|
||||||
if (time1 > time2) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(ConversationItem c1,
|
|
||||||
ConversationItem c2) {
|
|
||||||
return c1.getId().equals(c2.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(ConversationItem c1,
|
|
||||||
ConversationItem c2) {
|
|
||||||
return c1.equals(c2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IntroductionHandler {
|
interface IntroductionHandler {
|
||||||
void respondToIntroduction(SessionId sessionId, boolean accept);
|
void respondToIntroduction(SessionId sessionId, boolean accept);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.util.SortedList;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -13,73 +12,21 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
|
import org.briarproject.android.util.BriarAdapter;
|
||||||
import org.briarproject.android.view.TextAvatarView;
|
import org.briarproject.android.view.TextAvatarView;
|
||||||
import org.briarproject.api.forum.Forum;
|
import org.briarproject.api.forum.Forum;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
|
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
|
||||||
|
|
||||||
class ForumListAdapter extends
|
class ForumListAdapter
|
||||||
RecyclerView.Adapter<ForumListAdapter.ForumViewHolder> {
|
extends BriarAdapter<ForumListItem, ForumListAdapter.ForumViewHolder> {
|
||||||
|
|
||||||
private SortedList<ForumListItem> forums = new SortedList<>(
|
|
||||||
ForumListItem.class, new SortedList.Callback<ForumListItem>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(ForumListItem a, ForumListItem b) {
|
|
||||||
if (a == b) return 0;
|
|
||||||
// The forum with the newest message comes first
|
|
||||||
long aTime = a.getTimestamp(), bTime = b.getTimestamp();
|
|
||||||
if (aTime > bTime) return -1;
|
|
||||||
if (aTime < bTime) return 1;
|
|
||||||
// Break ties by forum name
|
|
||||||
String aName = a.getForum().getName();
|
|
||||||
String bName = b.getForum().getName();
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInserted(int position, int count) {
|
|
||||||
notifyItemRangeInserted(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemoved(int position, int count) {
|
|
||||||
notifyItemRangeRemoved(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMoved(int fromPosition, int toPosition) {
|
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChanged(int position, int count) {
|
|
||||||
notifyItemRangeChanged(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(ForumListItem a, ForumListItem b) {
|
|
||||||
return a.getForum().equals(b.getForum()) &&
|
|
||||||
a.getTimestamp() == b.getTimestamp() &&
|
|
||||||
a.getUnreadCount() == b.getUnreadCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(ForumListItem a, ForumListItem b) {
|
|
||||||
return a.getForum().equals(b.getForum());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
private final Context ctx;
|
|
||||||
|
|
||||||
ForumListAdapter(Context ctx) {
|
ForumListAdapter(Context ctx) {
|
||||||
this.ctx = ctx;
|
super(ctx, ForumListItem.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,7 +38,8 @@ class ForumListAdapter extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ForumViewHolder ui, int position) {
|
public void onBindViewHolder(ForumViewHolder ui, int position) {
|
||||||
final ForumListItem item = getItem(position);
|
final ForumListItem item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
// Avatar
|
// Avatar
|
||||||
ui.avatar.setText(item.getForum().getName().substring(0, 1));
|
ui.avatar.setText(item.getForum().getName().substring(0, 1));
|
||||||
@@ -142,18 +90,34 @@ class ForumListAdapter extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int compare(ForumListItem a, ForumListItem b) {
|
||||||
return forums.size();
|
if (a == b) return 0;
|
||||||
|
// The forum with the newest message comes first
|
||||||
|
long aTime = a.getTimestamp(), bTime = b.getTimestamp();
|
||||||
|
if (aTime > bTime) return -1;
|
||||||
|
if (aTime < bTime) return 1;
|
||||||
|
// Break ties by forum name
|
||||||
|
String aName = a.getForum().getName();
|
||||||
|
String bName = b.getForum().getName();
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForumListItem getItem(int position) {
|
@Override
|
||||||
return forums.get(position);
|
public boolean areContentsTheSame(ForumListItem a, ForumListItem b) {
|
||||||
|
return a.getForum().equals(b.getForum()) &&
|
||||||
|
a.getTimestamp() == b.getTimestamp() &&
|
||||||
|
a.getUnreadCount() == b.getUnreadCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areItemsTheSame(ForumListItem a, ForumListItem b) {
|
||||||
|
return a.getForum().equals(b.getForum());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ForumListItem getItem(GroupId g) {
|
public ForumListItem findItem(GroupId g) {
|
||||||
for (int i = 0; i < forums.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
ForumListItem item = forums.get(i);
|
ForumListItem item = items.get(i);
|
||||||
if (item.getForum().getGroup().getId().equals(g)) {
|
if (item.getForum().getGroup().getId().equals(g)) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -161,26 +125,10 @@ class ForumListAdapter extends
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(Collection<ForumListItem> items) {
|
|
||||||
forums.addAll(items);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateItem(ForumListItem item) {
|
void updateItem(ForumListItem item) {
|
||||||
ForumListItem oldItem = getItem(item.getForum().getGroup().getId());
|
ForumListItem oldItem = findItem(item.getForum().getGroup().getId());
|
||||||
int position = forums.indexOf(oldItem);
|
int position = items.indexOf(oldItem);
|
||||||
forums.updateItemAt(position, item);
|
items.updateItemAt(position, item);
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(ForumListItem item) {
|
|
||||||
forums.remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
forums.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return forums.size() == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ForumViewHolder extends RecyclerView.ViewHolder {
|
static class ForumViewHolder extends RecyclerView.ViewHolder {
|
||||||
@@ -191,7 +139,7 @@ class ForumListAdapter extends
|
|||||||
private final TextView postCount;
|
private final TextView postCount;
|
||||||
private final TextView date;
|
private final TextView date;
|
||||||
|
|
||||||
ForumViewHolder(View v) {
|
private ForumViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
|
|
||||||
layout = (ViewGroup) v;
|
layout = (ViewGroup) v;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
@@ -44,7 +45,7 @@ import static java.util.logging.Level.INFO;
|
|||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
public class ForumListFragment extends BaseEventFragment implements
|
public class ForumListFragment extends BaseEventFragment implements
|
||||||
View.OnClickListener {
|
OnClickListener {
|
||||||
|
|
||||||
public final static String TAG = "ForumListFragment";
|
public final static String TAG = "ForumListFragment";
|
||||||
|
|
||||||
@@ -288,7 +289,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
listener.runOnUiThread(new Runnable() {
|
listener.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ForumListItem item = adapter.getItem(g);
|
ForumListItem item = adapter.findItem(g);
|
||||||
if (item != null) adapter.remove(item);
|
if (item != null) adapter.remove(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ public class ContactChooserAdapter extends ContactListAdapter {
|
|||||||
public void onBindViewHolder(final ContactHolder ui, final int position) {
|
public void onBindViewHolder(final ContactHolder ui, final int position) {
|
||||||
super.onBindViewHolder(ui, position);
|
super.onBindViewHolder(ui, position);
|
||||||
|
|
||||||
final ContactListItem item = getItem(position);
|
final ContactListItem item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
ui.name.setText(item.getContact().getAuthor().getName());
|
ui.name.setText(item.getContact().getAuthor().getName());
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ public class ContactChooserAdapter extends ContactListAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareContactListItems(ContactListItem c1, ContactListItem c2) {
|
public int compare(ContactListItem c1, ContactListItem c2) {
|
||||||
return compareByName(c1, c2);
|
return compareByName(c1, c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ class BlogInvitationAdapter extends InvitationAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(InvitationsViewHolder ui, int position) {
|
public void onBindViewHolder(InvitationsViewHolder ui, int position) {
|
||||||
super.onBindViewHolder(ui, position);
|
super.onBindViewHolder(ui, position);
|
||||||
InvitationItem item = getItem(position);
|
InvitationItem item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
Blog blog = (Blog) item.getShareable();
|
Blog blog = (Blog) item.getShareable();
|
||||||
|
|
||||||
ui.avatar.setAuthorAvatar(blog.getAuthor());
|
ui.avatar.setAuthorAvatar(blog.getAuthor());
|
||||||
@@ -28,7 +30,8 @@ class BlogInvitationAdapter extends InvitationAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int compareInvitations(InvitationItem o1, InvitationItem o2) {
|
@Override
|
||||||
|
public int compare(InvitationItem o1, InvitationItem o2) {
|
||||||
return String.CASE_INSENSITIVE_ORDER
|
return String.CASE_INSENSITIVE_ORDER
|
||||||
.compare(((Blog) o1.getShareable()).getAuthor().getName(),
|
.compare(((Blog) o1.getShareable()).getAuthor().getName(),
|
||||||
((Blog) o2.getShareable()).getAuthor().getName());
|
((Blog) o2.getShareable()).getAuthor().getName());
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.contact.BaseContactListAdapter;
|
import org.briarproject.android.contact.BaseContactListAdapter;
|
||||||
import org.briarproject.android.contact.ContactListItem;
|
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -41,7 +40,8 @@ class ContactSelectorAdapter
|
|||||||
super.onBindViewHolder(ui, position);
|
super.onBindViewHolder(ui, position);
|
||||||
|
|
||||||
SelectableContactListItem item =
|
SelectableContactListItem item =
|
||||||
(SelectableContactListItem) getItem(position);
|
(SelectableContactListItem) getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
if (item.isSelected()) {
|
if (item.isSelected()) {
|
||||||
ui.checkBox.setChecked(true);
|
ui.checkBox.setChecked(true);
|
||||||
@@ -64,9 +64,9 @@ class ContactSelectorAdapter
|
|||||||
Collection<ContactId> getSelectedContactIds() {
|
Collection<ContactId> getSelectedContactIds() {
|
||||||
Collection<ContactId> selected = new ArrayList<>();
|
Collection<ContactId> selected = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < contacts.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
SelectableContactListItem item =
|
SelectableContactListItem item =
|
||||||
(SelectableContactListItem) contacts.get(i);
|
(SelectableContactListItem) items.get(i);
|
||||||
if (item.isSelected()) selected.add(item.getContact().getId());
|
if (item.isSelected()) selected.add(item.getContact().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ class ContactSelectorAdapter
|
|||||||
private final CheckBox checkBox;
|
private final CheckBox checkBox;
|
||||||
private final TextView shared;
|
private final TextView shared;
|
||||||
|
|
||||||
SelectableContactHolder(View v) {
|
private SelectableContactHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
|
|
||||||
checkBox = (CheckBox) v.findViewById(R.id.checkBox);
|
checkBox = (CheckBox) v.findViewById(R.id.checkBox);
|
||||||
@@ -87,11 +87,6 @@ class ContactSelectorAdapter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareContactListItems(ContactListItem c1, ContactListItem c2) {
|
|
||||||
return compareByName(c1, c2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void grayOutItem(SelectableContactHolder ui, boolean gray) {
|
private void grayOutItem(SelectableContactHolder ui, boolean gray) {
|
||||||
float alpha = gray ? 0.25f : 1f;
|
float alpha = gray ? 0.25f : 1f;
|
||||||
ui.avatar.setAlpha(alpha);
|
ui.avatar.setAlpha(alpha);
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ class ForumInvitationAdapter extends InvitationAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(InvitationsViewHolder ui, int position) {
|
public void onBindViewHolder(InvitationsViewHolder ui, int position) {
|
||||||
super.onBindViewHolder(ui, position);
|
super.onBindViewHolder(ui, position);
|
||||||
InvitationItem item = getItem(position);
|
InvitationItem item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
Forum forum = (Forum) item.getShareable();
|
Forum forum = (Forum) item.getShareable();
|
||||||
|
|
||||||
ui.avatar.setText(forum.getName().substring(0, 1));
|
ui.avatar.setText(forum.getName().substring(0, 1));
|
||||||
@@ -23,7 +25,8 @@ class ForumInvitationAdapter extends InvitationAdapter {
|
|||||||
ui.name.setText(forum.getName());
|
ui.name.setText(forum.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
int compareInvitations(InvitationItem o1, InvitationItem o2) {
|
@Override
|
||||||
|
public int compare(InvitationItem o1, InvitationItem o2) {
|
||||||
return String.CASE_INSENSITIVE_ORDER
|
return String.CASE_INSENSITIVE_ORDER
|
||||||
.compare(((Forum) o1.getShareable()).getName(),
|
.compare(((Forum) o1.getShareable()).getName(),
|
||||||
((Forum) o2.getShareable()).getName());
|
((Forum) o2.getShareable()).getName());
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.android.sharing;
|
package org.briarproject.android.sharing;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v7.util.SortedList;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -10,6 +9,7 @@ import android.widget.Button;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
|
import org.briarproject.android.util.BriarAdapter;
|
||||||
import org.briarproject.android.view.TextAvatarView;
|
import org.briarproject.android.view.TextAvatarView;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.sharing.InvitationItem;
|
import org.briarproject.api.sharing.InvitationItem;
|
||||||
@@ -22,16 +22,12 @@ import static android.view.View.GONE;
|
|||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
abstract class InvitationAdapter extends
|
abstract class InvitationAdapter extends
|
||||||
RecyclerView.Adapter<InvitationAdapter.InvitationsViewHolder> {
|
BriarAdapter<InvitationItem, InvitationAdapter.InvitationsViewHolder> {
|
||||||
|
|
||||||
protected final Context ctx;
|
|
||||||
private final AvailableForumClickListener listener;
|
private final AvailableForumClickListener listener;
|
||||||
private final SortedList<InvitationItem> invitations =
|
|
||||||
new SortedList<>(InvitationItem.class,
|
|
||||||
new SortedListCallBacks());
|
|
||||||
|
|
||||||
InvitationAdapter(Context ctx, AvailableForumClickListener listener) {
|
InvitationAdapter(Context ctx, AvailableForumClickListener listener) {
|
||||||
this.ctx = ctx;
|
super(ctx, InvitationItem.class);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +42,8 @@ abstract class InvitationAdapter extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(InvitationsViewHolder ui, int position) {
|
public void onBindViewHolder(InvitationsViewHolder ui, int position) {
|
||||||
final InvitationItem item = getItem(position);
|
final InvitationItem item = getItemAt(position);
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
Collection<String> names = new ArrayList<>();
|
Collection<String> names = new ArrayList<>();
|
||||||
for (Contact c : item.getNewSharers())
|
for (Contact c : item.getNewSharers())
|
||||||
@@ -75,40 +72,28 @@ abstract class InvitationAdapter extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public boolean areContentsTheSame(InvitationItem oldItem,
|
||||||
return invitations.size();
|
InvitationItem newItem) {
|
||||||
|
return oldItem.isSubscribed() == newItem.isSubscribed() &&
|
||||||
|
oldItem.getNewSharers().equals(newItem.getNewSharers());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvitationItem getItem(int position) {
|
@Override
|
||||||
return invitations.get(position);
|
public boolean areItemsTheSame(InvitationItem oldItem,
|
||||||
}
|
InvitationItem newItem) {
|
||||||
|
return oldItem.getShareable().equals(newItem.getShareable());
|
||||||
public void add(InvitationItem item) {
|
|
||||||
invitations.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAll(Collection<InvitationItem> list) {
|
|
||||||
invitations.addAll(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(InvitationItem item) {
|
|
||||||
invitations.remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
invitations.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class InvitationsViewHolder extends RecyclerView.ViewHolder {
|
static class InvitationsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
final TextAvatarView avatar;
|
final TextAvatarView avatar;
|
||||||
final TextView name;
|
final TextView name;
|
||||||
final TextView sharedBy;
|
private final TextView sharedBy;
|
||||||
final TextView subscribed;
|
final TextView subscribed;
|
||||||
final Button accept;
|
private final Button accept;
|
||||||
final Button decline;
|
private final Button decline;
|
||||||
|
|
||||||
InvitationsViewHolder(View v) {
|
private InvitationsViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
|
|
||||||
avatar = (TextAvatarView) v.findViewById(R.id.avatarView);
|
avatar = (TextAvatarView) v.findViewById(R.id.avatarView);
|
||||||
@@ -120,52 +105,6 @@ abstract class InvitationAdapter extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract int compareInvitations(InvitationItem o1, InvitationItem o2);
|
|
||||||
|
|
||||||
private class SortedListCallBacks
|
|
||||||
extends SortedList.Callback<InvitationItem> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(InvitationItem o1,
|
|
||||||
InvitationItem o2) {
|
|
||||||
return compareInvitations(o1, o2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInserted(int position, int count) {
|
|
||||||
notifyItemRangeInserted(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemoved(int position, int count) {
|
|
||||||
notifyItemRangeRemoved(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMoved(int fromPosition, int toPosition) {
|
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChanged(int position, int count) {
|
|
||||||
notifyItemRangeChanged(position, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(InvitationItem oldItem,
|
|
||||||
InvitationItem newItem) {
|
|
||||||
return oldItem.isSubscribed() == newItem.isSubscribed() &&
|
|
||||||
oldItem.getNewSharers().equals(newItem.getNewSharers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(InvitationItem oldItem,
|
|
||||||
InvitationItem newItem) {
|
|
||||||
return oldItem.getShareable().equals(newItem.getShareable());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface AvailableForumClickListener {
|
interface AvailableForumClickListener {
|
||||||
void onItemClick(InvitationItem item, boolean accept);
|
void onItemClick(InvitationItem item, boolean accept);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.contact.BaseContactListAdapter;
|
import org.briarproject.android.contact.BaseContactListAdapter;
|
||||||
import org.briarproject.android.contact.ContactListItem;
|
|
||||||
|
|
||||||
class SharingStatusAdapter
|
class SharingStatusAdapter
|
||||||
extends BaseContactListAdapter<BaseContactListAdapter.BaseContactHolder> {
|
extends BaseContactListAdapter<BaseContactListAdapter.BaseContactHolder> {
|
||||||
@@ -24,9 +23,4 @@ class SharingStatusAdapter
|
|||||||
return new BaseContactHolder(v);
|
return new BaseContactHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareContactListItems(ContactListItem c1, ContactListItem c2) {
|
|
||||||
return compareByName(c1, c2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package org.briarproject.android.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.util.SortedList;
|
||||||
|
import android.support.v7.widget.RecyclerView.Adapter;
|
||||||
|
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
||||||
|
|
||||||
|
public abstract class BriarAdapter<T, V extends ViewHolder>
|
||||||
|
extends Adapter<V> {
|
||||||
|
|
||||||
|
protected final Context ctx;
|
||||||
|
protected final SortedList<T> items;
|
||||||
|
|
||||||
|
public BriarAdapter(Context ctx, Class<T> c) {
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.items = new SortedList<>(c, new SortedList.Callback<T>() {
|
||||||
|
@Override
|
||||||
|
public int compare(T item1, T item2) {
|
||||||
|
return BriarAdapter.this.compare(item1, item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInserted(int position, int count) {
|
||||||
|
notifyItemRangeInserted(position, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoved(int position, int count) {
|
||||||
|
notifyItemRangeRemoved(position, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMoved(int fromPosition, int toPosition) {
|
||||||
|
notifyItemMoved(fromPosition, toPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChanged(int position, int count) {
|
||||||
|
notifyItemRangeChanged(position, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areContentsTheSame(T item1, T item2) {
|
||||||
|
return BriarAdapter.this.areContentsTheSame(item1, item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areItemsTheSame(T item1, T item2) {
|
||||||
|
return BriarAdapter.this.areItemsTheSame(item1, item2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract int compare(T item1, T item2);
|
||||||
|
|
||||||
|
public abstract boolean areContentsTheSame(T item1, T item2);
|
||||||
|
|
||||||
|
public abstract boolean areItemsTheSame(T item1, T item2);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(T item) {
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAll(Collection<T> items) {
|
||||||
|
this.items.addAll(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public T getItemAt(int position) {
|
||||||
|
if (position == INVALID_POSITION || position >= items.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return items.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int findItemPosition(T item) {
|
||||||
|
return items.indexOf(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateItemAt(int position, T item) {
|
||||||
|
items.updateItemAt(position, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(T item) {
|
||||||
|
items.remove(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
items.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return items.size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,7 +20,6 @@ import android.widget.TextView;
|
|||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.blogs.BlogActivity;
|
import org.briarproject.android.blogs.BlogActivity;
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
import org.briarproject.android.view.TrustIndicatorView;
|
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.Author.Status;
|
import org.briarproject.api.identity.Author.Status;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
|
|||||||
Reference in New Issue
Block a user