Fix some crashes

camel_tags
Thomas 2 years ago
parent 4837afcfb0
commit 5c73717373

@ -130,8 +130,12 @@ public class MastodonHelper {
* @return Pagination
*/
public static Pagination getPagination(Headers headers) {
String link = headers.get("Link");
Pagination pagination = new Pagination();
if (headers == null) {
return pagination;
}
String link = headers.get("Link");
if (link != null) {
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*");
Matcher matcherMaxId = patternMaxId.matcher(link);

@ -2137,7 +2137,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
//We hide the button
status.isFetchMore = false;
String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
} else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
@ -2158,7 +2158,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
statusIdMin = status.id;
}
}
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id;
} else {
statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id;
@ -2470,6 +2470,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public List<Attachment> getPreloadItems(int position) {
List<Attachment> attachments = new ArrayList<>();
int max_size = statusList.size();
if (max_size == 0) {
return attachments;
}
int siblings = 3;
int from = Math.max((position - siblings), 0);
if (from > max_size - 1) {
@ -2646,7 +2649,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
status.isFetchMore = false;
notifyItemChanged(holder.getBindingAdapterPosition());
String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
} else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
@ -2664,7 +2667,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
minId = status.id;
}
}
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
maxId = statusList.get(holder.getBindingAdapterPosition()).id;
} else {
maxId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
@ -2702,7 +2705,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
//We hide the button
status.isFetchMore = false;
String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
} else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;

@ -96,7 +96,9 @@ public class FragmentMediaProfile extends Fragment {
accountsVM.getAccountStatuses(tempInstance, null, accountId, null, null, null, null, null, true, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statuses -> initializeStatusesCommonView(statuses));
} else {
Toasty.error(requireActivity(), getString(R.string.toast_fetch_error), Toasty.LENGTH_LONG).show();
if (isAdded() && !requireActivity().isFinishing()) {
Toasty.error(requireActivity(), getString(R.string.toast_fetch_error), Toasty.LENGTH_LONG).show();
}
}
}
});

Loading…
Cancel
Save