mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Display lammy main threads
This commit is contained in:
parent
5ca288a04b
commit
58f193e71b
4 changed files with 59 additions and 17 deletions
|
@ -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) {
|
||||
|
|
|
@ -232,11 +232,11 @@ public interface MastodonTimelinesService {
|
|||
|
||||
|
||||
@GET("api/v3/post/list")
|
||||
Call<List<LemmyPost>> getLemmyMain(@Query("limit") Integer limit,
|
||||
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,
|
||||
Call<LemmyPost.LemmyComments> getLemmyThread(@Query("post_id") String post_id,
|
||||
@Query("limit") Integer limit,
|
||||
@Query("page") String page);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue