adapter bug fix, added cursor to twitterlist adapter
This commit is contained in:
parent
75adacf800
commit
a9e1018861
@ -6,6 +6,7 @@ import android.view.View.OnClickListener;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.MainThread;
|
import androidx.annotation.MainThread;
|
||||||
@ -16,16 +17,16 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
|||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
import org.nuclearfog.twidda.R;
|
import org.nuclearfog.twidda.R;
|
||||||
|
import org.nuclearfog.twidda.backend.holder.UserListList;
|
||||||
import org.nuclearfog.twidda.backend.items.TwitterList;
|
import org.nuclearfog.twidda.backend.items.TwitterList;
|
||||||
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||||
import org.nuclearfog.twidda.backend.utils.FontTool;
|
import org.nuclearfog.twidda.backend.utils.FontTool;
|
||||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
|
import static android.view.View.INVISIBLE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
import static org.nuclearfog.twidda.backend.utils.TimeString.getTimeString;
|
import static org.nuclearfog.twidda.backend.utils.TimeString.getTimeString;
|
||||||
@ -35,28 +36,48 @@ import static org.nuclearfog.twidda.backend.utils.TimeString.getTimeString;
|
|||||||
*
|
*
|
||||||
* @see org.nuclearfog.twidda.fragment.ListFragment
|
* @see org.nuclearfog.twidda.fragment.ListFragment
|
||||||
*/
|
*/
|
||||||
public class ListAdapter extends Adapter<ListAdapter.ListHolder> {
|
public class ListAdapter extends Adapter<ViewHolder> {
|
||||||
|
|
||||||
|
private static final int NO_LOADING = -1;
|
||||||
|
private static final int ITEM_FOOTER = 0;
|
||||||
|
private static final int ITEM_LIST = 1;
|
||||||
|
|
||||||
private final ListClickListener listener;
|
private final ListClickListener listener;
|
||||||
private final NumberFormat formatter;
|
private final NumberFormat formatter;
|
||||||
private final GlobalSettings settings;
|
private final GlobalSettings settings;
|
||||||
|
|
||||||
private final List<TwitterList> data;
|
private final UserListList data;
|
||||||
|
private int loadingIndex;
|
||||||
|
|
||||||
|
|
||||||
public ListAdapter(ListClickListener listener, GlobalSettings settings) {
|
public ListAdapter(ListClickListener listener, GlobalSettings settings) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
formatter = NumberFormat.getIntegerInstance();
|
formatter = NumberFormat.getIntegerInstance();
|
||||||
data = new ArrayList<>();
|
data = new UserListList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
public void setData(List<TwitterList> newData) {
|
public void setData(UserListList newData) {
|
||||||
data.clear();
|
if (data.isEmpty() || !newData.hasPrevious()) {
|
||||||
data.addAll(newData);
|
data.replace(newData);
|
||||||
notifyDataSetChanged();
|
if (data.hasNext()) {
|
||||||
|
// Add footer
|
||||||
|
data.add(null);
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
} else {
|
||||||
|
int end = data.size() - 1;
|
||||||
|
if (!data.hasNext()) {
|
||||||
|
// remove footer
|
||||||
|
data.remove(end);
|
||||||
|
notifyItemRemoved(end);
|
||||||
|
}
|
||||||
|
data.addListAt(newData, end);
|
||||||
|
notifyItemRangeInserted(end, newData.size());
|
||||||
|
}
|
||||||
|
disableLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,95 +112,145 @@ public class ListAdapter extends Adapter<ListAdapter.ListHolder> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
if (data.get(position) == null)
|
||||||
|
return ITEM_FOOTER;
|
||||||
|
return ITEM_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, parent, false);
|
if (viewType == ITEM_LIST) {
|
||||||
final ListHolder vh = new ListHolder(v);
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, parent, false);
|
||||||
FontTool.setViewFontAndColor(settings, v);
|
final ListHolder vh = new ListHolder(v);
|
||||||
|
FontTool.setViewFontAndColor(settings, v);
|
||||||
vh.pb_image.setOnClickListener(new OnClickListener() {
|
vh.pb_image.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int position = vh.getLayoutPosition();
|
int position = vh.getLayoutPosition();
|
||||||
if (position != NO_POSITION) {
|
if (position != NO_POSITION) {
|
||||||
listener.onClick(data.get(position), ListClickListener.Action.PROFILE);
|
listener.onClick(data.get(position), ListClickListener.Action.PROFILE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
vh.followList.setOnClickListener(new OnClickListener() {
|
||||||
vh.followList.setOnClickListener(new OnClickListener() {
|
@Override
|
||||||
@Override
|
public void onClick(View v) {
|
||||||
public void onClick(View v) {
|
int position = vh.getLayoutPosition();
|
||||||
int position = vh.getLayoutPosition();
|
if (position != NO_POSITION) {
|
||||||
if (position != NO_POSITION) {
|
listener.onClick(data.get(position), ListClickListener.Action.FOLLOW);
|
||||||
listener.onClick(data.get(position), ListClickListener.Action.FOLLOW);
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
vh.deleteList.setOnClickListener(new OnClickListener() {
|
||||||
vh.deleteList.setOnClickListener(new OnClickListener() {
|
@Override
|
||||||
@Override
|
public void onClick(View v) {
|
||||||
public void onClick(View v) {
|
int position = vh.getLayoutPosition();
|
||||||
int position = vh.getLayoutPosition();
|
if (position != NO_POSITION) {
|
||||||
if (position != NO_POSITION) {
|
listener.onClick(data.get(position), ListClickListener.Action.DELETE);
|
||||||
listener.onClick(data.get(position), ListClickListener.Action.DELETE);
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
vh.subscriberCount.setOnClickListener(new OnClickListener() {
|
||||||
vh.subscriberCount.setOnClickListener(new OnClickListener() {
|
@Override
|
||||||
@Override
|
public void onClick(View v) {
|
||||||
public void onClick(View v) {
|
int position = vh.getLayoutPosition();
|
||||||
int position = vh.getLayoutPosition();
|
if (position != NO_POSITION) {
|
||||||
if (position != NO_POSITION) {
|
listener.onClick(data.get(position), ListClickListener.Action.SUBSCRIBER);
|
||||||
listener.onClick(data.get(position), ListClickListener.Action.SUBSCRIBER);
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
vh.memberCount.setOnClickListener(new OnClickListener() {
|
||||||
vh.memberCount.setOnClickListener(new OnClickListener() {
|
@Override
|
||||||
@Override
|
public void onClick(View v) {
|
||||||
public void onClick(View v) {
|
int position = vh.getLayoutPosition();
|
||||||
int position = vh.getLayoutPosition();
|
if (position != NO_POSITION) {
|
||||||
if (position != NO_POSITION) {
|
listener.onClick(data.get(position), ListClickListener.Action.MEMBER);
|
||||||
listener.onClick(data.get(position), ListClickListener.Action.MEMBER);
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
return vh;
|
||||||
return vh;
|
} else {
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_placeholder, parent, false);
|
||||||
|
final PlaceHolder ph = new PlaceHolder(v);
|
||||||
|
ph.loadBtn.setTypeface(settings.getFontFace());
|
||||||
|
ph.loadBtn.setTextColor(settings.getFontColor());
|
||||||
|
ph.loadBtn.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int position = ph.getLayoutPosition();
|
||||||
|
if (position != NO_POSITION) {
|
||||||
|
listener.onFooterClick(data.getNext());
|
||||||
|
ph.loadCircle.setVisibility(VISIBLE);
|
||||||
|
ph.loadBtn.setVisibility(INVISIBLE);
|
||||||
|
loadingIndex = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ph;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ListHolder vh, int index) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int index) {
|
||||||
TwitterList item = data.get(index);
|
if (holder instanceof ListHolder) {
|
||||||
TwitterUser owner = item.getListOwner();
|
ListHolder vh = (ListHolder) holder;
|
||||||
vh.title.setText(item.getTitle());
|
TwitterList item = data.get(index);
|
||||||
vh.ownername.setText(owner.getScreenname());
|
TwitterUser owner = item.getListOwner();
|
||||||
vh.description.setText(item.getDescription());
|
vh.title.setText(item.getTitle());
|
||||||
vh.createdAt.setText(getTimeString(item.getCreatedAt()));
|
vh.ownername.setText(owner.getScreenname());
|
||||||
vh.memberCount.setText(formatter.format(item.getMemberCount()));
|
vh.description.setText(item.getDescription());
|
||||||
vh.subscriberCount.setText(formatter.format(item.getSubscriberCount()));
|
vh.createdAt.setText(getTimeString(item.getCreatedAt()));
|
||||||
if (settings.getImageLoad()) {
|
vh.memberCount.setText(formatter.format(item.getMemberCount()));
|
||||||
String pbLink = owner.getImageLink();
|
vh.subscriberCount.setText(formatter.format(item.getSubscriberCount()));
|
||||||
if (!owner.hasDefaultProfileImage()) {
|
if (settings.getImageLoad()) {
|
||||||
pbLink += "_mini";
|
String pbLink = owner.getImageLink();
|
||||||
|
if (!owner.hasDefaultProfileImage()) {
|
||||||
|
pbLink += "_mini";
|
||||||
|
}
|
||||||
|
Picasso.get().load(pbLink).error(R.drawable.no_image).into(vh.pb_image);
|
||||||
|
}
|
||||||
|
if (item.isFollowing()) {
|
||||||
|
vh.followList.setText(R.string.user_unfollow);
|
||||||
|
} else {
|
||||||
|
vh.followList.setText(R.string.user_follow);
|
||||||
|
}
|
||||||
|
if (item.isListOwner()) {
|
||||||
|
vh.followList.setVisibility(VISIBLE);
|
||||||
|
vh.deleteList.setVisibility(GONE);
|
||||||
|
} else {
|
||||||
|
vh.followList.setVisibility(GONE);
|
||||||
|
vh.deleteList.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
if (item.isPrivate()) {
|
||||||
|
vh.title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.lock, 0, 0, 0);
|
||||||
|
} else {
|
||||||
|
vh.title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
} else if (holder instanceof PlaceHolder) {
|
||||||
|
PlaceHolder placeHolder = (PlaceHolder) holder;
|
||||||
|
if (loadingIndex != NO_LOADING) {
|
||||||
|
placeHolder.loadCircle.setVisibility(VISIBLE);
|
||||||
|
placeHolder.loadBtn.setVisibility(INVISIBLE);
|
||||||
|
} else {
|
||||||
|
placeHolder.loadCircle.setVisibility(INVISIBLE);
|
||||||
|
placeHolder.loadBtn.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
Picasso.get().load(pbLink).error(R.drawable.no_image).into(vh.pb_image);
|
|
||||||
}
|
}
|
||||||
if (item.isFollowing()) {
|
}
|
||||||
vh.followList.setText(R.string.user_unfollow);
|
|
||||||
} else {
|
/**
|
||||||
vh.followList.setText(R.string.user_follow);
|
* disable loading animation in footer
|
||||||
}
|
*/
|
||||||
if (item.isListOwner()) {
|
public void disableLoading() {
|
||||||
vh.followList.setVisibility(VISIBLE);
|
if (loadingIndex != NO_LOADING) {
|
||||||
vh.deleteList.setVisibility(GONE);
|
int oldIndex = loadingIndex;
|
||||||
} else {
|
loadingIndex = NO_LOADING;
|
||||||
vh.followList.setVisibility(GONE);
|
notifyItemChanged(oldIndex);
|
||||||
vh.deleteList.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
if (item.isPrivate()) {
|
|
||||||
vh.title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.lock, 0, 0, 0);
|
|
||||||
} else {
|
|
||||||
vh.title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +275,18 @@ public class ListAdapter extends Adapter<ListAdapter.ListHolder> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class PlaceHolder extends ViewHolder {
|
||||||
|
|
||||||
|
final ProgressBar loadCircle;
|
||||||
|
final Button loadBtn;
|
||||||
|
|
||||||
|
PlaceHolder(@NonNull View v) {
|
||||||
|
super(v);
|
||||||
|
loadCircle = v.findViewById(R.id.placeholder_loading);
|
||||||
|
loadBtn = v.findViewById(R.id.placeholder_button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for an item
|
* Listener for an item
|
||||||
*/
|
*/
|
||||||
@ -224,5 +307,12 @@ public class ListAdapter extends Adapter<ListAdapter.ListHolder> {
|
|||||||
* @param action which button was clicked
|
* @param action which button was clicked
|
||||||
*/
|
*/
|
||||||
void onClick(TwitterList listItem, Action action);
|
void onClick(TwitterList listItem, Action action);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* called when the footer is clicked
|
||||||
|
*
|
||||||
|
* @param cursor next cursor of the list
|
||||||
|
*/
|
||||||
|
void onFooterClick(long cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,9 +23,6 @@ import org.nuclearfog.twidda.backend.items.TwitterUser;
|
|||||||
import org.nuclearfog.twidda.backend.utils.FontTool;
|
import org.nuclearfog.twidda.backend.utils.FontTool;
|
||||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static android.view.View.INVISIBLE;
|
import static android.view.View.INVISIBLE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static androidx.recyclerview.widget.RecyclerView.NO_ID;
|
import static androidx.recyclerview.widget.RecyclerView.NO_ID;
|
||||||
@ -45,77 +42,58 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
|||||||
private final UserClickListener itemClickListener;
|
private final UserClickListener itemClickListener;
|
||||||
private final GlobalSettings settings;
|
private final GlobalSettings settings;
|
||||||
|
|
||||||
private final List<TwitterUser> users;
|
private final TwitterUserList data;
|
||||||
private long nextCursor;
|
|
||||||
private int loadingIndex;
|
private int loadingIndex;
|
||||||
|
|
||||||
|
|
||||||
public UserAdapter(UserClickListener itemClickListener, GlobalSettings settings) {
|
public UserAdapter(UserClickListener itemClickListener, GlobalSettings settings) {
|
||||||
this.itemClickListener = itemClickListener;
|
this.itemClickListener = itemClickListener;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
users = new ArrayList<>();
|
data = new TwitterUserList();
|
||||||
loadingIndex = NO_INDEX;
|
loadingIndex = NO_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
public void setData(@NonNull TwitterUserList data) {
|
public void setData(@NonNull TwitterUserList newData) {
|
||||||
if (users.isEmpty() || !data.hasPrevious()) {
|
if (data.isEmpty() || !newData.hasPrevious()) {
|
||||||
if (!users.isEmpty()) {
|
data.replace(newData);
|
||||||
// replace previous data
|
if (newData.hasNext()) {
|
||||||
users.clear();
|
|
||||||
}
|
|
||||||
users.addAll(data);
|
|
||||||
if (data.hasNext()) {
|
|
||||||
// add footer
|
// add footer
|
||||||
users.add(null);
|
data.add(null);
|
||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
} else {
|
} else {
|
||||||
int end = users.size() - 1;
|
int end = data.size() - 1;
|
||||||
if (!data.hasNext()) {
|
if (!newData.hasNext()) {
|
||||||
// remove footer
|
// remove footer
|
||||||
users.remove(end);
|
data.remove(end);
|
||||||
notifyItemRemoved(end);
|
notifyItemRemoved(end);
|
||||||
} else {
|
|
||||||
disableLoading();
|
|
||||||
}
|
}
|
||||||
users.addAll(end, data);
|
data.addListAt(newData, end);
|
||||||
notifyItemRangeInserted(end, data.size());
|
notifyItemRangeInserted(end, newData.size());
|
||||||
}
|
|
||||||
nextCursor = data.getNext();
|
|
||||||
loadingIndex = NO_INDEX;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* disable loading animation in footer
|
|
||||||
*/
|
|
||||||
public void disableLoading() {
|
|
||||||
if (loadingIndex != NO_INDEX) {
|
|
||||||
int oldIndex = loadingIndex;
|
|
||||||
loadingIndex = NO_INDEX;
|
|
||||||
notifyItemChanged(oldIndex);
|
|
||||||
}
|
}
|
||||||
|
disableLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return users.size();
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int index) {
|
public long getItemId(int index) {
|
||||||
if (users.get(index) != null)
|
if (data.get(index) != null)
|
||||||
return users.get(index).getId();
|
return data.get(index).getId();
|
||||||
return NO_ID;
|
return NO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int index) {
|
public int getItemViewType(int index) {
|
||||||
if (users.get(index) == null)
|
if (data.get(index) == null)
|
||||||
return ITEM_GAP;
|
return ITEM_GAP;
|
||||||
return ITEM_USER;
|
return ITEM_USER;
|
||||||
}
|
}
|
||||||
@ -132,7 +110,7 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int position = vh.getLayoutPosition();
|
int position = vh.getLayoutPosition();
|
||||||
TwitterUser user = users.get(position);
|
TwitterUser user = data.get(position);
|
||||||
if (position != NO_POSITION && user != null) {
|
if (position != NO_POSITION && user != null) {
|
||||||
itemClickListener.onUserClick(user);
|
itemClickListener.onUserClick(user);
|
||||||
}
|
}
|
||||||
@ -149,7 +127,7 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int position = vh.getLayoutPosition();
|
int position = vh.getLayoutPosition();
|
||||||
if (position != NO_POSITION) {
|
if (position != NO_POSITION) {
|
||||||
itemClickListener.onFooterClick(nextCursor);
|
itemClickListener.onFooterClick(data.getNext());
|
||||||
vh.loadCircle.setVisibility(VISIBLE);
|
vh.loadCircle.setVisibility(VISIBLE);
|
||||||
vh.loadBtn.setVisibility(INVISIBLE);
|
vh.loadBtn.setVisibility(INVISIBLE);
|
||||||
loadingIndex = position;
|
loadingIndex = position;
|
||||||
@ -163,7 +141,7 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int index) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int index) {
|
||||||
TwitterUser user = users.get(index);
|
TwitterUser user = data.get(index);
|
||||||
if (holder instanceof ItemHolder && user != null) {
|
if (holder instanceof ItemHolder && user != null) {
|
||||||
ItemHolder vh = (ItemHolder) holder;
|
ItemHolder vh = (ItemHolder) holder;
|
||||||
vh.username.setText(user.getUsername());
|
vh.username.setText(user.getUsername());
|
||||||
@ -191,6 +169,17 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* disable loading animation in footer
|
||||||
|
*/
|
||||||
|
public void disableLoading() {
|
||||||
|
if (loadingIndex != NO_INDEX) {
|
||||||
|
int oldIndex = loadingIndex;
|
||||||
|
loadingIndex = NO_INDEX;
|
||||||
|
notifyItemChanged(oldIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setIcon(TextView tv, @DrawableRes int icon) {
|
private void setIcon(TextView tv, @DrawableRes int icon) {
|
||||||
tv.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
|
tv.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
|
||||||
@ -234,6 +223,11 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
|||||||
*/
|
*/
|
||||||
void onUserClick(TwitterUser user);
|
void onUserClick(TwitterUser user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handle footer click
|
||||||
|
*
|
||||||
|
* @param cursor next cursor of the list
|
||||||
|
*/
|
||||||
void onFooterClick(long cursor);
|
void onFooterClick(long cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,8 +11,19 @@ import java.util.LinkedList;
|
|||||||
*/
|
*/
|
||||||
public class TwitterUserList extends LinkedList<TwitterUser> {
|
public class TwitterUserList extends LinkedList<TwitterUser> {
|
||||||
|
|
||||||
private final long prevCursor, nextCursor;
|
private long prevCursor = 0;
|
||||||
|
private long nextCursor = 0;
|
||||||
|
|
||||||
|
public TwitterUserList() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates an empty list with defined cursors
|
||||||
|
*
|
||||||
|
* @param prevCursor previous cursor of the list
|
||||||
|
* @param nextCursor next cursor of the list
|
||||||
|
*/
|
||||||
public TwitterUserList(long prevCursor, long nextCursor) {
|
public TwitterUserList(long prevCursor, long nextCursor) {
|
||||||
super();
|
super();
|
||||||
this.prevCursor = prevCursor;
|
this.prevCursor = prevCursor;
|
||||||
@ -46,6 +57,44 @@ public class TwitterUserList extends LinkedList<TwitterUser> {
|
|||||||
return nextCursor;
|
return nextCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get previous cursor
|
||||||
|
*
|
||||||
|
* @return previous cursor
|
||||||
|
*/
|
||||||
|
public long getPrev() {
|
||||||
|
return prevCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* replace whole list including cursors
|
||||||
|
*
|
||||||
|
* @param list new list
|
||||||
|
*/
|
||||||
|
public void replace(TwitterUserList list) {
|
||||||
|
super.clear();
|
||||||
|
super.addAll(list);
|
||||||
|
prevCursor = list.getPrev();
|
||||||
|
nextCursor = list.getNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a sublist at the bottom of this list including next cursor
|
||||||
|
*
|
||||||
|
* @param list new sublist
|
||||||
|
*/
|
||||||
|
public void addListAt(TwitterUserList list, int index) {
|
||||||
|
super.addAll(index, list);
|
||||||
|
nextCursor = list.getNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
prevCursor = 0;
|
||||||
|
nextCursor = 0;
|
||||||
|
super.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -14,6 +14,10 @@ public class UserListList extends LinkedList<TwitterList> {
|
|||||||
private long prevCursor = 0;
|
private long prevCursor = 0;
|
||||||
private long nextCursor = 0;
|
private long nextCursor = 0;
|
||||||
|
|
||||||
|
public UserListList() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list single list item
|
* @param list single list item
|
||||||
*/
|
*/
|
||||||
@ -32,6 +36,15 @@ public class UserListList extends LinkedList<TwitterList> {
|
|||||||
this.nextCursor = nextCursor;
|
this.nextCursor = nextCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set next list cursor
|
||||||
|
*
|
||||||
|
* @param next
|
||||||
|
*/
|
||||||
|
public void setNextCursor(long next) {
|
||||||
|
nextCursor = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if list is linked to a previous list
|
* check if list is linked to a previous list
|
||||||
@ -51,6 +64,15 @@ public class UserListList extends LinkedList<TwitterList> {
|
|||||||
return nextCursor != 0;
|
return nextCursor != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get prev link to a list
|
||||||
|
*
|
||||||
|
* @return cursor
|
||||||
|
*/
|
||||||
|
public long getPrev() {
|
||||||
|
return prevCursor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get next link to a list
|
* get next link to a list
|
||||||
*
|
*
|
||||||
@ -60,6 +82,37 @@ public class UserListList extends LinkedList<TwitterList> {
|
|||||||
return nextCursor;
|
return nextCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* replace whole list including cursors
|
||||||
|
*
|
||||||
|
* @param list new list
|
||||||
|
*/
|
||||||
|
public void replace(UserListList list) {
|
||||||
|
super.clear();
|
||||||
|
super.addAll(list);
|
||||||
|
prevCursor = list.getPrev();
|
||||||
|
nextCursor = list.getNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a sublist at the bottom of this list including next cursor
|
||||||
|
*
|
||||||
|
* @param list new sublist
|
||||||
|
* @param index position where to insert at
|
||||||
|
*/
|
||||||
|
public void addListAt(UserListList list, int index) {
|
||||||
|
super.addAll(index, list);
|
||||||
|
nextCursor = list.getNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
// resetting cursors
|
||||||
|
prevCursor = 0;
|
||||||
|
nextCursor = 0;
|
||||||
|
super.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -27,12 +27,11 @@ import org.nuclearfog.twidda.adapter.ListAdapter;
|
|||||||
import org.nuclearfog.twidda.adapter.ListAdapter.ListClickListener;
|
import org.nuclearfog.twidda.adapter.ListAdapter.ListClickListener;
|
||||||
import org.nuclearfog.twidda.backend.TwitterListLoader;
|
import org.nuclearfog.twidda.backend.TwitterListLoader;
|
||||||
import org.nuclearfog.twidda.backend.engine.EngineException;
|
import org.nuclearfog.twidda.backend.engine.EngineException;
|
||||||
|
import org.nuclearfog.twidda.backend.holder.UserListList;
|
||||||
import org.nuclearfog.twidda.backend.items.TwitterList;
|
import org.nuclearfog.twidda.backend.items.TwitterList;
|
||||||
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
||||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static android.content.DialogInterface.BUTTON_POSITIVE;
|
import static android.content.DialogInterface.BUTTON_POSITIVE;
|
||||||
import static android.os.AsyncTask.Status.FINISHED;
|
import static android.os.AsyncTask.Status.FINISHED;
|
||||||
import static android.os.AsyncTask.Status.RUNNING;
|
import static android.os.AsyncTask.Status.RUNNING;
|
||||||
@ -189,6 +188,13 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void onFooterClick(long cursor) {
|
||||||
|
if (listTask != null && listTask.getStatus() != RUNNING) {
|
||||||
|
load(cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (which == BUTTON_POSITIVE) {
|
if (which == BUTTON_POSITIVE) {
|
||||||
@ -222,7 +228,7 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli
|
|||||||
*
|
*
|
||||||
* @param data List of Twitter list data
|
* @param data List of Twitter list data
|
||||||
*/
|
*/
|
||||||
public void setData(List<TwitterList> data) {
|
public void setData(UserListList data) {
|
||||||
adapter.setData(data);
|
adapter.setData(data);
|
||||||
setRefresh(false);
|
setRefresh(false);
|
||||||
}
|
}
|
||||||
@ -273,6 +279,7 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli
|
|||||||
public void onError(@Nullable EngineException error) {
|
public void onError(@Nullable EngineException error) {
|
||||||
if (getContext() != null && error != null)
|
if (getContext() != null && error != null)
|
||||||
ErrorHandler.handleFailure(getContext(), error);
|
ErrorHandler.handleFailure(getContext(), error);
|
||||||
|
adapter.disableLoading();
|
||||||
setRefresh(false);
|
setRefresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user