Merge pull request #940 from deltachat/unread_message_marker

show new message marker #447
This commit is contained in:
björn petersen
2019-06-06 01:10:25 +02:00
committed by GitHub
12 changed files with 733 additions and 794 deletions
+15 -16
View File
@@ -4,27 +4,26 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="24dp"
android:paddingBottom="20dp">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_marginLeft="28dp"
android:layout_marginRight="28dp"
android:layout_marginBottom="3dp"
android:background="?attr/conversation_item_last_seen_line_color" />
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:paddingLeft="28dp"
android:paddingRight="28dp">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="@style/Signal.Text.Caption"
android:textAllCaps="true"
android:fontFamily="sans-serif-medium"
android:textColor="?attr/conversation_item_last_seen_text_color"
android:gravity="center"
style="@style/Delta.Text.UpdateHeader"
android:textStyle="bold"
android:textColor="?conversation_item_update_text_color"
android:background="@drawable/conversation_item_update_background"
android:paddingLeft="10dp"
android:paddingTop="3dp"
android:paddingRight="10dp"
android:paddingBottom="3dp"
tools:text="3 unread messages" />
</LinearLayout>
</LinearLayout>
-2
View File
@@ -78,8 +78,6 @@
<attr name="conversation_item_sent_indicator_text_background" format="reference" />
<attr name="conversation_item_update_bg_color" format="reference|color"/>
<attr name="conversation_item_update_text_color" format="reference|color"/>
<attr name="conversation_item_last_seen_text_color" format="reference"/>
<attr name="conversation_item_last_seen_line_color" format="reference"/>
<attr name="conversation_item_date_line_color" format="reference"/>
<attr name="conversation_item_quote_text_color" format="reference"/>
<attr name="conversation_item_sticky_date_background" format="reference" />
+3 -3
View File
@@ -210,9 +210,9 @@
<string name="chat_please_enter_message">Please enter a message.</string>
<string name="chat_camera_unavailable">Camera unavailable.</string>
<string name="chat_unable_to_record_audio">Unable to record audio.</string>
<plurals name="chat_n_unread_messages">
<item quantity="one">%d unread message</item>
<item quantity="other">%d unread messages</item>
<plurals name="chat_n_new_messages">
<item quantity="one">%d new message</item>
<item quantity="other">%d new messages</item>
</plurals>
<string name="chat_no_messages_hint">Send message to %1$s:\n\n• It is okay if %2$s does not use Delta Chat.\n\n• Delivering the first message may take a while and may be unencrypted.</string>
<string name="chat_new_group_hint">Compose the first message, allowing others to reply within this group.\n\n• It is okay if not all members use Delta Chat.\n\n• Delivering the first message may take a while.</string>
-4
View File
@@ -163,8 +163,6 @@
<item name="conversation_item_update_bg_color">@color/universal_overlay</item>
<item name="conversation_item_update_text_color">@color/white</item>
<item name="conversation_item_last_seen_text_color">@color/core_light_90</item>
<item name="conversation_item_last_seen_line_color">@color/core_light_60</item>
<item name="conversation_item_date_line_color">@color/core_light_45</item>
<item name="conversation_item_quote_text_color">@color/core_light_90</item>
<item name="conversation_item_sticky_date_background">@drawable/sticky_date_header_background_light</item>
@@ -267,8 +265,6 @@
<item name="conversation_item_update_text_color">@color/core_light_35</item>
<item name="conversation_item_sent_indicator_text_background">@drawable/conversation_item_sent_indicator_text_shape_dark</item>
<item name="conversation_item_last_seen_text_color">@color/core_dark_30</item>
<item name="conversation_item_last_seen_line_color">@color/core_dark_30</item>
<item name="conversation_item_date_line_color">@color/core_dark_55</item>
<item name="conversation_item_quote_text_color">@color/core_dark_05</item>
<item name="conversation_item_sticky_date_background">@drawable/sticky_date_header_background_dark</item>
@@ -151,7 +151,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
public static final String CHAT_ID_EXTRA = "chat_id";
public static final String IS_ARCHIVED_EXTRA = "is_archived";
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";
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);
quickAttachmentDrawer.onPause();
inputPanel.onPause();
fragment.setLastSeen(System.currentTimeMillis());
AudioSlidePlayer.stopAll();
}
@@ -1163,7 +1159,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
return;
}
fragment.setLastSeen(0);
fragment.setLastSeen(-1);
if (refreshFragment) {
fragment.reload(recipient, chatId);
@@ -91,6 +91,8 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
private @NonNull DcChat dcChat;
private @NonNull int[] dcMsgList = new int[0];
private int positionToPulseHighlight = -1;
private int lastSeenPosition = -1;
private long lastSeen = -1;
protected static class ViewHolder extends RecyclerView.ViewHolder {
public <V extends View & BindableConversationItem> ViewHolder(final @NonNull V itemView) {
@@ -120,6 +122,19 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
return dcChat.getName();
}
public void setLastSeen(long timestamp) {
lastSeen = timestamp;
}
public void updateLastSeenPosition() {
this.lastSeenPosition = findLastSeenPosition(lastSeen);
}
public int getLastSeenPosition() {
return lastSeenPosition;
}
@Override
public int getItemCount() {
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) {
if (!batchSelected.remove(messageRecord)) {
batchSelected.add(messageRecord);
@@ -314,39 +311,78 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
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) {
return new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.conversation_item_last_seen, parent, false));
}
public void onBindLastSeenViewHolder(HeaderViewHolder viewHolder, int position) {
viewHolder.setText(getContext().getResources().getQuantityString(R.plurals.chat_n_unread_messages, (position + 1), (position + 1)));
viewHolder.setText(getContext().getResources().getQuantityString(R.plurals.chat_n_new_messages, (position + 1), (position + 1)));
}
static class LastSeenHeader extends StickyHeaderDecoration {
private final ConversationAdapter adapter;
private final long lastSeenTimestamp;
LastSeenHeader(ConversationAdapter adapter, long lastSeenTimestamp) {
LastSeenHeader(ConversationAdapter adapter) {
super(adapter, false, false);
this.adapter = adapter;
this.lastSeenTimestamp = lastSeenTimestamp;
}
@Override
protected boolean hasHeader(RecyclerView parent, StickyHeaderAdapter stickyAdapter, int position) {
if (!adapter.isActive()) {
return false;
}
if (lastSeenTimestamp <= 0) {
return false;
}
long currentRecordTimestamp = adapter.getSortTimestamp(position);
long previousRecordTimestamp = adapter.getSortTimestamp(position + 1);
return currentRecordTimestamp > lastSeenTimestamp && previousRecordTimestamp < lastSeenTimestamp;
return adapter.isActive() && position == adapter.getLastSeenPosition();
}
@Override
@@ -371,41 +407,5 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
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();
}
}
File diff suppressed because it is too large Load Diff
@@ -41,7 +41,6 @@ import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.Prefs;
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.map.MapDataManager.ALL_CHATS_GLOBAL_MAP;
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
@@ -217,16 +216,15 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
}
@Override
public void onCreateConversation(int chatId, long lastSeen) {
openConversation(chatId, lastSeen, -1);
public void onCreateConversation(int chatId) {
openConversation(chatId, -1);
}
public void openConversation(int chatId, long lastSeen, int startingPosition) {
public void openConversation(int chatId, int startingPosition) {
searchToolbar.clearFocus();
Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(CHAT_ID_EXTRA, chatId);
intent.putExtra(LAST_SEEN_EXTRA, lastSeen);
intent.putExtra(STARTING_POSITION_EXTRA, startingPosition);
if (isRelayingMessageContent(this)) {
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.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.acquireRelayMessageContent;
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
@@ -63,11 +62,10 @@ public class ConversationListArchiveActivity extends PassphraseRequiredActionBar
}
@Override
public void onCreateConversation(int chatId, long lastSeenTime) {
public void onCreateConversation(int chatId) {
Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(CHAT_ID_EXTRA, chatId);
intent.putExtra(IS_ARCHIVED_EXTRA, true);
intent.putExtra(LAST_SEEN_EXTRA, lastSeenTime);
if (isRelayingMessageContent(this)) {
acquireRelayMessageContent(this, intent);
startActivityForResult(intent, REQUEST_RELAY);
@@ -341,8 +341,8 @@ public class ConversationListFragment extends Fragment
actionMode.setTitle(String.valueOf(getListAdapter().getBatchSelections().size()));
}
private void handleCreateConversation(int threadId, long lastSeen) {
((ConversationSelectedListener)getActivity()).onCreateConversation(threadId, lastSeen);
private void handleCreateConversation(int chatId) {
((ConversationSelectedListener)getActivity()).onCreateConversation(chatId);
}
@Override
@@ -413,7 +413,7 @@ public class ConversationListFragment extends Fragment
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
int belongingChatId = dcContext.createChatByMsgId(msgId);
if( belongingChatId != 0 ) {
handleCreateConversation(belongingChatId, 0);
handleCreateConversation(belongingChatId);
}
})
.setNegativeButton(R.string.not_now, null)
@@ -424,7 +424,7 @@ public class ConversationListFragment extends Fragment
return;
}
handleCreateConversation(chatId, 0);
handleCreateConversation(chatId);
} else {
ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter();
adapter.toggleThreadInBatchSet(item.getChatId());
@@ -454,7 +454,7 @@ public class ConversationListFragment extends Fragment
}
public interface ConversationSelectedListener {
void onCreateConversation(int threadId, long lastSeen);
void onCreateConversation(int chatId);
void onSwitchToArchive();
}
@@ -297,7 +297,6 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
Intent intent = new Intent(MapActivity.this, ConversationActivity.class);
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, dcMsgChatId);
intent.putExtra(ConversationActivity.LAST_SEEN_EXTRA, 0);
intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, startingPosition);
startActivity(intent);
return true;
@@ -133,7 +133,7 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
public void onConversationClicked(@NonNull DcChatlist.Item chatlistItem) {
ConversationListActivity conversationList = (ConversationListActivity) getActivity();
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)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
int chatId1 = dcContext.createChatByContactId(contact.getId());
conversationList.onCreateConversation(chatId1,0);
conversationList.onCreateConversation(chatId1);
}).show();
}
else {
conversationList.onCreateConversation(chatId,0);
conversationList.onCreateConversation(chatId);
}
}
}
@@ -174,7 +174,7 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
break;
}
}
conversationList.openConversation(chatId, 0, startingPosition);
conversationList.openConversation(chatId, startingPosition);
}
}