ContactsController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * Nextcloud Talk application
  3. *
  4. * @author Mario Danic
  5. * Copyright (C) 2017 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.app.SearchManager;
  22. import android.content.Context;
  23. import android.content.Intent;
  24. import android.os.Bundle;
  25. import android.os.Handler;
  26. import android.support.annotation.NonNull;
  27. import android.support.annotation.Nullable;
  28. import android.support.design.widget.BottomNavigationView;
  29. import android.support.v4.view.MenuItemCompat;
  30. import android.support.v4.widget.SwipeRefreshLayout;
  31. import android.support.v7.widget.DividerItemDecoration;
  32. import android.support.v7.widget.RecyclerView;
  33. import android.support.v7.widget.SearchView;
  34. import android.text.InputType;
  35. import android.text.TextUtils;
  36. import android.view.LayoutInflater;
  37. import android.view.Menu;
  38. import android.view.MenuInflater;
  39. import android.view.MenuItem;
  40. import android.view.View;
  41. import android.view.ViewGroup;
  42. import android.view.ViewTreeObserver;
  43. import android.view.inputmethod.EditorInfo;
  44. import android.widget.Button;
  45. import android.widget.LinearLayout;
  46. import com.bluelinelabs.conductor.RouterTransaction;
  47. import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
  48. import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
  49. import com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler;
  50. import com.nextcloud.talk.R;
  51. import com.nextcloud.talk.activities.CallActivity;
  52. import com.nextcloud.talk.adapters.items.EmptyFooterItem;
  53. import com.nextcloud.talk.adapters.items.NewCallHeaderItem;
  54. import com.nextcloud.talk.adapters.items.UserHeaderItem;
  55. import com.nextcloud.talk.adapters.items.UserItem;
  56. import com.nextcloud.talk.api.NcApi;
  57. import com.nextcloud.talk.application.NextcloudTalkApplication;
  58. import com.nextcloud.talk.controllers.base.BaseController;
  59. import com.nextcloud.talk.models.RetrofitBucket;
  60. import com.nextcloud.talk.models.database.UserEntity;
  61. import com.nextcloud.talk.models.json.participants.Participant;
  62. import com.nextcloud.talk.models.json.rooms.RoomOverall;
  63. import com.nextcloud.talk.models.json.sharees.Sharee;
  64. import com.nextcloud.talk.models.json.sharees.ShareesOverall;
  65. import com.nextcloud.talk.utils.ApiUtils;
  66. import com.nextcloud.talk.utils.bundle.BundleKeys;
  67. import com.nextcloud.talk.utils.database.user.UserUtils;
  68. import org.parceler.Parcels;
  69. import java.util.ArrayList;
  70. import java.util.Collections;
  71. import java.util.HashMap;
  72. import java.util.HashSet;
  73. import java.util.List;
  74. import java.util.Set;
  75. import javax.inject.Inject;
  76. import autodagger.AutoInjector;
  77. import butterknife.BindView;
  78. import butterknife.OnClick;
  79. import butterknife.Optional;
  80. import eu.davidea.fastscroller.FastScroller;
  81. import eu.davidea.flexibleadapter.FlexibleAdapter;
  82. import eu.davidea.flexibleadapter.SelectableAdapter;
  83. import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
  84. import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
  85. import eu.davidea.flexibleadapter.items.IFlexible;
  86. import eu.davidea.flipview.FlipView;
  87. import io.reactivex.Observer;
  88. import io.reactivex.android.schedulers.AndroidSchedulers;
  89. import io.reactivex.disposables.Disposable;
  90. import io.reactivex.schedulers.Schedulers;
  91. import retrofit2.HttpException;
  92. @AutoInjector(NextcloudTalkApplication.class)
  93. public class ContactsController extends BaseController implements SearchView.OnQueryTextListener,
  94. FlexibleAdapter.OnItemClickListener, FastScroller.OnScrollStateChangeListener {
  95. public static final String TAG = "ContactsController";
  96. private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery";
  97. @Inject
  98. UserUtils userUtils;
  99. @Inject
  100. NcApi ncApi;
  101. @BindView(R.id.recycler_view)
  102. RecyclerView recyclerView;
  103. @BindView(R.id.swipe_refresh_layout)
  104. SwipeRefreshLayout swipeRefreshLayout;
  105. @Nullable
  106. @BindView(R.id.bottom_buttons_layout)
  107. LinearLayout bottomButtonsLinearLayout;
  108. @BindView(R.id.fast_scroller)
  109. FastScroller fastScroller;
  110. @Nullable
  111. @BindView(R.id.clear_button)
  112. Button clearButton;
  113. private UserEntity userEntity;
  114. private Disposable contactsQueryDisposable;
  115. private Disposable cacheQueryDisposable;
  116. private FlexibleAdapter adapter;
  117. private List<AbstractFlexibleItem> contactItems = new ArrayList<>();
  118. private SmoothScrollLinearLayoutManager layoutManager;
  119. private MenuItem searchItem;
  120. private SearchView searchView;
  121. private String searchQuery;
  122. private boolean isNewConversationView;
  123. private boolean isPublicCall;
  124. private HashMap<String, UserHeaderItem> userHeaderItems = new HashMap<String, UserHeaderItem>();
  125. public ContactsController() {
  126. super();
  127. setHasOptionsMenu(true);
  128. }
  129. public ContactsController(Bundle args) {
  130. super(args);
  131. setHasOptionsMenu(true);
  132. if (args.containsKey(BundleKeys.KEY_NEW_CONVERSATION)) {
  133. isNewConversationView = true;
  134. }
  135. }
  136. @Override
  137. protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
  138. return inflater.inflate(R.layout.controller_generic_rv, container, false);
  139. }
  140. @Override
  141. protected void onAttach(@NonNull View view) {
  142. super.onAttach(view);
  143. if (isNewConversationView) {
  144. checkAndHandleBottomButtons();
  145. if (getActionBar() != null) {
  146. getActionBar().setDisplayHomeAsUpEnabled(true);
  147. }
  148. }
  149. }
  150. @Override
  151. protected void onViewBound(@NonNull View view) {
  152. super.onViewBound(view);
  153. NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
  154. FlipView.resetLayoutAnimationDelay(true, 1000L);
  155. FlipView.stopLayoutAnimation();
  156. userEntity = userUtils.getCurrentUser();
  157. if (userEntity == null) {
  158. if (getParentController().getRouter() != null) {
  159. getParentController().getRouter().setRoot((RouterTransaction.with(new ServerSelectionController())
  160. .pushChangeHandler(new HorizontalChangeHandler())
  161. .popChangeHandler(new HorizontalChangeHandler())));
  162. }
  163. }
  164. if (adapter == null) {
  165. adapter = new FlexibleAdapter<>(contactItems, getActivity(), false);
  166. adapter.setNotifyChangeOfUnfilteredItems(true)
  167. .setMode(SelectableAdapter.Mode.MULTI);
  168. if (userEntity != null) {
  169. fetchData();
  170. }
  171. }
  172. adapter.setStickyHeaderElevation(5)
  173. .setUnlinkAllItemsOnRemoveHeaders(true)
  174. .setDisplayHeadersAtStartUp(true)
  175. .setStickyHeaders(true);
  176. adapter.addListener(this);
  177. prepareViews();
  178. }
  179. @Optional
  180. @OnClick(R.id.clear_button)
  181. public void onClearButtonClick() {
  182. if (adapter != null) {
  183. List<Integer> selectedPositions = adapter.getSelectedPositions();
  184. for (Integer position : selectedPositions) {
  185. if (adapter.getItem(position) instanceof UserItem) {
  186. UserItem userItem = (UserItem) adapter.getItem(position);
  187. adapter.toggleSelection(position);
  188. if (userItem != null) {
  189. userItem.flipItemSelection();
  190. }
  191. }
  192. }
  193. }
  194. checkAndHandleBottomButtons();
  195. }
  196. @Optional
  197. @OnClick(R.id.done_button)
  198. public void onDoneButtonClick() {
  199. }
  200. private void initSearchView() {
  201. if (getActivity() != null) {
  202. SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
  203. if (searchItem != null) {
  204. searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  205. searchView.setMaxWidth(Integer.MAX_VALUE);
  206. searchView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
  207. searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN);
  208. searchView.setQueryHint(getResources().getString(R.string.nc_search));
  209. if (searchManager != null) {
  210. searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
  211. }
  212. searchView.setOnQueryTextListener(this);
  213. }
  214. }
  215. final View mSearchEditFrame = searchView
  216. .findViewById(android.support.v7.appcompat.R.id.search_edit_frame);
  217. BottomNavigationView bottomNavigationView = null;
  218. if (getParentController() != null && getParentController().getView() != null) {
  219. bottomNavigationView = getParentController().getView().findViewById(R.id.navigation);
  220. }
  221. Handler handler = new Handler();
  222. ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver();
  223. BottomNavigationView finalBottomNavigationView = bottomNavigationView;
  224. vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  225. int oldVisibility = -1;
  226. @Override
  227. public void onGlobalLayout() {
  228. int currentVisibility = mSearchEditFrame.getVisibility();
  229. if (currentVisibility != oldVisibility) {
  230. if (currentVisibility == View.VISIBLE) {
  231. if (finalBottomNavigationView != null) {
  232. handler.postDelayed(() -> finalBottomNavigationView.setVisibility(View.GONE), 100);
  233. }
  234. } else {
  235. handler.postDelayed(() -> {
  236. if (finalBottomNavigationView != null) {
  237. finalBottomNavigationView.setVisibility(View.VISIBLE);
  238. }
  239. searchItem.setVisible(contactItems.size() > 0);
  240. }, 500);
  241. }
  242. oldVisibility = currentVisibility;
  243. }
  244. }
  245. });
  246. }
  247. @Override
  248. public boolean onOptionsItemSelected(@NonNull MenuItem item) {
  249. switch (item.getItemId()) {
  250. case android.R.id.home:
  251. getRouter().popCurrentController();
  252. return true;
  253. default:
  254. return super.onOptionsItemSelected(item);
  255. }
  256. }
  257. @Override
  258. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  259. super.onCreateOptionsMenu(menu, inflater);
  260. inflater.inflate(R.menu.menu_conversation_plus_filter, menu);
  261. searchItem = menu.findItem(R.id.action_search);
  262. menu.findItem(R.id.action_new_conversation).setVisible(false);
  263. initSearchView();
  264. }
  265. @Override
  266. public void onPrepareOptionsMenu(Menu menu) {
  267. super.onPrepareOptionsMenu(menu);
  268. searchItem.setVisible(contactItems.size() > 0);
  269. if (adapter.hasSearchText()) {
  270. searchItem.expandActionView();
  271. searchView.setQuery(adapter.getSearchText(), false);
  272. }
  273. }
  274. private void fetchData() {
  275. dispose(null);
  276. Set<Sharee> shareeHashSet = new HashSet<>();
  277. contactItems = new ArrayList<>();
  278. userHeaderItems = new HashMap<>();
  279. RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForContactsSearch(userEntity.getBaseUrl(),
  280. "");
  281. contactsQueryDisposable = ncApi.getContactsWithSearchParam(
  282. ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()),
  283. retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
  284. .subscribeOn(Schedulers.newThread())
  285. .observeOn(AndroidSchedulers.mainThread())
  286. .subscribe((ShareesOverall shareesOverall) -> {
  287. if (shareesOverall != null) {
  288. if (shareesOverall.getOcs().getData().getUsers() != null) {
  289. shareeHashSet.addAll(shareesOverall.getOcs().getData().getUsers());
  290. }
  291. if (shareesOverall.getOcs().getData().getExactUsers() != null &&
  292. shareesOverall.getOcs().getData().getExactUsers().getExactSharees() != null) {
  293. shareeHashSet.addAll(shareesOverall.getOcs().getData().
  294. getExactUsers().getExactSharees());
  295. }
  296. Participant participant;
  297. for (Sharee sharee : shareeHashSet) {
  298. if (!sharee.getValue().getShareWith().equals(userEntity.getUsername())) {
  299. participant = new Participant();
  300. participant.setName(sharee.getLabel());
  301. String headerTitle;
  302. headerTitle = sharee.getLabel().substring(0, 1).toUpperCase();
  303. UserHeaderItem userHeaderItem;
  304. if (!userHeaderItems.containsKey(headerTitle)) {
  305. userHeaderItem = new UserHeaderItem(headerTitle);
  306. userHeaderItems.put(headerTitle, userHeaderItem);
  307. }
  308. participant.setUserId(sharee.getValue().getShareWith());
  309. contactItems.add(new UserItem(participant, userEntity,
  310. userHeaderItems.get(headerTitle)));
  311. }
  312. }
  313. userHeaderItems = new HashMap<>();
  314. Collections.sort(contactItems, (o1, o2) -> {
  315. String firstName;
  316. String secondName;
  317. if (o1 instanceof UserItem) {
  318. firstName = ((UserItem) o1).getModel().getName();
  319. } else {
  320. firstName = ((UserHeaderItem) o1).getModel();
  321. }
  322. if (o2 instanceof UserItem) {
  323. secondName = ((UserItem) o2).getModel().getName();
  324. } else {
  325. secondName = ((UserHeaderItem) o2).getModel();
  326. }
  327. return firstName.compareToIgnoreCase(secondName);
  328. });
  329. if (isNewConversationView) {
  330. contactItems.add(0, new NewCallHeaderItem());
  331. }
  332. adapter.updateDataSet(contactItems, true);
  333. searchItem.setVisible(contactItems.size() > 0);
  334. swipeRefreshLayout.setRefreshing(false);
  335. if (isNewConversationView) {
  336. checkAndHandleBottomButtons();
  337. }
  338. }
  339. }, throwable -> {
  340. if (searchItem != null) {
  341. searchItem.setVisible(false);
  342. }
  343. if (throwable instanceof HttpException) {
  344. HttpException exception = (HttpException) throwable;
  345. switch (exception.code()) {
  346. case 401:
  347. if (getParentController() != null &&
  348. getParentController().getRouter() != null) {
  349. getParentController().getRouter().pushController((RouterTransaction.with
  350. (new WebViewLoginController(userEntity.getBaseUrl(),
  351. true))
  352. .pushChangeHandler(new VerticalChangeHandler())
  353. .popChangeHandler(new VerticalChangeHandler())));
  354. }
  355. break;
  356. default:
  357. break;
  358. }
  359. }
  360. swipeRefreshLayout.setRefreshing(false);
  361. dispose(contactsQueryDisposable);
  362. }
  363. , () -> {
  364. swipeRefreshLayout.setRefreshing(false);
  365. dispose(contactsQueryDisposable);
  366. });
  367. }
  368. private void prepareViews() {
  369. layoutManager = new SmoothScrollLinearLayoutManager(getActivity());
  370. recyclerView.setLayoutManager(layoutManager);
  371. recyclerView.setHasFixedSize(true);
  372. recyclerView.setAdapter(adapter);
  373. recyclerView.addItemDecoration(new DividerItemDecoration(
  374. recyclerView.getContext(),
  375. layoutManager.getOrientation()
  376. ));
  377. swipeRefreshLayout.setOnRefreshListener(this::fetchData);
  378. swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
  379. fastScroller.addOnScrollStateChangeListener(this);
  380. adapter.setFastScroller(fastScroller);
  381. fastScroller.setBubbleTextCreator(position -> {
  382. IFlexible abstractFlexibleItem = adapter.getItem(position);
  383. if (abstractFlexibleItem instanceof UserItem) {
  384. return ((UserItem) adapter.getItem(position)).getHeader().getModel();
  385. } else {
  386. return ((UserHeaderItem) adapter.getItem(position)).getModel();
  387. }
  388. });
  389. }
  390. private void dispose(@Nullable Disposable disposable) {
  391. if (disposable != null && !disposable.isDisposed()) {
  392. disposable.dispose();
  393. } else if (disposable == null) {
  394. if (contactsQueryDisposable != null && !contactsQueryDisposable.isDisposed()) {
  395. contactsQueryDisposable.dispose();
  396. contactsQueryDisposable = null;
  397. }
  398. if (cacheQueryDisposable != null && !cacheQueryDisposable.isDisposed()) {
  399. cacheQueryDisposable.dispose();
  400. cacheQueryDisposable = null;
  401. }
  402. }
  403. }
  404. @Override
  405. public void onSaveViewState(@NonNull View view, @NonNull Bundle outState) {
  406. adapter.onSaveInstanceState(outState);
  407. super.onSaveViewState(view, outState);
  408. if (searchView != null && !TextUtils.isEmpty(searchView.getQuery())) {
  409. outState.putString(KEY_SEARCH_QUERY, searchView.getQuery().toString());
  410. }
  411. }
  412. @Override
  413. public void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) {
  414. super.onRestoreViewState(view, savedViewState);
  415. searchQuery = savedViewState.getString(KEY_SEARCH_QUERY, "");
  416. if (adapter != null) {
  417. adapter.onRestoreInstanceState(savedViewState);
  418. }
  419. }
  420. @Override
  421. public void onDestroy() {
  422. super.onDestroy();
  423. dispose(null);
  424. }
  425. @Override
  426. public boolean onQueryTextChange(String newText) {
  427. if (adapter.hasNewSearchText(newText) || !TextUtils.isEmpty(searchQuery)) {
  428. if (!TextUtils.isEmpty(searchQuery)) {
  429. adapter.setSearchText(searchQuery);
  430. searchQuery = "";
  431. adapter.filterItems();
  432. } else {
  433. adapter.setSearchText(newText);
  434. adapter.filterItems(300);
  435. }
  436. }
  437. if (swipeRefreshLayout != null) {
  438. swipeRefreshLayout.setEnabled(!adapter.hasSearchText());
  439. }
  440. return true;
  441. }
  442. @Override
  443. public boolean onQueryTextSubmit(String query) {
  444. return onQueryTextChange(query);
  445. }
  446. @Override
  447. public boolean onItemClick(int position) {
  448. if (adapter.getItem(position) instanceof UserItem) {
  449. if (!isNewConversationView) {
  450. UserItem userItem = (UserItem) adapter.getItem(position);
  451. RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), "1",
  452. userItem.getModel().getUserId());
  453. ncApi.createRoom(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()),
  454. retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
  455. .subscribeOn(Schedulers.newThread())
  456. .observeOn(AndroidSchedulers.mainThread())
  457. .subscribe(new Observer<RoomOverall>() {
  458. @Override
  459. public void onSubscribe(Disposable d) {
  460. }
  461. @Override
  462. public void onNext(RoomOverall roomOverall) {
  463. overridePushHandler(new NoOpControllerChangeHandler());
  464. overridePopHandler(new NoOpControllerChangeHandler());
  465. Intent callIntent = new Intent(getActivity(), CallActivity.class);
  466. Bundle bundle = new Bundle();
  467. bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
  468. bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(userEntity));
  469. callIntent.putExtras(bundle);
  470. startActivity(callIntent);
  471. }
  472. @Override
  473. public void onError(Throwable e) {
  474. }
  475. @Override
  476. public void onComplete() {
  477. }
  478. });
  479. } else {
  480. ((UserItem) adapter.getItem(position)).flipItemSelection();
  481. adapter.toggleSelection(position);
  482. checkAndHandleBottomButtons();
  483. }
  484. } else if (adapter.getItem(position) instanceof NewCallHeaderItem) {
  485. adapter.toggleSelection(position);
  486. isPublicCall = adapter.isSelected(position);
  487. ((NewCallHeaderItem) adapter.getItem(position)).togglePublicCall(isPublicCall);
  488. checkAndHandleBottomButtons();
  489. }
  490. return true;
  491. }
  492. private void checkAndHandleBottomButtons() {
  493. if (adapter != null && bottomButtonsLinearLayout != null && clearButton != null) {
  494. if (adapter.getSelectedItemCount() > 0 || isPublicCall) {
  495. if (bottomButtonsLinearLayout.getVisibility() != View.VISIBLE) {
  496. bottomButtonsLinearLayout.setVisibility(View.VISIBLE);
  497. }
  498. if (isPublicCall && adapter.getSelectedItemCount() < 2) {
  499. clearButton.setVisibility(View.GONE);
  500. } else {
  501. clearButton.setVisibility(View.VISIBLE);
  502. }
  503. } else {
  504. bottomButtonsLinearLayout.setVisibility(View.GONE);
  505. }
  506. } else if (bottomButtonsLinearLayout != null) {
  507. bottomButtonsLinearLayout.setVisibility(View.GONE);
  508. }
  509. if (bottomButtonsLinearLayout != null && bottomButtonsLinearLayout.getVisibility() == View.VISIBLE) {
  510. if (adapter.getScrollableFooters().size() == 0) {
  511. adapter.addScrollableFooterWithDelay(new EmptyFooterItem(999), 0, layoutManager
  512. .findLastVisibleItemPosition() == adapter.getItemCount() - 1);
  513. }
  514. } else {
  515. if (adapter != null) {
  516. adapter.removeAllScrollableFooters();
  517. }
  518. }
  519. }
  520. @Override
  521. protected String getTitle() {
  522. if (!isNewConversationView) {
  523. return getResources().getString(R.string.nc_app_name);
  524. } else {
  525. return getResources().getString(R.string.nc_select_contacts);
  526. }
  527. }
  528. @Override
  529. public void onFastScrollerStateChange(boolean scrolling) {
  530. swipeRefreshLayout.setEnabled(!scrolling);
  531. }
  532. }