mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Merge branch '1467-conversation-scrolling' into 'master'
Only scroll conversation list to bottom, when already at bottom Closes #1467 See merge request briar/briar!1000
This commit is contained in:
@@ -32,6 +32,7 @@ import static android.support.media.ExifInterface.TAG_IMAGE_WIDTH;
|
||||
import static android.support.media.ExifInterface.TAG_ORIENTATION;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
@@ -122,11 +123,7 @@ class AttachmentController {
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
tryToClose(is, LOG, WARNING);
|
||||
}
|
||||
|
||||
// calculate thumbnail size
|
||||
|
||||
@@ -148,6 +148,7 @@ public class ConversationActivity extends BriarActivity
|
||||
private ImageView toolbarStatus;
|
||||
private TextView toolbarTitle;
|
||||
private BriarRecyclerView list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private TextInputView textInputView;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@@ -227,7 +228,8 @@ public class ConversationActivity extends BriarActivity
|
||||
viewModel.getContactDisplayName());
|
||||
adapter = new ConversationAdapter(this, this);
|
||||
list = findViewById(R.id.conversationView);
|
||||
list.setLayoutManager(new LinearLayoutManager(this));
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
list.setLayoutManager(layoutManager);
|
||||
list.setAdapter(adapter);
|
||||
list.setEmptyText(getString(R.string.no_private_messages));
|
||||
|
||||
@@ -434,8 +436,9 @@ public class ConversationActivity extends BriarActivity
|
||||
adapter.getMessageItem(m);
|
||||
if (pair != null) {
|
||||
pair.getSecond().setText(text);
|
||||
boolean bottom = adapter.isScrolledToBottom(layoutManager);
|
||||
adapter.notifyItemChanged(pair.getFirst());
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
if (bottom) list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -464,8 +467,9 @@ public class ConversationActivity extends BriarActivity
|
||||
adapter.getMessageItem(m);
|
||||
if (pair != null) {
|
||||
pair.getSecond().setAttachments(items);
|
||||
boolean bottom = adapter.isScrolledToBottom(layoutManager);
|
||||
adapter.notifyItemChanged(pair.getFirst());
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
if (bottom) list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -514,10 +518,10 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void addConversationItem(ConversationItem item) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
boolean bottom = adapter.isScrolledToBottom(layoutManager);
|
||||
adapter.incrementRevision();
|
||||
adapter.add(item);
|
||||
// Scroll to the bottom
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
if (bottom) list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -112,4 +113,8 @@ class ConversationAdapter
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isScrolledToBottom(LinearLayoutManager layoutManager) {
|
||||
return layoutManager.findLastVisibleItemPosition() == items.size() - 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOption
|
||||
class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
||||
|
||||
@DrawableRes
|
||||
private static final int errorRes = R.drawable.ic_image_broken;
|
||||
private static final int ERROR_RES = R.drawable.ic_image_broken;
|
||||
|
||||
private final ImageView imageView;
|
||||
private final ViewGroup statusLayout;
|
||||
@@ -125,7 +125,7 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
||||
|
||||
if (attachment.hasError()) {
|
||||
clearImage();
|
||||
imageView.setImageResource(errorRes);
|
||||
imageView.setImageResource(ERROR_RES);
|
||||
} else {
|
||||
loadImage(item, attachment);
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
||||
GlideApp.with(imageView)
|
||||
.load(attachment)
|
||||
.diskCacheStrategy(NONE)
|
||||
.error(errorRes)
|
||||
.error(ERROR_RES)
|
||||
.transform(transformation)
|
||||
.transition(withCrossFade())
|
||||
.into(imageView)
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.android.conversation.AttachmentItem;
|
||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
@@ -23,7 +22,7 @@ import javax.inject.Inject;
|
||||
import static com.bumptech.glide.load.DataSource.LOCAL;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
|
||||
@NotNullByDefault
|
||||
class BriarDataFetcher implements DataFetcher<InputStream> {
|
||||
@@ -65,14 +64,7 @@ class BriarDataFetcher implements DataFetcher<InputStream> {
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
final InputStream stream = inputStream;
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
tryToClose(inputStream, LOG, WARNING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user