Add info banner to the new local timeline

This commit is contained in:
Grishka 2023-10-28 18:56:15 +03:00
parent fe0e854e72
commit edb64fff2e
2 changed files with 42 additions and 1 deletions

View File

@ -43,6 +43,7 @@ import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.TimelineMarkers;
import org.joinmastodon.android.ui.displayitems.GapStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper;
import org.joinmastodon.android.ui.viewcontrollers.HomeTimelineMenuController;
import org.joinmastodon.android.ui.viewcontrollers.ToolbarDropdownMenuController;
import org.joinmastodon.android.ui.views.FixedAspectRatioImageView;
@ -61,6 +62,7 @@ import me.grishka.appkit.api.Callback;
import me.grishka.appkit.api.ErrorResponse;
import me.grishka.appkit.api.SimpleCallback;
import me.grishka.appkit.utils.CubicBezierInterpolator;
import me.grishka.appkit.utils.MergeRecyclerAdapter;
import me.grishka.appkit.utils.V;
public class HomeTimelineFragment extends StatusListFragment implements ToolbarDropdownMenuController.HostFragment{
@ -77,6 +79,8 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
private List<FollowList> lists=List.of();
private ListMode listMode=ListMode.FOLLOWING;
private FollowList currentList;
private MergeRecyclerAdapter mergeAdapter;
private DiscoverInfoBannerHelper localTimelineBannerHelper;
private String maxID;
private String lastSavedMarkerID;
@ -85,6 +89,12 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
setListLayoutId(R.layout.fragment_timeline);
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
localTimelineBannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.LOCAL_TIMELINE, accountID);
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
@ -619,6 +629,25 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
invalidateOptionsMenu();
}
@Override
protected RecyclerView.Adapter getAdapter(){
mergeAdapter=new MergeRecyclerAdapter();
mergeAdapter.addAdapter(super.getAdapter());
return mergeAdapter;
}
@Override
protected void onDataLoaded(List<Status> d, boolean more){
if(refreshing){
if(listMode==ListMode.LOCAL){
localTimelineBannerHelper.maybeAddBanner(list, mergeAdapter);
}else{
localTimelineBannerHelper.removeBanner(mergeAdapter);
}
}
super.onDataLoaded(d, more);
}
private String getCurrentListTitle(){
return switch(listMode){
case FOLLOWING -> getString(R.string.timeline_following);

View File

@ -22,6 +22,8 @@ public class DiscoverInfoBannerHelper{
private final BannerType type;
private final String accountID;
private static EnumSet<BannerType> bannerTypesToShow=EnumSet.noneOf(BannerType.class);
private SingleViewRecyclerAdapter bannerAdapter;
private boolean added;
static{
for(BannerType t:BannerType.values()){
@ -40,6 +42,8 @@ public class DiscoverInfoBannerHelper{
}
public void maybeAddBanner(RecyclerView list, MergeRecyclerAdapter adapter){
if(added)
return;
if(bannerTypesToShow.contains(type)){
banner=((Activity)list.getContext()).getLayoutInflater().inflate(R.layout.discover_info_banner, list, false);
TextView text=banner.findViewById(R.id.banner_text);
@ -56,7 +60,8 @@ public class DiscoverInfoBannerHelper{
case LOCAL_TIMELINE -> R.drawable.ic_stream_24px;
case ACCOUNTS -> R.drawable.ic_group_add_24px;
});
adapter.addAdapter(new SingleViewRecyclerAdapter(banner));
adapter.addAdapter(0, bannerAdapter=new SingleViewRecyclerAdapter(banner));
added=true;
}
}
@ -65,6 +70,13 @@ public class DiscoverInfoBannerHelper{
// bannerTypesToShow is not updated here on purpose so the banner keeps showing until the app is relaunched
}
public void removeBanner(MergeRecyclerAdapter adapter){
if(bannerAdapter!=null){
adapter.removeAdapter(bannerAdapter);
added=false;
}
}
public static void reset(){
SharedPreferences prefs=getPrefs();
SharedPreferences.Editor e=prefs.edit();