ConversationsOverviewFragment.java

  1/*
  2 * Copyright (c) 2018, Daniel Gultsch All rights reserved.
  3 *
  4 * Redistribution and use in source and binary forms, with or without modification,
  5 * are permitted provided that the following conditions are met:
  6 *
  7 * 1. Redistributions of source code must retain the above copyright notice, this
  8 * list of conditions and the following disclaimer.
  9 *
 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
 11 * this list of conditions and the following disclaimer in the documentation and/or
 12 * other materials provided with the distribution.
 13 *
 14 * 3. Neither the name of the copyright holder nor the names of its contributors
 15 * may be used to endorse or promote products derived from this software without
 16 * specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28 */
 29
 30package eu.siacs.conversations.ui;
 31
 32import static androidx.recyclerview.widget.ItemTouchHelper.LEFT;
 33import static androidx.recyclerview.widget.ItemTouchHelper.RIGHT;
 34
 35import android.app.Activity;
 36import android.app.Fragment;
 37import android.content.Intent;
 38import android.graphics.Canvas;
 39import android.os.Bundle;
 40import android.util.Log;
 41import android.view.ContextMenu;
 42import android.view.LayoutInflater;
 43import android.view.Menu;
 44import android.view.MenuInflater;
 45import android.view.MenuItem;
 46import android.view.View;
 47import android.view.ViewGroup;
 48import android.widget.AdapterView.AdapterContextMenuInfo;
 49import android.widget.PopupMenu;
 50import android.widget.Toast;
 51import androidx.annotation.NonNull;
 52import androidx.databinding.DataBindingUtil;
 53import androidx.recyclerview.widget.ItemTouchHelper;
 54import androidx.recyclerview.widget.LinearLayoutManager;
 55import androidx.recyclerview.widget.RecyclerView;
 56import com.google.android.material.dialog.MaterialAlertDialogBuilder;
 57import com.google.android.material.snackbar.Snackbar;
 58import com.google.common.base.Optional;
 59import com.google.common.collect.Collections2;
 60import eu.siacs.conversations.BuildConfig;
 61import eu.siacs.conversations.Config;
 62import eu.siacs.conversations.R;
 63import eu.siacs.conversations.databinding.FragmentConversationsOverviewBinding;
 64import eu.siacs.conversations.entities.Account;
 65import eu.siacs.conversations.entities.Conversation;
 66import eu.siacs.conversations.entities.Conversational;
 67import eu.siacs.conversations.services.XmppConnectionService;
 68import eu.siacs.conversations.services.QuickConversationsService;
 69import eu.siacs.conversations.ui.adapter.ConversationAdapter;
 70import eu.siacs.conversations.ui.interfaces.OnConversationArchived;
 71import eu.siacs.conversations.ui.interfaces.OnConversationSelected;
 72import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
 73import eu.siacs.conversations.ui.util.PendingActionHelper;
 74import eu.siacs.conversations.ui.util.PendingItem;
 75import eu.siacs.conversations.ui.util.ScrollState;
 76import eu.siacs.conversations.utils.AccountUtils;
 77import eu.siacs.conversations.utils.EasyOnboardingInvite;
 78import eu.siacs.conversations.utils.ThemeHelper;
 79import eu.siacs.conversations.xmpp.jingle.OngoingRtpSession;
 80
 81import static androidx.recyclerview.widget.ItemTouchHelper.LEFT;
 82import static androidx.recyclerview.widget.ItemTouchHelper.RIGHT;
 83
 84import java.util.ArrayList;
 85import java.util.List;
 86import java.util.concurrent.atomic.AtomicReference;
 87
 88public class ConversationsOverviewFragment extends XmppFragment {
 89
 90    private static final String STATE_SCROLL_POSITION =
 91            ConversationsOverviewFragment.class.getName() + ".scroll_state";
 92
 93    private final List<Conversation> conversations = new ArrayList<>();
 94    private final PendingItem<Conversation> swipedConversation = new PendingItem<>();
 95    private final PendingItem<ScrollState> pendingScrollState = new PendingItem<>();
 96    private FragmentConversationsOverviewBinding binding;
 97    private ConversationAdapter conversationsAdapter;
 98    private XmppActivity activity;
 99    private final PendingActionHelper pendingActionHelper = new PendingActionHelper();
100
101    private final ItemTouchHelper.SimpleCallback callback =
102            new ItemTouchHelper.SimpleCallback(0, LEFT | RIGHT) {
103                @Override
104                public boolean onMove(
105                        @NonNull RecyclerView recyclerView,
106                        @NonNull RecyclerView.ViewHolder viewHolder,
107                        @NonNull RecyclerView.ViewHolder target) {
108                    return false;
109                }
110
111                @Override
112                public void onChildDraw(
113                        @NonNull Canvas c,
114                        @NonNull RecyclerView recyclerView,
115                        @NonNull RecyclerView.ViewHolder viewHolder,
116                        float dX,
117                        float dY,
118                        int actionState,
119                        boolean isCurrentlyActive) {
120                    if (viewHolder
121                            instanceof
122                            ConversationAdapter.ConversationViewHolder conversationViewHolder) {
123                        getDefaultUIUtil()
124                                .onDraw(
125                                        c,
126                                        recyclerView,
127                                        conversationViewHolder.binding.frame,
128                                        dX,
129                                        dY,
130                                        actionState,
131                                        isCurrentlyActive);
132                    }
133                }
134
135                @Override
136                public void clearView(
137                        @NonNull RecyclerView recyclerView,
138                        @NonNull RecyclerView.ViewHolder viewHolder) {
139                    if (viewHolder
140                            instanceof
141                            ConversationAdapter.ConversationViewHolder conversationViewHolder) {
142                        getDefaultUIUtil().clearView(conversationViewHolder.binding.frame);
143                    }
144                }
145
146                @Override
147                public float getSwipeEscapeVelocity(final float defaultEscapeVelocity) {
148                    return 32 * defaultEscapeVelocity;
149                }
150
151                @Override
152                public void onSwiped(
153                        final RecyclerView.ViewHolder viewHolder, final int direction) {
154                    pendingActionHelper.execute();
155                    int position = viewHolder.getLayoutPosition();
156                    try {
157                        swipedConversation.push(conversations.get(position));
158                    } catch (IndexOutOfBoundsException e) {
159                        return;
160                    }
161                    conversationsAdapter.remove(swipedConversation.peek(), position);
162                    activity.xmppConnectionService.markRead(swipedConversation.peek());
163
164                    if (position == 0 && conversationsAdapter.getItemCount() == 0) {
165                        final Conversation c = swipedConversation.pop();
166                        activity.xmppConnectionService.archiveConversation(c);
167                        return;
168                    }
169                    final boolean formerlySelected =
170                            ConversationFragment.getConversation(getActivity())
171                                    == swipedConversation.peek();
172                    if (activity instanceof OnConversationArchived) {
173                        ((OnConversationArchived) activity)
174                                .onConversationArchived(swipedConversation.peek());
175                    }
176                    final Conversation c = swipedConversation.peek();
177                    final int title;
178                    if (c.getMode() == Conversational.MODE_MULTI) {
179                        if (c.getMucOptions().isPrivateAndNonAnonymous()) {
180                            title = R.string.title_undo_swipe_out_group_chat;
181                        } else {
182                            title = R.string.title_undo_swipe_out_channel;
183                        }
184                    } else {
185                        title = R.string.title_undo_swipe_out_chat;
186                    }
187
188                    final Snackbar snackbar =
189                            Snackbar.make(binding.list, title, 5000)
190                                    .setAction(
191                                            R.string.undo,
192                                            v -> {
193                                                pendingActionHelper.undo();
194                                                Conversation conversation =
195                                                        swipedConversation.pop();
196                                                conversationsAdapter.insert(conversation, position);
197                                                if (formerlySelected) {
198                                                    if (activity
199                                                            instanceof OnConversationSelected) {
200                                                        ((OnConversationSelected) activity)
201                                                                .onConversationSelected(c);
202                                                    }
203                                                }
204                                                LinearLayoutManager layoutManager =
205                                                        (LinearLayoutManager)
206                                                                binding.list.getLayoutManager();
207                                                if (position
208                                                        > layoutManager
209                                                                .findLastVisibleItemPosition()) {
210                                                    binding.list.smoothScrollToPosition(position);
211                                                }
212                                            })
213                                    .addCallback(
214                                            new Snackbar.Callback() {
215                                                @Override
216                                                public void onDismissed(
217                                                        Snackbar transientBottomBar, int event) {
218                                                    switch (event) {
219                                                        case DISMISS_EVENT_SWIPE:
220                                                        case DISMISS_EVENT_TIMEOUT:
221                                                            pendingActionHelper.execute();
222                                                            break;
223                                                    }
224                                                }
225                                            });
226
227                    pendingActionHelper.push(
228                            () -> {
229                                if (snackbar.isShownOrQueued()) {
230                                    snackbar.dismiss();
231                                }
232                                final Conversation conversation = swipedConversation.pop();
233                                if (conversation != null) {
234                                    if (!conversation.isRead(activity.xmppConnectionService)
235                                            && conversation.getMode() == Conversation.MODE_SINGLE) {
236                                        return;
237                                    }
238                                    activity.xmppConnectionService.archiveConversation(c);
239                                }
240                            });
241                    snackbar.show();
242                }
243            };
244
245    private ItemTouchHelper touchHelper;
246
247    public static Conversation getSuggestion(Activity activity) {
248        final Conversation exception;
249        Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
250        if (fragment instanceof ConversationsOverviewFragment) {
251            exception = ((ConversationsOverviewFragment) fragment).swipedConversation.peek();
252        } else {
253            exception = null;
254        }
255        return getSuggestion(activity, exception);
256    }
257
258    public static Conversation getSuggestion(Activity activity, Conversation exception) {
259        Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
260        if (fragment instanceof ConversationsOverviewFragment) {
261            List<Conversation> conversations =
262                    ((ConversationsOverviewFragment) fragment).conversations;
263            if (conversations.size() > 0) {
264                Conversation suggestion = conversations.get(0);
265                if (suggestion == exception) {
266                    if (conversations.size() > 1) {
267                        return conversations.get(1);
268                    }
269                } else {
270                    return suggestion;
271                }
272            }
273        }
274        return null;
275    }
276
277    @Override
278    public void onActivityCreated(Bundle savedInstanceState) {
279        super.onActivityCreated(savedInstanceState);
280        if (savedInstanceState == null) {
281            return;
282        }
283        pendingScrollState.push(savedInstanceState.getParcelable(STATE_SCROLL_POSITION));
284    }
285
286    @Override
287    public void onAttach(Activity activity) {
288        super.onAttach(activity);
289        if (activity instanceof XmppActivity) {
290            this.activity = (XmppActivity) activity;
291        } else {
292            throw new IllegalStateException(
293                    "Trying to attach fragment to activity that is not an XmppActivity");
294        }
295    }
296
297    @Override
298    public void onDestroyView() {
299        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.onDestroyView()");
300        super.onDestroyView();
301        this.binding = null;
302        this.conversationsAdapter = null;
303        this.touchHelper = null;
304    }
305
306    @Override
307    public void onDestroy() {
308        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.onDestroy()");
309        super.onDestroy();
310    }
311
312    @Override
313    public void onPause() {
314        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.onPause()");
315        pendingActionHelper.execute();
316        super.onPause();
317    }
318
319    @Override
320    public void onDetach() {
321        super.onDetach();
322        this.activity = null;
323    }
324
325    @Override
326    public void onCreate(Bundle savedInstanceState) {
327        super.onCreate(savedInstanceState);
328        setHasOptionsMenu(true);
329    }
330
331    @Override
332    public View onCreateView(
333            final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
334        this.binding =
335                DataBindingUtil.inflate(
336                        inflater, R.layout.fragment_conversations_overview, container, false);
337        this.binding.fab.setOnClickListener(
338                (view) -> activity.launchStartConversation()
339        );
340
341        this.conversationsAdapter = new ConversationAdapter(this.activity, this.conversations);
342        this.conversationsAdapter.setConversationClickListener(
343                (view, conversation) -> {
344                    if (activity instanceof OnConversationSelected) {
345                        ((OnConversationSelected) activity).onConversationSelected(conversation);
346                    } else {
347                        Log.w(
348                                ConversationsOverviewFragment.class.getCanonicalName(),
349                                "Activity does not implement OnConversationSelected");
350                    }
351                });
352        this.binding.list.setAdapter(this.conversationsAdapter);
353        this.binding.list.setLayoutManager(
354                new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
355          registerForContextMenu(this.binding.list);
356        this.binding.list.addOnScrollListener(ExtendedFabSizeChanger.of(binding.fab));
357        this.touchHelper = new ItemTouchHelper(this.callback);
358        this.touchHelper.attachToRecyclerView(this.binding.list);
359        return binding.getRoot();
360    }
361
362    @Override
363    public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
364        menuInflater.inflate(R.menu.fragment_conversations_overview, menu);
365        AccountUtils.showHideMenuItems(menu);
366        final MenuItem easyOnboardInvite = menu.findItem(R.id.action_easy_invite);
367        easyOnboardInvite.setVisible(EasyOnboardingInvite.anyHasSupport(activity == null ? null : activity.xmppConnectionService));
368        if (activity != null && activity.xmppConnectionService != null && activity.xmppConnectionService.isOnboarding()) {
369            final MenuItem manageAccounts = menu.findItem(R.id.action_accounts);
370            if (manageAccounts != null) manageAccounts.setVisible(false);
371
372            final MenuItem settings = menu.findItem(R.id.action_settings);
373            if (settings != null) settings.setVisible(false);
374        }
375    }
376
377    @Override
378    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
379        activity.getMenuInflater().inflate(R.menu.conversations, menu);
380
381        final MenuItem menuMucDetails = menu.findItem(R.id.action_muc_details);
382        final MenuItem menuContactDetails = menu.findItem(R.id.action_contact_details);
383        final MenuItem menuMute = menu.findItem(R.id.action_mute);
384        final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
385        final MenuItem menuOngoingCall = menu.findItem(R.id.action_ongoing_call);
386        final MenuItem menuTogglePinned = menu.findItem(R.id.action_toggle_pinned);
387        final MenuItem menuArchiveChat = menu.findItem(R.id.action_archive);
388
389        if (menuInfo == null) return;
390        int pos = ((AdapterContextMenuInfo) menuInfo).position;
391        if (pos < 0) return;
392        Conversation conversation = conversations.get(pos);
393        if (conversation != null) {
394            if (conversation.getMode() == Conversation.MODE_MULTI) {
395                menuContactDetails.setVisible(false);
396                menuMucDetails.setTitle(conversation.getMucOptions().isPrivateAndNonAnonymous() ? R.string.action_muc_details : R.string.channel_details);
397                menuOngoingCall.setVisible(false);
398                menuArchiveChat.setTitle("Leave " + (conversation.getMucOptions().isPrivateAndNonAnonymous() ? "group chat" : "Channel"));
399            } else {
400                final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
401                final Optional<OngoingRtpSession> ongoingRtpSession = service == null ? Optional.absent() : service.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact());
402                if (ongoingRtpSession.isPresent()) {
403                    menuOngoingCall.setVisible(true);
404                } else {
405                    menuOngoingCall.setVisible(false);
406                }
407                menuContactDetails.setVisible(!conversation.withSelf());
408                menuMucDetails.setVisible(false);
409                menuArchiveChat.setTitle(R.string.action_archive_chat);
410            }
411            if (conversation.isMuted()) {
412                menuMute.setVisible(false);
413            } else {
414                menuUnmute.setVisible(false);
415            }
416            if (conversation.getBooleanAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, false)) {
417                menuTogglePinned.setTitle(R.string.remove_from_favorites);
418            } else {
419                menuTogglePinned.setTitle(R.string.add_to_favorites);
420            }
421        }
422        super.onCreateContextMenu(menu, view, menuInfo);
423    }
424
425    @Override
426    public boolean onContextItemSelected(MenuItem item) {
427        final var info = ((AdapterContextMenuInfo) item.getMenuInfo());
428        if (info == null) return false;
429
430        int pos = info.position;
431        if (conversations == null || conversations.size() <= pos || pos < 0) return false;
432
433        Conversation conversation = conversations.get(pos);
434        ConversationFragment fragment = new ConversationFragment();
435        fragment.setHasOptionsMenu(false);
436        fragment.onAttach(activity);
437        fragment.reInit(conversation, null);
438        boolean r = fragment.onOptionsItemSelected(item);
439        refresh();
440        return r;
441    }
442
443    @Override
444    public void onBackendConnected() {
445        refresh();
446    }
447
448    private void setupSwipe() {
449        if (this.touchHelper == null && (activity.xmppConnectionService == null || !activity.xmppConnectionService.isOnboarding())) {
450            this.touchHelper = new ItemTouchHelper(this.callback);
451            this.touchHelper.attachToRecyclerView(this.binding.list);
452        }
453    }
454
455    @Override
456    public void onSaveInstanceState(Bundle bundle) {
457        super.onSaveInstanceState(bundle);
458        ScrollState scrollState = getScrollState();
459        if (scrollState != null) {
460            bundle.putParcelable(STATE_SCROLL_POSITION, scrollState);
461        }
462    }
463
464    private ScrollState getScrollState() {
465        if (this.binding == null) {
466            return null;
467        }
468        if (this.binding.list.getLayoutManager()
469                instanceof LinearLayoutManager linearLayoutManager) {
470            final int position = linearLayoutManager.findFirstVisibleItemPosition();
471            final View view = this.binding.list.getChildAt(0);
472            if (view != null) {
473                return new ScrollState(position, view.getTop());
474            } else {
475                return new ScrollState(position, 0);
476            }
477        }
478        return null;
479    }
480
481    @Override
482    public void onStart() {
483        super.onStart();
484        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.onStart()");
485        if (activity.xmppConnectionService != null) {
486            refresh();
487        }
488    }
489
490    @Override
491    public void onResume() {
492        super.onResume();
493        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.onResume()");
494    }
495
496    @Override
497    public boolean onOptionsItemSelected(final MenuItem item) {
498        if (MenuDoubleTabUtil.shouldIgnoreTap()) {
499            return false;
500        }
501        switch (item.getItemId()) {
502            case R.id.action_search:
503                startActivity(new Intent(getActivity(), SearchActivity.class));
504                return true;
505            case R.id.action_easy_invite:
506                selectAccountToStartEasyInvite();
507                return true;
508        }
509        return super.onOptionsItemSelected(item);
510    }
511
512    private void selectAccountToStartEasyInvite() {
513        final List<Account> accounts =
514                EasyOnboardingInvite.getSupportingAccounts(activity.xmppConnectionService);
515        if (accounts.isEmpty()) {
516            // This can technically happen if opening the menu item races with accounts reconnecting
517            // or something
518            Toast.makeText(
519                            getActivity(),
520                            R.string.no_active_accounts_support_this,
521                            Toast.LENGTH_LONG)
522                    .show();
523        } else if (accounts.size() == 1) {
524            openEasyInviteScreen(accounts.get(0));
525        } else {
526            final AtomicReference<Account> selectedAccount = new AtomicReference<>(accounts.get(0));
527            final MaterialAlertDialogBuilder alertDialogBuilder =
528                    new MaterialAlertDialogBuilder(activity);
529            alertDialogBuilder.setTitle(R.string.choose_account);
530            final String[] asStrings =
531                    Collections2.transform(accounts, a -> a.getJid().asBareJid().toString())
532                            .toArray(new String[0]);
533            alertDialogBuilder.setSingleChoiceItems(
534                    asStrings, 0, (dialog, which) -> selectedAccount.set(accounts.get(which)));
535            alertDialogBuilder.setNegativeButton(R.string.cancel, null);
536            alertDialogBuilder.setPositiveButton(
537                    R.string.ok, (dialog, which) -> openEasyInviteScreen(selectedAccount.get()));
538            alertDialogBuilder.create().show();
539        }
540    }
541
542    private void openEasyInviteScreen(final Account account) {
543        EasyOnboardingInviteActivity.launch(account, activity);
544    }
545
546    @Override
547    protected void refresh() {
548        if (binding == null || this.activity == null) {
549            Log.d(Config.LOGTAG,"ConversationsOverviewFragment.refresh() skipped updated because view binding or activity was null");
550            return;
551        }
552        this.activity.populateWithOrderedConversations(this.conversations);
553        Conversation removed = this.swipedConversation.peek();
554        if (removed != null) {
555            if (removed.isRead(activity == null ? null : activity.xmppConnectionService)) {
556                this.conversations.remove(removed);
557            } else {
558                pendingActionHelper.execute();
559            }
560        }
561        this.conversationsAdapter.notifyDataSetChanged();
562        final var scrollState = pendingScrollState.pop();
563        if (scrollState != null) {
564            setScrollPosition(scrollState);
565        }
566
567        if (activity.xmppConnectionService != null && activity.xmppConnectionService.isOnboarding()) {
568            binding.fab.setVisibility(View.GONE);
569
570            if (this.conversations.size() == 1) {
571                if (activity instanceof OnConversationSelected) {
572                    ((OnConversationSelected) activity).onConversationSelected(this.conversations.get(0));
573                } else {
574                    Log.w(ConversationsOverviewFragment.class.getCanonicalName(), "Activity does not implement OnConversationSelected");
575                }
576            }
577        } else {
578            binding.fab.setVisibility(View.VISIBLE);
579        }
580        setupSwipe();
581
582        if (activity.xmppConnectionService == null || binding == null || binding.overviewSnackbar == null) return;
583        binding.overviewSnackbar.setVisibility(View.GONE);
584        for (final var account : activity.xmppConnectionService.getAccounts()) {
585            if (activity.getPreferences().getBoolean("no_mam_pref_warn:" + account.getUuid(), false)) continue;
586            if (account.mamPrefs() != null && !"always".equals(account.mamPrefs().getAttribute("default"))) {
587                binding.overviewSnackbar.setVisibility(View.VISIBLE);
588                binding.overviewSnackbarMessage.setText("Your account " + account.getJid().asBareJid().toString() + " does not have archiving fully enabled. This may result in missed messages if you use multiple devices or apps.");
589                binding.overviewSnackbarAction.setOnClickListener((v) -> {
590                    final var prefs = account.mamPrefs();
591                    prefs.setAttribute("default", "always");
592                    activity.xmppConnectionService.pushMamPreferences(account, prefs);
593                    refresh();
594                });
595
596                binding.overviewSnackbarAction.setOnLongClickListener((v) -> {
597                    PopupMenu popupMenu = new PopupMenu(getActivity(), v);
598                    popupMenu.inflate(R.menu.mam_pref_fix);
599                    popupMenu.setOnMenuItemClickListener(menuItem -> {
600                            switch (menuItem.getItemId()) {
601                            case R.id.ignore:
602                                final var editor = activity.getPreferences().edit();
603                                editor.putBoolean("no_mam_pref_warn:" + account.getUuid(), true).apply();
604                                editor.apply();
605                                refresh();
606                                return true;
607                            }
608                            return true;
609                    });
610                    popupMenu.show();
611                    return true;
612                });
613                break;
614            }
615        }
616    }
617
618    private void setScrollPosition(@NonNull final ScrollState scrollPosition) {
619        if (binding.list.getLayoutManager() instanceof LinearLayoutManager linearLayoutManager) {
620            linearLayoutManager.scrollToPositionWithOffset(
621                    scrollPosition.position, scrollPosition.offset);
622            if (scrollPosition.position > 0) {
623                binding.fab.shrink();
624            } else {
625                binding.fab.extend();
626            }
627            binding.fab.clearAnimation();
628        }
629    }
630}