Display lammy main threads

This commit is contained in:
Thomas 2023-07-08 16:32:02 +02:00
parent 5ca288a04b
commit 58f193e71b
4 changed files with 59 additions and 17 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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();

View file

@ -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));
}
}