Fix issue #445 - Timelines not reloaded when applying filters

pull/483/head
Thomas 2 years ago
parent 5b9534adc2
commit 03f8c33cb2

@ -798,6 +798,7 @@ public class PinnedTimelineHelper {
} catch (DBException e) {
e.printStackTrace();
}
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(activity.getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + slug, null);
editor.commit();
@ -813,6 +814,7 @@ public class PinnedTimelineHelper {
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
fragTransaction2.attach(fragmentMastodonTimeline);
fragTransaction2.commit();
((FragmentMastodonTimeline) fragmentMastodonTimeline).recreate();
}
}
}
@ -1057,6 +1059,7 @@ public class PinnedTimelineHelper {
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
fragTransaction2.attach(fragmentMastodonTimeline);
fragTransaction2.commit();
fragmentMastodonTimeline.recreate();
popup.getMenu().close();
return false;
});
@ -1108,6 +1111,7 @@ public class PinnedTimelineHelper {
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
fragTransaction2.attach(fragmentMastodonTimeline);
fragTransaction2.commit();
fragmentMastodonTimeline.recreate();
return false;
});
}
@ -1187,6 +1191,7 @@ public class PinnedTimelineHelper {
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
fragTransaction2.attach(fragmentMastodonTimeline);
fragTransaction2.commit();
fragmentMastodonTimeline.recreate();
}
});
@ -1256,6 +1261,7 @@ public class PinnedTimelineHelper {
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
fragTransaction2.attach(fragmentMastodonTimeline);
fragTransaction2.commit();
fragmentMastodonTimeline.recreate();
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();

@ -167,6 +167,32 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private boolean canBeFederated;
private boolean rememberPosition;
//Allow to recreate data when detaching/attaching fragment
public void recreate() {
initialStatuses = null;
int count = 0;
if (timelineStatuses != null && timelineStatuses.size() > 0) {
count = timelineStatuses.size();
timelineStatuses.clear();
timelineStatuses = new ArrayList<>();
if (statusAdapter != null) {
statusAdapter.notifyItemRangeRemoved(0, count);
max_id = statusReport != null ? statusReport.id : null;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
rememberPosition = sharedpreferences.getBoolean(getString(R.string.SET_REMEMBER_POSITION), true);
//Inner marker are only for pinned timelines and main timelines, they have isViewInitialized set to false
if (max_id == null && !isViewInitialized && rememberPosition) {
max_id = sharedpreferences.getString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + slug, null);
}
//Only fragment in main view pager should not have the view initialized
//AND Only the first fragment will initialize its view
flagLoading = false;
router(null);
}
}
}
@Override
public void onResume() {
super.onResume();
@ -250,12 +276,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
timelineType = Timeline.TimeLineEnum.HOME;
canBeFederated = true;
if (getArguments() != null) {
@ -589,7 +613,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
*/
private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) {
if (binding == null || getActivity() == null || !isAdded()) {
return;
}
@ -809,7 +832,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
if (direction == null) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
.observe(getViewLifecycleOwner(), nitterStatuses -> {
initialStatuses = nitterStatuses;
initializeStatusesCommonView(nitterStatuses);
});
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
@ -993,6 +1019,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
FETCH_NEW
}
public interface UpdateCounters {
void onUpdate(int count, Timeline.TimeLineEnum type, String slug);
}

Loading…
Cancel
Save