Adds correct footer behaviour to account lists and unifies it with how timelines use them.

This commit is contained in:
Vavassor 2017-06-30 18:30:25 -04:00
commit 275cd51a6d
15 changed files with 164 additions and 124 deletions

View file

@ -36,6 +36,7 @@ import com.keylesspalace.tusky.adapter.AccountAdapter;
import com.keylesspalace.tusky.adapter.BlocksAdapter;
import com.keylesspalace.tusky.adapter.FollowAdapter;
import com.keylesspalace.tusky.adapter.FollowRequestsAdapter;
import com.keylesspalace.tusky.adapter.FooterViewHolder;
import com.keylesspalace.tusky.adapter.MutesAdapter;
import com.keylesspalace.tusky.BaseActivity;
import com.keylesspalace.tusky.entity.Account;
@ -358,7 +359,12 @@ public class AccountListFragment extends BaseFragment implements AccountActionLi
}
private void onRespondToFollowRequestFailure(boolean accept, String accountId) {
String verb = (accept) ? "accept" : "reject";
String verb;
if (accept) {
verb = "accept";
} else {
verb = "reject";
}
String message = String.format("Failed to %s account id %s.", verb, accountId);
Log.e(TAG, message);
}
@ -399,6 +405,11 @@ public class AccountListFragment extends BaseFragment implements AccountActionLi
bottomFetches++;
return;
}
if (fromId != null || adapter.getItemCount() <= 1) {
setFooterState(FooterViewHolder.State.LOADING);
}
Callback<List<Account>> cb = new Callback<List<Account>>() {
@Override
public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
@ -456,6 +467,11 @@ public class AccountListFragment extends BaseFragment implements AccountActionLi
}
}
fulfillAnyQueuedFetches(fetchEnd);
if (accounts.size() == 0 && adapter.getItemCount() == 1) {
setFooterState(FooterViewHolder.State.EMPTY);
} else {
setFooterState(FooterViewHolder.State.END);
}
}
private void onFetchAccountsFailure(Exception exception, FetchEnd fetchEnd) {
@ -463,6 +479,20 @@ public class AccountListFragment extends BaseFragment implements AccountActionLi
fulfillAnyQueuedFetches(fetchEnd);
}
/* This needs to be called from the endless scroll listener, which does not allow notifying the
* adapter during the callback. So, this is the workaround. */
private void setFooterState(FooterViewHolder.State state) {
// Set the adapter to set its state when it's bound, if the current Footer is offscreen.
adapter.setFooterState(state);
// Check if it's onscreen, and update it directly if it is.
RecyclerView.ViewHolder viewHolder =
recyclerView.findViewHolderForAdapterPosition(adapter.getItemCount() - 1);
if (viewHolder != null) {
FooterViewHolder holder = (FooterViewHolder) viewHolder;
holder.setState(state);
}
}
private void onRefresh() {
fetchAccounts(null, adapter.getTopId(), FetchEnd.TOP);
}
@ -478,7 +508,6 @@ public class AccountListFragment extends BaseFragment implements AccountActionLi
bottomLoading = false;
if (bottomFetches > 0) {
bottomFetches--;
Log.d(TAG, "extra fetchos " + bottomFetches);
onLoadMore(recyclerView);
}
break;

View file

@ -34,6 +34,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.keylesspalace.tusky.MainActivity;
import com.keylesspalace.tusky.adapter.FooterViewHolder;
import com.keylesspalace.tusky.adapter.NotificationsAdapter;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Notification;
@ -274,7 +275,7 @@ public class NotificationsFragment extends SFragment implements
}
if (fromId != null || adapter.getItemCount() <= 1) {
adapter.setFooterState(NotificationsAdapter.FooterState.LOADING);
setFooterState(FooterViewHolder.State.LOADING);
}
Call<List<Notification>> call = mastodonApi.notifications(fromId, uptoId, null);
@ -341,9 +342,9 @@ public class NotificationsFragment extends SFragment implements
}
fulfillAnyQueuedFetches(fetchEnd);
if (notifications.size() == 0 && adapter.getItemCount() == 1) {
adapter.setFooterState(NotificationsAdapter.FooterState.EMPTY);
setFooterState(FooterViewHolder.State.EMPTY);
} else {
adapter.setFooterState(NotificationsAdapter.FooterState.END);
setFooterState(FooterViewHolder.State.END);
}
swipeRefreshLayout.setRefreshing(false);
}
@ -354,6 +355,20 @@ public class NotificationsFragment extends SFragment implements
fulfillAnyQueuedFetches(fetchEnd);
}
/* This needs to be called from the endless scroll listener, which does not allow notifying the
* adapter during the callback. So, this is the workaround. */
private void setFooterState(FooterViewHolder.State state) {
// Set the adapter to set its state when it's bound, if the current Footer is offscreen.
adapter.setFooterState(state);
// Check if it's onscreen, and update it directly if it is.
RecyclerView.ViewHolder viewHolder =
recyclerView.findViewHolderForAdapterPosition(adapter.getItemCount() - 1);
if (viewHolder != null) {
FooterViewHolder holder = (FooterViewHolder) viewHolder;
holder.setState(state);
}
}
private void fulfillAnyQueuedFetches(FetchEnd fetchEnd) {
switch (fetchEnd) {
case BOTTOM: {

View file

@ -35,6 +35,7 @@ import android.view.ViewGroup;
import com.keylesspalace.tusky.MainActivity;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.adapter.FooterViewHolder;
import com.keylesspalace.tusky.adapter.TimelineAdapter;
import com.keylesspalace.tusky.entity.Status;
import com.keylesspalace.tusky.interfaces.StatusActionListener;
@ -359,7 +360,7 @@ public class TimelineFragment extends SFragment implements
}
if (fromId != null || adapter.getItemCount() <= 1) {
adapter.setFooterState(TimelineAdapter.FooterState.LOADING);
setFooterState(FooterViewHolder.State.LOADING);
}
Callback<List<Status>> callback = new Callback<List<Status>>() {
@ -422,9 +423,9 @@ public class TimelineFragment extends SFragment implements
}
fulfillAnyQueuedFetches(fetchEnd);
if (statuses.size() == 0 && adapter.getItemCount() == 1) {
adapter.setFooterState(TimelineAdapter.FooterState.EMPTY);
setFooterState(FooterViewHolder.State.EMPTY);
} else {
adapter.setFooterState(TimelineAdapter.FooterState.END);
setFooterState(FooterViewHolder.State.END);
}
swipeRefreshLayout.setRefreshing(false);
}
@ -435,6 +436,20 @@ public class TimelineFragment extends SFragment implements
fulfillAnyQueuedFetches(fetchEnd);
}
/* This needs to be called from the endless scroll listener, which does not allow notifying the
* adapter during the callback. So, this is the workaround. */
private void setFooterState(FooterViewHolder.State state) {
// Set the adapter to set its state when it's bound, if the current Footer is offscreen.
adapter.setFooterState(state);
// Check if it's onscreen, and update it directly if it is.
RecyclerView.ViewHolder viewHolder =
recyclerView.findViewHolderForAdapterPosition(adapter.getItemCount() - 1);
if (viewHolder != null) {
FooterViewHolder holder = (FooterViewHolder) viewHolder;
holder.setState(state);
}
}
private void fulfillAnyQueuedFetches(FetchEnd fetchEnd) {
switch (fetchEnd) {
case BOTTOM: {