Improve and avoid last empty when coming back

This commit is contained in:
Thomas 2022-11-09 10:59:49 +01:00
parent e93f194bb5
commit 230ed4b2ba
3 changed files with 23 additions and 30 deletions

View file

@ -15,9 +15,6 @@ package app.fedilab.android.ui.fragment.timeline;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.currentUserID;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -43,7 +40,6 @@ import app.fedilab.android.client.entities.app.StatusCache;
import app.fedilab.android.client.entities.app.Timeline; import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.FragmentPaginationBinding; import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.exception.DBException; import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper; import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.ConversationAdapter; import app.fedilab.android.ui.drawer.ConversationAdapter;
@ -70,6 +66,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
flagLoading = false; flagLoading = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false); binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity())); binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
isViewInitialized = false;
return binding.getRoot(); return binding.getRoot();
} }
@ -86,9 +83,11 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (Timeline.TimeLineEnum.CONVERSATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) != 0 && !isViewInitialized) { if (!isViewInitialized) {
isViewInitialized = true; isViewInitialized = true;
initializeConversationCommonView(initialConversations); if (initialConversations != null) {
initializeConversationCommonView(initialConversations);
}
} }
} }
@ -221,7 +220,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
isViewInitialized = Timeline.TimeLineEnum.CONVERSATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0;
int c1 = getResources().getColor(R.color.cyanea_accent_reference); int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference)); binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors( binding.swipeContainer.setColorSchemeColors(

View file

@ -14,9 +14,6 @@ package app.fedilab.android.ui.fragment.timeline;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.currentUserID;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -170,7 +167,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
flagLoading = false; flagLoading = false;
isViewInitialized = Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0; isViewInitialized = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false); binding = FragmentPaginationBinding.inflate(inflater, container, false);
View root = binding.getRoot(); View root = binding.getRoot();
if (getArguments() != null) { if (getArguments() != null) {
@ -323,9 +320,11 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) != 0 && !isViewInitialized) { if (!isViewInitialized) {
isViewInitialized = true; isViewInitialized = true;
initializeNotificationView(initialNotifications); if (initialNotifications != null) {
initializeNotificationView(initialNotifications);
}
} }
} }

View file

@ -164,17 +164,17 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private PinnedTimeline pinnedTimeline; private PinnedTimeline pinnedTimeline;
private String ident; private String ident;
private String slug; private String slug;
private TimelinesVM.TimelineParams timelineParams;
private boolean canBeFederated; private boolean canBeFederated;
private boolean rememberPosition; private boolean rememberPosition;
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (slug != null && slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) != 0 if (!isViewInitialized) {
&& !isViewInitialized) {
isViewInitialized = true; isViewInitialized = true;
initializeStatusesCommonView(initialStatuses); if (initialStatuses != null) {
initializeStatusesCommonView(initialStatuses);
}
} }
if (timelineStatuses != null && timelineStatuses.size() > 0) { if (timelineStatuses != null && timelineStatuses.size() > 0) {
route(DIRECTION.FETCH_NEW, true); route(DIRECTION.FETCH_NEW, true);
@ -229,7 +229,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class); timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class); accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);
initialStatuses = null; initialStatuses = null;
@ -244,22 +243,20 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} }
//Only fragment in main view pager should not have the view initialized //Only fragment in main view pager should not have the view initialized
//AND Only the first fragment will initialize its view //AND Only the first fragment will initialize its view
if (!isViewInitialized) {
if (slug != null) {
isViewInitialized = slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0;
}
}
flagLoading = false; flagLoading = false;
router(null); router(null);
} }
@Override
public void onCreate(@Nullable Bundle 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) {
timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE); timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE);
@ -592,14 +589,12 @@ 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 (direction == null && !isViewInitialized && slug != null) {
isViewInitialized = slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0;
}
if (binding == null || getActivity() == null || !isAdded()) { if (binding == null || getActivity() == null || !isAdded()) {
return; return;
} }
//Initialize with default params //Initialize with default params
timelineParams = new TimelinesVM.TimelineParams(timelineType, direction, ident); TimelinesVM.TimelineParams timelineParams = new TimelinesVM.TimelineParams(timelineType, direction, ident);
timelineParams.limit = MastodonHelper.statusesPerCall(requireActivity()); timelineParams.limit = MastodonHelper.statusesPerCall(requireActivity());
if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.FETCH_NEW) { if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.FETCH_NEW) {
timelineParams.maxId = null; timelineParams.maxId = null;