mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-07 00:20:08 +02:00
Same logic for notifications and conversations
This commit is contained in:
parent
382a198572
commit
4dc8695c75
2 changed files with 44 additions and 2 deletions
|
@ -15,6 +15,8 @@ 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.slugOfFirstFragment;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -57,6 +59,8 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
||||||
private ConversationAdapter conversationAdapter;
|
private ConversationAdapter conversationAdapter;
|
||||||
private LinearLayoutManager mLayoutManager;
|
private LinearLayoutManager mLayoutManager;
|
||||||
public UpdateCounters update;
|
public UpdateCounters update;
|
||||||
|
private boolean isViewInitialized;
|
||||||
|
private Conversations initialConversations;
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -75,6 +79,16 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
||||||
route(direction, fetchingMissing, null);
|
route(direction, fetchingMissing, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (Timeline.TimeLineEnum.CONVERSATION.getValue().compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) {
|
||||||
|
isViewInitialized = true;
|
||||||
|
initializeConversationCommonView(initialConversations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router for timelines
|
* Router for timelines
|
||||||
*
|
*
|
||||||
|
@ -123,6 +137,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
||||||
if (conversationsCached == null || conversationsCached.conversations == null || conversationsCached.conversations.size() == 0) {
|
if (conversationsCached == null || conversationsCached.conversations == null || conversationsCached.conversations.size() == 0) {
|
||||||
getLiveConversations(null, fetchingMissing, timelineParams, null);
|
getLiveConversations(null, fetchingMissing, timelineParams, null);
|
||||||
} else {
|
} else {
|
||||||
|
initialConversations = conversationsCached;
|
||||||
initializeConversationCommonView(conversationsCached);
|
initializeConversationCommonView(conversationsCached);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -160,7 +175,10 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
||||||
private void getLiveConversations(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, Conversation conversationToUpdate) {
|
private void getLiveConversations(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, Conversation conversationToUpdate) {
|
||||||
if (direction == null) {
|
if (direction == null) {
|
||||||
timelinesVM.getConversations(conversationList, timelineParams)
|
timelinesVM.getConversations(conversationList, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), this::initializeConversationCommonView);
|
.observe(getViewLifecycleOwner(), conversations -> {
|
||||||
|
initialConversations = conversations;
|
||||||
|
initializeConversationCommonView(conversations);
|
||||||
|
});
|
||||||
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
||||||
timelinesVM.getConversations(conversationList, timelineParams)
|
timelinesVM.getConversations(conversationList, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), conversationsBottom -> dealWithPagination(conversationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing, conversationToUpdate));
|
.observe(getViewLifecycleOwner(), conversationsBottom -> dealWithPagination(conversationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing, conversationToUpdate));
|
||||||
|
@ -219,6 +237,9 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
|
||||||
*/
|
*/
|
||||||
private void initializeConversationCommonView(final Conversations conversations) {
|
private void initializeConversationCommonView(final Conversations conversations) {
|
||||||
flagLoading = false;
|
flagLoading = false;
|
||||||
|
if (!isViewInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (binding == null || !isAdded() || getActivity() == null) {
|
if (binding == null || !isAdded() || getActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ 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.slugOfFirstFragment;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -63,6 +65,8 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
private boolean flagLoading;
|
private boolean flagLoading;
|
||||||
private List<Notification> notificationList;
|
private List<Notification> notificationList;
|
||||||
private NotificationAdapter notificationAdapter;
|
private NotificationAdapter notificationAdapter;
|
||||||
|
private boolean isViewInitialized;
|
||||||
|
private Notifications initialNotifications;
|
||||||
|
|
||||||
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
|
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -134,6 +138,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
flagLoading = false;
|
flagLoading = false;
|
||||||
|
isViewInitialized = Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(slugOfFirstFragment) == 0;
|
||||||
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) {
|
||||||
|
@ -199,6 +204,9 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
*/
|
*/
|
||||||
private void initializeNotificationView(final Notifications notifications) {
|
private void initializeNotificationView(final Notifications notifications) {
|
||||||
flagLoading = false;
|
flagLoading = false;
|
||||||
|
if (!isViewInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (binding == null || !isAdded() || getActivity() == null) {
|
if (binding == null || !isAdded() || getActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -283,6 +291,15 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) {
|
||||||
|
isViewInitialized = true;
|
||||||
|
initializeNotificationView(initialNotifications);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router for timelines
|
* Router for timelines
|
||||||
*
|
*
|
||||||
|
@ -343,6 +360,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
if (notificationsCached == null || notificationsCached.notifications == null || notificationsCached.notifications.size() == 0) {
|
if (notificationsCached == null || notificationsCached.notifications == null || notificationsCached.notifications.size() == 0) {
|
||||||
getLiveNotifications(null, fetchingMissing, timelineParams, null);
|
getLiveNotifications(null, fetchingMissing, timelineParams, null);
|
||||||
} else {
|
} else {
|
||||||
|
initialNotifications = notificationsCached;
|
||||||
initializeNotificationView(notificationsCached);
|
initializeNotificationView(notificationsCached);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -380,7 +398,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
private void getLiveNotifications(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, Notification notificationToUpdate) {
|
private void getLiveNotifications(FragmentMastodonTimeline.DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, Notification notificationToUpdate) {
|
||||||
if (direction == null) {
|
if (direction == null) {
|
||||||
notificationsVM.getNotifications(notificationList, timelineParams)
|
notificationsVM.getNotifications(notificationList, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), this::initializeNotificationView);
|
.observe(getViewLifecycleOwner(), notifications -> {
|
||||||
|
initialNotifications = notifications;
|
||||||
|
initializeNotificationView(notifications);
|
||||||
|
});
|
||||||
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
} else if (direction == FragmentMastodonTimeline.DIRECTION.BOTTOM) {
|
||||||
notificationsVM.getNotifications(notificationList, timelineParams)
|
notificationsVM.getNotifications(notificationList, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), notificationsBottom -> dealWithPagination(notificationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing, notificationToUpdate));
|
.observe(getViewLifecycleOwner(), notificationsBottom -> dealWithPagination(notificationsBottom, FragmentMastodonTimeline.DIRECTION.BOTTOM, fetchingMissing, notificationToUpdate));
|
||||||
|
|
Loading…
Reference in a new issue