From e0b8b60fed0dbd1cdb02867d4001ab5a81a8c543 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 1 Mar 2025 16:06:39 +0100 Subject: [PATCH] Fix issue #1130 - Follow Pixelfed instance from the discover timeline --- app/build.gradle | 2 +- .../activities/ReorderTimelinesActivity.java | 2 +- .../endpoints/MastodonTimelinesService.java | 5 ++ .../endpoints/PixelfedTimelinesService.java | 32 +++++++ .../timeline/FragmentMastodonTimeline.java | 7 +- .../viewmodel/mastodon/TimelinesVM.java | 30 +++++++ .../mastodon/layout/popup_search_instance.xml | 90 ++++++++++--------- 7 files changed, 123 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/app/fedilab/android/mastodon/client/endpoints/PixelfedTimelinesService.java diff --git a/app/build.gradle b/app/build.gradle index 96a077ed..df864493 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -100,7 +100,7 @@ allprojects { } } dependencies { - implementation 'org.unifiedpush.android:connector:3.0.4' + implementation 'org.unifiedpush.android:connector:3.0.5' playstoreImplementation('org.unifiedpush.android:embedded-fcm-distributor:3.0.0') 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 a63b2fd4..c611418f 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 @@ -200,7 +200,7 @@ public class ReorderTimelinesActivity extends BaseBarActivity implements OnStart } else if (popupSearchInstanceBinding.setAttachmentGroup.getCheckedRadioButtonId() == R.id.peertube_instance) { url = "https://" + instanceName + "/api/v1/videos/"; } else if (popupSearchInstanceBinding.setAttachmentGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) { - url = "https://" + instanceName + "/api/v1/timelines/public"; + url = "https://" + instanceName + "/api/pixelfed/v2/discover/posts/trending?range=daily"; } else if (popupSearchInstanceBinding.setAttachmentGroup.getCheckedRadioButtonId() == R.id.misskey_instance) { url = "https://" + instanceName + "/api/notes/local-timeline"; getCall = false; 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 f12b0c43..1722eb79 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 @@ -231,6 +231,11 @@ public interface MastodonTimelinesService { Call> getMisskey(@Body MisskeyNote.MisskeyParams params); + @GET("discover/posts/trending") + Call> getPixelDiscoverTrending( + @Query("range") String range + ); + @GET("api/v3/post/list?sort=New") Call getLemmyMain(@Query("limit") Integer limit, @Query("page") String page); diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/PixelfedTimelinesService.java b/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/PixelfedTimelinesService.java new file mode 100644 index 00000000..91144266 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/PixelfedTimelinesService.java @@ -0,0 +1,32 @@ +package app.fedilab.android.mastodon.client.endpoints; +/* Copyright 2025 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + +import java.util.List; + +import app.fedilab.android.mastodon.client.entities.api.Status; +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface PixelfedTimelinesService { + + //Public timelines + @GET("discover/posts/trending") + Call> getTrending( + @Query("range") String range + ); + +} 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 a8406bea..b6131c3e 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 @@ -1127,7 +1127,12 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } }); } - } else { //Other remote timelines + } else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.PIXELFED) { + if (direction == null) { + timelinesVM.getPixelfedDiscoverTrending(remoteInstance) + .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); + } + }else { //Other remote timelines routeCommon(direction, fetchingMissing, fetchStatus); } } else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE 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 169a1cb1..72c81c72 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 @@ -39,6 +39,7 @@ import java.util.List; import app.fedilab.android.R; import app.fedilab.android.activities.MainActivity; import app.fedilab.android.mastodon.client.endpoints.MastodonTimelinesService; +import app.fedilab.android.mastodon.client.endpoints.PixelfedTimelinesService; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Conversation; import app.fedilab.android.mastodon.client.entities.api.Conversations; @@ -330,6 +331,35 @@ public class TimelinesVM extends AndroidViewModel { return statusesMutableLiveData; } + /** + * Public discover timeline for Pixelfed + * + * @param instance String Pixelfed instance + * @return {@link LiveData} containing a {@link Statuses} + */ + public LiveData getPixelfedDiscoverTrending(String instance) { + statusesMutableLiveData = new MutableLiveData<>(); + MastodonTimelinesService mastodonTimelinesService = initInstanceOnly(instance+"/api/pixelfed/v2/"); + new Thread(() -> { + Statuses statuses = new Statuses(); + Call> timelineCall = mastodonTimelinesService.getPixelDiscoverTrending("daily"); + if (timelineCall != null) { + try { + Response> timelineResponse = timelineCall.execute(); + if (timelineResponse.isSuccessful()) { + statuses.statuses = timelineResponse.body(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> statusesMutableLiveData.setValue(statuses); + mainHandler.post(myRunnable); + }).start(); + return statusesMutableLiveData; + } + /** * Public timeline for Lemmy diff --git a/app/src/main/res/layouts/mastodon/layout/popup_search_instance.xml b/app/src/main/res/layouts/mastodon/layout/popup_search_instance.xml index 3fc942d2..4a09646a 100644 --- a/app/src/main/res/layouts/mastodon/layout/popup_search_instance.xml +++ b/app/src/main/res/layouts/mastodon/layout/popup_search_instance.xml @@ -2,63 +2,69 @@ - - - - + + android:orientation="vertical"> - + - + - + - + - + - - + + + + + \ No newline at end of file