Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
add federation tab and change tab order
Browse files Browse the repository at this point in the history
  • Loading branch information
sk22 committed May 2, 2022
1 parent 5562bf9 commit 318d271
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
private DiscoverAccountsFragment accountsFragment;
private SearchFragment searchFragment;
private LocalTimelineFragment localTimelineFragment;
private FederatedTimelineFragment federatedTimelineFragment;

private String accountID;
private Runnable searchDebouncer=this::onSearchChangedDebounced;
Expand All @@ -72,15 +73,16 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
tabLayout=view.findViewById(R.id.tabbar);
pager=view.findViewById(R.id.pager);

tabViews=new FrameLayout[5];
tabViews=new FrameLayout[6];
for(int i=0;i<tabViews.length;i++){
FrameLayout tabView=new FrameLayout(getActivity());
tabView.setId(switch(i){
case 0 -> R.id.discover_posts;
case 1 -> R.id.discover_hashtags;
case 2 -> R.id.discover_news;
case 3 -> R.id.discover_local_timeline;
case 4 -> R.id.discover_users;
case 0 -> R.id.discover_local_timeline;
case 1 -> R.id.discover_federated_timeline;
case 2 -> R.id.discover_hashtags;
case 3 -> R.id.discover_posts;
case 4 -> R.id.discover_news;
case 5 -> R.id.discover_users;
default -> throw new IllegalStateException("Unexpected value: "+i);
});
tabView.setVisibility(View.GONE);
Expand All @@ -106,7 +108,7 @@ public void onPageSelected(int position){
}
});

if(postsFragment==null){
if(localTimelineFragment==null){
Bundle args=new Bundle();
args.putString("account", accountID);
args.putBoolean("__is_tab", true);
Expand All @@ -126,9 +128,13 @@ public void onPageSelected(int position){
localTimelineFragment=new LocalTimelineFragment();
localTimelineFragment.setArguments(args);

federatedTimelineFragment=new FederatedTimelineFragment();
federatedTimelineFragment.setArguments(args);

getChildFragmentManager().beginTransaction()
.add(R.id.discover_posts, postsFragment)
.add(R.id.discover_local_timeline, localTimelineFragment)
.add(R.id.discover_federated_timeline, federatedTimelineFragment)
.add(R.id.discover_hashtags, hashtagsFragment)
.add(R.id.discover_news, newsFragment)
.add(R.id.discover_users, accountsFragment)
Expand All @@ -139,11 +145,12 @@ public void onPageSelected(int position){
@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.local_timeline;
case 4 -> R.string.for_you;
case 0 -> R.string.local_timeline;
case 1 -> R.string.federated_timeline;
case 2 -> R.string.hashtags;
case 3 -> R.string.posts;
case 4 -> R.string.news;
case 5 -> R.string.for_you;
default -> throw new IllegalStateException("Unexpected value: "+position);
});
tab.view.textView.setAllCaps(true);
Expand Down Expand Up @@ -217,8 +224,8 @@ public void scrollToTop(){
}

public void loadData(){
if(postsFragment!=null && !postsFragment.loaded && !postsFragment.dataLoading)
postsFragment.loadData();
if(localTimelineFragment!=null && !localTimelineFragment.loaded && !localTimelineFragment.dataLoading)
localTimelineFragment.loadData();
}

private void onSearchEditFocusChanged(View v, boolean hasFocus){
Expand Down Expand Up @@ -254,11 +261,12 @@ protected void onHidden(){

private Fragment getFragmentForPage(int page){
return switch(page){
case 0 -> postsFragment;
case 1 -> hashtagsFragment;
case 2 -> newsFragment;
case 3 -> localTimelineFragment;
case 4 -> accountsFragment;
case 0 -> localTimelineFragment;
case 1 -> federatedTimelineFragment;
case 2 -> hashtagsFragment;
case 3 -> postsFragment;
case 4 -> newsFragment;
case 5 -> accountsFragment;
default -> throw new IllegalStateException("Unexpected value: "+page);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.joinmastodon.android.fragments.discover;

import android.os.Bundle;
import android.view.View;

import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline;
import org.joinmastodon.android.fragments.StatusListFragment;
import org.joinmastodon.android.model.Filter;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper;
import org.joinmastodon.android.utils.StatusFilterPredicate;

import java.util.List;
import java.util.stream.Collectors;

import me.grishka.appkit.api.SimpleCallback;

public class FederatedTimelineFragment extends StatusListFragment{
private DiscoverInfoBannerHelper bannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.FEDERATED_TIMELINE);
private String maxID;

@Override
protected void doLoadData(int offset, int count){
currentRequest=new GetPublicTimeline(false, false, refreshing ? null : maxID, count)
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(List<Status> result){
if(!result.isEmpty())
maxID=result.get(result.size()-1).id;
onDataLoaded(result.stream().filter(new StatusFilterPredicate(accountID, Filter.FilterContext.PUBLIC)).collect(Collectors.toList()), !result.isEmpty());
}
})
.exec(accountID);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
bannerHelper.maybeAddBanner(contentWrap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void maybeAddBanner(FrameLayout view){
case TRENDING_HASHTAGS -> R.string.trending_hashtags_info_banner;
case TRENDING_LINKS -> R.string.trending_links_info_banner;
case LOCAL_TIMELINE -> R.string.local_timeline_info_banner;
case FEDERATED_TIMELINE -> R.string.federated_timeline_info_banner;
});
}
}
Expand All @@ -59,6 +60,7 @@ public enum BannerType{
TRENDING_HASHTAGS,
TRENDING_LINKS,
LOCAL_TIMELINE,
FEDERATED_TIMELINE,
// ACCOUNTS
}
}
1 change: 1 addition & 0 deletions mastodon/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<item name="discover_news" type="id"/>
<item name="discover_users" type="id"/>
<item name="discover_local_timeline" type="id"/>
<item name="discover_federated_timeline" type="id"/>

<item name="notifications_all" type="id"/>
<item name="notifications_mentions" type="id"/>
Expand Down
3 changes: 3 additions & 0 deletions mastodon/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<string name="alt_text_subtitle">Alt text describes your photos for people with low or no vision. Try to only include enough detail to understand the context.</string>
<string name="alt_text_hint">e.g. A dog looking around suspiciously with narrowed eyes at the camera.</string>
<string name="visibility_public">Public</string>
<string name="visibility_unlisted">Unlisted</string>
<string name="visibility_followers_only">Followers only</string>
<string name="visibility_private">Only people I mention</string>
<string name="search_all">All</string>
Expand Down Expand Up @@ -307,10 +308,12 @@
<string name="downloading">Downloading…</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="federated_timeline">Federation</string>
<string name="trending_posts_info_banner">These are the posts gaining traction in your corner of Mastodon.</string>
<string name="trending_hashtags_info_banner">These are the hashtags gaining traction in your corner of Mastodon.</string>
<string name="trending_links_info_banner">These are the news stories being shared the most in your corner of Mastodon.</string>
<string name="local_timeline_info_banner">These are the most recent posts by the people who use the same Mastodon server as you.</string>
<string name="federated_timeline_info_banner">These are the most recent posts by the people in your federation.</string>
<string name="dismiss">Dismiss</string>
<string name="see_new_posts">See new posts</string>
<string name="load_missing_posts">Load missing posts</string>
Expand Down

0 comments on commit 318d271

Please sign in to comment.