mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Fix some crashes
This commit is contained in:
parent
4837afcfb0
commit
5c73717373
3 changed files with 16 additions and 7 deletions
|
@ -130,8 +130,12 @@ public class MastodonHelper {
|
||||||
* @return Pagination
|
* @return Pagination
|
||||||
*/
|
*/
|
||||||
public static Pagination getPagination(Headers headers) {
|
public static Pagination getPagination(Headers headers) {
|
||||||
String link = headers.get("Link");
|
|
||||||
Pagination pagination = new Pagination();
|
Pagination pagination = new Pagination();
|
||||||
|
if (headers == null) {
|
||||||
|
return pagination;
|
||||||
|
}
|
||||||
|
String link = headers.get("Link");
|
||||||
if (link != null) {
|
if (link != null) {
|
||||||
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*");
|
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*");
|
||||||
Matcher matcherMaxId = patternMaxId.matcher(link);
|
Matcher matcherMaxId = patternMaxId.matcher(link);
|
||||||
|
|
|
@ -2137,7 +2137,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
//We hide the button
|
//We hide the button
|
||||||
status.isFetchMore = false;
|
status.isFetchMore = false;
|
||||||
String fromId;
|
String fromId;
|
||||||
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
|
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
|
||||||
} else {
|
} else {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
||||||
|
@ -2158,7 +2158,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
statusIdMin = status.id;
|
statusIdMin = status.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
|
||||||
statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id;
|
statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id;
|
||||||
} else {
|
} else {
|
||||||
statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
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) {
|
public List<Attachment> getPreloadItems(int position) {
|
||||||
List<Attachment> attachments = new ArrayList<>();
|
List<Attachment> attachments = new ArrayList<>();
|
||||||
int max_size = statusList.size();
|
int max_size = statusList.size();
|
||||||
|
if (max_size == 0) {
|
||||||
|
return attachments;
|
||||||
|
}
|
||||||
int siblings = 3;
|
int siblings = 3;
|
||||||
int from = Math.max((position - siblings), 0);
|
int from = Math.max((position - siblings), 0);
|
||||||
if (from > max_size - 1) {
|
if (from > max_size - 1) {
|
||||||
|
@ -2646,7 +2649,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
status.isFetchMore = false;
|
status.isFetchMore = false;
|
||||||
notifyItemChanged(holder.getBindingAdapterPosition());
|
notifyItemChanged(holder.getBindingAdapterPosition());
|
||||||
String fromId;
|
String fromId;
|
||||||
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
|
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
|
||||||
} else {
|
} else {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
||||||
|
@ -2664,7 +2667,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
minId = status.id;
|
minId = status.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
|
||||||
maxId = statusList.get(holder.getBindingAdapterPosition()).id;
|
maxId = statusList.get(holder.getBindingAdapterPosition()).id;
|
||||||
} else {
|
} else {
|
||||||
maxId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
maxId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
||||||
|
@ -2702,7 +2705,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
//We hide the button
|
//We hide the button
|
||||||
status.isFetchMore = false;
|
status.isFetchMore = false;
|
||||||
String fromId;
|
String fromId;
|
||||||
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
|
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
|
||||||
} else {
|
} else {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
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()))
|
accountsVM.getAccountStatuses(tempInstance, null, accountId, null, null, null, null, null, true, false, MastodonHelper.statusesPerCall(requireActivity()))
|
||||||
.observe(getViewLifecycleOwner(), statuses -> initializeStatusesCommonView(statuses));
|
.observe(getViewLifecycleOwner(), statuses -> initializeStatusesCommonView(statuses));
|
||||||
} else {
|
} 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…
Reference in a new issue