diff --git a/mastodon/build.gradle b/mastodon/build.gradle index b82a70876..eddc40750 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 31 - versionCode 30 - versionName "1.0.1" + versionCode 31 + versionName "1.0.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/timelines/GetPublicTimeline.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/timelines/GetPublicTimeline.java new file mode 100644 index 000000000..6723c18b9 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/timelines/GetPublicTimeline.java @@ -0,0 +1,24 @@ +package org.joinmastodon.android.api.requests.timelines; + +import android.text.TextUtils; + +import com.google.gson.reflect.TypeToken; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.Status; + +import java.util.List; + +public class GetPublicTimeline extends MastodonAPIRequest>{ + public GetPublicTimeline(boolean local, boolean remote, String maxID, int limit){ + super(HttpMethod.GET, "/timelines/public", new TypeToken<>(){}); + if(local) + addQueryParameter("local", "true"); + if(remote) + addQueryParameter("remote", "true"); + if(!TextUtils.isEmpty(maxID)) + addQueryParameter("max_id", maxID); + if(limit>0) + addQueryParameter("limit", limit+""); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java index 1dc9978b5..e3a616aec 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java @@ -50,6 +50,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, private DiscoverNewsFragment newsFragment; private DiscoverAccountsFragment accountsFragment; private SearchFragment searchFragment; + private LocalTimelineFragment localTimelineFragment; private String accountID; private Runnable searchDebouncer=this::onSearchChangedDebounced; @@ -71,14 +72,15 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, tabLayout=view.findViewById(R.id.tabbar); pager=view.findViewById(R.id.pager); - tabViews=new FrameLayout[4]; + tabViews=new FrameLayout[5]; for(int i=0;i R.id.discover_posts; - case 1 -> R.id.discover_hashtags; - case 2 -> R.id.discover_news; - case 3 -> R.id.discover_users; + case 1 -> R.id.discover_local_timeline; + case 2 -> R.id.discover_hashtags; + case 3 -> R.id.discover_news; + case 4 -> R.id.discover_users; default -> throw new IllegalStateException("Unexpected value: "+i); }); tabView.setVisibility(View.GONE); @@ -121,8 +123,12 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, accountsFragment=new DiscoverAccountsFragment(); accountsFragment.setArguments(args); + localTimelineFragment=new LocalTimelineFragment(); + localTimelineFragment.setArguments(args); + getChildFragmentManager().beginTransaction() .add(R.id.discover_posts, postsFragment) + .add(R.id.discover_local_timeline, localTimelineFragment) .add(R.id.discover_hashtags, hashtagsFragment) .add(R.id.discover_news, newsFragment) .add(R.id.discover_users, accountsFragment) @@ -133,10 +139,11 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, @Override public void onConfigureTab(@NonNull TabLayout.Tab tab, int position){ tab.setText(switch(position){ - case 0 -> R.string.posts; - case 1 -> R.string.hashtags; - case 2 -> R.string.news; - case 3 -> R.string.for_you; + case 0 -> R.string.trending_posts; + case 1 -> R.string.local_timeline; + case 2 -> R.string.hashtags; + case 3 -> R.string.news; + case 4 -> R.string.for_you; default -> throw new IllegalStateException("Unexpected value: "+position); }); tab.view.textView.setAllCaps(true); @@ -248,9 +255,10 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, private Fragment getFragmentForPage(int page){ return switch(page){ case 0 -> postsFragment; - case 1 -> hashtagsFragment; - case 2 -> newsFragment; - case 3 -> accountsFragment; + case 1 -> localTimelineFragment; + case 2 -> hashtagsFragment; + case 3 -> newsFragment; + case 4 -> accountsFragment; default -> throw new IllegalStateException("Unexpected value: "+page); }; } @@ -299,7 +307,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, @Override public int getItemCount(){ - return 4; + return tabViews.length; } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java new file mode 100644 index 000000000..830651f83 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java @@ -0,0 +1,23 @@ +package org.joinmastodon.android.fragments.discover; + +import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline; +import org.joinmastodon.android.fragments.StatusListFragment; +import org.joinmastodon.android.model.Status; + +import java.util.List; + +import me.grishka.appkit.api.SimpleCallback; + +public class LocalTimelineFragment extends StatusListFragment{ + @Override + protected void doLoadData(int offset, int count){ + currentRequest=new GetPublicTimeline(true, false, refreshing ? null : getMaxID(), count) + .setCallback(new SimpleCallback<>(this){ + @Override + public void onSuccess(List result){ + onDataLoaded(result, !result.isEmpty()); + } + }) + .exec(accountID); + } +} diff --git a/mastodon/src/main/res/values/ids.xml b/mastodon/src/main/res/values/ids.xml index 094823ed6..6545f9cad 100644 --- a/mastodon/src/main/res/values/ids.xml +++ b/mastodon/src/main/res/values/ids.xml @@ -11,6 +11,7 @@ + diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index 42d80cc86..12bb45646 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -306,4 +306,6 @@ File saved Downloading… There\'s no app to handle this action + Community + Trending \ No newline at end of file