1
0
mirror of https://github.com/nextcloud/talk-android synced 2025-03-07 06:39:45 +00:00
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-04-11 10:59:36 +02:00
parent f35c4b486c
commit f3877b4bb5
3 changed files with 111 additions and 3 deletions
app/src/main/java/com/nextcloud/talk

View File

@ -59,6 +59,8 @@ import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.callbacks.MentionAutocompleteCallback;
import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.UserMentionClickEvent;
import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.call.Call;
import com.nextcloud.talk.models.json.call.CallOverall;
@ -98,6 +100,9 @@ import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.parceler.Parcels;
import retrofit2.HttpException;
import retrofit2.Response;
@ -120,6 +125,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
AppPreferences appPreferences;
@Inject
Context context;
@Inject
EventBus eventBus;
@BindView(R.id.messagesListView)
MessagesList messagesListView;
@BindView(R.id.messageInputView)
@ -170,6 +177,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
private MenuItem conversationVideoMenuItem;
private boolean readOnlyCheckPerformed;
public ChatController(Bundle args) {
super(args);
setHasOptionsMenu(true);
@ -502,6 +510,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override
protected void onAttach(@NonNull View view) {
super.onAttach(view);
eventBus.register(this);
isLeavingForConversation = false;
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(roomId);
@ -544,7 +553,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
NotificationUtils.cancelExistingNotifications(getApplicationContext(), conversationUser);
if (inChat) {
if (wasDetached & conversationUser.hasSpreedCapabilityWithName("no-ping")) {
if (wasDetached && conversationUser.hasSpreedCapabilityWithName("no-ping")) {
wasDetached = false;
joinRoomWithPassword();
}
@ -555,6 +564,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
protected void onDetach(@NonNull View view) {
super.onDetach(view);
ApplicationWideCurrentRoomHolder.getInstance().clear();
eventBus.unregister(this);
if (conversationUser.hasSpreedCapabilityWithName("no-ping")
&& getActivity() != null && !getActivity().isChangingConfigurations() && !isLeavingForConversation) {
@ -683,7 +693,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
} else {
pullChatMessages(1);
}
}
}
}
private void leaveRoom() {
@ -701,7 +711,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override
public void onNext(GenericOverall genericOverall) {
dispose();
currentConversation = null;
if (!isDestroyed() && !isBeingDestroyed() && !wasDetached) {
getRouter().popCurrentController();
}
@ -1160,4 +1169,63 @@ public class ChatController extends BaseController implements MessagesListAdapte
return false;
}
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(UserMentionClickEvent userMentionClickEvent) {
if ((!currentConversation.getType().equals(Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) || !currentConversation.getName().equals(userMentionClickEvent.getUserId()))) {
RetrofitBucket retrofitBucket =
ApiUtils.getRetrofitBucketForCreateRoom(conversationUser.getBaseUrl(), "1",
userMentionClickEvent.getUserId(), null);
ncApi.createRoom(credentials,
retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<RoomOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(RoomOverall roomOverall) {
Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
if (conversationUser.hasSpreedCapabilityWithName("chat-v2")) {
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
Parcels.wrap(roomOverall.getOcs().getData()));
conversationIntent.putExtras(bundle);
getRouter().pushController((RouterTransaction.with(new ChatController(bundle))
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())));
} else {
conversationIntent.putExtras(bundle);
startActivity(conversationIntent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!isDestroyed() && !isBeingDestroyed()) {
getRouter().popCurrentController();
}
}
}, 100);
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
}
}

View File

@ -0,0 +1,28 @@
/*
* 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/>.
*/
package com.nextcloud.talk.events;
import lombok.Data;
@Data
public class UserMentionClickEvent {
private final String userId;
}

View File

@ -65,10 +65,12 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.google.android.material.chip.ChipDrawable;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.events.UserMentionClickEvent;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.utils.text.Spans;
import com.vanniktech.emoji.EmojiEditText;
import com.vanniktech.emoji.EmojiTextView;
import org.greenrobot.eventbus.EventBus;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@ -291,6 +293,13 @@ public class DisplayUtils {
Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.MULTILINE)
.matcher(spannableString);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
EventBus.getDefault().post(new UserMentionClickEvent(id));
}
};
int lastStartIndex = -1;
Spans.MentionChipSpan mentionChipSpan;
while (m.find()) {
@ -302,6 +311,9 @@ public class DisplayUtils {
DynamicDrawableSpan.ALIGN_BASELINE, id,
label);
spannableString.setSpan(mentionChipSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if ("user".equals(type) && !conversationUser.getUserId().equals(id)) {
spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
return spannableString;