Hide news discovery on Iceshrimp
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.joinmastodon.android.fragments.discover;
|
package org.joinmastodon.android.fragments.discover;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -28,6 +29,9 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.viewpager2.widget.ViewPager2;
|
import androidx.viewpager2.widget.ViewPager2;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import me.grishka.appkit.Nav;
|
import me.grishka.appkit.Nav;
|
||||||
import me.grishka.appkit.fragments.AppKitFragment;
|
import me.grishka.appkit.fragments.AppKitFragment;
|
||||||
import me.grishka.appkit.fragments.BaseRecyclerFragment;
|
import me.grishka.appkit.fragments.BaseRecyclerFragment;
|
||||||
@@ -57,6 +61,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
|
|||||||
private String currentQuery;
|
private String currentQuery;
|
||||||
|
|
||||||
private boolean disableDiscover;
|
private boolean disableDiscover;
|
||||||
|
private boolean isIceshrimp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState){
|
public void onCreate(Bundle savedInstanceState){
|
||||||
@@ -75,13 +80,17 @@ 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];
|
Optional<Instance> instance=AccountSessionManager.get(accountID).getInstance();
|
||||||
|
disableDiscover=instance.map(Instance::isAkkoma).orElse(false);
|
||||||
|
isIceshrimp=instance.map(Instance::isIceshrimp).orElse(false);
|
||||||
|
|
||||||
|
tabViews=new FrameLayout[isIceshrimp ? 3 : 4];
|
||||||
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_hashtags;
|
case 0 -> R.id.discover_hashtags;
|
||||||
case 1 -> R.id.discover_posts;
|
case 1 -> R.id.discover_posts;
|
||||||
case 2 -> R.id.discover_news;
|
case 2 -> isIceshrimp ? R.id.discover_users : R.id.discover_news;
|
||||||
case 3 -> R.id.discover_users;
|
case 3 -> R.id.discover_users;
|
||||||
default -> throw new IllegalStateException("Unexpected value: "+i);
|
default -> throw new IllegalStateException("Unexpected value: "+i);
|
||||||
});
|
});
|
||||||
@@ -123,12 +132,15 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
|
|||||||
accountsFragment=new DiscoverAccountsFragment();
|
accountsFragment=new DiscoverAccountsFragment();
|
||||||
accountsFragment.setArguments(args);
|
accountsFragment.setArguments(args);
|
||||||
|
|
||||||
getChildFragmentManager().beginTransaction()
|
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||||
.add(R.id.discover_hashtags, hashtagsFragment)
|
transaction
|
||||||
.add(R.id.discover_posts, postsFragment)
|
.add(R.id.discover_hashtags, hashtagsFragment)
|
||||||
.add(R.id.discover_news, newsFragment)
|
.add(R.id.discover_posts, postsFragment);
|
||||||
.add(R.id.discover_users, accountsFragment)
|
if(!isIceshrimp)
|
||||||
.commit();
|
transaction.add(R.id.discover_news, newsFragment);
|
||||||
|
transaction
|
||||||
|
.add(R.id.discover_users, accountsFragment)
|
||||||
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
tabLayoutMediator=new TabLayoutMediator(tabLayout, pager, new TabLayoutMediator.TabConfigurationStrategy(){
|
tabLayoutMediator=new TabLayoutMediator(tabLayout, pager, new TabLayoutMediator.TabConfigurationStrategy(){
|
||||||
@@ -137,7 +149,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
|
|||||||
tab.setText(switch(position){
|
tab.setText(switch(position){
|
||||||
case 0 -> R.string.hashtags;
|
case 0 -> R.string.hashtags;
|
||||||
case 1 -> R.string.posts;
|
case 1 -> R.string.posts;
|
||||||
case 2 -> R.string.news;
|
case 2 -> isIceshrimp ? R.string.for_you : R.string.news;
|
||||||
case 3 -> R.string.for_you;
|
case 3 -> R.string.for_you;
|
||||||
default -> throw new IllegalStateException("Unexpected value: "+position);
|
default -> throw new IllegalStateException("Unexpected value: "+position);
|
||||||
});
|
});
|
||||||
@@ -157,7 +169,6 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
disableDiscover=AccountSessionManager.get(accountID).getInstance().map(Instance::isAkkoma).orElse(false);
|
|
||||||
searchView=view.findViewById(R.id.search_fragment);
|
searchView=view.findViewById(R.id.search_fragment);
|
||||||
if(searchFragment==null){
|
if(searchFragment==null){
|
||||||
searchFragment=new SearchFragment();
|
searchFragment=new SearchFragment();
|
||||||
@@ -254,7 +265,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop,
|
|||||||
return switch(page){
|
return switch(page){
|
||||||
case 0 -> hashtagsFragment;
|
case 0 -> hashtagsFragment;
|
||||||
case 1 -> postsFragment;
|
case 1 -> postsFragment;
|
||||||
case 2 -> newsFragment;
|
case 2 -> isIceshrimp ? accountsFragment : newsFragment;
|
||||||
case 3 -> accountsFragment;
|
case 3 -> accountsFragment;
|
||||||
default -> throw new IllegalStateException("Unexpected value: "+page);
|
default -> throw new IllegalStateException("Unexpected value: "+page);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user