From 1f4611bc4ed8ba298baaf43a0d2e8fa5381bea76 Mon Sep 17 00:00:00 2001 From: Grishka Date: Mon, 7 Feb 2022 15:44:00 +0300 Subject: [PATCH] Trending statuses --- .../requests/trends/GetTrendingStatuses.java | 20 +++++++++++++++++ .../android/fragments/SearchFragment.java | 22 ++++++++++++------- 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/api/requests/trends/GetTrendingStatuses.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/trends/GetTrendingStatuses.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/trends/GetTrendingStatuses.java new file mode 100644 index 00000000..7c947954 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/trends/GetTrendingStatuses.java @@ -0,0 +1,20 @@ +package org.joinmastodon.android.api.requests.trends; + +import com.google.gson.reflect.TypeToken; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.Status; + +import java.util.List; + +public class GetTrendingStatuses extends MastodonAPIRequest>{ + public GetTrendingStatuses(String maxID, String minID, int limit){ + super(HttpMethod.GET, "/trends/statuses", new TypeToken<>(){}); + if(maxID!=null) + addQueryParameter("max_id", maxID); + if(minID!=null) + addQueryParameter("min_id", minID); + if(limit>0) + addQueryParameter("limit", ""+limit); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SearchFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SearchFragment.java index cde339c4..6137a86c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SearchFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SearchFragment.java @@ -1,15 +1,21 @@ package org.joinmastodon.android.fragments; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; +import org.joinmastodon.android.api.requests.trends.GetTrendingStatuses; +import org.joinmastodon.android.model.Status; -import me.grishka.appkit.fragments.ToolbarFragment; +import java.util.List; -public class SearchFragment extends ToolbarFragment{ +import me.grishka.appkit.api.SimpleCallback; + +public class SearchFragment extends StatusListFragment{ @Override - public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ - return new View(getActivity()); + protected void doLoadData(int offset, int count){ + currentRequest=new GetTrendingStatuses(offset>0 ? getMaxID() : null, null, count) + .setCallback(new SimpleCallback<>(this){ + @Override + public void onSuccess(List result){ + onDataLoaded(result, !result.isEmpty()); + } + }).exec(accountID); } }