mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Add UnreadMessageButton to threaded conversations
This commit is contained in:
@@ -4,7 +4,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.LayoutRes;
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
@@ -90,12 +89,6 @@ public class ForumActivity extends
|
|||||||
setTitle(forum.getName());
|
setTitle(forum.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@LayoutRes
|
|
||||||
protected int getLayout() {
|
|
||||||
return R.layout.activity_threaded_conversation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThreadItemAdapter<ForumItem> createAdapter(
|
protected ThreadItemAdapter<ForumItem> createAdapter(
|
||||||
LinearLayoutManager layoutManager) {
|
LinearLayoutManager layoutManager) {
|
||||||
@@ -158,12 +151,6 @@ public class ForumActivity extends
|
|||||||
return R.string.forum_new_entry_posted;
|
return R.string.forum_new_entry_posted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@StringRes
|
|
||||||
protected int getItemReceivedString() {
|
|
||||||
return R.string.forum_new_entry_received;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showUnsubscribeDialog() {
|
private void showUnsubscribeDialog() {
|
||||||
OnClickListener okListener = new OnClickListener() {
|
OnClickListener okListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.LayoutRes;
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
@@ -92,12 +91,6 @@ public class GroupActivity extends
|
|||||||
setGroupEnabled(false);
|
setGroupEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@LayoutRes
|
|
||||||
protected int getLayout() {
|
|
||||||
return R.layout.activity_threaded_conversation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GroupMessageAdapter createAdapter(
|
protected GroupMessageAdapter createAdapter(
|
||||||
LinearLayoutManager layoutManager) {
|
LinearLayoutManager layoutManager) {
|
||||||
@@ -205,12 +198,6 @@ public class GroupActivity extends
|
|||||||
return R.string.groups_message_sent;
|
return R.string.groups_message_sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@StringRes
|
|
||||||
protected int getItemReceivedString() {
|
|
||||||
return R.string.groups_message_received;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReplyClick(GroupMessageItem item) {
|
public void onReplyClick(GroupMessageItem item) {
|
||||||
if (!isDissolved) super.onReplyClick(item);
|
if (!isDissolved) super.onReplyClick(item);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import android.support.v4.content.ContextCompat;
|
|||||||
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;
|
||||||
|
import android.view.animation.AccelerateInterpolator;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
@@ -19,6 +20,9 @@ import org.briarproject.briar.R;
|
|||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
||||||
import org.briarproject.briar.android.view.AuthorView;
|
import org.briarproject.briar.android.view.AuthorView;
|
||||||
|
|
||||||
|
import static android.view.View.INVISIBLE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
|
public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
|
||||||
@@ -48,9 +52,9 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
|
|||||||
textView.setText(StringUtils.trim(item.getText()));
|
textView.setText(StringUtils.trim(item.getText()));
|
||||||
|
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
topDivider.setVisibility(View.INVISIBLE);
|
topDivider.setVisibility(INVISIBLE);
|
||||||
} else {
|
} else {
|
||||||
topDivider.setVisibility(View.VISIBLE);
|
topDivider.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
author.setAuthor(item.getAuthor());
|
author.setAuthor(item.getAuthor());
|
||||||
@@ -58,16 +62,13 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
|
|||||||
author.setAuthorStatus(item.getStatus());
|
author.setAuthorStatus(item.getStatus());
|
||||||
|
|
||||||
if (item.equals(adapter.getReplyItem())) {
|
if (item.equals(adapter.getReplyItem())) {
|
||||||
layout.setBackgroundColor(ContextCompat
|
layout.setActivated(true);
|
||||||
.getColor(getContext(), R.color.forum_cell_highlight));
|
} else if (!item.isRead()) {
|
||||||
} else if (item.equals(adapter.getAddedItem())) {
|
layout.setActivated(true);
|
||||||
layout.setBackgroundColor(ContextCompat
|
animateFadeOut(adapter, item);
|
||||||
.getColor(getContext(), R.color.forum_cell_highlight));
|
listener.onUnreadItemVisible(item);
|
||||||
animateFadeOut(adapter, adapter.getAddedItem());
|
|
||||||
adapter.clearAddedItem();
|
|
||||||
} else {
|
} else {
|
||||||
layout.setBackgroundColor(ContextCompat
|
layout.setActivated(false);
|
||||||
.getColor(getContext(), R.color.window_background));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,31 +78,29 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
|
|||||||
setIsRecyclable(false);
|
setIsRecyclable(false);
|
||||||
ValueAnimator anim = new ValueAnimator();
|
ValueAnimator anim = new ValueAnimator();
|
||||||
adapter.addAnimatingItem(addedItem, anim);
|
adapter.addAnimatingItem(addedItem, anim);
|
||||||
ColorDrawable viewColor = (ColorDrawable) layout.getBackground();
|
ColorDrawable viewColor = new ColorDrawable(ContextCompat
|
||||||
|
.getColor(getContext(), R.color.forum_cell_highlight));
|
||||||
anim.setIntValues(viewColor.getColor(), ContextCompat
|
anim.setIntValues(viewColor.getColor(), ContextCompat
|
||||||
.getColor(getContext(), R.color.window_background));
|
.getColor(getContext(), R.color.window_background));
|
||||||
anim.setEvaluator(new ArgbEvaluator());
|
anim.setEvaluator(new ArgbEvaluator());
|
||||||
|
anim.setInterpolator(new AccelerateInterpolator());
|
||||||
anim.addListener(new Animator.AnimatorListener() {
|
anim.addListener(new Animator.AnimatorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationStart(Animator animation) {
|
public void onAnimationStart(Animator animation) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Animator animation) {
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
layout.setBackgroundResource(
|
||||||
|
R.drawable.list_item_thread_background);
|
||||||
|
layout.setActivated(false);
|
||||||
setIsRecyclable(true);
|
setIsRecyclable(true);
|
||||||
adapter.removeAnimatingItem(addedItem);
|
adapter.removeAnimatingItem(addedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationCancel(Animator animation) {
|
public void onAnimationCancel(Animator animation) {
|
||||||
setIsRecyclable(true);
|
|
||||||
adapter.removeAnimatingItem(addedItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationRepeat(Animator animation) {
|
public void onAnimationRepeat(Animator animation) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.briar.android.threaded;
|
package org.briarproject.briar.android.threaded;
|
||||||
|
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@@ -18,8 +19,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static android.support.v7.widget.RecyclerView.NO_POSITION;
|
import static android.support.v7.widget.RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
public class ThreadItemAdapter<I extends ThreadItem>
|
public class ThreadItemAdapter<I extends ThreadItem>
|
||||||
@@ -33,10 +32,8 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
private final ThreadItemListener<I> listener;
|
private final ThreadItemListener<I> listener;
|
||||||
private final LinearLayoutManager layoutManager;
|
private final LinearLayoutManager layoutManager;
|
||||||
|
|
||||||
// highlight not dependant on time
|
@Nullable
|
||||||
private I replyItem;
|
private I replyItem;
|
||||||
// temporary highlight
|
|
||||||
private I addedItem;
|
|
||||||
|
|
||||||
private volatile int revision = 0;
|
private volatile int revision = 0;
|
||||||
|
|
||||||
@@ -58,7 +55,6 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
public void onBindViewHolder(BaseThreadItemViewHolder<I> ui, int position) {
|
public void onBindViewHolder(BaseThreadItemViewHolder<I> ui, int position) {
|
||||||
I item = getVisibleItem(position);
|
I item = getVisibleItem(position);
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
listener.onItemVisible(item);
|
|
||||||
ui.bind(this, listener, item, position);
|
ui.bind(this, listener, item, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +68,7 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
return getVisiblePos(null);
|
return getVisiblePos(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
I getReplyItem() {
|
I getReplyItem() {
|
||||||
return replyItem;
|
return replyItem;
|
||||||
}
|
}
|
||||||
@@ -84,7 +81,6 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
|
|
||||||
public void add(I item) {
|
public void add(I item) {
|
||||||
items.add(item);
|
items.add(item);
|
||||||
addedItem = item;
|
|
||||||
if (item.getParentId() == null) {
|
if (item.getParentId() == null) {
|
||||||
notifyItemInserted(getVisiblePos(item));
|
notifyItemInserted(getVisiblePos(item));
|
||||||
} else {
|
} else {
|
||||||
@@ -262,10 +258,6 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isVisible(I item) {
|
|
||||||
return getVisiblePos(item) != NO_POSITION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the visible position of the given item.
|
* Returns the visible position of the given item.
|
||||||
*
|
*
|
||||||
@@ -296,14 +288,6 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
return item == null ? visibleCounter : NO_POSITION;
|
return item == null ? visibleCounter : NO_POSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
I getAddedItem() {
|
|
||||||
return addedItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearAddedItem() {
|
|
||||||
addedItem = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addAnimatingItem(I item, ValueAnimator anim) {
|
void addAnimatingItem(I item, ValueAnimator anim) {
|
||||||
animatingItems.put(item, anim);
|
animatingItems.put(item, anim);
|
||||||
}
|
}
|
||||||
@@ -323,10 +307,108 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
revision++;
|
revision++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ThreadItemListener<I> {
|
|
||||||
|
|
||||||
void onItemVisible(I item);
|
/**
|
||||||
|
* Gets the number of unread items above and below the current view port.
|
||||||
|
*
|
||||||
|
* Attention: Do not call this when the list is still scrolling,
|
||||||
|
* because then the view port is unknown.
|
||||||
|
*/
|
||||||
|
public UnreadCount getUnreadCount() {
|
||||||
|
final int positionTop = layoutManager.findFirstVisibleItemPosition();
|
||||||
|
final int positionBottom = layoutManager.findLastVisibleItemPosition();
|
||||||
|
if (positionTop == NO_POSITION && positionBottom == NO_POSITION)
|
||||||
|
return new UnreadCount(0, 0);
|
||||||
|
|
||||||
|
int unreadCounterTop = 0, unreadCounterBottom = 0;
|
||||||
|
int visibleCounter = 0;
|
||||||
|
int levelLimit = UNDEFINED;
|
||||||
|
for (I i : items) {
|
||||||
|
if (levelLimit >= 0) {
|
||||||
|
if (i.getLevel() > levelLimit) {
|
||||||
|
// skip all the items below a non visible branch
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
levelLimit = UNDEFINED;
|
||||||
|
}
|
||||||
|
if (visibleCounter > positionBottom && !i.isRead()) {
|
||||||
|
unreadCounterBottom++;
|
||||||
|
} else if (visibleCounter < positionTop && !i.isRead()) {
|
||||||
|
unreadCounterTop++;
|
||||||
|
} else if (!i.isShowingDescendants()) {
|
||||||
|
levelLimit = i.getLevel();
|
||||||
|
}
|
||||||
|
visibleCounter++;
|
||||||
|
}
|
||||||
|
return new UnreadCount(unreadCounterTop, unreadCounterBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the position of the first unread item below the current viewport
|
||||||
|
*/
|
||||||
|
public int getVisibleUnreadPosBottom() {
|
||||||
|
final int positionBottom = layoutManager.findLastVisibleItemPosition();
|
||||||
|
int visibleCounter = 0;
|
||||||
|
int levelLimit = UNDEFINED;
|
||||||
|
for (I i : items) {
|
||||||
|
if (levelLimit >= 0) {
|
||||||
|
if (i.getLevel() > levelLimit) {
|
||||||
|
// skip all the items below a non visible branch
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
levelLimit = UNDEFINED;
|
||||||
|
}
|
||||||
|
if (visibleCounter > positionBottom && !i.isRead()) {
|
||||||
|
return visibleCounter;
|
||||||
|
} else if (!i.isShowingDescendants()) {
|
||||||
|
levelLimit = i.getLevel();
|
||||||
|
}
|
||||||
|
visibleCounter++;
|
||||||
|
}
|
||||||
|
return NO_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the position of the first unread item above the current viewport
|
||||||
|
*/
|
||||||
|
public int getVisibleUnreadPosTop() {
|
||||||
|
final int positionTop = layoutManager.findFirstVisibleItemPosition();
|
||||||
|
int position = NO_POSITION;
|
||||||
|
int visibleCounter = 0;
|
||||||
|
int levelLimit = UNDEFINED;
|
||||||
|
for (I i : items) {
|
||||||
|
if (levelLimit >= 0) {
|
||||||
|
if (i.getLevel() > levelLimit) {
|
||||||
|
// skip all the items below a non visible branch
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
levelLimit = UNDEFINED;
|
||||||
|
}
|
||||||
|
if (visibleCounter < positionTop && !i.isRead()) {
|
||||||
|
position = visibleCounter;
|
||||||
|
} if (visibleCounter >= positionTop) {
|
||||||
|
return position;
|
||||||
|
} else if (!i.isShowingDescendants()) {
|
||||||
|
levelLimit = i.getLevel();
|
||||||
|
}
|
||||||
|
visibleCounter++;
|
||||||
|
}
|
||||||
|
return NO_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class UnreadCount {
|
||||||
|
final int top, bottom;
|
||||||
|
|
||||||
|
private UnreadCount(int top, int bottom) {
|
||||||
|
this.top = top;
|
||||||
|
this.bottom = bottom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ThreadItemListener<I> {
|
||||||
|
void onUnreadItemVisible(I item);
|
||||||
|
|
||||||
void onReplyClick(I item);
|
void onReplyClick(I item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ package org.briarproject.briar.android.threaded;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.CallSuper;
|
import android.support.annotation.CallSuper;
|
||||||
import android.support.annotation.LayoutRes;
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -30,6 +29,7 @@ import org.briarproject.briar.android.threaded.ThreadListController.ThreadListLi
|
|||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
|
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
|
||||||
|
import org.briarproject.briar.android.view.UnreadMessageButton;
|
||||||
import org.briarproject.briar.api.client.NamedGroup;
|
import org.briarproject.briar.api.client.NamedGroup;
|
||||||
import org.briarproject.briar.api.client.PostHeader;
|
import org.briarproject.briar.api.client.PostHeader;
|
||||||
|
|
||||||
@@ -40,8 +40,12 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static android.support.design.widget.Snackbar.make;
|
import static android.support.design.widget.Snackbar.make;
|
||||||
|
import static android.support.v7.widget.RecyclerView.NO_POSITION;
|
||||||
|
import static android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE;
|
||||||
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 java.util.logging.Level.INFO;
|
||||||
|
import static org.briarproject.briar.android.threaded.ThreadItemAdapter.UnreadCount;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -60,6 +64,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
protected BriarRecyclerView list;
|
protected BriarRecyclerView list;
|
||||||
protected TextInputView textInput;
|
protected TextInputView textInput;
|
||||||
protected GroupId groupId;
|
protected GroupId groupId;
|
||||||
|
private UnreadMessageButton upButton, downButton;
|
||||||
private MessageId replyId;
|
private MessageId replyId;
|
||||||
|
|
||||||
protected abstract ThreadListController<G, I, H> getController();
|
protected abstract ThreadListController<G, I, H> getController();
|
||||||
@@ -72,7 +77,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
public void onCreate(@Nullable Bundle state) {
|
public void onCreate(@Nullable Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
|
||||||
setContentView(getLayout());
|
setContentView(R.layout.activity_threaded_conversation);
|
||||||
|
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||||
@@ -89,6 +94,47 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
adapter = createAdapter(linearLayoutManager);
|
adapter = createAdapter(linearLayoutManager);
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
|
|
||||||
|
list.getRecyclerView().addOnScrollListener(
|
||||||
|
new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrolled(RecyclerView recyclerView, int dx,
|
||||||
|
int dy) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
|
if (dx == 0 && dy == 0) {
|
||||||
|
// scrollToPosition has been called and finished
|
||||||
|
updateUnreadCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(RecyclerView recyclerView,
|
||||||
|
int newState) {
|
||||||
|
super.onScrollStateChanged(recyclerView, newState);
|
||||||
|
if (newState == SCROLL_STATE_IDLE) {
|
||||||
|
updateUnreadCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
upButton = (UnreadMessageButton) findViewById(R.id.upButton);
|
||||||
|
downButton = (UnreadMessageButton) findViewById(R.id.downButton);
|
||||||
|
upButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int position = adapter.getVisibleUnreadPosTop();
|
||||||
|
if (position != NO_POSITION) {
|
||||||
|
list.getRecyclerView().scrollToPosition(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
downButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int position = adapter.getVisibleUnreadPosBottom();
|
||||||
|
if (position != NO_POSITION) {
|
||||||
|
list.getRecyclerView().scrollToPosition(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
byte[] replyIdBytes = state.getByteArray(KEY_REPLY_ID);
|
byte[] replyIdBytes = state.getByteArray(KEY_REPLY_ID);
|
||||||
if (replyIdBytes != null) replyId = new MessageId(replyIdBytes);
|
if (replyIdBytes != null) replyId = new MessageId(replyIdBytes);
|
||||||
@@ -99,9 +145,6 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
loadSharingContacts();
|
loadSharingContacts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
|
||||||
protected abstract int getLayout();
|
|
||||||
|
|
||||||
protected abstract A createAdapter(LinearLayoutManager layoutManager);
|
protected abstract A createAdapter(LinearLayoutManager layoutManager);
|
||||||
|
|
||||||
protected void loadNamedGroup() {
|
protected void loadNamedGroup() {
|
||||||
@@ -225,7 +268,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemVisible(I item) {
|
public void onUnreadItemVisible(I item) {
|
||||||
if (!item.isRead()) {
|
if (!item.isRead()) {
|
||||||
item.setRead(true);
|
item.setRead(true);
|
||||||
getController().markItemRead(item);
|
getController().markItemRead(item);
|
||||||
@@ -329,34 +372,28 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
supportFinishAfterTransition();
|
supportFinishAfterTransition();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addItem(final I item, boolean isLocal) {
|
protected void addItem(I item, boolean isLocal) {
|
||||||
adapter.incrementRevision();
|
adapter.incrementRevision();
|
||||||
adapter.add(item);
|
adapter.add(item);
|
||||||
if (isLocal && adapter.isVisible(item)) {
|
|
||||||
|
if (isLocal) {
|
||||||
displaySnackbarShort(getItemPostedString());
|
displaySnackbarShort(getItemPostedString());
|
||||||
} else {
|
} else {
|
||||||
Snackbar snackbar = Snackbar.make(list,
|
updateUnreadCount();
|
||||||
isLocal ? getItemPostedString() : getItemReceivedString(),
|
|
||||||
Snackbar.LENGTH_LONG);
|
|
||||||
snackbar.getView().setBackgroundResource(R.color.briar_primary);
|
|
||||||
snackbar.setActionTextColor(ContextCompat
|
|
||||||
.getColor(ThreadListActivity.this,
|
|
||||||
R.color.briar_button_positive));
|
|
||||||
snackbar.setAction(R.string.show, new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
adapter.scrollTo(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
snackbar.getView().setBackgroundResource(R.color.briar_primary);
|
|
||||||
snackbar.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateUnreadCount() {
|
||||||
|
UnreadCount unreadCount = adapter.getUnreadCount();
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Updating unread count: top=" + unreadCount.top +
|
||||||
|
" bottom=" + unreadCount.bottom);
|
||||||
|
}
|
||||||
|
upButton.setUnreadCount(unreadCount.top);
|
||||||
|
downButton.setUnreadCount(unreadCount.bottom);
|
||||||
|
}
|
||||||
|
|
||||||
@StringRes
|
@StringRes
|
||||||
protected abstract int getItemPostedString();
|
protected abstract int getItemPostedString();
|
||||||
|
|
||||||
@StringRes
|
|
||||||
protected abstract int getItemReceivedString();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import org.briarproject.briar.R;
|
|||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.INVISIBLE;
|
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -64,7 +63,7 @@ public class ThreadPostViewHolder<I extends ThreadItem>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.hasDescendants()) {
|
if (item.hasDescendants()) {
|
||||||
chevron.setVisibility(VISIBLE);
|
// chevron.setVisibility(VISIBLE);
|
||||||
if (item.isShowingDescendants()) {
|
if (item.isShowingDescendants()) {
|
||||||
chevron.setSelected(false);
|
chevron.setSelected(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -82,7 +81,7 @@ public class ThreadPostViewHolder<I extends ThreadItem>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
chevron.setVisibility(INVISIBLE);
|
// chevron.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
replyButton.setOnClickListener(new View.OnClickListener() {
|
replyButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -64,12 +64,16 @@ public class UnreadMessageButton extends FrameLayout {
|
|||||||
|
|
||||||
public void setUnreadCount(int count) {
|
public void setUnreadCount(int count) {
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
unread.setVisibility(INVISIBLE);
|
fab.setVisibility(GONE);
|
||||||
fab.hide();
|
// fab.hide();
|
||||||
|
unread.setVisibility(GONE);
|
||||||
} else {
|
} else {
|
||||||
|
// FIXME: Use animations when upgrading to support library 24.2.0
|
||||||
|
// https://code.google.com/p/android/issues/detail?id=216469
|
||||||
|
fab.setVisibility(VISIBLE);
|
||||||
|
// if (!fab.isShown()) fab.show();
|
||||||
unread.setVisibility(VISIBLE);
|
unread.setVisibility(VISIBLE);
|
||||||
unread.setText(String.valueOf(count));
|
unread.setText(String.valueOf(count));
|
||||||
if (!fab.isShown()) fab.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:drawable="@color/forum_cell_highlight"
|
||||||
|
android:state_activated="true"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@color/window_background"/>
|
||||||
|
|
||||||
|
</selector>
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<include layout="@layout/toolbar"/>
|
<include layout="@layout/toolbar"/>
|
||||||
|
|
||||||
<android.support.design.widget.CoordinatorLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="top|right"
|
android:layout_gravity="top|right"
|
||||||
app:layout_anchorGravity="top|right"
|
|
||||||
app:direction="up"/>
|
app:direction="up"/>
|
||||||
|
|
||||||
<org.briarproject.briar.android.view.UnreadMessageButton
|
<org.briarproject.briar.android.view.UnreadMessageButton
|
||||||
@@ -35,10 +34,9 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|right"
|
android:layout_gravity="bottom|right"
|
||||||
app:layout_anchorGravity="bottom|right"
|
|
||||||
app:direction="down"/>
|
app:direction="down"/>
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<org.briarproject.briar.android.view.TextInputView
|
<org.briarproject.briar.android.view.TextInputView
|
||||||
android:id="@+id/text_input_container"
|
android:id="@+id/text_input_container"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/list_item_thread_background"
|
||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
@@ -113,6 +114,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignBottom="@+id/author"
|
android:layout_alignBottom="@+id/author"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
android:layout_toLeftOf="@+id/chevron"
|
android:layout_toLeftOf="@+id/chevron"
|
||||||
android:text="@string/btn_reply"
|
android:text="@string/btn_reply"
|
||||||
android:textSize="@dimen/text_size_tiny"/>
|
android:textSize="@dimen/text_size_tiny"/>
|
||||||
@@ -127,7 +129,8 @@
|
|||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:padding="@dimen/margin_medium"
|
android:padding="@dimen/margin_medium"
|
||||||
android:scaleType="center"
|
android:scaleType="center"
|
||||||
android:src="@drawable/selector_chevron"/>
|
android:src="@drawable/selector_chevron"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/top_divider"
|
android:id="@+id/top_divider"
|
||||||
|
|||||||
@@ -164,7 +164,6 @@
|
|||||||
<string name="groups_invitation_sent">Group invitation has been sent</string>
|
<string name="groups_invitation_sent">Group invitation has been sent</string>
|
||||||
<string name="groups_compose_message">Compose Message</string>
|
<string name="groups_compose_message">Compose Message</string>
|
||||||
<string name="groups_message_sent">Message sent</string>
|
<string name="groups_message_sent">Message sent</string>
|
||||||
<string name="groups_message_received">Message received</string>
|
|
||||||
<string name="groups_member_list">Member List</string>
|
<string name="groups_member_list">Member List</string>
|
||||||
<string name="groups_invite_members">Invite Members</string>
|
<string name="groups_invite_members">Invite Members</string>
|
||||||
<string name="groups_member_created_you">You created the group</string>
|
<string name="groups_member_created_you">You created the group</string>
|
||||||
@@ -218,7 +217,6 @@
|
|||||||
</plurals>
|
</plurals>
|
||||||
<string name="forum_compose_post">New Forum Post</string>
|
<string name="forum_compose_post">New Forum Post</string>
|
||||||
<string name="forum_new_entry_posted">Forum entry posted</string>
|
<string name="forum_new_entry_posted">Forum entry posted</string>
|
||||||
<string name="forum_new_entry_received">New forum entry</string>
|
|
||||||
<string name="forum_new_message_hint">New Entry</string>
|
<string name="forum_new_message_hint">New Entry</string>
|
||||||
<string name="forum_message_reply_hint">New Reply</string>
|
<string name="forum_message_reply_hint">New Reply</string>
|
||||||
<string name="btn_reply">Reply</string>
|
<string name="btn_reply">Reply</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user