ChatController.java 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. /*
  2. * Nextcloud Talk application
  3. *
  4. * @author Mario Danic
  5. * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package com.nextcloud.talk.controllers;
  21. import android.content.ClipData;
  22. import android.content.ClipboardManager;
  23. import android.content.Context;
  24. import android.content.Intent;
  25. import android.graphics.Color;
  26. import android.graphics.PorterDuff;
  27. import android.graphics.drawable.ColorDrawable;
  28. import android.graphics.drawable.Drawable;
  29. import android.os.Bundle;
  30. import android.os.Handler;
  31. import android.text.Editable;
  32. import android.text.InputFilter;
  33. import android.text.TextUtils;
  34. import android.text.TextWatcher;
  35. import android.util.Log;
  36. import android.view.*;
  37. import android.widget.*;
  38. import androidx.annotation.NonNull;
  39. import androidx.recyclerview.widget.LinearLayoutManager;
  40. import androidx.recyclerview.widget.RecyclerView;
  41. import autodagger.AutoInjector;
  42. import butterknife.BindView;
  43. import butterknife.OnClick;
  44. import com.bluelinelabs.conductor.RouterTransaction;
  45. import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
  46. import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
  47. import com.facebook.drawee.backends.pipeline.Fresco;
  48. import com.facebook.drawee.interfaces.DraweeController;
  49. import com.facebook.drawee.view.SimpleDraweeView;
  50. import com.nextcloud.talk.R;
  51. import com.nextcloud.talk.activities.MagicCallActivity;
  52. import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder;
  53. import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder;
  54. import com.nextcloud.talk.adapters.messages.MagicPreviewMessageViewHolder;
  55. import com.nextcloud.talk.adapters.messages.MagicSystemMessageViewHolder;
  56. import com.nextcloud.talk.api.NcApi;
  57. import com.nextcloud.talk.application.NextcloudTalkApplication;
  58. import com.nextcloud.talk.callbacks.MentionAutocompleteCallback;
  59. import com.nextcloud.talk.components.filebrowser.controllers.BrowserController;
  60. import com.nextcloud.talk.controllers.base.BaseController;
  61. import com.nextcloud.talk.events.UserMentionClickEvent;
  62. import com.nextcloud.talk.models.RetrofitBucket;
  63. import com.nextcloud.talk.models.database.UserEntity;
  64. import com.nextcloud.talk.models.json.call.Call;
  65. import com.nextcloud.talk.models.json.call.CallOverall;
  66. import com.nextcloud.talk.models.json.chat.ChatMessage;
  67. import com.nextcloud.talk.models.json.chat.ChatOverall;
  68. import com.nextcloud.talk.models.json.generic.GenericOverall;
  69. import com.nextcloud.talk.models.json.mention.Mention;
  70. import com.nextcloud.talk.models.json.rooms.Conversation;
  71. import com.nextcloud.talk.models.json.rooms.RoomOverall;
  72. import com.nextcloud.talk.models.json.rooms.RoomsOverall;
  73. import com.nextcloud.talk.presenters.MentionAutocompletePresenter;
  74. import com.nextcloud.talk.utils.*;
  75. import com.nextcloud.talk.utils.bundle.BundleKeys;
  76. import com.nextcloud.talk.utils.database.user.UserUtils;
  77. import com.nextcloud.talk.utils.preferences.AppPreferences;
  78. import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
  79. import com.nextcloud.talk.utils.text.Spans;
  80. import com.otaliastudios.autocomplete.Autocomplete;
  81. import com.otaliastudios.autocomplete.AutocompleteCallback;
  82. import com.otaliastudios.autocomplete.AutocompletePresenter;
  83. import com.stfalcon.chatkit.commons.ImageLoader;
  84. import com.stfalcon.chatkit.commons.models.IMessage;
  85. import com.stfalcon.chatkit.messages.MessageHolders;
  86. import com.stfalcon.chatkit.messages.MessageInput;
  87. import com.stfalcon.chatkit.messages.MessagesList;
  88. import com.stfalcon.chatkit.messages.MessagesListAdapter;
  89. import com.stfalcon.chatkit.utils.DateFormatter;
  90. import com.vanniktech.emoji.EmojiEditText;
  91. import com.vanniktech.emoji.EmojiImageView;
  92. import com.vanniktech.emoji.EmojiPopup;
  93. import com.vanniktech.emoji.emoji.Emoji;
  94. import com.vanniktech.emoji.listeners.OnEmojiClickListener;
  95. import com.vanniktech.emoji.listeners.OnEmojiPopupDismissListener;
  96. import com.vanniktech.emoji.listeners.OnEmojiPopupShownListener;
  97. import com.webianks.library.PopupBubble;
  98. import io.reactivex.Observer;
  99. import io.reactivex.android.schedulers.AndroidSchedulers;
  100. import io.reactivex.disposables.Disposable;
  101. import io.reactivex.schedulers.Schedulers;
  102. import org.greenrobot.eventbus.EventBus;
  103. import org.greenrobot.eventbus.Subscribe;
  104. import org.greenrobot.eventbus.ThreadMode;
  105. import org.parceler.Parcels;
  106. import retrofit2.HttpException;
  107. import retrofit2.Response;
  108. import javax.inject.Inject;
  109. import java.lang.reflect.Field;
  110. import java.util.*;
  111. import java.util.concurrent.TimeUnit;
  112. @AutoInjector(NextcloudTalkApplication.class)
  113. public class ChatController extends BaseController implements MessagesListAdapter.OnLoadMoreListener,
  114. MessagesListAdapter.Formatter<Date>, MessagesListAdapter.OnMessageLongClickListener, MessageHolders.ContentChecker {
  115. private static final String TAG = "ChatController";
  116. private static final byte CONTENT_TYPE_SYSTEM_MESSAGE = 1;
  117. @Inject
  118. NcApi ncApi;
  119. @Inject
  120. UserUtils userUtils;
  121. @Inject
  122. AppPreferences appPreferences;
  123. @Inject
  124. Context context;
  125. @Inject
  126. EventBus eventBus;
  127. @BindView(R.id.messagesListView)
  128. MessagesList messagesListView;
  129. @BindView(R.id.messageInputView)
  130. MessageInput messageInputView;
  131. @BindView(R.id.messageInput)
  132. EmojiEditText messageInput;
  133. @BindView(R.id.popupBubbleView)
  134. PopupBubble popupBubble;
  135. @BindView(R.id.progressBar)
  136. ProgressBar loadingProgressBar;
  137. @BindView(R.id.smileyButton)
  138. ImageButton smileyButton;
  139. private List<Disposable> disposableList = new ArrayList<>();
  140. private String conversationName;
  141. private String roomToken;
  142. private UserEntity conversationUser;
  143. private String roomPassword;
  144. private String credentials;
  145. private Conversation currentConversation;
  146. private Call currentCall;
  147. private boolean inChat = false;
  148. private boolean historyRead = false;
  149. private int globalLastKnownFutureMessageId = -1;
  150. private int globalLastKnownPastMessageId = -1;
  151. private MessagesListAdapter<ChatMessage> adapter;
  152. private Autocomplete mentionAutocomplete;
  153. private LinearLayoutManager layoutManager;
  154. private boolean lookingIntoFuture = false;
  155. private int newMessagesCount = 0;
  156. private Boolean startCallFromNotification = null;
  157. private String roomId;
  158. private boolean voiceOnly;
  159. private boolean isFirstMessagesProcessing = true;
  160. private boolean isHelloClicked;
  161. private boolean isLeavingForConversation;
  162. private boolean isLinkPreviewAllowed;
  163. private boolean wasDetached;
  164. private EmojiPopup emojiPopup;
  165. private CharSequence myFirstMessage;
  166. private MenuItem conversationInfoMenuItem;
  167. private MenuItem conversationVoiceCallMenuItem;
  168. private MenuItem conversationVideoMenuItem;
  169. private boolean readOnlyCheckPerformed;
  170. public ChatController(Bundle args) {
  171. super(args);
  172. setHasOptionsMenu(true);
  173. NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
  174. this.conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY);
  175. this.roomId = args.getString(BundleKeys.KEY_ROOM_ID, "");
  176. this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN, "");
  177. if (args.containsKey(BundleKeys.KEY_ACTIVE_CONVERSATION)) {
  178. this.currentConversation = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION));
  179. if (currentConversation != null) {
  180. conversationName = currentConversation.getDisplayName();
  181. }
  182. }
  183. this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
  184. if (conversationUser.getUserId().equals("?")) {
  185. credentials = null;
  186. } else {
  187. credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken());
  188. }
  189. if (args.containsKey(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
  190. this.startCallFromNotification = args.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL);
  191. }
  192. this.voiceOnly = args.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false);
  193. }
  194. private void getRoomInfo() {
  195. ncApi.getRoom(credentials, ApiUtils.getRoom(conversationUser.getBaseUrl(), roomToken))
  196. .subscribeOn(Schedulers.io())
  197. .observeOn(AndroidSchedulers.mainThread())
  198. .subscribe(new Observer<RoomOverall>() {
  199. @Override
  200. public void onSubscribe(Disposable d) {
  201. disposableList.add(d);
  202. }
  203. @Override
  204. public void onNext(RoomOverall roomOverall) {
  205. currentConversation = roomOverall.getOcs().getData();
  206. conversationName = currentConversation.getDisplayName();
  207. setTitle();
  208. setupMentionAutocomplete();
  209. joinRoomWithPassword();
  210. }
  211. @Override
  212. public void onError(Throwable e) {
  213. }
  214. @Override
  215. public void onComplete() {
  216. }
  217. });
  218. }
  219. private void handleFromNotification() {
  220. ncApi.getRooms(credentials, ApiUtils.getUrlForGetRooms(conversationUser.getBaseUrl()))
  221. .subscribeOn(Schedulers.io())
  222. .observeOn(AndroidSchedulers.mainThread())
  223. .subscribe(new Observer<RoomsOverall>() {
  224. @Override
  225. public void onSubscribe(Disposable d) {
  226. disposableList.add(d);
  227. }
  228. @Override
  229. public void onNext(RoomsOverall roomsOverall) {
  230. for (Conversation conversation : roomsOverall.getOcs().getData()) {
  231. if (roomId.equals(conversation.getRoomId())) {
  232. roomToken = conversation.getToken();
  233. currentConversation = conversation;
  234. conversationName = conversation.getDisplayName();
  235. setTitle();
  236. break;
  237. }
  238. }
  239. if (!TextUtils.isEmpty(roomToken)) {
  240. setupMentionAutocomplete();
  241. joinRoomWithPassword();
  242. }
  243. }
  244. @Override
  245. public void onError(Throwable e) {
  246. }
  247. @Override
  248. public void onComplete() {
  249. }
  250. });
  251. }
  252. @Override
  253. protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
  254. return inflater.inflate(R.layout.controller_chat, container, false);
  255. }
  256. @Override
  257. protected void onViewBound(@NonNull View view) {
  258. super.onViewBound(view);
  259. getActionBar().show();
  260. boolean adapterWasNull = false;
  261. if (adapter == null) {
  262. loadingProgressBar.setVisibility(View.VISIBLE);
  263. adapterWasNull = true;
  264. MessageHolders messageHolders = new MessageHolders();
  265. messageHolders.setIncomingTextConfig(MagicIncomingTextMessageViewHolder.class, R.layout.item_custom_incoming_text_message);
  266. messageHolders.setOutcomingTextConfig(MagicOutcomingTextMessageViewHolder.class, R.layout.item_custom_outcoming_text_message);
  267. messageHolders.setIncomingImageConfig(MagicPreviewMessageViewHolder.class, R.layout.item_custom_incoming_preview_message);
  268. messageHolders.setOutcomingImageConfig(MagicPreviewMessageViewHolder.class, R.layout.item_custom_outcoming_preview_message);
  269. messageHolders.registerContentType(CONTENT_TYPE_SYSTEM_MESSAGE, MagicSystemMessageViewHolder.class,
  270. R.layout.item_system_message, MagicSystemMessageViewHolder.class, R.layout.item_system_message,
  271. this);
  272. adapter = new MessagesListAdapter<>(conversationUser.getUserId(), messageHolders, new ImageLoader() {
  273. @Override
  274. public void loadImage(SimpleDraweeView imageView, String url) {
  275. DraweeController draweeController = Fresco.newDraweeControllerBuilder()
  276. .setImageRequest(DisplayUtils.getImageRequestForUrl(url, conversationUser))
  277. .setControllerListener(DisplayUtils.getImageControllerListener(imageView))
  278. .setOldController(imageView.getController())
  279. .setAutoPlayAnimations(true)
  280. .build();
  281. imageView.setController(draweeController);
  282. }
  283. });
  284. } else {
  285. messagesListView.setVisibility(View.VISIBLE);
  286. }
  287. messagesListView.setAdapter(adapter);
  288. adapter.setLoadMoreListener(this);
  289. adapter.setDateHeadersFormatter(this::format);
  290. adapter.setOnMessageLongClickListener(this);
  291. layoutManager = (LinearLayoutManager) messagesListView.getLayoutManager();
  292. popupBubble.setRecyclerView(messagesListView);
  293. popupBubble.setPopupBubbleListener(context -> {
  294. if (newMessagesCount != 0) {
  295. int scrollPosition;
  296. if (newMessagesCount - 1 < 0) {
  297. scrollPosition = 0;
  298. } else {
  299. scrollPosition = newMessagesCount - 1;
  300. }
  301. new Handler().postDelayed(() -> messagesListView.smoothScrollToPosition(scrollPosition), 200);
  302. }
  303. });
  304. messagesListView.addOnScrollListener(new RecyclerView.OnScrollListener() {
  305. @Override
  306. public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  307. super.onScrollStateChanged(recyclerView, newState);
  308. if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
  309. if (newMessagesCount != 0) {
  310. if (layoutManager.findFirstCompletelyVisibleItemPosition() < newMessagesCount) {
  311. newMessagesCount = 0;
  312. if (popupBubble != null && popupBubble.isShown()) {
  313. popupBubble.hide();
  314. }
  315. }
  316. }
  317. }
  318. }
  319. });
  320. InputFilter[] filters = new InputFilter[1];
  321. int lenghtFilter = conversationUser.getMessageMaxLength();
  322. filters[0] = new InputFilter.LengthFilter(lenghtFilter);
  323. messageInput.setFilters(filters);
  324. messageInput.addTextChangedListener(new TextWatcher() {
  325. @Override
  326. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  327. }
  328. @Override
  329. public void onTextChanged(CharSequence s, int start, int before, int count) {
  330. if (s.length() >= lenghtFilter) {
  331. messageInput.setError(String.format(Objects.requireNonNull(getResources()).getString(R.string.nc_limit_hit), Integer.toString(lenghtFilter)));
  332. } else {
  333. messageInput.setError(null);
  334. }
  335. Editable editable = messageInput.getEditableText();
  336. Spans.MentionChipSpan[] mentionSpans = editable.getSpans(0, messageInput.length(),
  337. Spans.MentionChipSpan.class);
  338. Spans.MentionChipSpan mentionSpan;
  339. for (int i = 0; i < mentionSpans.length; i++) {
  340. mentionSpan = mentionSpans[i];
  341. if (start >= editable.getSpanStart(mentionSpan) && start < editable.getSpanEnd(mentionSpan)) {
  342. if (!editable.subSequence(editable.getSpanStart(mentionSpan),
  343. editable.getSpanEnd(mentionSpan)).toString().trim().equals(mentionSpan.getLabel())) {
  344. editable.removeSpan(mentionSpan);
  345. }
  346. }
  347. }
  348. }
  349. @Override
  350. public void afterTextChanged(Editable s) {
  351. }
  352. });
  353. messageInputView.setAttachmentsListener(new MessageInput.AttachmentsListener() {
  354. @Override
  355. public void onAddAttachments() {
  356. showBrowserScreen(BrowserController.BrowserType.DAV_BROWSER);
  357. }
  358. });
  359. messageInputView.getButton().setOnClickListener(v -> submitMessage());
  360. messageInputView.getButton().setContentDescription(getResources()
  361. .getString(R.string.nc_description_send_message_button));
  362. if (!conversationUser.getUserId().equals("?") && conversationUser.hasSpreedFeatureCapability("mention-flag") && getActivity() != null) {
  363. getActivity().findViewById(R.id.toolbar).setOnClickListener(v -> showConversationInfoScreen());
  364. }
  365. if (adapterWasNull) {
  366. // we're starting
  367. if (TextUtils.isEmpty(roomToken)) {
  368. handleFromNotification();
  369. } else if (TextUtils.isEmpty(conversationName)) {
  370. getRoomInfo();
  371. } else {
  372. setupMentionAutocomplete();
  373. joinRoomWithPassword();
  374. }
  375. }
  376. }
  377. private void checkReadOnlyState() {
  378. if (currentConversation != null && !readOnlyCheckPerformed) {
  379. readOnlyCheckPerformed = true;
  380. if (currentConversation.getConversationReadOnlyState() != null && currentConversation.getConversationReadOnlyState().equals(Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY)) {
  381. messageInput.setHint(R.string.nc_readonly_hint);
  382. conversationVoiceCallMenuItem.getIcon().setAlpha(99);
  383. conversationVideoMenuItem.getIcon().setAlpha(99);
  384. setChildrenState(messageInputView, false);
  385. } else {
  386. messageInput.setHint("");
  387. conversationVoiceCallMenuItem.getIcon().setAlpha(255);
  388. conversationVideoMenuItem.getIcon().setAlpha(255);
  389. setChildrenState(messageInputView, true);
  390. }
  391. }
  392. }
  393. private void setChildrenState(View view, boolean enabled) {
  394. if (view.getId() != R.id.messageSendButton) {
  395. view.setEnabled(enabled);
  396. }
  397. if (enabled) {
  398. view.setAlpha(1.0f);
  399. } else {
  400. view.setAlpha(0.38f);
  401. }
  402. if (view instanceof ViewGroup) {
  403. ViewGroup viewGroup = (ViewGroup) view;
  404. for (int i = 0; i < viewGroup.getChildCount(); i++) {
  405. View child = viewGroup.getChildAt(i);
  406. setChildrenState(child, enabled);
  407. }
  408. }
  409. }
  410. private void showBrowserScreen(BrowserController.BrowserType browserType) {
  411. Bundle bundle = new Bundle();
  412. bundle.putParcelable(BundleKeys.KEY_BROWSER_TYPE, Parcels.wrap(browserType));
  413. bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser));
  414. bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
  415. getRouter().pushController((RouterTransaction.with(new BrowserController(bundle))
  416. .pushChangeHandler(new VerticalChangeHandler())
  417. .popChangeHandler(new VerticalChangeHandler())));
  418. }
  419. private void showConversationInfoScreen() {
  420. Bundle bundle = new Bundle();
  421. bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
  422. bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
  423. getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle))
  424. .pushChangeHandler(new HorizontalChangeHandler())
  425. .popChangeHandler(new HorizontalChangeHandler())));
  426. }
  427. private void setupMentionAutocomplete() {
  428. float elevation = 6f;
  429. Drawable backgroundDrawable = new ColorDrawable(Color.WHITE);
  430. AutocompletePresenter<Mention> presenter = new MentionAutocompletePresenter(getApplicationContext(), roomToken);
  431. AutocompleteCallback<Mention> callback = new MentionAutocompleteCallback(getActivity(),
  432. conversationUser, messageInput);
  433. if (mentionAutocomplete == null && messageInput != null) {
  434. mentionAutocomplete = Autocomplete.<Mention>on(messageInput)
  435. .with(elevation)
  436. .with(backgroundDrawable)
  437. .with(new MagicCharPolicy('@'))
  438. .with(presenter)
  439. .with(callback)
  440. .build();
  441. }
  442. }
  443. @Override
  444. protected void onAttach(@NonNull View view) {
  445. super.onAttach(view);
  446. eventBus.register(this);
  447. isLeavingForConversation = false;
  448. ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(roomId);
  449. ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomToken(roomId);
  450. ApplicationWideCurrentRoomHolder.getInstance().setInCall(false);
  451. ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(conversationUser);
  452. isLinkPreviewAllowed = appPreferences.getAreLinkPreviewsAllowed();
  453. emojiPopup = EmojiPopup.Builder.fromRootView(view).setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() {
  454. @Override
  455. public void onEmojiPopupShown() {
  456. if (getResources() != null) {
  457. smileyButton.setColorFilter(getResources().getColor(R.color.colorPrimary),
  458. PorterDuff.Mode.SRC_IN);
  459. }
  460. }
  461. }).setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() {
  462. @Override
  463. public void onEmojiPopupDismiss() {
  464. if (smileyButton != null) {
  465. smileyButton.setColorFilter(getResources().getColor(R.color.emoji_icons),
  466. PorterDuff.Mode.SRC_IN);
  467. }
  468. }
  469. }).setOnEmojiClickListener(new OnEmojiClickListener() {
  470. @Override
  471. public void onEmojiClick(@NonNull EmojiImageView emoji, @NonNull Emoji imageView) {
  472. messageInput.getEditableText().append(" ");
  473. }
  474. }).build(messageInput);
  475. if (getActivity() != null) {
  476. new KeyboardUtils(getActivity(), getView(), false);
  477. }
  478. cancelNotificationsForCurrentConversation();
  479. if (inChat) {
  480. if (wasDetached && conversationUser.hasSpreedFeatureCapability("no-ping")) {
  481. wasDetached = false;
  482. joinRoomWithPassword();
  483. }
  484. }
  485. }
  486. private void cancelNotificationsForCurrentConversation() {
  487. if (!conversationUser.hasSpreedFeatureCapability("no-ping") && !TextUtils.isEmpty(roomId)) {
  488. NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomId);
  489. } else if (!TextUtils.isEmpty(roomToken)){
  490. NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomToken);
  491. }
  492. }
  493. @Override
  494. protected void onDetach(@NonNull View view) {
  495. super.onDetach(view);
  496. ApplicationWideCurrentRoomHolder.getInstance().clear();
  497. eventBus.unregister(this);
  498. if (conversationUser.hasSpreedFeatureCapability("no-ping")
  499. && getActivity() != null && !getActivity().isChangingConfigurations() && !isLeavingForConversation) {
  500. wasDetached = true;
  501. leaveRoom();
  502. }
  503. if (mentionAutocomplete != null && mentionAutocomplete.isPopupShowing()) {
  504. mentionAutocomplete.dismissPopup();
  505. }
  506. }
  507. @Override
  508. protected String getTitle() {
  509. return conversationName;
  510. }
  511. @Override
  512. public void onDestroy() {
  513. super.onDestroy();
  514. if (getActivity() != null) {
  515. getActivity().findViewById(R.id.toolbar).setOnClickListener(null);
  516. }
  517. adapter = null;
  518. inChat = false;
  519. }
  520. private void dispose() {
  521. Disposable disposable;
  522. for (int i = 0; i < disposableList.size(); i++) {
  523. if (!(disposable = disposableList.get(i)).isDisposed()) {
  524. disposable.dispose();
  525. }
  526. }
  527. }
  528. private void startPing() {
  529. if (!conversationUser.hasSpreedFeatureCapability("no-ping")) {
  530. ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(conversationUser.getBaseUrl(), roomToken))
  531. .subscribeOn(Schedulers.io())
  532. .observeOn(AndroidSchedulers.mainThread())
  533. .repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS))
  534. .takeWhile(observable -> inChat)
  535. .retry(3, observable -> inChat)
  536. .subscribe(new Observer<GenericOverall>() {
  537. @Override
  538. public void onSubscribe(Disposable d) {
  539. disposableList.add(d);
  540. }
  541. @Override
  542. public void onNext(GenericOverall genericOverall) {
  543. }
  544. @Override
  545. public void onError(Throwable e) {
  546. }
  547. @Override
  548. public void onComplete() {
  549. }
  550. });
  551. }
  552. }
  553. @OnClick(R.id.smileyButton)
  554. void onSmileyClick() {
  555. emojiPopup.toggle();
  556. }
  557. private void joinRoomWithPassword() {
  558. if (currentCall == null) {
  559. ncApi.joinRoom(credentials,
  560. ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser.getBaseUrl(), roomToken), roomPassword)
  561. .subscribeOn(Schedulers.io())
  562. .observeOn(AndroidSchedulers.mainThread())
  563. .retry(3)
  564. .subscribe(new Observer<CallOverall>() {
  565. @Override
  566. public void onSubscribe(Disposable d) {
  567. disposableList.add(d);
  568. }
  569. @Override
  570. public void onNext(CallOverall callOverall) {
  571. inChat = true;
  572. currentCall = callOverall.getOcs().getData();
  573. ApplicationWideCurrentRoomHolder.getInstance().setSession(currentCall.getSessionId());
  574. startPing();
  575. if (isFirstMessagesProcessing) {
  576. pullChatMessages(0);
  577. } else {
  578. pullChatMessages(1);
  579. }
  580. if (startCallFromNotification != null && startCallFromNotification) {
  581. startCallFromNotification = false;
  582. startACall(voiceOnly);
  583. }
  584. }
  585. @Override
  586. public void onError(Throwable e) {
  587. }
  588. @Override
  589. public void onComplete() {
  590. }
  591. });
  592. } else {
  593. inChat = true;
  594. ApplicationWideCurrentRoomHolder.getInstance().setSession(currentCall.getSessionId());
  595. startPing();
  596. if (isFirstMessagesProcessing) {
  597. pullChatMessages(0);
  598. } else {
  599. pullChatMessages(1);
  600. }
  601. }
  602. }
  603. private void leaveRoom() {
  604. ncApi.leaveRoom(credentials,
  605. ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser.getBaseUrl(),
  606. roomToken))
  607. .subscribeOn(Schedulers.io())
  608. .observeOn(AndroidSchedulers.mainThread())
  609. .subscribe(new Observer<GenericOverall>() {
  610. @Override
  611. public void onSubscribe(Disposable d) {
  612. disposableList.add(d);
  613. }
  614. @Override
  615. public void onNext(GenericOverall genericOverall) {
  616. dispose();
  617. if (!isDestroyed() && !isBeingDestroyed() && !wasDetached) {
  618. getRouter().popCurrentController();
  619. }
  620. }
  621. @Override
  622. public void onError(Throwable e) {
  623. }
  624. @Override
  625. public void onComplete() {
  626. dispose();
  627. }
  628. });
  629. }
  630. private void setSenderId() {
  631. try {
  632. final Field senderId = adapter.getClass().getDeclaredField("senderId");
  633. senderId.setAccessible(true);
  634. senderId.set(adapter, conversationUser.getUserId());
  635. } catch (NoSuchFieldException e) {
  636. Log.w(TAG, "Failed to set sender id");
  637. } catch (IllegalAccessException e) {
  638. Log.w(TAG, "Failed to access and set field");
  639. }
  640. }
  641. private void submitMessage() {
  642. final Editable editable = messageInput.getEditableText();
  643. Spans.MentionChipSpan mentionSpans[] = editable.getSpans(0, editable.length(),
  644. Spans.MentionChipSpan.class);
  645. Spans.MentionChipSpan mentionSpan;
  646. for (int i = 0; i < mentionSpans.length; i++) {
  647. mentionSpan = mentionSpans[i];
  648. editable.replace(editable.getSpanStart(mentionSpan), editable.getSpanEnd(mentionSpan), "@" + mentionSpan.getId());
  649. }
  650. messageInput.setText("");
  651. sendMessage(editable);
  652. }
  653. private void sendMessage(CharSequence message) {
  654. ncApi.sendChatMessage(credentials, ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken),
  655. message, conversationUser
  656. .getDisplayName())
  657. .subscribeOn(Schedulers.io())
  658. .observeOn(AndroidSchedulers.mainThread())
  659. .subscribe(new Observer<GenericOverall>() {
  660. @Override
  661. public void onSubscribe(Disposable d) {
  662. }
  663. @Override
  664. public void onNext(GenericOverall genericOverall) {
  665. myFirstMessage = message;
  666. if (popupBubble != null && popupBubble.isShown()) {
  667. popupBubble.hide();
  668. }
  669. if (messagesListView != null) {
  670. messagesListView.smoothScrollToPosition(0);
  671. }
  672. }
  673. @Override
  674. public void onError(Throwable e) {
  675. if (e instanceof HttpException) {
  676. int code = ((HttpException) e).code();
  677. if (Integer.toString(code).startsWith("2")) {
  678. myFirstMessage = message;
  679. if (popupBubble != null && popupBubble.isShown()) {
  680. popupBubble.hide();
  681. }
  682. messagesListView.smoothScrollToPosition(0);
  683. }
  684. }
  685. }
  686. @Override
  687. public void onComplete() {
  688. }
  689. });
  690. }
  691. private void pullChatMessages(int lookIntoFuture) {
  692. if (!inChat) {
  693. return;
  694. }
  695. if (!lookingIntoFuture && lookIntoFuture == 1) {
  696. lookingIntoFuture = true;
  697. }
  698. Map<String, Integer> fieldMap = new HashMap<>();
  699. fieldMap.put("lookIntoFuture", lookIntoFuture);
  700. fieldMap.put("limit", 25);
  701. int lastKnown;
  702. if (lookIntoFuture == 1) {
  703. lastKnown = globalLastKnownFutureMessageId;
  704. } else {
  705. lastKnown = globalLastKnownPastMessageId;
  706. }
  707. if (lastKnown != -1) {
  708. fieldMap.put("lastKnownMessageId", lastKnown);
  709. }
  710. if (!wasDetached) {
  711. if (lookIntoFuture == 1) {
  712. ncApi.pullChatMessages(credentials, ApiUtils.getUrlForChat(conversationUser.getBaseUrl(),
  713. roomToken),
  714. fieldMap)
  715. .subscribeOn(Schedulers.io())
  716. .observeOn(AndroidSchedulers.mainThread())
  717. .takeWhile(observable -> inChat && !wasDetached)
  718. .retry(3, observable -> inChat && !wasDetached)
  719. .subscribe(new Observer<Response>() {
  720. @Override
  721. public void onSubscribe(Disposable d) {
  722. disposableList.add(d);
  723. }
  724. @Override
  725. public void onNext(Response response) {
  726. processMessages(response, true);
  727. }
  728. @Override
  729. public void onError(Throwable e) {
  730. }
  731. @Override
  732. public void onComplete() {
  733. pullChatMessages(1);
  734. }
  735. });
  736. } else {
  737. ncApi.pullChatMessages(credentials,
  738. ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap)
  739. .subscribeOn(Schedulers.io())
  740. .observeOn(AndroidSchedulers.mainThread())
  741. .retry(3, observable -> inChat && !wasDetached)
  742. .takeWhile(observable -> inChat && !wasDetached)
  743. .subscribe(new Observer<Response>() {
  744. @Override
  745. public void onSubscribe(Disposable d) {
  746. disposableList.add(d);
  747. }
  748. @Override
  749. public void onNext(Response response) {
  750. processMessages(response, false);
  751. }
  752. @Override
  753. public void onError(Throwable e) {
  754. }
  755. @Override
  756. public void onComplete() {
  757. }
  758. });
  759. }
  760. }
  761. }
  762. private void processMessages(Response response, boolean isFromTheFuture) {
  763. if (response.code() == 200) {
  764. ChatOverall chatOverall = (ChatOverall) response.body();
  765. List<ChatMessage> chatMessageList = chatOverall.getOcs().getData();
  766. if (isFirstMessagesProcessing) {
  767. cancelNotificationsForCurrentConversation();
  768. isFirstMessagesProcessing = false;
  769. if (loadingProgressBar != null) {
  770. loadingProgressBar.setVisibility(View.GONE);
  771. }
  772. if (messagesListView != null) {
  773. messagesListView.setVisibility(View.VISIBLE);
  774. }
  775. }
  776. int countGroupedMessages = 0;
  777. if (!isFromTheFuture) {
  778. for (int i = 0; i < chatMessageList.size(); i++) {
  779. if (chatMessageList.size() > i + 1) {
  780. if (TextUtils.isEmpty(chatMessageList.get(i).getSystemMessage()) &&
  781. TextUtils.isEmpty(chatMessageList.get(i + 1).getSystemMessage()) &&
  782. chatMessageList.get(i + 1).getActorId().equals(chatMessageList.get(i).getActorId()) &&
  783. countGroupedMessages < 4 && DateFormatter.isSameDay(chatMessageList.get(i).getCreatedAt(),
  784. chatMessageList.get(i + 1).getCreatedAt())) {
  785. chatMessageList.get(i).setGrouped(true);
  786. countGroupedMessages++;
  787. } else {
  788. countGroupedMessages = 0;
  789. }
  790. }
  791. ChatMessage chatMessage = chatMessageList.get(i);
  792. chatMessage.setLinkPreviewAllowed(isLinkPreviewAllowed);
  793. chatMessage.setActiveUser(conversationUser);
  794. if (globalLastKnownPastMessageId == -1 || chatMessageList.get(i).getJsonMessageId() <
  795. globalLastKnownPastMessageId) {
  796. globalLastKnownPastMessageId = chatMessageList.get(i).getJsonMessageId();
  797. }
  798. if (globalLastKnownFutureMessageId == -1) {
  799. if (chatMessageList.get(i).getJsonMessageId() > globalLastKnownFutureMessageId) {
  800. globalLastKnownFutureMessageId = chatMessageList.get(i).getJsonMessageId();
  801. }
  802. }
  803. }
  804. if (adapter != null) {
  805. adapter.addToEnd(chatMessageList, false);
  806. }
  807. } else {
  808. ChatMessage chatMessage;
  809. for (int i = 0; i < chatMessageList.size(); i++) {
  810. chatMessage = chatMessageList.get(i);
  811. chatMessage.setActiveUser(conversationUser);
  812. chatMessage.setLinkPreviewAllowed(isLinkPreviewAllowed);
  813. // if credentials are empty, we're acting as a guest
  814. if (TextUtils.isEmpty(credentials) && myFirstMessage != null && !TextUtils.isEmpty(myFirstMessage.toString())) {
  815. if (chatMessage.getActorType().equals("guests")) {
  816. conversationUser.setUserId(chatMessage.getActorId());
  817. setSenderId();
  818. }
  819. }
  820. boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0 ||
  821. (adapter != null && adapter.getItemCount() == 0);
  822. if (!shouldScroll && popupBubble != null) {
  823. if (!popupBubble.isShown()) {
  824. newMessagesCount = 1;
  825. popupBubble.show();
  826. } else if (popupBubble.isShown()) {
  827. newMessagesCount++;
  828. }
  829. } else {
  830. newMessagesCount = 0;
  831. }
  832. if (adapter != null) {
  833. chatMessage.setGrouped(adapter.isPreviousSameAuthor(chatMessage.getActorId(), -1) && (adapter.getSameAuthorLastMessagesCount(chatMessage.getActorId()) % 5) > 0);
  834. adapter.addToStart(chatMessage, shouldScroll);
  835. }
  836. }
  837. String xChatLastGivenHeader;
  838. if (response.headers().size() > 0 && !TextUtils.isEmpty((xChatLastGivenHeader = response.headers().get
  839. ("X-Chat-Last-Given")))) {
  840. if (xChatLastGivenHeader != null) {
  841. globalLastKnownFutureMessageId = Integer.parseInt(xChatLastGivenHeader);
  842. }
  843. }
  844. }
  845. if (!lookingIntoFuture && inChat) {
  846. pullChatMessages(1);
  847. }
  848. } else if (response.code() == 304 && !isFromTheFuture) {
  849. if (isFirstMessagesProcessing) {
  850. cancelNotificationsForCurrentConversation();
  851. isFirstMessagesProcessing = false;
  852. if (loadingProgressBar != null) {
  853. loadingProgressBar.setVisibility(View.GONE);
  854. }
  855. }
  856. historyRead = true;
  857. if (!lookingIntoFuture && inChat) {
  858. pullChatMessages(1);
  859. }
  860. }
  861. }
  862. @Override
  863. public void onLoadMore(int page, int totalItemsCount) {
  864. if (!historyRead && inChat) {
  865. pullChatMessages(0);
  866. }
  867. }
  868. @Override
  869. public String format(Date date) {
  870. if (DateFormatter.isToday(date)) {
  871. return getResources().getString(R.string.nc_date_header_today);
  872. } else if (DateFormatter.isYesterday(date)) {
  873. return getResources().getString(R.string.nc_date_header_yesterday);
  874. } else {
  875. return DateFormatter.format(date, DateFormatter.Template.STRING_DAY_MONTH_YEAR);
  876. }
  877. }
  878. @Override
  879. public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
  880. super.onCreateOptionsMenu(menu, inflater);
  881. inflater.inflate(R.menu.menu_conversation, menu);
  882. if (conversationUser.getUserId().equals("?")) {
  883. menu.removeItem(R.id.conversation_info);
  884. } else {
  885. conversationInfoMenuItem = menu.findItem(R.id.conversation_info);
  886. conversationVoiceCallMenuItem = menu.findItem(R.id.conversation_voice_call);
  887. conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call);
  888. }
  889. }
  890. @Override
  891. public void onPrepareOptionsMenu(@NonNull Menu menu) {
  892. super.onPrepareOptionsMenu(menu);
  893. if (conversationUser.hasSpreedFeatureCapability("read-only-rooms")) {
  894. checkReadOnlyState();
  895. }
  896. }
  897. @Override
  898. public boolean onOptionsItemSelected(@NonNull MenuItem item) {
  899. switch (item.getItemId()) {
  900. case android.R.id.home:
  901. getRouter().popCurrentController();
  902. return true;
  903. case R.id.conversation_video_call:
  904. if (conversationVideoMenuItem.getIcon().getAlpha() == 255) {
  905. startACall(false);
  906. return true;
  907. }
  908. return false;
  909. case R.id.conversation_voice_call:
  910. if (conversationVoiceCallMenuItem.getIcon().getAlpha() == 255) {
  911. startACall(true);
  912. return true;
  913. }
  914. return false;
  915. case R.id.conversation_info:
  916. showConversationInfoScreen();
  917. return true;
  918. default:
  919. return super.onOptionsItemSelected(item);
  920. }
  921. }
  922. private void startACall(boolean isVoiceOnlyCall) {
  923. isLeavingForConversation = true;
  924. if (!isVoiceOnlyCall) {
  925. Intent videoCallIntent = getIntentForCall(false);
  926. if (videoCallIntent != null) {
  927. startActivity(videoCallIntent);
  928. }
  929. } else {
  930. Intent voiceCallIntent = getIntentForCall(true);
  931. if (voiceCallIntent != null) {
  932. startActivity(voiceCallIntent);
  933. }
  934. }
  935. }
  936. private Intent getIntentForCall(boolean isVoiceOnlyCall) {
  937. if (currentConversation != null) {
  938. Bundle bundle = new Bundle();
  939. bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
  940. bundle.putString(BundleKeys.KEY_ROOM_ID, roomId);
  941. bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
  942. bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword);
  943. bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, conversationUser.getBaseUrl());
  944. if (isVoiceOnlyCall) {
  945. bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true);
  946. }
  947. if (getActivity() != null) {
  948. Intent callIntent = new Intent(getActivity(), MagicCallActivity.class);
  949. callIntent.putExtras(bundle);
  950. return callIntent;
  951. } else {
  952. return null;
  953. }
  954. } else {
  955. return null;
  956. }
  957. }
  958. @Override
  959. public void onMessageLongClick(IMessage message) {
  960. if (getActivity() != null) {
  961. ClipboardManager clipboardManager = (android.content.ClipboardManager)
  962. getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
  963. ClipData clipData = android.content.ClipData.newPlainText(
  964. getResources().getString(R.string.nc_app_name), message.getText());
  965. if (clipboardManager != null) {
  966. clipboardManager.setPrimaryClip(clipData);
  967. }
  968. }
  969. }
  970. @Override
  971. public boolean hasContentFor(IMessage message, byte type) {
  972. switch (type) {
  973. case CONTENT_TYPE_SYSTEM_MESSAGE:
  974. return !TextUtils.isEmpty(message.getSystemMessage());
  975. }
  976. return false;
  977. }
  978. @Subscribe(threadMode = ThreadMode.BACKGROUND)
  979. public void onMessageEvent(UserMentionClickEvent userMentionClickEvent) {
  980. if ((!currentConversation.getType().equals(Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) || !currentConversation.getName().equals(userMentionClickEvent.getUserId()))) {
  981. RetrofitBucket retrofitBucket =
  982. ApiUtils.getRetrofitBucketForCreateRoom(conversationUser.getBaseUrl(), "1",
  983. userMentionClickEvent.getUserId(), null);
  984. ncApi.createRoom(credentials,
  985. retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
  986. .subscribeOn(Schedulers.io())
  987. .observeOn(AndroidSchedulers.mainThread())
  988. .subscribe(new Observer<RoomOverall>() {
  989. @Override
  990. public void onSubscribe(Disposable d) {
  991. }
  992. @Override
  993. public void onNext(RoomOverall roomOverall) {
  994. Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class);
  995. Bundle bundle = new Bundle();
  996. bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
  997. bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
  998. bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
  999. if (conversationUser.hasSpreedFeatureCapability("chat-v2")) {
  1000. bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
  1001. Parcels.wrap(roomOverall.getOcs().getData()));
  1002. conversationIntent.putExtras(bundle);
  1003. ConductorRemapping.remapChatController(getRouter(), conversationUser.getId(),
  1004. roomOverall.getOcs().getData().getToken(), bundle, false);
  1005. } else {
  1006. conversationIntent.putExtras(bundle);
  1007. startActivity(conversationIntent);
  1008. new Handler().postDelayed(new Runnable() {
  1009. @Override
  1010. public void run() {
  1011. if (!isDestroyed() && !isBeingDestroyed()) {
  1012. getRouter().popCurrentController();
  1013. }
  1014. }
  1015. }, 100);
  1016. }
  1017. }
  1018. @Override
  1019. public void onError(Throwable e) {
  1020. }
  1021. @Override
  1022. public void onComplete() {
  1023. }
  1024. });
  1025. }
  1026. }
  1027. }