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) -> StartConversationActivity.launch(getActivity()));
339
340        this.conversationsAdapter = new ConversationAdapter(this.activity, this.conversations);
341        this.conversationsAdapter.setConversationClickListener(
342                (view, conversation) -> {
343                    if (activity instanceof OnConversationSelected) {
344                        ((OnConversationSelected) activity).onConversationSelected(conversation);
345                    } else {
346                        Log.w(
347                                ConversationsOverviewFragment.class.getCanonicalName(),
348                                "Activity does not implement OnConversationSelected");
349                    }
350                });
351        this.binding.list.setAdapter(this.conversationsAdapter);
352        this.binding.list.setLayoutManager(
353                new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
354          registerForContextMenu(this.binding.list);
355        this.binding.list.addOnScrollListener(ExtendedFabSizeChanger.of(binding.fab));
356        this.touchHelper = new ItemTouchHelper(this.callback);
357        this.touchHelper.attachToRecyclerView(this.binding.list);
358        return binding.getRoot();
359    }
360
361    @Override
362    public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
363        menuInflater.inflate(R.menu.fragment_conversations_overview, menu);
364        AccountUtils.showHideMenuItems(menu);
365        final MenuItem easyOnboardInvite = menu.findItem(R.id.action_easy_invite);
366        easyOnboardInvite.setVisible(EasyOnboardingInvite.anyHasSupport(activity == null ? null : activity.xmppConnectionService));
367        if (activity != null && activity.xmppConnectionService != null && activity.xmppConnectionService.isOnboarding()) {
368            final MenuItem manageAccounts = menu.findItem(R.id.action_accounts);
369            if (manageAccounts != null) manageAccounts.setVisible(false);
370
371            final MenuItem settings = menu.findItem(R.id.action_settings);
372            if (settings != null) settings.setVisible(false);
373        }
374    }
375
376    @Override
377    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
378        activity.getMenuInflater().inflate(R.menu.conversations, menu);
379
380        final MenuItem menuMucDetails = menu.findItem(R.id.action_muc_details);
381        final MenuItem menuContactDetails = menu.findItem(R.id.action_contact_details);
382        final MenuItem menuMute = menu.findItem(R.id.action_mute);
383        final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
384        final MenuItem menuOngoingCall = menu.findItem(R.id.action_ongoing_call);
385        final MenuItem menuTogglePinned = menu.findItem(R.id.action_toggle_pinned);
386        final MenuItem menuArchiveChat = menu.findItem(R.id.action_archive);
387
388        if (menuInfo == null) return;
389        int pos = ((AdapterContextMenuInfo) menuInfo).position;
390        if (pos < 0) return;
391        Conversation conversation = conversations.get(pos);
392        if (conversation != null) {
393            if (conversation.getMode() == Conversation.MODE_MULTI) {
394                menuContactDetails.setVisible(false);
395                menuMucDetails.setTitle(conversation.getMucOptions().isPrivateAndNonAnonymous() ? R.string.action_muc_details : R.string.channel_details);
396                menuOngoingCall.setVisible(false);
397                menuArchiveChat.setTitle("Leave " + (conversation.getMucOptions().isPrivateAndNonAnonymous() ? "group chat" : "Channel"));
398            } else {
399                final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
400                final Optional<OngoingRtpSession> ongoingRtpSession = service == null ? Optional.absent() : service.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact());
401                if (ongoingRtpSession.isPresent()) {
402                    menuOngoingCall.setVisible(true);
403                } else {
404                    menuOngoingCall.setVisible(false);
405                }
406                menuContactDetails.setVisible(!conversation.withSelf());
407                menuMucDetails.setVisible(false);
408                menuArchiveChat.setTitle(R.string.action_archive_chat);
409            }
410            if (conversation.isMuted()) {
411                menuMute.setVisible(false);
412            } else {
413                menuUnmute.setVisible(false);
414            }
415            if (conversation.getBooleanAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, false)) {
416                menuTogglePinned.setTitle(R.string.remove_from_favorites);
417            } else {
418                menuTogglePinned.setTitle(R.string.add_to_favorites);
419            }
420        }
421        super.onCreateContextMenu(menu, view, menuInfo);
422    }
423
424    @Override
425    public boolean onContextItemSelected(MenuItem item) {
426        final var info = ((AdapterContextMenuInfo) item.getMenuInfo());
427        if (info == null) return false;
428
429        int pos = info.position;
430        if (conversations == null || conversations.size() <= pos || pos < 0) return false;
431
432        Conversation conversation = conversations.get(pos);
433        ConversationFragment fragment = new ConversationFragment();
434        fragment.setHasOptionsMenu(false);
435        fragment.onAttach(activity);
436        fragment.reInit(conversation, null);
437        boolean r = fragment.onOptionsItemSelected(item);
438        refresh();
439        return r;
440    }
441
442    @Override
443    public void onBackendConnected() {
444        refresh();
445    }
446
447    private void setupSwipe() {
448        if (this.touchHelper == null && (activity.xmppConnectionService == null || !activity.xmppConnectionService.isOnboarding())) {
449            this.touchHelper = new ItemTouchHelper(this.callback);
450            this.touchHelper.attachToRecyclerView(this.binding.list);
451        }
452    }
453
454    @Override
455    public void onSaveInstanceState(Bundle bundle) {
456        super.onSaveInstanceState(bundle);
457        ScrollState scrollState = getScrollState();
458        if (scrollState != null) {
459            bundle.putParcelable(STATE_SCROLL_POSITION, scrollState);
460        }
461    }
462
463    private ScrollState getScrollState() {
464        if (this.binding == null) {
465            return null;
466        }
467        if (this.binding.list.getLayoutManager()
468                instanceof LinearLayoutManager linearLayoutManager) {
469            final int position = linearLayoutManager.findFirstVisibleItemPosition();
470            final View view = this.binding.list.getChildAt(0);
471            if (view != null) {
472                return new ScrollState(position, view.getTop());
473            } else {
474                return new ScrollState(position, 0);
475            }
476        }
477        return null;
478    }
479
480    @Override
481    public void onStart() {
482        super.onStart();
483        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.onStart()");
484        if (activity.xmppConnectionService != null) {
485            refresh();
486        }
487    }
488
489    @Override
490    public void onResume() {
491        super.onResume();
492        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.onResume()");
493    }
494
495    @Override
496    public boolean onOptionsItemSelected(final MenuItem item) {
497        if (MenuDoubleTabUtil.shouldIgnoreTap()) {
498            return false;
499        }
500        switch (item.getItemId()) {
501            case R.id.action_search:
502                startActivity(new Intent(getActivity(), SearchActivity.class));
503                return true;
504            case R.id.action_easy_invite:
505                selectAccountToStartEasyInvite();
506                return true;
507        }
508        return super.onOptionsItemSelected(item);
509    }
510
511    private void selectAccountToStartEasyInvite() {
512        final List<Account> accounts =
513                EasyOnboardingInvite.getSupportingAccounts(activity.xmppConnectionService);
514        if (accounts.isEmpty()) {
515            // This can technically happen if opening the menu item races with accounts reconnecting
516            // or something
517            Toast.makeText(
518                            getActivity(),
519                            R.string.no_active_accounts_support_this,
520                            Toast.LENGTH_LONG)
521                    .show();
522        } else if (accounts.size() == 1) {
523            openEasyInviteScreen(accounts.get(0));
524        } else {
525            final AtomicReference<Account> selectedAccount = new AtomicReference<>(accounts.get(0));
526            final MaterialAlertDialogBuilder alertDialogBuilder =
527                    new MaterialAlertDialogBuilder(activity);
528            alertDialogBuilder.setTitle(R.string.choose_account);
529            final String[] asStrings =
530                    Collections2.transform(accounts, a -> a.getJid().asBareJid().toString())
531                            .toArray(new String[0]);
532            alertDialogBuilder.setSingleChoiceItems(
533                    asStrings, 0, (dialog, which) -> selectedAccount.set(accounts.get(which)));
534            alertDialogBuilder.setNegativeButton(R.string.cancel, null);
535            alertDialogBuilder.setPositiveButton(
536                    R.string.ok, (dialog, which) -> openEasyInviteScreen(selectedAccount.get()));
537            alertDialogBuilder.create().show();
538        }
539    }
540
541    private void openEasyInviteScreen(final Account account) {
542        EasyOnboardingInviteActivity.launch(account, activity);
543    }
544
545    @Override
546    protected void refresh() {
547        if (binding == null || this.activity == null) {
548            Log.d(Config.LOGTAG,"ConversationsOverviewFragment.refresh() skipped updated because view binding or activity was null");
549            return;
550        }
551        this.activity.populateWithOrderedConversations(this.conversations);
552        Conversation removed = this.swipedConversation.peek();
553        if (removed != null) {
554            if (removed.isRead(activity == null ? null : activity.xmppConnectionService)) {
555                this.conversations.remove(removed);
556            } else {
557                pendingActionHelper.execute();
558            }
559        }
560        this.conversationsAdapter.notifyDataSetChanged();
561        final var scrollState = pendingScrollState.pop();
562        if (scrollState != null) {
563            setScrollPosition(scrollState);
564        }
565
566        if (activity.xmppConnectionService != null && activity.xmppConnectionService.isOnboarding()) {
567            binding.fab.setVisibility(View.GONE);
568
569            if (this.conversations.size() == 1) {
570                if (activity instanceof OnConversationSelected) {
571                    ((OnConversationSelected) activity).onConversationSelected(this.conversations.get(0));
572                } else {
573                    Log.w(ConversationsOverviewFragment.class.getCanonicalName(), "Activity does not implement OnConversationSelected");
574                }
575            }
576        } else {
577            binding.fab.setVisibility(View.VISIBLE);
578        }
579        setupSwipe();
580
581        if (activity.xmppConnectionService == null || binding == null || binding.overviewSnackbar == null) return;
582        binding.overviewSnackbar.setVisibility(View.GONE);
583        for (final var account : activity.xmppConnectionService.getAccounts()) {
584            if (activity.getPreferences().getBoolean("no_mam_pref_warn:" + account.getUuid(), false)) continue;
585            if (account.mamPrefs() != null && !"always".equals(account.mamPrefs().getAttribute("default"))) {
586                binding.overviewSnackbar.setVisibility(View.VISIBLE);
587                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.");
588                binding.overviewSnackbarAction.setOnClickListener((v) -> {
589                    final var prefs = account.mamPrefs();
590                    prefs.setAttribute("default", "always");
591                    activity.xmppConnectionService.pushMamPreferences(account, prefs);
592                    refresh();
593                });
594
595                binding.overviewSnackbarAction.setOnLongClickListener((v) -> {
596                    PopupMenu popupMenu = new PopupMenu(getActivity(), v);
597                    popupMenu.inflate(R.menu.mam_pref_fix);
598                    popupMenu.setOnMenuItemClickListener(menuItem -> {
599                            switch (menuItem.getItemId()) {
600                            case R.id.ignore:
601                                final var editor = activity.getPreferences().edit();
602                                editor.putBoolean("no_mam_pref_warn:" + account.getUuid(), true).apply();
603                                editor.apply();
604                                refresh();
605                                return true;
606                            }
607                            return true;
608                    });
609                    popupMenu.show();
610                    return true;
611                });
612                break;
613            }
614        }
615    }
616
617    private void setScrollPosition(@NonNull final ScrollState scrollPosition) {
618        if (binding.list.getLayoutManager() instanceof LinearLayoutManager linearLayoutManager) {
619            linearLayoutManager.scrollToPositionWithOffset(
620                    scrollPosition.position, scrollPosition.offset);
621            if (scrollPosition.position > 0) {
622                binding.fab.shrink();
623            } else {
624                binding.fab.extend();
625            }
626            binding.fab.clearAnimation();
627        }
628    }
629}