This commit is contained in:
nuclearfog 2020-08-13 10:04:07 +02:00
parent 394ad911fd
commit f1db94bb6b
No known key found for this signature in database
GPG Key ID: ED35E22099354A64
4 changed files with 26 additions and 9 deletions

View File

@ -71,11 +71,7 @@ public class TweetAdapter extends Adapter<ViewHolder> {
*/
@MainThread
public void insertAt(@NonNull List<Tweet> data, int index) {
if (loadingIndex != NO_INDEX) {
int oldIndex = loadingIndex;
loadingIndex = NO_INDEX;
notifyItemChanged(oldIndex);
}
disableLoading();
if (data.size() > MIN_COUNT) {
if (tweets.isEmpty() || tweets.get(index) != null) {
// Add placeholder
@ -138,6 +134,16 @@ public class TweetAdapter extends Adapter<ViewHolder> {
return tweets.isEmpty();
}
/**
* disable placeholder load animation
*/
public void disableLoading() {
if (loadingIndex != NO_INDEX) {
int oldIndex = loadingIndex;
loadingIndex = NO_INDEX;
notifyItemChanged(oldIndex);
}
}
@Override
public long getItemId(int index) {

View File

@ -77,10 +77,8 @@ public class UserAdapter extends Adapter<ViewHolder> {
// remove footer
users.remove(end);
notifyItemRemoved(end);
} else if (loadingIndex != NO_INDEX) {
int oldIndex = loadingIndex;
loadingIndex = NO_INDEX;
notifyItemChanged(oldIndex);
} else {
disableLoading();
}
users.addAll(end, data.getUsers());
notifyItemRangeInserted(end, data.getSize());
@ -88,6 +86,17 @@ public class UserAdapter extends Adapter<ViewHolder> {
nextCursor = data.getNext();
}
/**
* disable loading animation in footer
*/
public void disableLoading() {
if (loadingIndex != NO_INDEX) {
int oldIndex = loadingIndex;
loadingIndex = NO_INDEX;
notifyItemChanged(oldIndex);
}
}
@Override
public int getItemCount() {

View File

@ -195,6 +195,7 @@ public class TweetFragment extends Fragment implements OnRefreshListener, TweetC
if (getContext() != null) {
ErrorHandler.handleFailure(getContext(), error);
}
adapter.disableLoading();
}

View File

@ -160,6 +160,7 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
if (getContext() != null) {
ErrorHandler.handleFailure(getContext(), error);
}
adapter.disableLoading();
}