Local timeline

This commit is contained in:
Grishka 2022-04-24 13:51:03 +03:00
parent f499444a86
commit 61d537779b
6 changed files with 72 additions and 14 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "org.joinmastodon.android" applicationId "org.joinmastodon.android"
minSdk 23 minSdk 23
targetSdk 31 targetSdk 31
versionCode 30 versionCode 31
versionName "1.0.1" versionName "1.0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -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<List<Status>>{
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+"");
}
}

View File

@ -50,6 +50,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
private DiscoverNewsFragment newsFragment; private DiscoverNewsFragment newsFragment;
private DiscoverAccountsFragment accountsFragment; private DiscoverAccountsFragment accountsFragment;
private SearchFragment searchFragment; private SearchFragment searchFragment;
private LocalTimelineFragment localTimelineFragment;
private String accountID; private String accountID;
private Runnable searchDebouncer=this::onSearchChangedDebounced; private Runnable searchDebouncer=this::onSearchChangedDebounced;
@ -71,14 +72,15 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
tabLayout=view.findViewById(R.id.tabbar); tabLayout=view.findViewById(R.id.tabbar);
pager=view.findViewById(R.id.pager); pager=view.findViewById(R.id.pager);
tabViews=new FrameLayout[4]; tabViews=new FrameLayout[5];
for(int i=0;i<tabViews.length;i++){ for(int i=0;i<tabViews.length;i++){
FrameLayout tabView=new FrameLayout(getActivity()); FrameLayout tabView=new FrameLayout(getActivity());
tabView.setId(switch(i){ tabView.setId(switch(i){
case 0 -> R.id.discover_posts; case 0 -> R.id.discover_posts;
case 1 -> R.id.discover_hashtags; case 1 -> R.id.discover_local_timeline;
case 2 -> R.id.discover_news; case 2 -> R.id.discover_hashtags;
case 3 -> R.id.discover_users; case 3 -> R.id.discover_news;
case 4 -> R.id.discover_users;
default -> throw new IllegalStateException("Unexpected value: "+i); default -> throw new IllegalStateException("Unexpected value: "+i);
}); });
tabView.setVisibility(View.GONE); tabView.setVisibility(View.GONE);
@ -121,8 +123,12 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
accountsFragment=new DiscoverAccountsFragment(); accountsFragment=new DiscoverAccountsFragment();
accountsFragment.setArguments(args); accountsFragment.setArguments(args);
localTimelineFragment=new LocalTimelineFragment();
localTimelineFragment.setArguments(args);
getChildFragmentManager().beginTransaction() getChildFragmentManager().beginTransaction()
.add(R.id.discover_posts, postsFragment) .add(R.id.discover_posts, postsFragment)
.add(R.id.discover_local_timeline, localTimelineFragment)
.add(R.id.discover_hashtags, hashtagsFragment) .add(R.id.discover_hashtags, hashtagsFragment)
.add(R.id.discover_news, newsFragment) .add(R.id.discover_news, newsFragment)
.add(R.id.discover_users, accountsFragment) .add(R.id.discover_users, accountsFragment)
@ -133,10 +139,11 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
@Override @Override
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position){ public void onConfigureTab(@NonNull TabLayout.Tab tab, int position){
tab.setText(switch(position){ tab.setText(switch(position){
case 0 -> R.string.posts; case 0 -> R.string.trending_posts;
case 1 -> R.string.hashtags; case 1 -> R.string.local_timeline;
case 2 -> R.string.news; case 2 -> R.string.hashtags;
case 3 -> R.string.for_you; case 3 -> R.string.news;
case 4 -> R.string.for_you;
default -> throw new IllegalStateException("Unexpected value: "+position); default -> throw new IllegalStateException("Unexpected value: "+position);
}); });
tab.view.textView.setAllCaps(true); tab.view.textView.setAllCaps(true);
@ -248,9 +255,10 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
private Fragment getFragmentForPage(int page){ private Fragment getFragmentForPage(int page){
return switch(page){ return switch(page){
case 0 -> postsFragment; case 0 -> postsFragment;
case 1 -> hashtagsFragment; case 1 -> localTimelineFragment;
case 2 -> newsFragment; case 2 -> hashtagsFragment;
case 3 -> accountsFragment; case 3 -> newsFragment;
case 4 -> accountsFragment;
default -> throw new IllegalStateException("Unexpected value: "+page); default -> throw new IllegalStateException("Unexpected value: "+page);
}; };
} }
@ -299,7 +307,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
@Override @Override
public int getItemCount(){ public int getItemCount(){
return 4; return tabViews.length;
} }
@Override @Override

View File

@ -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<Status> result){
onDataLoaded(result, !result.isEmpty());
}
})
.exec(accountID);
}
}

View File

@ -11,6 +11,7 @@
<item name="discover_hashtags" type="id"/> <item name="discover_hashtags" type="id"/>
<item name="discover_news" type="id"/> <item name="discover_news" type="id"/>
<item name="discover_users" type="id"/> <item name="discover_users" type="id"/>
<item name="discover_local_timeline" type="id"/>
<item name="notifications_all" type="id"/> <item name="notifications_all" type="id"/>
<item name="notifications_mentions" type="id"/> <item name="notifications_mentions" type="id"/>

View File

@ -306,4 +306,6 @@
<string name="file_saved">File saved</string> <string name="file_saved">File saved</string>
<string name="downloading">Downloading…</string> <string name="downloading">Downloading…</string>
<string name="no_app_to_handle_action">There\'s no app to handle this action</string> <string name="no_app_to_handle_action">There\'s no app to handle this action</string>
<string name="local_timeline">Community</string>
<string name="trending_posts">Trending</string>
</resources> </resources>