Implement part of #164

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-05-09 13:46:22 +02:00
parent 4f2880bf9b
commit b3ea73f6a9
17 changed files with 106 additions and 35 deletions

View File

@ -155,6 +155,8 @@ dependencies {
implementation 'com.github.Kennyc1012:BottomSheet:2.4.0' implementation 'com.github.Kennyc1012:BottomSheet:2.4.0'
implementation 'eu.davidea:flipview:1.1.3' implementation 'eu.davidea:flipview:1.1.3'
implementation 'com.webianks.library:popup-bubble:1.0.5'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation ('com.android.support.test.espresso:espresso-core:3.0.1', { androidTestImplementation ('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'

View File

@ -31,6 +31,8 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSmoothScroller;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -76,6 +78,7 @@ import com.stfalcon.chatkit.messages.MessageInput;
import com.stfalcon.chatkit.messages.MessagesList; import com.stfalcon.chatkit.messages.MessagesList;
import com.stfalcon.chatkit.messages.MessagesListAdapter; import com.stfalcon.chatkit.messages.MessagesListAdapter;
import com.stfalcon.chatkit.utils.DateFormatter; import com.stfalcon.chatkit.utils.DateFormatter;
import com.webianks.library.PopupBubble;
import org.parceler.Parcels; import org.parceler.Parcels;
@ -109,6 +112,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
MessageInput messageInput; MessageInput messageInput;
@BindView(R.id.messagesList) @BindView(R.id.messagesList)
MessagesList messagesList; MessagesList messagesList;
@BindView(R.id.popupBubble)
PopupBubble popupBubble;
private List<Disposable> disposableList = new ArrayList<>(); private List<Disposable> disposableList = new ArrayList<>();
private String conversationName; private String conversationName;
private String roomToken; private String roomToken;
@ -122,8 +127,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
private MessagesListAdapter<ChatMessage> adapter; private MessagesListAdapter<ChatMessage> adapter;
private Menu globalMenu; private Menu globalMenu;
private RecyclerView.SmoothScroller smoothScroller;
private Autocomplete mentionAutocomplete; private Autocomplete mentionAutocomplete;
/* /*
TODO: TODO:
- check push notifications - check push notifications
@ -150,6 +155,15 @@ public class ChatController extends BaseController implements MessagesListAdapte
boolean adapterWasNull = false; boolean adapterWasNull = false;
if (getActivity() != null) {
smoothScroller = new LinearSmoothScroller(getActivity()) {
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
}
if (adapter == null) { if (adapter == null) {
adapterWasNull = true; adapterWasNull = true;
@ -178,9 +192,10 @@ public class ChatController extends BaseController implements MessagesListAdapte
messagesList.setAdapter(adapter); messagesList.setAdapter(adapter);
adapter.setLoadMoreListener(this); adapter.setLoadMoreListener(this);
adapter.setDateHeadersFormatter(this::format); adapter.setDateHeadersFormatter(this::format);
adapter.setOnMessageLongClickListener(this); adapter.setOnMessageLongClickListener(this);
popupBubble.setRecyclerView(messagesList);
setupMentionAutocomplete(); setupMentionAutocomplete();
messageInput.getInputEditText().setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); messageInput.getInputEditText().setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
@ -312,7 +327,14 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override @Override
public void onNext(GenericOverall genericOverall) { public void onNext(GenericOverall genericOverall) {
LinearLayoutManager layoutManager = (LinearLayoutManager) messagesList.getLayoutManager();
if (popupBubble.isShown()) {
popupBubble.hide();
}
smoothScroller.setTargetPosition(0);
layoutManager.startSmoothScroll(smoothScroller);
} }
@Override @Override
@ -433,8 +455,14 @@ public class ChatController extends BaseController implements MessagesListAdapte
LinearLayoutManager layoutManager = (LinearLayoutManager) messagesList.getLayoutManager(); LinearLayoutManager layoutManager = (LinearLayoutManager) messagesList.getLayoutManager();
for (int i = 0; i < chatMessageList.size(); i++) { for (int i = 0; i < chatMessageList.size(); i++) {
chatMessageList.get(i).setBaseUrl(currentUser.getBaseUrl()); chatMessageList.get(i).setBaseUrl(currentUser.getBaseUrl());
adapter.addToStart(chatMessageList.get(i), boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0;
layoutManager.findLastVisibleItemPosition() <= adapter.getItemCount() - 10);
if (!shouldScroll && !popupBubble.isShown()) {
popupBubble.show();
}
adapter.addToStart(chatMessageList.get(i), shouldScroll);
} }
globalLastKnownFutureMessageId = Integer.parseInt(response.headers().get("X-Chat-Last-Given")); globalLastKnownFutureMessageId = Integer.parseInt(response.headers().get("X-Chat-Last-Given"));

View File

@ -0,0 +1,26 @@
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#ffffff"
android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"/>
</vector>

View File

@ -32,21 +32,35 @@
app:incomingDefaultBubbleColor="@color/white_two" app:incomingDefaultBubbleColor="@color/white_two"
app:incomingDefaultBubblePressedColor="@color/white_two" app:incomingDefaultBubblePressedColor="@color/white_two"
app:incomingDefaultBubbleSelectedColor="@color/colorPrimaryDark" app:incomingDefaultBubbleSelectedColor="@color/colorPrimaryDark"
app:incomingTextColor="@color/nc_incoming_text_default"
app:incomingTextLinkColor="@color/nc_incoming_text_default"
app:incomingTextSize="@dimen/chat_text_size" app:incomingTextSize="@dimen/chat_text_size"
app:incomingTimeTextSize="12sp" app:incomingTimeTextSize="12sp"
app:outcomingDefaultBubbleColor="@color/colorPrimary" app:outcomingDefaultBubbleColor="@color/colorPrimary"
app:outcomingDefaultBubblePressedColor="@color/colorPrimary" app:outcomingDefaultBubblePressedColor="@color/colorPrimary"
app:outcomingDefaultBubbleSelectedColor="@color/colorPrimaryDark" app:outcomingDefaultBubbleSelectedColor="@color/colorPrimaryDark"
app:outcomingTextSize="@dimen/chat_text_size"
app:outcomingTimeTextSize="12sp"
app:outcomingTimeTextColor="@color/warm_grey_four"
app:outcomingTextColor="@color/nc_outcoming_text_default" app:outcomingTextColor="@color/nc_outcoming_text_default"
app:outcomingTextLinkColor="@color/nc_outcoming_text_default" app:outcomingTextLinkColor="@color/nc_outcoming_text_default"
app:incomingTextColor="@color/nc_incoming_text_default" app:outcomingTextSize="@dimen/chat_text_size"
app:incomingTextLinkColor="@color/nc_incoming_text_default" app:outcomingTimeTextColor="@color/warm_grey_four"
app:outcomingTimeTextSize="12sp"
app:textAutoLink="all"/> app:textAutoLink="all"/>
<com.webianks.library.PopupBubble
android:id="@+id/popupBubble"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/separator"
android:layout_centerHorizontal="true"
android:paddingEnd="8dp"
app:pb_backgroundColor="@color/colorPrimary"
app:pb_icon="@drawable/ic_baseline_arrow_downward_24px"
app:pb_text="@string/nc_new_messages"
app:pb_textColor="@color/white"/>
<View <View
android:id="@+id/separator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_above="@+id/input" android:layout_above="@+id/input"

View File

@ -25,13 +25,13 @@
<item <item
android:id="@+id/conversation_voice_call" android:id="@+id/conversation_voice_call"
android:icon="@drawable/ic_call_white_24dp" android:icon="@drawable/ic_call_white_24dp"
android:title="@string/conversation_menu_voice_call" android:title="@string/nc_conversation_menu_voice_call"
android:visible="false" android:visible="false"
app:showAsAction="always"/> app:showAsAction="always"/>
<item <item
android:id="@+id/conversation_video_call" android:id="@+id/conversation_video_call"
android:icon="@drawable/ic_videocam_white_24px" android:icon="@drawable/ic_videocam_white_24px"
android:title="@string/conversation_menu_video_call" android:title="@string/nc_conversation_menu_video_call"
app:showAsAction="always"/> app:showAsAction="always"/>
</menu> </menu>

View File

@ -171,7 +171,7 @@ Find Nextcloud on https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Enter a message…</string> <string name="nc_hint_enter_a_message">Enter a message…</string>
<string name="nc_date_header_yesterday">Yesterday</string> <string name="nc_date_header_yesterday">Yesterday</string>
<string name="nc_date_header_today">Today</string> <string name="nc_date_header_today">Today</string>
<string name="conversation_menu_voice_call">Voice call</string> <string name="nc_conversation_menu_voice_call">Voice call</string>
<string name="conversation_menu_video_call">Video call</string> <string name="nc_conversation_menu_video_call">Video call</string>
</resources> </resources>

View File

@ -170,7 +170,7 @@ Finden Sie Nextcloud auf https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Eine Nachricht eingeben…</string> <string name="nc_hint_enter_a_message">Eine Nachricht eingeben…</string>
<string name="nc_date_header_yesterday">Gestern</string> <string name="nc_date_header_yesterday">Gestern</string>
<string name="nc_date_header_today">Heute</string> <string name="nc_date_header_today">Heute</string>
<string name="conversation_menu_voice_call">Sprachanruf</string> <string name="nc_conversation_menu_voice_call">Sprachanruf</string>
<string name="conversation_menu_video_call">Videoanruf</string> <string name="nc_conversation_menu_video_call">Videoanruf</string>
</resources> </resources>

View File

@ -170,7 +170,7 @@ Finden Sie Nextcloud auf https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Neue Nachricht eingeben…</string> <string name="nc_hint_enter_a_message">Neue Nachricht eingeben…</string>
<string name="nc_date_header_yesterday">Gestern</string> <string name="nc_date_header_yesterday">Gestern</string>
<string name="nc_date_header_today">Heute</string> <string name="nc_date_header_today">Heute</string>
<string name="conversation_menu_voice_call">Sprachanruf</string> <string name="nc_conversation_menu_voice_call">Sprachanruf</string>
<string name="conversation_menu_video_call">Videoanruf</string> <string name="nc_conversation_menu_video_call">Videoanruf</string>
</resources> </resources>

View File

@ -172,7 +172,7 @@ Visita a Nextcloud en https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Introduce un mensaje...</string> <string name="nc_hint_enter_a_message">Introduce un mensaje...</string>
<string name="nc_date_header_yesterday">Ayer</string> <string name="nc_date_header_yesterday">Ayer</string>
<string name="nc_date_header_today">Hoy</string> <string name="nc_date_header_today">Hoy</string>
<string name="conversation_menu_voice_call">Llamada de voz</string> <string name="nc_conversation_menu_voice_call">Llamada de voz</string>
<string name="conversation_menu_video_call">Video llamada</string> <string name="nc_conversation_menu_video_call">Video llamada</string>
</resources> </resources>

View File

@ -171,7 +171,7 @@ Encuentra Nextcloud en https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Escribe un mensaje…</string> <string name="nc_hint_enter_a_message">Escribe un mensaje…</string>
<string name="nc_date_header_yesterday">Ayer</string> <string name="nc_date_header_yesterday">Ayer</string>
<string name="nc_date_header_today">Hoy</string> <string name="nc_date_header_today">Hoy</string>
<string name="conversation_menu_voice_call">Llamada de audio</string> <string name="nc_conversation_menu_voice_call">Llamada de audio</string>
<string name="conversation_menu_video_call">Llamada de vídeo</string> <string name="nc_conversation_menu_video_call">Llamada de vídeo</string>
</resources> </resources>

View File

@ -170,7 +170,7 @@ Trouvez Nextcloud sur https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Saisir un message…</string> <string name="nc_hint_enter_a_message">Saisir un message…</string>
<string name="nc_date_header_yesterday">Hier</string> <string name="nc_date_header_yesterday">Hier</string>
<string name="nc_date_header_today">Aujourd\'hui</string> <string name="nc_date_header_today">Aujourd\'hui</string>
<string name="conversation_menu_voice_call">Appel audio</string> <string name="nc_conversation_menu_voice_call">Appel audio</string>
<string name="conversation_menu_video_call">Appel vidéo</string> <string name="nc_conversation_menu_video_call">Appel vidéo</string>
</resources> </resources>

View File

@ -171,7 +171,7 @@ Trovi Nextcloud su https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Digita un messaggio</string> <string name="nc_hint_enter_a_message">Digita un messaggio</string>
<string name="nc_date_header_yesterday">Ieri</string> <string name="nc_date_header_yesterday">Ieri</string>
<string name="nc_date_header_today">Oggi</string> <string name="nc_date_header_today">Oggi</string>
<string name="conversation_menu_voice_call">Chiamata vocale</string> <string name="nc_conversation_menu_voice_call">Chiamata vocale</string>
<string name="conversation_menu_video_call">Chiamata video</string> <string name="nc_conversation_menu_video_call">Chiamata video</string>
</resources> </resources>

View File

@ -171,7 +171,7 @@ Encontre o Nextcloud em https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Digite uma mensagem...</string> <string name="nc_hint_enter_a_message">Digite uma mensagem...</string>
<string name="nc_date_header_yesterday">Ontem</string> <string name="nc_date_header_yesterday">Ontem</string>
<string name="nc_date_header_today">Hoje</string> <string name="nc_date_header_today">Hoje</string>
<string name="conversation_menu_voice_call">Chamada de áudio</string> <string name="nc_conversation_menu_voice_call">Chamada de áudio</string>
<string name="conversation_menu_video_call">Chamada de vídeo</string> <string name="nc_conversation_menu_video_call">Chamada de vídeo</string>
</resources> </resources>

View File

@ -170,7 +170,7 @@ Nextcloud ежедневно используется как для работы
<string name="nc_hint_enter_a_message">Напишите сообщение…</string> <string name="nc_hint_enter_a_message">Напишите сообщение…</string>
<string name="nc_date_header_yesterday">Вчера</string> <string name="nc_date_header_yesterday">Вчера</string>
<string name="nc_date_header_today">Сегодня</string> <string name="nc_date_header_today">Сегодня</string>
<string name="conversation_menu_voice_call">Голосовой вызов</string> <string name="nc_conversation_menu_voice_call">Голосовой вызов</string>
<string name="conversation_menu_video_call">Видеозвонок</string> <string name="nc_conversation_menu_video_call">Видеозвонок</string>
</resources> </resources>

View File

@ -166,7 +166,7 @@ Nextcloud Talk апликација захтева да имате Некстк
<string name="nc_hint_enter_a_message">Унесите поруку…</string> <string name="nc_hint_enter_a_message">Унесите поруку…</string>
<string name="nc_date_header_yesterday">Јуче</string> <string name="nc_date_header_yesterday">Јуче</string>
<string name="nc_date_header_today">Данас</string> <string name="nc_date_header_today">Данас</string>
<string name="conversation_menu_voice_call">Аудио позив</string> <string name="nc_conversation_menu_voice_call">Аудио позив</string>
<string name="conversation_menu_video_call">Видео позив</string> <string name="nc_conversation_menu_video_call">Видео позив</string>
</resources> </resources>

View File

@ -173,7 +173,7 @@ Nextcloud web sitesi https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Bir ileti yazın…</string> <string name="nc_hint_enter_a_message">Bir ileti yazın…</string>
<string name="nc_date_header_yesterday">Dün</string> <string name="nc_date_header_yesterday">Dün</string>
<string name="nc_date_header_today">Bugün</string> <string name="nc_date_header_today">Bugün</string>
<string name="conversation_menu_voice_call">Sesli arama</string> <string name="nc_conversation_menu_voice_call">Sesli arama</string>
<string name="conversation_menu_video_call">Görüntülü arama</string> <string name="nc_conversation_menu_video_call">Görüntülü arama</string>
</resources> </resources>

View File

@ -171,7 +171,8 @@ Find Nextcloud on https://nextcloud.com</string>
<string name="nc_hint_enter_a_message">Enter a message…</string> <string name="nc_hint_enter_a_message">Enter a message…</string>
<string name="nc_date_header_yesterday">Yesterday</string> <string name="nc_date_header_yesterday">Yesterday</string>
<string name="nc_date_header_today">Today</string> <string name="nc_date_header_today">Today</string>
<string name="conversation_menu_voice_call">Voice call</string> <string name="nc_conversation_menu_voice_call">Voice call</string>
<string name="conversation_menu_video_call">Video call</string> <string name="nc_conversation_menu_video_call">Video call</string>
<string name="nc_new_messages">New messages</string>
</resources> </resources>