fix crash in TimelineFragment
This commit is contained in:
parent
b2c0ed69f6
commit
67f90d050c
1 changed files with 24 additions and 20 deletions
|
@ -206,6 +206,9 @@ public class TimelineFragment extends SFragment implements
|
||||||
|| kind == Kind.LIST) {
|
|| kind == Kind.LIST) {
|
||||||
hashtagOrId = arguments.getString(HASHTAG_OR_ID_ARG);
|
hashtagOrId = arguments.getString(HASHTAG_OR_ID_ARG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adapter = new TimelineAdapter(dataSource, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -218,9 +221,6 @@ public class TimelineFragment extends SFragment implements
|
||||||
progressBar = rootView.findViewById(R.id.progress_bar);
|
progressBar = rootView.findViewById(R.id.progress_bar);
|
||||||
nothingMessageView = rootView.findViewById(R.id.nothing_message);
|
nothingMessageView = rootView.findViewById(R.id.nothing_message);
|
||||||
|
|
||||||
adapter = new TimelineAdapter(dataSource, this);
|
|
||||||
|
|
||||||
|
|
||||||
setupSwipeRefreshLayout();
|
setupSwipeRefreshLayout();
|
||||||
setupRecyclerView();
|
setupRecyclerView();
|
||||||
updateAdapter();
|
updateAdapter();
|
||||||
|
@ -835,22 +835,24 @@ public class TimelineFragment extends SFragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onFetchTimelineFailure(Exception exception, FetchEnd fetchEnd, int position) {
|
private void onFetchTimelineFailure(Exception exception, FetchEnd fetchEnd, int position) {
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
if(isAdded()) {
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
|
||||||
if (fetchEnd == FetchEnd.MIDDLE && !statuses.get(position).isRight()) {
|
if (fetchEnd == FetchEnd.MIDDLE && !statuses.get(position).isRight()) {
|
||||||
Placeholder placeholder = statuses.get(position).getAsLeftOrNull();
|
Placeholder placeholder = statuses.get(position).getAsLeftOrNull();
|
||||||
StatusViewData newViewData;
|
StatusViewData newViewData;
|
||||||
if (placeholder == null) {
|
if (placeholder == null) {
|
||||||
placeholder = newPlaceholder();
|
placeholder = newPlaceholder();
|
||||||
|
}
|
||||||
|
newViewData = new StatusViewData.Placeholder(placeholder.id, false);
|
||||||
|
statuses.setPairedItem(position, newViewData);
|
||||||
|
updateAdapter();
|
||||||
}
|
}
|
||||||
newViewData = new StatusViewData.Placeholder(placeholder.id, false);
|
|
||||||
statuses.setPairedItem(position, newViewData);
|
|
||||||
updateAdapter();
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.e(TAG, "Fetch Failure: " + exception.getMessage());
|
Log.e(TAG, "Fetch Failure: " + exception.getMessage());
|
||||||
fulfillAnyQueuedFetches(fetchEnd);
|
fulfillAnyQueuedFetches(fetchEnd);
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fulfillAnyQueuedFetches(FetchEnd fetchEnd) {
|
private void fulfillAnyQueuedFetches(FetchEnd fetchEnd) {
|
||||||
|
@ -1055,10 +1057,12 @@ public class TimelineFragment extends SFragment implements
|
||||||
private final ListUpdateCallback listUpdateCallback = new ListUpdateCallback() {
|
private final ListUpdateCallback listUpdateCallback = new ListUpdateCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onInserted(int position, int count) {
|
public void onInserted(int position, int count) {
|
||||||
adapter.notifyItemRangeInserted(position, count);
|
if(isAdded()) {
|
||||||
Context context = getContext();
|
adapter.notifyItemRangeInserted(position, count);
|
||||||
if (position == 0 && context != null) {
|
Context context = getContext();
|
||||||
recyclerView.scrollBy(0, Utils.dpToPx(context, -30));
|
if (position == 0 && context != null) {
|
||||||
|
recyclerView.scrollBy(0, Utils.dpToPx(context, -30));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue