mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-05 10:39:24 +02:00
show new message marker #447
This commit is contained in:
parent
b74c654451
commit
96814700cb
8 changed files with 711 additions and 768 deletions
|
@ -151,7 +151,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
public static final String CHAT_ID_EXTRA = "chat_id";
|
public static final String CHAT_ID_EXTRA = "chat_id";
|
||||||
public static final String IS_ARCHIVED_EXTRA = "is_archived";
|
public static final String IS_ARCHIVED_EXTRA = "is_archived";
|
||||||
public static final String TEXT_EXTRA = "draft_text";
|
public static final String TEXT_EXTRA = "draft_text";
|
||||||
public static final String LAST_SEEN_EXTRA = "last_seen";
|
|
||||||
public static final String STARTING_POSITION_EXTRA = "starting_position";
|
public static final String STARTING_POSITION_EXTRA = "starting_position";
|
||||||
|
|
||||||
private static final int PICK_GALLERY = 1;
|
private static final int PICK_GALLERY = 1;
|
||||||
|
@ -310,9 +309,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
if (isFinishing()) overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
|
if (isFinishing()) overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
|
||||||
quickAttachmentDrawer.onPause();
|
quickAttachmentDrawer.onPause();
|
||||||
inputPanel.onPause();
|
inputPanel.onPause();
|
||||||
|
|
||||||
fragment.setLastSeen(System.currentTimeMillis());
|
|
||||||
|
|
||||||
AudioSlidePlayer.stopAll();
|
AudioSlidePlayer.stopAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1163,7 +1159,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment.setLastSeen(0);
|
fragment.setLastSeen(-1);
|
||||||
|
|
||||||
if (refreshFragment) {
|
if (refreshFragment) {
|
||||||
fragment.reload(recipient, chatId);
|
fragment.reload(recipient, chatId);
|
||||||
|
|
|
@ -91,6 +91,8 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||||
private @NonNull DcChat dcChat;
|
private @NonNull DcChat dcChat;
|
||||||
private @NonNull int[] dcMsgList = new int[0];
|
private @NonNull int[] dcMsgList = new int[0];
|
||||||
private int positionToPulseHighlight = -1;
|
private int positionToPulseHighlight = -1;
|
||||||
|
private int lastSeenPosition = -1;
|
||||||
|
private long lastSeen = -1;
|
||||||
|
|
||||||
protected static class ViewHolder extends RecyclerView.ViewHolder {
|
protected static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
public <V extends View & BindableConversationItem> ViewHolder(final @NonNull V itemView) {
|
public <V extends View & BindableConversationItem> ViewHolder(final @NonNull V itemView) {
|
||||||
|
@ -120,6 +122,19 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||||
return dcChat.getName();
|
return dcChat.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastSeen(long timestamp) {
|
||||||
|
lastSeen = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateLastSeenPosition() {
|
||||||
|
this.lastSeenPosition = findLastSeenPosition(lastSeen);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastSeenPosition() {
|
||||||
|
return lastSeenPosition;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return dcMsgList.length;
|
return dcMsgList.length;
|
||||||
|
@ -261,24 +276,6 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int findLastSeenPosition(long lastSeen) {
|
|
||||||
/* TODO -- we shoud do this without loading all messages in the chat
|
|
||||||
if (lastSeen <= 0) return -1;
|
|
||||||
if (!isActive()) return -1;
|
|
||||||
|
|
||||||
int count = getItemCount();
|
|
||||||
|
|
||||||
for (int i = 0;i<count;i++) {
|
|
||||||
DcMsg msg = getMsg(i);
|
|
||||||
if (msg.isOutgoing() || msg.getTimestamp() <= lastSeen) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleSelection(DcMsg messageRecord) {
|
public void toggleSelection(DcMsg messageRecord) {
|
||||||
if (!batchSelected.remove(messageRecord)) {
|
if (!batchSelected.remove(messageRecord)) {
|
||||||
batchSelected.add(messageRecord);
|
batchSelected.add(messageRecord);
|
||||||
|
@ -314,6 +311,59 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getHeaderId(int position) {
|
||||||
|
if (position >= getItemCount()) return -1;
|
||||||
|
if (position < 0) return -1;
|
||||||
|
|
||||||
|
calendar.setTime(new Date(getSortTimestamp(position)));
|
||||||
|
return Util.hashCode(calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_YEAR));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
|
||||||
|
return new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.conversation_item_header, parent, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date header view
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onBindHeaderViewHolder(HeaderViewHolder viewHolder, int position) {
|
||||||
|
viewHolder.setText(DateUtils.getRelativeDate(getContext(), locale, getSortTimestamp(position)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void changeData(@Nullable int[] dcMsgList) {
|
||||||
|
// should be called when there are new messages
|
||||||
|
this.dcMsgList = dcMsgList == null ? new int[0] : dcMsgList;
|
||||||
|
reloadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadData() {
|
||||||
|
// should be called when some items in a message are changed, eg. seen-state
|
||||||
|
recordCache.clear();
|
||||||
|
updateLastSeenPosition();
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findLastSeenPosition(long lastSeen) {
|
||||||
|
if (lastSeen <= 0) return -1;
|
||||||
|
if (!isActive()) return -1;
|
||||||
|
|
||||||
|
int count = getItemCount();
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
DcMsg msg = getMsg(i);
|
||||||
|
if (msg.isOutgoing() || msg.getTimestamp() <= lastSeen) {
|
||||||
|
return i - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public HeaderViewHolder onCreateLastSeenViewHolder(ViewGroup parent) {
|
public HeaderViewHolder onCreateLastSeenViewHolder(ViewGroup parent) {
|
||||||
return new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.conversation_item_last_seen, parent, false));
|
return new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.conversation_item_last_seen, parent, false));
|
||||||
}
|
}
|
||||||
|
@ -323,30 +373,16 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||||
}
|
}
|
||||||
|
|
||||||
static class LastSeenHeader extends StickyHeaderDecoration {
|
static class LastSeenHeader extends StickyHeaderDecoration {
|
||||||
|
|
||||||
private final ConversationAdapter adapter;
|
private final ConversationAdapter adapter;
|
||||||
private final long lastSeenTimestamp;
|
|
||||||
|
|
||||||
LastSeenHeader(ConversationAdapter adapter, long lastSeenTimestamp) {
|
LastSeenHeader(ConversationAdapter adapter) {
|
||||||
super(adapter, false, false);
|
super(adapter, false, false);
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
this.lastSeenTimestamp = lastSeenTimestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasHeader(RecyclerView parent, StickyHeaderAdapter stickyAdapter, int position) {
|
protected boolean hasHeader(RecyclerView parent, StickyHeaderAdapter stickyAdapter, int position) {
|
||||||
if (!adapter.isActive()) {
|
return adapter.isActive() && position == adapter.getLastSeenPosition();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastSeenTimestamp <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
long currentRecordTimestamp = adapter.getSortTimestamp(position);
|
|
||||||
long previousRecordTimestamp = adapter.getSortTimestamp(position + 1);
|
|
||||||
|
|
||||||
return currentRecordTimestamp > lastSeenTimestamp && previousRecordTimestamp < lastSeenTimestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -371,41 +407,5 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||||
return viewHolder;
|
return viewHolder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getHeaderId(int position) {
|
|
||||||
if (position >= getItemCount()) return -1;
|
|
||||||
if (position < 0) return -1;
|
|
||||||
|
|
||||||
DcMsg dcMsg = getMsg(position);
|
|
||||||
|
|
||||||
calendar.setTime(new Date(getSortTimestamp(position)));
|
|
||||||
return Util.hashCode(calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_YEAR));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
|
|
||||||
return new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.conversation_item_header, parent, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindHeaderViewHolder(HeaderViewHolder viewHolder, int position) {
|
|
||||||
DcMsg msg = getMsg(position);
|
|
||||||
viewHolder.setText(DateUtils.getRelativeDate(getContext(), locale, getSortTimestamp(position)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void changeData(@Nullable int[] dcMsgList) {
|
|
||||||
// should be called when there are new messages
|
|
||||||
this.dcMsgList = dcMsgList==null? new int[0] : dcMsgList;
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadData() {
|
|
||||||
// should be called when some items in a message are changed, eg. seen-state
|
|
||||||
recordCache.clear();
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.LoaderManager;
|
|
||||||
import android.support.v4.content.Loader;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.view.ActionMode;
|
import android.support.v7.view.ActionMode;
|
||||||
|
@ -63,7 +61,6 @@ import org.thoughtcrime.securesms.ConversationAdapter.HeaderViewHolder;
|
||||||
import org.thoughtcrime.securesms.ConversationAdapter.ItemClickListener;
|
import org.thoughtcrime.securesms.ConversationAdapter.ItemClickListener;
|
||||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||||
import org.thoughtcrime.securesms.connect.DcMsgListLoader;
|
|
||||||
import org.thoughtcrime.securesms.database.Address;
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||||
|
@ -86,8 +83,7 @@ import static org.thoughtcrime.securesms.util.RelayUtil.setForwardingMessageIds;
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
public class ConversationFragment extends Fragment
|
public class ConversationFragment extends Fragment
|
||||||
implements LoaderManager.LoaderCallbacks<int[]>,
|
implements DcEventCenter.DcEventDelegate
|
||||||
DcEventCenter.DcEventDelegate
|
|
||||||
{
|
{
|
||||||
private static final String TAG = ConversationFragment.class.getSimpleName();
|
private static final String TAG = ConversationFragment.class.getSimpleName();
|
||||||
private static final String KEY_LIMIT = "limit";
|
private static final String KEY_LIMIT = "limit";
|
||||||
|
@ -102,11 +98,9 @@ public class ConversationFragment extends Fragment
|
||||||
|
|
||||||
private Recipient recipient;
|
private Recipient recipient;
|
||||||
private long chatId;
|
private long chatId;
|
||||||
private long lastSeen;
|
|
||||||
private int startingPosition;
|
private int startingPosition;
|
||||||
private int previousOffset;
|
private int previousOffset;
|
||||||
private boolean firstLoad;
|
private boolean firstLoad;
|
||||||
private long loaderStartTime;
|
|
||||||
private ActionMode actionMode;
|
private ActionMode actionMode;
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
private RecyclerView list;
|
private RecyclerView list;
|
||||||
|
@ -160,7 +154,6 @@ public class ConversationFragment extends Fragment
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle bundle) {
|
public void onActivityCreated(Bundle bundle) {
|
||||||
super.onActivityCreated(bundle);
|
super.onActivityCreated(bundle);
|
||||||
|
|
||||||
initializeResources();
|
initializeResources();
|
||||||
initializeListAdapter();
|
initializeListAdapter();
|
||||||
}
|
}
|
||||||
|
@ -209,12 +202,19 @@ public class ConversationFragment extends Fragment
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
dcContext.marknoticedChat(Long.valueOf(chatId).intValue());
|
dcContext.marknoticedChat((int) chatId);
|
||||||
if (list.getAdapter() != null) {
|
if (list.getAdapter() != null) {
|
||||||
list.getAdapter().notifyDataSetChanged();
|
list.getAdapter().notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
setLastSeen(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
public void onNewIntent() {
|
public void onNewIntent() {
|
||||||
if (actionMode != null) {
|
if (actionMode != null) {
|
||||||
actionMode.finish();
|
actionMode.finish();
|
||||||
|
@ -230,23 +230,20 @@ public class ConversationFragment extends Fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveToLastSeen() {
|
public void moveToLastSeen() {
|
||||||
if (lastSeen <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list == null || getListAdapter() == null) {
|
if (list == null || getListAdapter() == null) {
|
||||||
Log.w(TAG, "Tried to move to last seen position, but we hadn't initialized the view yet.");
|
Log.w(TAG, "Tried to move to last seen position, but we hadn't initialized the view yet.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int position = getListAdapter().findLastSeenPosition(lastSeen);
|
if (getListAdapter().getLastSeenPosition() < 0) {
|
||||||
scrollToLastSeenPosition(position);
|
return;
|
||||||
|
}
|
||||||
|
scrollToLastSeenPosition(getListAdapter().getLastSeenPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeResources() {
|
private void initializeResources() {
|
||||||
this.chatId = this.getActivity().getIntent().getIntExtra(ConversationActivity.CHAT_ID_EXTRA, -1);
|
this.chatId = this.getActivity().getIntent().getIntExtra(ConversationActivity.CHAT_ID_EXTRA, -1);
|
||||||
this.recipient = Recipient.from(getActivity(), Address.fromChat((int)this.chatId));
|
this.recipient = Recipient.from(getActivity(), Address.fromChat((int)this.chatId));
|
||||||
this.lastSeen = this.getActivity().getIntent().getLongExtra(ConversationActivity.LAST_SEEN_EXTRA, -1);
|
|
||||||
this.startingPosition = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);
|
this.startingPosition = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);
|
||||||
this.firstLoad = true;
|
this.firstLoad = true;
|
||||||
|
|
||||||
|
@ -260,7 +257,6 @@ public class ConversationFragment extends Fragment
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.addItemDecoration(new StickyHeaderDecoration(adapter, false, false));
|
list.addItemDecoration(new StickyHeaderDecoration(adapter, false, false));
|
||||||
|
|
||||||
setLastSeen(lastSeen);
|
|
||||||
reloadList();
|
reloadList();
|
||||||
updateLocationButton();
|
updateLocationButton();
|
||||||
}
|
}
|
||||||
|
@ -313,14 +309,16 @@ public class ConversationFragment extends Fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastSeen(long lastSeen) {
|
public void setLastSeen(long lastSeen) {
|
||||||
this.lastSeen = lastSeen;
|
getListAdapter().setLastSeen(lastSeen);
|
||||||
if (lastSeenDecoration != null) {
|
if (lastSeenDecoration != null) {
|
||||||
list.removeItemDecoration(lastSeenDecoration);
|
list.removeItemDecoration(lastSeenDecoration);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSeenDecoration = new ConversationAdapter.LastSeenHeader(getListAdapter(), lastSeen);
|
if (lastSeen > 0) {
|
||||||
|
lastSeenDecoration = new ConversationAdapter.LastSeenHeader(getListAdapter()/*, lastSeen*/);
|
||||||
list.addItemDecoration(lastSeenDecoration);
|
list.addItemDecoration(lastSeenDecoration);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getMessageContent(DcMsg msg, DcMsg prev_msg)
|
private String getMessageContent(DcMsg msg, DcMsg prev_msg)
|
||||||
{
|
{
|
||||||
|
@ -442,60 +440,15 @@ public class ConversationFragment extends Fragment
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: clarify scroll behavior
|
||||||
private void reloadList() {
|
private void reloadList() {
|
||||||
ConversationAdapter adapter = getListAdapter();
|
ConversationAdapter adapter = getListAdapter();
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// just for testing, here are two variants.
|
|
||||||
final boolean loadSynchronous = true;
|
|
||||||
if (loadSynchronous) {
|
|
||||||
// this typically takes <1 ms ...
|
|
||||||
loaderStartTime = System.currentTimeMillis();
|
|
||||||
int[] msgs = DcHelper.getContext(getContext()).getChatMsgs((int) chatId, 0, 0);
|
int[] msgs = DcHelper.getContext(getContext()).getChatMsgs((int) chatId, 0, 0);
|
||||||
onLoadFinished(null, msgs);
|
adapter.changeData(msgs);
|
||||||
}
|
int lastSeenPosition = adapter.getLastSeenPosition();
|
||||||
//FIXME: remove dead code
|
|
||||||
else {
|
|
||||||
// ... while this takes >100 ms
|
|
||||||
LoaderManager loaderManager = getLoaderManager();
|
|
||||||
if (loaderManager != null) {
|
|
||||||
loaderManager.restartLoader(0, Bundle.EMPTY, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateLocationButton() {
|
|
||||||
floatingLocationButton.setVisibility(dcContext.isSendingLocationsToChat((int) chatId)? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Loader<int[]> onCreateLoader(int id, Bundle args) {
|
|
||||||
Log.w(TAG, "onCreateLoader");
|
|
||||||
loaderStartTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
return new DcMsgListLoader(getActivity(), (int) chatId, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadFinished(Loader<int[]> arg0, int[] dcMsgList) {
|
|
||||||
long loadTime = System.currentTimeMillis() - loaderStartTime;
|
|
||||||
int count = dcMsgList.length;
|
|
||||||
Log.w(TAG, "onLoadFinished - took " + loadTime + " ms to load a message list of size " + count);
|
|
||||||
|
|
||||||
ConversationAdapter adapter = getListAdapter();
|
|
||||||
if (adapter == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastSeen == -1) {
|
|
||||||
//setLastSeen(loader.getLastSeen()); -- TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter.changeData(dcMsgList);
|
|
||||||
|
|
||||||
int lastSeenPosition = adapter.findLastSeenPosition(lastSeen);
|
|
||||||
|
|
||||||
if (firstLoad) {
|
if (firstLoad) {
|
||||||
if (startingPosition >= 0) {
|
if (startingPosition >= 0) {
|
||||||
|
@ -505,6 +458,7 @@ public class ConversationFragment extends Fragment
|
||||||
}
|
}
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
} else if (previousOffset > 0) {
|
} else if (previousOffset > 0) {
|
||||||
|
int count = msgs.length;
|
||||||
int scrollPosition = previousOffset + ((LinearLayoutManager) list.getLayoutManager()).findFirstVisibleItemPosition();
|
int scrollPosition = previousOffset + ((LinearLayoutManager) list.getLayoutManager()).findFirstVisibleItemPosition();
|
||||||
scrollPosition = Math.min(scrollPosition, count - 1);
|
scrollPosition = Math.min(scrollPosition, count - 1);
|
||||||
|
|
||||||
|
@ -522,17 +476,10 @@ public class ConversationFragment extends Fragment
|
||||||
else{
|
else{
|
||||||
noMessageTextView.setVisibility(View.GONE);
|
noMessageTextView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastSeenPosition <= 0) {
|
|
||||||
setLastSeen(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void updateLocationButton() {
|
||||||
public void onLoaderReset(Loader<int[]> arg0) {
|
floatingLocationButton.setVisibility(dcContext.isSendingLocationsToChat((int) chatId)? View.VISIBLE : View.GONE);
|
||||||
if (list.getAdapter() != null) {
|
|
||||||
getListAdapter().changeData(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToStartingPosition(final int startingPosition) {
|
private void scrollToStartingPosition(final int startingPosition) {
|
||||||
|
@ -543,9 +490,10 @@ public class ConversationFragment extends Fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToLastSeenPosition(final int lastSeenPosition) {
|
private void scrollToLastSeenPosition(final int lastSeenPosition) {
|
||||||
if (lastSeenPosition > 0) {
|
//TODO: consider if we want that or not
|
||||||
list.post(() -> ((LinearLayoutManager)list.getLayoutManager()).scrollToPositionWithOffset(lastSeenPosition, list.getHeight()));
|
// if (lastSeenPosition > 0) {
|
||||||
}
|
// list.post(() -> ((LinearLayoutManager)list.getLayoutManager()).scrollToPositionWithOffset(lastSeenPosition, list.getHeight()));
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ConversationFragmentListener {
|
public interface ConversationFragmentListener {
|
||||||
|
@ -660,9 +608,9 @@ public class ConversationFragment extends Fragment
|
||||||
|
|
||||||
View gl = View.inflate(getActivity(), R.layout.setup_code_grid, null);
|
View gl = View.inflate(getActivity(), R.layout.setup_code_grid, null);
|
||||||
final EditText[] editTexts = {
|
final EditText[] editTexts = {
|
||||||
(EditText) gl.findViewById(R.id.setupCode0), (EditText) gl.findViewById(R.id.setupCode1), (EditText) gl.findViewById(R.id.setupCode2),
|
gl.findViewById(R.id.setupCode0), gl.findViewById(R.id.setupCode1), gl.findViewById(R.id.setupCode2),
|
||||||
(EditText) gl.findViewById(R.id.setupCode3), (EditText) gl.findViewById(R.id.setupCode4), (EditText) gl.findViewById(R.id.setupCode5),
|
gl.findViewById(R.id.setupCode3), gl.findViewById(R.id.setupCode4), gl.findViewById(R.id.setupCode5),
|
||||||
(EditText) gl.findViewById(R.id.setupCode6), (EditText) gl.findViewById(R.id.setupCode7), (EditText) gl.findViewById(R.id.setupCode8)
|
gl.findViewById(R.id.setupCode6), gl.findViewById(R.id.setupCode7), gl.findViewById(R.id.setupCode8)
|
||||||
};
|
};
|
||||||
AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
|
||||||
builder1.setView(gl);
|
builder1.setView(gl);
|
||||||
|
@ -860,6 +808,10 @@ public class ConversationFragment extends Fragment
|
||||||
updateLocationButton();
|
updateLocationButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventId == DcContext.DC_EVENT_INCOMING_MSG && isResumed()) {
|
||||||
|
setLastSeen(-1);
|
||||||
|
}
|
||||||
|
|
||||||
reloadList();
|
reloadList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
import org.thoughtcrime.securesms.util.Prefs;
|
import org.thoughtcrime.securesms.util.Prefs;
|
||||||
|
|
||||||
import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA;
|
import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA;
|
||||||
import static org.thoughtcrime.securesms.ConversationActivity.LAST_SEEN_EXTRA;
|
|
||||||
import static org.thoughtcrime.securesms.ConversationActivity.STARTING_POSITION_EXTRA;
|
import static org.thoughtcrime.securesms.ConversationActivity.STARTING_POSITION_EXTRA;
|
||||||
import static org.thoughtcrime.securesms.map.MapDataManager.ALL_CHATS_GLOBAL_MAP;
|
import static org.thoughtcrime.securesms.map.MapDataManager.ALL_CHATS_GLOBAL_MAP;
|
||||||
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
||||||
|
@ -217,16 +216,15 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateConversation(int chatId, long lastSeen) {
|
public void onCreateConversation(int chatId) {
|
||||||
openConversation(chatId, lastSeen, -1);
|
openConversation(chatId, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openConversation(int chatId, long lastSeen, int startingPosition) {
|
public void openConversation(int chatId, int startingPosition) {
|
||||||
searchToolbar.clearFocus();
|
searchToolbar.clearFocus();
|
||||||
|
|
||||||
Intent intent = new Intent(this, ConversationActivity.class);
|
Intent intent = new Intent(this, ConversationActivity.class);
|
||||||
intent.putExtra(CHAT_ID_EXTRA, chatId);
|
intent.putExtra(CHAT_ID_EXTRA, chatId);
|
||||||
intent.putExtra(LAST_SEEN_EXTRA, lastSeen);
|
|
||||||
intent.putExtra(STARTING_POSITION_EXTRA, startingPosition);
|
intent.putExtra(STARTING_POSITION_EXTRA, startingPosition);
|
||||||
if (isRelayingMessageContent(this)) {
|
if (isRelayingMessageContent(this)) {
|
||||||
acquireRelayMessageContent(this, intent);
|
acquireRelayMessageContent(this, intent);
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
|
|
||||||
import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA;
|
import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA;
|
||||||
import static org.thoughtcrime.securesms.ConversationActivity.IS_ARCHIVED_EXTRA;
|
import static org.thoughtcrime.securesms.ConversationActivity.IS_ARCHIVED_EXTRA;
|
||||||
import static org.thoughtcrime.securesms.ConversationActivity.LAST_SEEN_EXTRA;
|
|
||||||
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
||||||
import static org.thoughtcrime.securesms.util.RelayUtil.acquireRelayMessageContent;
|
import static org.thoughtcrime.securesms.util.RelayUtil.acquireRelayMessageContent;
|
||||||
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
||||||
|
@ -63,11 +62,10 @@ public class ConversationListArchiveActivity extends PassphraseRequiredActionBar
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateConversation(int chatId, long lastSeenTime) {
|
public void onCreateConversation(int chatId) {
|
||||||
Intent intent = new Intent(this, ConversationActivity.class);
|
Intent intent = new Intent(this, ConversationActivity.class);
|
||||||
intent.putExtra(CHAT_ID_EXTRA, chatId);
|
intent.putExtra(CHAT_ID_EXTRA, chatId);
|
||||||
intent.putExtra(IS_ARCHIVED_EXTRA, true);
|
intent.putExtra(IS_ARCHIVED_EXTRA, true);
|
||||||
intent.putExtra(LAST_SEEN_EXTRA, lastSeenTime);
|
|
||||||
if (isRelayingMessageContent(this)) {
|
if (isRelayingMessageContent(this)) {
|
||||||
acquireRelayMessageContent(this, intent);
|
acquireRelayMessageContent(this, intent);
|
||||||
startActivityForResult(intent, REQUEST_RELAY);
|
startActivityForResult(intent, REQUEST_RELAY);
|
||||||
|
|
|
@ -341,8 +341,8 @@ public class ConversationListFragment extends Fragment
|
||||||
actionMode.setTitle(String.valueOf(getListAdapter().getBatchSelections().size()));
|
actionMode.setTitle(String.valueOf(getListAdapter().getBatchSelections().size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCreateConversation(int threadId, long lastSeen) {
|
private void handleCreateConversation(int chatId) {
|
||||||
((ConversationSelectedListener)getActivity()).onCreateConversation(threadId, lastSeen);
|
((ConversationSelectedListener)getActivity()).onCreateConversation(chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -413,7 +413,7 @@ public class ConversationListFragment extends Fragment
|
||||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||||
int belongingChatId = dcContext.createChatByMsgId(msgId);
|
int belongingChatId = dcContext.createChatByMsgId(msgId);
|
||||||
if( belongingChatId != 0 ) {
|
if( belongingChatId != 0 ) {
|
||||||
handleCreateConversation(belongingChatId, 0);
|
handleCreateConversation(belongingChatId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.not_now, null)
|
.setNegativeButton(R.string.not_now, null)
|
||||||
|
@ -424,7 +424,7 @@ public class ConversationListFragment extends Fragment
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCreateConversation(chatId, 0);
|
handleCreateConversation(chatId);
|
||||||
} else {
|
} else {
|
||||||
ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter();
|
ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter();
|
||||||
adapter.toggleThreadInBatchSet(item.getChatId());
|
adapter.toggleThreadInBatchSet(item.getChatId());
|
||||||
|
@ -454,7 +454,7 @@ public class ConversationListFragment extends Fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ConversationSelectedListener {
|
public interface ConversationSelectedListener {
|
||||||
void onCreateConversation(int threadId, long lastSeen);
|
void onCreateConversation(int chatId);
|
||||||
void onSwitchToArchive();
|
void onSwitchToArchive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,7 +297,6 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
|
||||||
|
|
||||||
Intent intent = new Intent(MapActivity.this, ConversationActivity.class);
|
Intent intent = new Intent(MapActivity.this, ConversationActivity.class);
|
||||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, dcMsgChatId);
|
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, dcMsgChatId);
|
||||||
intent.putExtra(ConversationActivity.LAST_SEEN_EXTRA, 0);
|
|
||||||
intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, startingPosition);
|
intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, startingPosition);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
|
||||||
public void onConversationClicked(@NonNull DcChatlist.Item chatlistItem) {
|
public void onConversationClicked(@NonNull DcChatlist.Item chatlistItem) {
|
||||||
ConversationListActivity conversationList = (ConversationListActivity) getActivity();
|
ConversationListActivity conversationList = (ConversationListActivity) getActivity();
|
||||||
if (conversationList != null) {
|
if (conversationList != null) {
|
||||||
conversationList.onCreateConversation(chatlistItem.chatId,0);
|
conversationList.onCreateConversation(chatlistItem.chatId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,11 +150,11 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||||
int chatId1 = dcContext.createChatByContactId(contact.getId());
|
int chatId1 = dcContext.createChatByContactId(contact.getId());
|
||||||
conversationList.onCreateConversation(chatId1,0);
|
conversationList.onCreateConversation(chatId1);
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
conversationList.onCreateConversation(chatId,0);
|
conversationList.onCreateConversation(chatId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conversationList.openConversation(chatId, 0, startingPosition);
|
conversationList.openConversation(chatId, startingPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue