Search in sources :

Example 11 with NotificationViewData

use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by Vavassor.

the class NotificationsFragment method onFetchNotificationsFailure.

private void onFetchNotificationsFailure(Throwable throwable, FetchEnd fetchEnd, int position) {
    swipeRefreshLayout.setRefreshing(false);
    if (fetchEnd == FetchEnd.MIDDLE && !notifications.get(position).isRight()) {
        Placeholder placeholder = notifications.get(position).asLeft();
        NotificationViewData placeholderVD = new NotificationViewData.Placeholder(placeholder.id, false);
        notifications.setPairedItem(position, placeholderVD);
        updateAdapter();
    } else if (this.notifications.isEmpty()) {
        this.statusView.setVisibility(View.VISIBLE);
        swipeRefreshLayout.setEnabled(false);
        this.showingError = true;
        if (throwable instanceof IOException) {
            this.statusView.setup(R.drawable.elephant_offline, R.string.error_network, __ -> {
                this.progressBar.setVisibility(View.VISIBLE);
                this.onRefresh();
                return Unit.INSTANCE;
            });
        } else {
            this.statusView.setup(R.drawable.elephant_error, R.string.error_generic, __ -> {
                this.progressBar.setVisibility(View.VISIBLE);
                this.onRefresh();
                return Unit.INSTANCE;
            });
        }
        updateFilterVisibility();
    }
    Log.e(TAG, "Fetch failure: " + throwable.getMessage());
    if (fetchEnd == FetchEnd.TOP) {
        topLoading = false;
    }
    if (fetchEnd == FetchEnd.BOTTOM) {
        bottomLoading = false;
    }
    progressBar.setVisibility(View.GONE);
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) AsyncDifferConfig(androidx.recyclerview.widget.AsyncDifferConfig) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) Utils(at.connyduck.sparkbutton.helpers.Utils) AccountActionListener(com.keylesspalace.tusky.interfaces.AccountActionListener) NotificationTypeConverterKt(com.keylesspalace.tusky.util.NotificationTypeConverterKt) AppBarLayout(com.google.android.material.appbar.AppBarLayout) BackgroundMessageView(com.keylesspalace.tusky.view.BackgroundMessageView) Locale(java.util.Locale) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) Function(androidx.arch.core.util.Function) Log(android.util.Log) ViewDataUtils(com.keylesspalace.tusky.util.ViewDataUtils) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) ListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback) DiffUtil(androidx.recyclerview.widget.DiffUtil) PreferenceChangedEvent(com.keylesspalace.tusky.appstore.PreferenceChangedEvent) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) Set(java.util.Set) Function1(kotlin.jvm.functions.Function1) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) ReselectableFragment(com.keylesspalace.tusky.interfaces.ReselectableFragment) Objects(java.util.Objects) FavoriteEvent(com.keylesspalace.tusky.appstore.FavoriteEvent) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) List(java.util.List) Unit(kotlin.Unit) AutoDispose.autoDisposable(autodispose2.AutoDispose.autoDisposable) Nullable(androidx.annotation.Nullable) Pair(androidx.core.util.Pair) Disposable(io.reactivex.rxjava3.disposables.Disposable) CollectionsKt(kotlin.collections.CollectionsKt) AsyncListDiffer(androidx.recyclerview.widget.AsyncListDiffer) ListView(android.widget.ListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StringUtils.isLessThan(com.keylesspalace.tusky.util.StringUtils.isLessThan) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) BookmarkEvent(com.keylesspalace.tusky.appstore.BookmarkEvent) Notification(com.keylesspalace.tusky.entity.Notification) Single(io.reactivex.rxjava3.core.Single) AlertDialog(androidx.appcompat.app.AlertDialog) Status(com.keylesspalace.tusky.entity.Status) AndroidLifecycleScopeProvider.from(autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider.from) ReblogEvent(com.keylesspalace.tusky.appstore.ReblogEvent) Poll(com.keylesspalace.tusky.entity.Poll) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) PairedList(com.keylesspalace.tusky.util.PairedList) ArrayList(java.util.ArrayList) StatusBaseViewHolder(com.keylesspalace.tusky.adapter.StatusBaseViewHolder) PrefKeys(com.keylesspalace.tusky.settings.PrefKeys) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lifecycle(androidx.lifecycle.Lifecycle) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) Observable(io.reactivex.rxjava3.core.Observable) AttachmentViewData(com.keylesspalace.tusky.viewdata.AttachmentViewData) DialogInterface(android.content.DialogInterface) ListStatusAccessibilityDelegate(com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate) EventHub(com.keylesspalace.tusky.appstore.EventHub) BlockEvent(com.keylesspalace.tusky.appstore.BlockEvent) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) PopupWindow(android.widget.PopupWindow) HttpHeaderLink(com.keylesspalace.tusky.util.HttpHeaderLink) Either(com.keylesspalace.tusky.util.Either) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) ArrayAdapter(android.widget.ArrayAdapter) SparseBooleanArray(android.util.SparseBooleanArray) PinEvent(com.keylesspalace.tusky.appstore.PinEvent) SharedPreferences(android.content.SharedPreferences) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) PreferenceManager(androidx.preference.PreferenceManager) ListUtils(com.keylesspalace.tusky.util.ListUtils) AccountManager(com.keylesspalace.tusky.db.AccountManager) EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) Injectable(com.keylesspalace.tusky.di.Injectable) Activity(android.app.Activity) Collections(java.util.Collections) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) IOException(java.io.IOException)

Example 12 with NotificationViewData

use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by Vavassor.

the class NotificationsFragment method onLoadMore.

@Override
public void onLoadMore(int position) {
    // check bounds before accessing list,
    if (notifications.size() >= position && position > 0) {
        Notification previous = notifications.get(position - 1).asRightOrNull();
        Notification next = notifications.get(position + 1).asRightOrNull();
        if (previous == null || next == null) {
            Log.e(TAG, "Failed to load more, invalid placeholder position: " + position);
            return;
        }
        sendFetchNotificationsRequest(previous.getId(), next.getId(), FetchEnd.MIDDLE, position);
        Placeholder placeholder = notifications.get(position).asLeft();
        NotificationViewData notificationViewData = new NotificationViewData.Placeholder(placeholder.id, true);
        notifications.setPairedItem(position, notificationViewData);
        updateAdapter();
    } else {
        Log.d(TAG, "error loading more");
    }
}
Also used : NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) Notification(com.keylesspalace.tusky.entity.Notification)

Aggregations

NotificationViewData (com.keylesspalace.tusky.viewdata.NotificationViewData)12 Notification (com.keylesspalace.tusky.entity.Notification)7 StatusViewData (com.keylesspalace.tusky.viewdata.StatusViewData)6 Status (com.keylesspalace.tusky.entity.Status)3 Either (com.keylesspalace.tusky.util.Either)3 Activity (android.app.Activity)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 SparseBooleanArray (android.util.SparseBooleanArray)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ArrayAdapter (android.widget.ArrayAdapter)2 Button (android.widget.Button)2 ListView (android.widget.ListView)2 PopupWindow (android.widget.PopupWindow)2 ProgressBar (android.widget.ProgressBar)2