summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2023-07-08 16:32:02 +0200
committerThomas <tschneider.ac@gmail.com>2023-07-08 16:32:02 +0200
commit58f193e71bfdbd4c8e535af2e9ed583eca162e4e (patch)
tree4315038e4e406e746e8971f31dfa133ddf050b9f
parent5ca288a04bbcf47014b0c29fb774b619fabf353b (diff)
Display lammy main threads
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java1
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonTimelinesService.java10
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/client/entities/lemmy/LemmyPost.java9
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/TimelinesVM.java56
4 files changed, 59 insertions, 17 deletions
diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java
index 7c878b032..5af29524a 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java
@@ -205,7 +205,6 @@ public class ReorderTimelinesActivity extends BaseBarActivity implements OnStart
getCall = false;
} else if (popupSearchInstanceBinding.setAttachmentGroup.getCheckedRadioButtonId() == R.id.lemmy_instance) {
url = "https://" + instanceName + "/api/v3/post/list";
- getCall = false;
} else if (popupSearchInstanceBinding.setAttachmentGroup.getCheckedRadioButtonId() == R.id.gnu_instance) {
url = "https://" + instanceName + "/api/statuses/public_timeline.json";
} else if (popupSearchInstanceBinding.setAttachmentGroup.getCheckedRadioButtonId() == R.id.twitter_accounts) {
diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonTimelinesService.java b/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonTimelinesService.java
index f786199bd..ae4c49c97 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonTimelinesService.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonTimelinesService.java
@@ -232,13 +232,13 @@ public interface MastodonTimelinesService {
@GET("api/v3/post/list")
- Call<List<LemmyPost>> getLemmyMain(@Query("limit") Integer limit,
- @Query("page") String page);
+ Call<LemmyPost.LemmyPosts> getLemmyMain(@Query("limit") Integer limit,
+ @Query("page") String page);
@GET("api/v3/comment/list")
- Call<List<LemmyPost>> getLemmyThread(@Query("post_id") String post_id,
- @Query("limit") Integer limit,
- @Query("page") String page);
+ Call<LemmyPost.LemmyComments> getLemmyThread(@Query("post_id") String post_id,
+ @Query("limit") Integer limit,
+ @Query("page") String page);
//Public timelines for Misskey
@FormUrlEncoded
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 f6020e8de..4e7513260 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
@@ -48,6 +48,15 @@ public class LemmyPost implements Serializable {
@SerializedName("unread_comments")
public int unread_comments;
+ public static class LemmyPosts {
+ @SerializedName("posts")
+ public List<LemmyPost> posts;
+ }
+
+ public static class LemmyComments {
+ @SerializedName("comments")
+ public List<LemmyPost> comments;
+ }
public static Status convert(LemmyPost lemmyPost, String instance) {
Status status = new Status();
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 64abd9725..a6e1849a6 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
@@ -351,30 +351,64 @@ public class TimelinesVM extends AndroidViewModel {
statusesMutableLiveData = new MutableLiveData<>();
new Thread(() -> {
- Call<List<LemmyPost>> publicTlCall;
+ Call<LemmyPost.LemmyPosts> lemmyPostsCall = null;
+ Call<LemmyPost.LemmyComments> lemmyCommentsCall = null;
if (post_id == null) {
- publicTlCall = mastodonTimelinesService.getLemmyMain(limit, page);
+ lemmyPostsCall = mastodonTimelinesService.getLemmyMain(limit, page);
} else {
- publicTlCall = mastodonTimelinesService.getLemmyThread(post_id, limit, page);
+ lemmyCommentsCall = mastodonTimelinesService.getLemmyThread(post_id, limit, page);
}
Statuses statuses = new Statuses();
- if (publicTlCall != null) {
+ if (lemmyPostsCall != null) {
try {
- Response<List<LemmyPost>> publicTlResponse = publicTlCall.execute();
+ Response<LemmyPost.LemmyPosts> publicTlResponse = lemmyPostsCall.execute();
if (publicTlResponse.isSuccessful()) {
- List<LemmyPost> lemmyPostList = publicTlResponse.body();
+ LemmyPost.LemmyPosts lemmyPosts = publicTlResponse.body();
List<Status> statusList = new ArrayList<>();
- if (lemmyPostList != null) {
- for (LemmyPost lemmyPost : lemmyPostList) {
+ if (lemmyPosts != null) {
+ for (LemmyPost lemmyPost : lemmyPosts.posts) {
Status status = LemmyPost.convert(lemmyPost, instance);
statusList.add(status);
}
}
statuses.statuses = TimelineHelper.filterStatus(getApplication(), statusList, Timeline.TimeLineEnum.PUBLIC);
statuses.pagination = new Pagination();
- if (statusList.size() > 0) {
- statuses.pagination.min_id = statusList.get(0).id;
- statuses.pagination.max_id = statusList.get(statusList.size() - 1).id;
+ if (page == null) {
+ statuses.pagination.min_id = "0";
+ statuses.pagination.max_id = "1";
+ } else {
+ int pageInt = Integer.parseInt(page);
+ statuses.pagination.min_id = page;
+ statuses.pagination.max_id = String.valueOf((pageInt + 1));
+
+ }
+
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (lemmyCommentsCall != null) {
+ try {
+ Response<LemmyPost.LemmyComments> publicTlResponse = lemmyCommentsCall.execute();
+ if (publicTlResponse.isSuccessful()) {
+ LemmyPost.LemmyComments lemmyComments = publicTlResponse.body();
+ List<Status> statusList = new ArrayList<>();
+ if (lemmyComments != null) {
+ for (LemmyPost lemmyPost : lemmyComments.comments) {
+ Status status = LemmyPost.convert(lemmyPost, instance);
+ statusList.add(status);
+ }
+ }
+ statuses.statuses = TimelineHelper.filterStatus(getApplication(), statusList, Timeline.TimeLineEnum.PUBLIC);
+ statuses.pagination = new Pagination();
+ if (page == null) {
+ statuses.pagination.min_id = "0";
+ statuses.pagination.max_id = "1";
+ } else {
+ int pageInt = Integer.parseInt(page);
+ statuses.pagination.min_id = page;
+ statuses.pagination.max_id = String.valueOf((pageInt + 1));
}
}