From cbd1332213d01c55a5df489188bde04832dfb8c0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 11 Jul 2023 17:08:42 +0200 Subject: [PATCH] Pass first message --- .../android/mastodon/activities/TimelineActivity.java | 8 +++++++- .../android/mastodon/client/entities/api/Status.java | 1 + .../android/mastodon/client/entities/lemmy/LemmyPost.java | 7 +++++-- .../fedilab/android/mastodon/ui/drawer/StatusAdapter.java | 6 +++--- .../ui/fragment/timeline/FragmentMastodonTimeline.java | 6 +++++- .../android/mastodon/viewmodel/mastodon/TimelinesVM.java | 1 + 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java index b0431973..6686f207 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull; import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityTimelineBinding; +import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.helper.Helper; @@ -45,19 +46,24 @@ public class TimelineActivity extends BaseBarActivity { Timeline.TimeLineEnum timelineType = null; String lemmy_post_id = null; PinnedTimeline pinnedTimeline = null; + Status status = null; if (b != null) { timelineType = (Timeline.TimeLineEnum) b.get(Helper.ARG_TIMELINE_TYPE); lemmy_post_id = b.getString(Helper.ARG_LEMMY_POST_ID, null); pinnedTimeline = (PinnedTimeline) b.getSerializable(Helper.ARG_REMOTE_INSTANCE); + status = (Status) b.getSerializable(Helper.ARG_STATUS); } if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) { - setTitle(pinnedTimeline.remoteInstance.displayName); + setTitle(pinnedTimeline.remoteInstance.host); } FragmentMastodonTimeline fragmentMastodonTimeline = new FragmentMastodonTimeline(); Bundle bundle = new Bundle(); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, timelineType); bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinnedTimeline); bundle.putSerializable(Helper.ARG_LEMMY_POST_ID, lemmy_post_id); + if (status != null) { + bundle.putSerializable(Helper.ARG_STATUS, status); + } fragmentMastodonTimeline.setArguments(bundle); getSupportFragmentManager().beginTransaction() diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java index e81d537f..5dadc381 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java @@ -139,6 +139,7 @@ public class Status implements Serializable, Cloneable { public transient Spannable contentSpoilerSpan; public transient Spannable contentTranslateSpan; public transient MathJaxView mathJaxView; + public String lemmy_post_id; @Override public boolean equals(@Nullable Object obj) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/lemmy/LemmyPost.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/lemmy/LemmyPost.java index b63a9f21..122e6e3b 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/lemmy/LemmyPost.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/lemmy/LemmyPost.java @@ -33,8 +33,8 @@ public class LemmyPost implements Serializable { public Comment comment; @SerializedName("creator") public Creator creator; - @SerializedName("community") - public Community community; + /*@SerializedName("community") + public Community community;*/ @SerializedName("counts") public Counts counts; @SerializedName("creator_banned_from_community") @@ -63,6 +63,9 @@ public class LemmyPost implements Serializable { status.id = lemmyPost.comment == null ? lemmyPost.post.id : lemmyPost.comment.id; if (lemmyPost.comment != null) { status.in_reply_to_id = lemmyPost.comment.post_id; + status.lemmy_post_id = null; + } else { + status.lemmy_post_id = lemmyPost.post.id; } status.content = lemmyPost.comment == null ? lemmyPost.post.name : lemmyPost.comment.content; status.visibility = "public"; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index b5d9c408..a7d92830 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -1995,15 +1995,15 @@ public class StatusAdapter extends RecyclerView.Adapter } else { if (remote) { //Lemmy main post that should open Lemmy threads - if (adapter instanceof StatusAdapter && ((StatusAdapter) adapter).type == RemoteInstance.InstanceType.LEMMY) { + if (adapter instanceof StatusAdapter && ((StatusAdapter) adapter).type == RemoteInstance.InstanceType.LEMMY && status.lemmy_post_id != null) { Bundle bundle = new Bundle(); bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, ((StatusAdapter) adapter).pinnedTimeline); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE); - bundle.putString(Helper.ARG_LEMMY_POST_ID, status.id); + bundle.putString(Helper.ARG_LEMMY_POST_ID, status.lemmy_post_id); + bundle.putSerializable(Helper.ARG_STATUS, status); Intent intent = new Intent(context, TimelineActivity.class); intent.putExtras(bundle); context.startActivity(intent); - } //Classic other cases for remote instances that will search the remote context else if (!(context instanceof ContextActivity)) { //We are not already checking a remote conversation Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java index 20b69fed..b0a0cd7e 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -81,7 +81,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. private AccountsVM accountsVM; private boolean flagLoading; private String search, searchCache; - private Status statusReport; + private Status statusReport, initialStatus /*Used to put a message at the top*/; private String max_id, min_id, min_id_fetch_more, max_id_fetch_more; private Integer offset; private StatusAdapter statusAdapter; @@ -414,6 +414,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. viewModelKey = getArguments().getString(Helper.ARG_VIEW_MODEL_KEY, ""); minified = getArguments().getBoolean(Helper.ARG_MINIFIED, false); statusReport = (Status) getArguments().getSerializable(Helper.ARG_STATUS_REPORT); + initialStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS); } @@ -615,6 +616,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. if (statusReport != null) { timelineStatuses.add(statusReport); } + if (initialStatus != null) { + timelineStatuses.add(initialStatus); + } timelineStatuses.addAll(statuses.statuses); if (max_id == null || (statuses.pagination.max_id != null && Helper.compareTo(statuses.pagination.max_id, max_id) < 0) || timelineType.getValue().startsWith("TREND_")) { max_id = statuses.pagination.max_id; diff --git a/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/TimelinesVM.java index a6e1849a..3239e6fa 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/TimelinesVM.java @@ -336,6 +336,7 @@ public class TimelinesVM extends AndroidViewModel { return statusesMutableLiveData; } + /** * Public timeline for Lemmy *