Fix issue #445 - Timelines not reloaded when applying filters

This commit is contained in:
Thomas 2022-11-14 17:18:40 +01:00
parent 5b9534adc2
commit 03f8c33cb2
2 changed files with 37 additions and 4 deletions

View file

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

View file

@ -167,6 +167,32 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private boolean canBeFederated; private boolean canBeFederated;
private boolean rememberPosition; 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 @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -250,12 +276,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
timelineType = Timeline.TimeLineEnum.HOME; timelineType = Timeline.TimeLineEnum.HOME;
canBeFederated = true; canBeFederated = true;
if (getArguments() != null) { 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 * @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) { private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) {
if (binding == null || getActivity() == null || !isAdded()) { if (binding == null || getActivity() == null || !isAdded()) {
return; return;
} }
@ -809,7 +832,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) { if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
if (direction == null) { if (direction == null) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null) timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), nitterStatuses -> {
initialStatuses = nitterStatuses;
initializeStatusesCommonView(nitterStatuses);
});
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id) timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
@ -993,6 +1019,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
FETCH_NEW FETCH_NEW
} }
public interface UpdateCounters { public interface UpdateCounters {
void onUpdate(int count, Timeline.TimeLineEnum type, String slug); void onUpdate(int count, Timeline.TimeLineEnum type, String slug);
} }