Cleanup NotificationFragment to make future conversion to Kotlin easier (#2993)

* Convert NotificationsFragment to use view binding

* Use requireContext() in places a context is required

Removes a nullness warning.

* Simplify code by using .sublist() and .contains()

Removes a lint warning.

* Add @NonNull annotations to onViewTag and onViewAccount

* Use consistent comment styles
This commit is contained in:
Nik Clayton 2022-12-05 14:51:45 +01:00 committed by GitHub
parent 11de43f470
commit 965d51100c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 85 additions and 95 deletions

View File

@ -30,10 +30,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.ProgressBar;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -65,6 +63,7 @@ import com.keylesspalace.tusky.appstore.FavoriteEvent;
import com.keylesspalace.tusky.appstore.PinEvent; import com.keylesspalace.tusky.appstore.PinEvent;
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent; import com.keylesspalace.tusky.appstore.PreferenceChangedEvent;
import com.keylesspalace.tusky.appstore.ReblogEvent; import com.keylesspalace.tusky.appstore.ReblogEvent;
import com.keylesspalace.tusky.databinding.FragmentTimelineNotificationsBinding;
import com.keylesspalace.tusky.db.AccountEntity; import com.keylesspalace.tusky.db.AccountEntity;
import com.keylesspalace.tusky.db.AccountManager; import com.keylesspalace.tusky.db.AccountManager;
import com.keylesspalace.tusky.di.Injectable; import com.keylesspalace.tusky.di.Injectable;
@ -87,7 +86,6 @@ import com.keylesspalace.tusky.util.NotificationTypeConverterKt;
import com.keylesspalace.tusky.util.PairedList; import com.keylesspalace.tusky.util.PairedList;
import com.keylesspalace.tusky.util.StatusDisplayOptions; import com.keylesspalace.tusky.util.StatusDisplayOptions;
import com.keylesspalace.tusky.util.ViewDataUtils; import com.keylesspalace.tusky.util.ViewDataUtils;
import com.keylesspalace.tusky.view.BackgroundMessageView;
import com.keylesspalace.tusky.view.EndlessOnScrollListener; import com.keylesspalace.tusky.view.EndlessOnScrollListener;
import com.keylesspalace.tusky.viewdata.AttachmentViewData; import com.keylesspalace.tusky.viewdata.AttachmentViewData;
import com.keylesspalace.tusky.viewdata.NotificationViewData; import com.keylesspalace.tusky.viewdata.NotificationViewData;
@ -158,16 +156,11 @@ public class NotificationsFragment extends SFragment implements
@Inject @Inject
EventHub eventHub; EventHub eventHub;
private SwipeRefreshLayout swipeRefreshLayout; private FragmentTimelineNotificationsBinding binding;
private RecyclerView recyclerView;
private ProgressBar progressBar;
private BackgroundMessageView statusView;
private AppBarLayout appBarOptions;
private LinearLayoutManager layoutManager; private LinearLayoutManager layoutManager;
private EndlessOnScrollListener scrollListener; private EndlessOnScrollListener scrollListener;
private NotificationsAdapter adapter; private NotificationsAdapter adapter;
private Button buttonFilter;
private boolean hideFab; private boolean hideFab;
private boolean topLoading; private boolean topLoading;
private boolean bottomLoading; private boolean bottomLoading;
@ -211,10 +204,10 @@ public class NotificationsFragment extends SFragment implements
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_timeline_notifications, container, false); binding = FragmentTimelineNotificationsBinding.inflate(inflater, container, false);
@NonNull Context context = inflater.getContext(); // from inflater to silence warning @NonNull Context context = inflater.getContext(); // from inflater to silence warning
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
boolean showNotificationsFilterSetting = preferences.getBoolean("showNotificationsFilter", true); boolean showNotificationsFilterSetting = preferences.getBoolean("showNotificationsFilter", true);
// Clear notifications on filter visibility change to force refresh // Clear notifications on filter visibility change to force refresh
@ -223,23 +216,17 @@ public class NotificationsFragment extends SFragment implements
showNotificationsFilter = showNotificationsFilterSetting; showNotificationsFilter = showNotificationsFilterSetting;
// Setup the SwipeRefreshLayout. // Setup the SwipeRefreshLayout.
swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout); binding.swipeRefreshLayout.setOnRefreshListener(this);
recyclerView = rootView.findViewById(R.id.recyclerView); binding.swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
progressBar = rootView.findViewById(R.id.progressBar);
statusView = rootView.findViewById(R.id.statusView);
appBarOptions = rootView.findViewById(R.id.appBarOptions);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
loadNotificationsFilter(); loadNotificationsFilter();
// Setup the RecyclerView. // Setup the RecyclerView.
recyclerView.setHasFixedSize(true); binding.recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(context); layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager); binding.recyclerView.setLayoutManager(layoutManager);
recyclerView.setAccessibilityDelegateCompat( binding.recyclerView.setAccessibilityDelegateCompat(
new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> { new ListStatusAccessibilityDelegate(binding.recyclerView, this, (pos) -> {
NotificationViewData notification = notifications.getPairedItemOrNull(pos); NotificationViewData notification = notifications.getPairedItemOrNull(pos);
// We support replies only for now // We support replies only for now
if (notification instanceof NotificationViewData.Concrete) { if (notification instanceof NotificationViewData.Concrete) {
@ -249,7 +236,7 @@ public class NotificationsFragment extends SFragment implements
} }
})); }));
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); binding.recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
StatusDisplayOptions statusDisplayOptions = new StatusDisplayOptions( StatusDisplayOptions statusDisplayOptions = new StatusDisplayOptions(
preferences.getBoolean("animateGifAvatars", false), preferences.getBoolean("animateGifAvatars", false),
@ -268,7 +255,7 @@ public class NotificationsFragment extends SFragment implements
dataSource, statusDisplayOptions, this, this, this); dataSource, statusDisplayOptions, this, this, this);
alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia(); alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler(); alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler();
recyclerView.setAdapter(adapter); binding.recyclerView.setAdapter(adapter);
topLoading = false; topLoading = false;
bottomLoading = false; bottomLoading = false;
@ -276,43 +263,47 @@ public class NotificationsFragment extends SFragment implements
updateAdapter(); updateAdapter();
Button buttonClear = rootView.findViewById(R.id.buttonClear); binding.buttonClear.setOnClickListener(v -> confirmClearNotifications());
buttonClear.setOnClickListener(v -> confirmClearNotifications()); binding.buttonFilter.setOnClickListener(v -> showFilterMenu());
buttonFilter = rootView.findViewById(R.id.buttonFilter);
buttonFilter.setOnClickListener(v -> showFilterMenu());
if (notifications.isEmpty()) { if (notifications.isEmpty()) {
swipeRefreshLayout.setEnabled(false); binding.swipeRefreshLayout.setEnabled(false);
sendFetchNotificationsRequest(null, null, FetchEnd.BOTTOM, -1); sendFetchNotificationsRequest(null, null, FetchEnd.BOTTOM, -1);
} else { } else {
progressBar.setVisibility(View.GONE); binding.progressBar.setVisibility(View.GONE);
} }
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false); ((SimpleItemAnimator) binding.recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
updateFilterVisibility(); updateFilterVisibility();
return rootView; return binding.getRoot();
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
} }
private void updateFilterVisibility() { private void updateFilterVisibility() {
CoordinatorLayout.LayoutParams params = CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) swipeRefreshLayout.getLayoutParams(); (CoordinatorLayout.LayoutParams) binding.swipeRefreshLayout.getLayoutParams();
if (showNotificationsFilter && !showingError) { if (showNotificationsFilter && !showingError) {
appBarOptions.setExpanded(true, false); binding.appBarOptions.setExpanded(true, false);
appBarOptions.setVisibility(View.VISIBLE); binding.appBarOptions.setVisibility(View.VISIBLE);
// Set content behaviour to hide filter on scroll // Set content behaviour to hide filter on scroll
params.setBehavior(new AppBarLayout.ScrollingViewBehavior()); params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
} else { } else {
appBarOptions.setExpanded(false, false); binding.appBarOptions.setExpanded(false, false);
appBarOptions.setVisibility(View.GONE); binding.appBarOptions.setVisibility(View.GONE);
// Clear behaviour to hide app bar // Clear behaviour to hide app bar
params.setBehavior(null); params.setBehavior(null);
} }
} }
private void confirmClearNotifications() { private void confirmClearNotifications() {
new AlertDialog.Builder(getContext()) new AlertDialog.Builder(requireContext())
.setMessage(R.string.notification_clear_text) .setMessage(R.string.notification_clear_text)
.setPositiveButton(android.R.string.ok, (DialogInterface dia, int which) -> clearNotifications()) .setPositiveButton(android.R.string.ok, (DialogInterface dia, int which) -> clearNotifications())
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
@ -325,10 +316,10 @@ public class NotificationsFragment extends SFragment implements
Activity activity = getActivity(); Activity activity = getActivity();
if (activity == null) throw new AssertionError("Activity is null"); if (activity == null) throw new AssertionError("Activity is null");
/* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't // This is delayed until onActivityCreated solely because MainActivity.composeButton
* guaranteed to be set until then. // isn't guaranteed to be set until then.
* Use a modified scroll listener that both loads more notificationsEnabled as it goes, and hides // Use a modified scroll listener that both loads more notificationsEnabled as it
* the compose button on down-scroll. */ // goes, and hides the compose button on down-scroll.
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
hideFab = preferences.getBoolean("fabHide", false); hideFab = preferences.getBoolean("fabHide", false);
scrollListener = new EndlessOnScrollListener(layoutManager) { scrollListener = new EndlessOnScrollListener(layoutManager) {
@ -342,9 +333,9 @@ public class NotificationsFragment extends SFragment implements
if (composeButton != null) { if (composeButton != null) {
if (hideFab) { if (hideFab) {
if (dy > 0 && composeButton.isShown()) { if (dy > 0 && composeButton.isShown()) {
composeButton.hide(); // hides the button if we're scrolling down composeButton.hide(); // Hides the button if we're scrolling down
} else if (dy < 0 && !composeButton.isShown()) { } else if (dy < 0 && !composeButton.isShown()) {
composeButton.show(); // shows it if we are scrolling up composeButton.show(); // Shows it if we are scrolling up
} }
} else if (!composeButton.isShown()) { } else if (!composeButton.isShown()) {
composeButton.show(); composeButton.show();
@ -358,7 +349,7 @@ public class NotificationsFragment extends SFragment implements
} }
}; };
recyclerView.addOnScrollListener(scrollListener); binding.recyclerView.addOnScrollListener(scrollListener);
eventHub.getEvents() eventHub.getEvents()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -382,7 +373,7 @@ public class NotificationsFragment extends SFragment implements
@Override @Override
public void onRefresh() { public void onRefresh() {
this.statusView.setVisibility(View.GONE); binding.statusView.setVisibility(View.GONE);
this.showingError = false; this.showingError = false;
Either<Placeholder, Notification> first = CollectionsKt.firstOrNull(this.notifications); Either<Placeholder, Notification> first = CollectionsKt.firstOrNull(this.notifications);
String topId; String topId;
@ -518,7 +509,7 @@ public class NotificationsFragment extends SFragment implements
@Override @Override
public void onLoadMore(int position) { public void onLoadMore(int position) {
//check bounds before accessing list, // Check bounds before accessing list,
if (notifications.size() >= position && position > 0) { if (notifications.size() >= position && position > 0) {
Notification previous = notifications.get(position - 1).asRightOrNull(); Notification previous = notifications.get(position - 1).asRightOrNull();
Notification next = notifications.get(position + 1).asRightOrNull(); Notification next = notifications.get(position + 1).asRightOrNull();
@ -540,7 +531,6 @@ public class NotificationsFragment extends SFragment implements
@Override @Override
public void onContentCollapsedChange(boolean isCollapsed, int position) { public void onContentCollapsedChange(boolean isCollapsed, int position) {
updateViewDataAt(position, (vd) -> vd.copyWithCollapsed(isCollapsed)); updateViewDataAt(position, (vd) -> vd.copyWithCollapsed(isCollapsed));
;
} }
private void updateStatus(String statusId, Function<Status, Status> mapper) { private void updateStatus(String statusId, Function<Status, Status> mapper) {
@ -616,12 +606,12 @@ public class NotificationsFragment extends SFragment implements
private void clearNotifications() { private void clearNotifications() {
// Cancel all ongoing requests // Cancel all ongoing requests
swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
resetNotificationsLoad(); resetNotificationsLoad();
// Show friend elephant // Show friend elephant
this.statusView.setVisibility(View.VISIBLE); binding.statusView.setVisibility(View.VISIBLE);
this.statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null); binding.statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null);
updateFilterVisibility(); updateFilterVisibility();
// Update adapter // Update adapter
@ -633,7 +623,7 @@ public class NotificationsFragment extends SFragment implements
.to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))) .to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
.subscribe( .subscribe(
response -> { response -> {
// nothing to do // Nothing to do
}, },
throwable -> { throwable -> {
// Reload notifications on failure // Reload notifications on failure
@ -688,7 +678,7 @@ public class NotificationsFragment extends SFragment implements
window.setFocusable(true); window.setFocusable(true);
window.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); window.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
window.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); window.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
window.showAsDropDown(buttonFilter); window.showAsDropDown(binding.buttonFilter);
} }
@ -756,12 +746,12 @@ public class NotificationsFragment extends SFragment implements
} }
@Override @Override
public void onViewTag(String tag) { public void onViewTag(@NonNull String tag) {
super.viewTag(tag); super.viewTag(tag);
} }
@Override @Override
public void onViewAccount(String id) { public void onViewAccount(@NonNull String id) {
super.viewAccount(id); super.viewAccount(id);
} }
@ -805,13 +795,13 @@ public class NotificationsFragment extends SFragment implements
@Override @Override
public void onViewReport(String reportId) { public void onViewReport(String reportId) {
LinkHelper.openLink(getContext(), String.format("https://%s/admin/reports/%s", accountManager.getActiveAccount().getDomain(), reportId)); LinkHelper.openLink(requireContext(), String.format("https://%s/admin/reports/%s", accountManager.getActiveAccount().getDomain(), reportId));
} }
private void onPreferenceChanged(String key) { private void onPreferenceChanged(String key) {
switch (key) { switch (key) {
case "fabHide": { case "fabHide": {
hideFab = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("fabHide", false); hideFab = PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("fabHide", false);
break; break;
} }
case "mediaPreviewEnabled": { case "mediaPreviewEnabled": {
@ -824,7 +814,7 @@ public class NotificationsFragment extends SFragment implements
} }
case "showNotificationsFilter": { case "showNotificationsFilter": {
if (isAdded()) { if (isAdded()) {
showNotificationsFilter = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("showNotificationsFilter", true); showNotificationsFilter = PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("showNotificationsFilter", true);
updateFilterVisibility(); updateFilterVisibility();
fullyRefreshWithProgressBar(true); fullyRefreshWithProgressBar(true);
} }
@ -840,7 +830,7 @@ public class NotificationsFragment extends SFragment implements
} }
private void removeAllByAccountId(String accountId) { private void removeAllByAccountId(String accountId) {
// using iterator to safely remove items while iterating // Using iterator to safely remove items while iterating
Iterator<Either<Placeholder, Notification>> iterator = notifications.iterator(); Iterator<Either<Placeholder, Notification>> iterator = notifications.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Either<Placeholder, Notification> notification = iterator.next(); Either<Placeholder, Notification> notification = iterator.next();
@ -854,7 +844,7 @@ public class NotificationsFragment extends SFragment implements
private void onLoadMore() { private void onLoadMore() {
if (bottomId == null) { if (bottomId == null) {
// already loaded everything // Already loaded everything
return; return;
} }
@ -884,7 +874,7 @@ public class NotificationsFragment extends SFragment implements
private void jumpToTop() { private void jumpToTop() {
if (isAdded()) { if (isAdded()) {
appBarOptions.setExpanded(true, false); binding.appBarOptions.setExpanded(true, false);
layoutManager.scrollToPosition(0); layoutManager.scrollToPosition(0);
scrollListener.reset(); scrollListener.reset();
} }
@ -892,8 +882,8 @@ public class NotificationsFragment extends SFragment implements
private void sendFetchNotificationsRequest(String fromId, String uptoId, private void sendFetchNotificationsRequest(String fromId, String uptoId,
final FetchEnd fetchEnd, final int pos) { final FetchEnd fetchEnd, final int pos) {
/* If there is a fetch already ongoing, record however many fetches are requested and // If there is a fetch already ongoing, record however many fetches are requested and
* fulfill them after it's complete. */ // fulfill them after it's complete.
if (fetchEnd == FetchEnd.TOP && topLoading) { if (fetchEnd == FetchEnd.TOP && topLoading) {
return; return;
} }
@ -969,18 +959,18 @@ public class NotificationsFragment extends SFragment implements
} }
if (notifications.size() == 0 && adapter.getItemCount() == 0) { if (notifications.size() == 0 && adapter.getItemCount() == 0) {
this.statusView.setVisibility(View.VISIBLE); binding.statusView.setVisibility(View.VISIBLE);
this.statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null); binding.statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null);
} }
updateFilterVisibility(); updateFilterVisibility();
swipeRefreshLayout.setEnabled(true); binding.swipeRefreshLayout.setEnabled(true);
swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
progressBar.setVisibility(View.GONE); binding.progressBar.setVisibility(View.GONE);
} }
private void onFetchNotificationsFailure(Throwable throwable, FetchEnd fetchEnd, int position) { private void onFetchNotificationsFailure(Throwable throwable, FetchEnd fetchEnd, int position) {
swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
if (fetchEnd == FetchEnd.MIDDLE && !notifications.get(position).isRight()) { if (fetchEnd == FetchEnd.MIDDLE && !notifications.get(position).isRight()) {
Placeholder placeholder = notifications.get(position).asLeft(); Placeholder placeholder = notifications.get(position).asLeft();
NotificationViewData placeholderVD = NotificationViewData placeholderVD =
@ -988,18 +978,18 @@ public class NotificationsFragment extends SFragment implements
notifications.setPairedItem(position, placeholderVD); notifications.setPairedItem(position, placeholderVD);
updateAdapter(); updateAdapter();
} else if (this.notifications.isEmpty()) { } else if (this.notifications.isEmpty()) {
this.statusView.setVisibility(View.VISIBLE); binding.statusView.setVisibility(View.VISIBLE);
swipeRefreshLayout.setEnabled(false); binding.swipeRefreshLayout.setEnabled(false);
this.showingError = true; this.showingError = true;
if (throwable instanceof IOException) { if (throwable instanceof IOException) {
this.statusView.setup(R.drawable.elephant_offline, R.string.error_network, __ -> { binding.statusView.setup(R.drawable.elephant_offline, R.string.error_network, __ -> {
this.progressBar.setVisibility(View.VISIBLE); binding.progressBar.setVisibility(View.VISIBLE);
this.onRefresh(); this.onRefresh();
return Unit.INSTANCE; return Unit.INSTANCE;
}); });
} else { } else {
this.statusView.setup(R.drawable.elephant_error, R.string.error_generic, __ -> { binding.statusView.setup(R.drawable.elephant_error, R.string.error_generic, __ -> {
this.progressBar.setVisibility(View.VISIBLE); binding.progressBar.setVisibility(View.VISIBLE);
this.onRefresh(); this.onRefresh();
return Unit.INSTANCE; return Unit.INSTANCE;
}); });
@ -1015,7 +1005,7 @@ public class NotificationsFragment extends SFragment implements
bottomLoading = false; bottomLoading = false;
} }
progressBar.setVisibility(View.GONE); binding.progressBar.setVisibility(View.GONE);
} }
private void saveNewestNotificationId(List<Notification> notifications) { private void saveNewestNotificationId(List<Notification> notifications) {
@ -1052,8 +1042,8 @@ public class NotificationsFragment extends SFragment implements
notifications.addAll(liftedNew); notifications.addAll(liftedNew);
} else { } else {
int index = notifications.indexOf(liftedNew.get(newNotifications.size() - 1)); int index = notifications.indexOf(liftedNew.get(newNotifications.size() - 1));
for (int i = 0; i < index; i++) { if (index > 0) {
notifications.remove(0); notifications.subList(0, index).clear();
} }
int newIndex = liftedNew.indexOf(notifications.get(0)); int newIndex = liftedNew.indexOf(notifications.get(0));
@ -1077,7 +1067,7 @@ public class NotificationsFragment extends SFragment implements
int end = notifications.size(); int end = notifications.size();
List<Either<Placeholder, Notification>> liftedNew = liftNotificationList(newNotifications); List<Either<Placeholder, Notification>> liftedNew = liftNotificationList(newNotifications);
Either<Placeholder, Notification> last = notifications.get(end - 1); Either<Placeholder, Notification> last = notifications.get(end - 1);
if (last != null && liftedNew.indexOf(last) == -1) { if (last != null && !liftedNew.contains(last)) {
notifications.addAll(liftedNew); notifications.addAll(liftedNew);
updateAdapter(); updateAdapter();
} }
@ -1115,8 +1105,8 @@ public class NotificationsFragment extends SFragment implements
private void fullyRefreshWithProgressBar(boolean isShow) { private void fullyRefreshWithProgressBar(boolean isShow) {
resetNotificationsLoad(); resetNotificationsLoad();
if (isShow) { if (isShow) {
progressBar.setVisibility(View.VISIBLE); binding.progressBar.setVisibility(View.VISIBLE);
statusView.setVisibility(View.GONE); binding.statusView.setVisibility(View.GONE);
} }
updateAdapter(); updateAdapter();
sendFetchNotificationsRequest(null, null, FetchEnd.TOP, -1); sendFetchNotificationsRequest(null, null, FetchEnd.TOP, -1);
@ -1155,7 +1145,7 @@ public class NotificationsFragment extends SFragment implements
// scroll up when new items at the top are loaded while being at the start // scroll up when new items at the top are loaded while being at the start
// https://github.com/tuskyapp/Tusky/pull/1905#issuecomment-677819724 // https://github.com/tuskyapp/Tusky/pull/1905#issuecomment-677819724
if (position == 0 && context != null && adapter.getItemCount() != count) { if (position == 0 && context != null && adapter.getItemCount() != count) {
recyclerView.scrollBy(0, Utils.dpToPx(context, -30)); binding.recyclerView.scrollBy(0, Utils.dpToPx(context, -30));
} }
} }
} }
@ -1236,7 +1226,7 @@ public class NotificationsFragment extends SFragment implements
* Auto dispose observable on pause * Auto dispose observable on pause
*/ */
private void startUpdateTimestamp() { private void startUpdateTimestamp() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
boolean useAbsoluteTime = preferences.getBoolean("absoluteTimeView", false); boolean useAbsoluteTime = preferences.getBoolean("absoluteTimeView", false);
if (!useAbsoluteTime) { if (!useAbsoluteTime) {
Observable.interval(0, 1, TimeUnit.MINUTES) Observable.interval(0, 1, TimeUnit.MINUTES)