diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 91fd22aeb..094dc13c1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -16,6 +16,7 @@ import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; +import android.widget.ImageButton; import android.widget.Toolbar; import org.joinmastodon.android.E; @@ -57,6 +58,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; + +import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.fragments.BaseRecyclerFragment; @@ -75,9 +78,15 @@ public abstract class BaseStatusListFragment exten protected HashMap knownAccounts=new HashMap<>(); protected HashMap relationships=new HashMap<>(); protected Rect tmpRect=new Rect(); + protected ImageButton fab; public BaseStatusListFragment(){ super(20); + if (withComposeButton()) setListLayoutId(R.layout.recycler_fragment_with_fab); + } + + protected boolean withComposeButton() { + return false; } @Override @@ -91,6 +100,8 @@ public abstract class BaseStatusListFragment exten setRetainInstance(true); } + + @Override protected RecyclerView.Adapter getAdapter(){ return adapter=new DisplayItemsAdapter(); @@ -314,6 +325,13 @@ public abstract class BaseStatusListFragment exten list.setItemAnimator(new BetterItemAnimator()); ((UsableRecyclerView) list).setIncludeMarginsInItemHitbox(true); updateToolbar(); + + if (withComposeButton()) { + fab = view.findViewById(R.id.fab); + fab.setVisibility(View.VISIBLE); + fab.setOnClickListener(this::onFabClick); + fab.setOnLongClickListener(this::onFabLongClick); + } } @Override @@ -646,6 +664,16 @@ public abstract class BaseStatusListFragment exten currentPhotoViewer.onPause(); } + protected void onFabClick(View v){ + Bundle args=new Bundle(); + args.putString("account", accountID); + Nav.go(getActivity(), ComposeFragment.class, args); + } + + protected boolean onFabLongClick(View v) { + return UiUtils.pickAccountForCompose(getActivity(), accountID); + } + protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter> implements ImageLoaderRecyclerAdapter{ public DisplayItemsAdapter(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/FabStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/FabStatusListFragment.java deleted file mode 100644 index c4443a2c8..000000000 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/FabStatusListFragment.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.joinmastodon.android.fragments; - -import android.content.res.Configuration; -import android.os.Bundle; -import android.view.View; -import android.widget.ImageButton; - -import org.joinmastodon.android.R; -import org.joinmastodon.android.ui.utils.UiUtils; - -import me.grishka.appkit.Nav; - -public abstract class FabStatusListFragment extends StatusListFragment { - protected ImageButton fab; - - public FabStatusListFragment() { - setListLayoutId(R.layout.recycler_fragment_with_fab); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - fab = view.findViewById(R.id.fab); - fab.setOnClickListener(this::onFabClick); - fab.setOnLongClickListener(this::onFabLongClick); - } - - protected void onFabClick(View v){ - Bundle args=new Bundle(); - args.putString("account", accountID); - Nav.go(getActivity(), ComposeFragment.class, args); - } - - protected boolean onFabLongClick(View v) { - return UiUtils.pickAccountForCompose(getActivity(), accountID); - } -} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java index 20587b995..ce95a9731 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java @@ -36,11 +36,11 @@ import me.grishka.appkit.utils.V; public class HashtagTimelineFragment extends PinnableStatusListFragment { private String hashtag; private boolean following; - private ImageButton fab; private MenuItem followButton; - public HashtagTimelineFragment(){ - setListLayoutId(R.layout.recycler_fragment_with_fab); + @Override + protected boolean withComposeButton() { + return true; } @Override @@ -138,14 +138,12 @@ public class HashtagTimelineFragment extends PinnableStatusListFragment { } @Override - public void onViewCreated(View view, Bundle savedInstanceState){ - super.onViewCreated(view, savedInstanceState); - fab=view.findViewById(R.id.fab); - fab.setOnClickListener(this::onFabClick); - fab.setOnLongClickListener(v -> UiUtils.pickAccountForCompose(getActivity(), accountID, '#'+hashtag+' ')); + protected boolean onFabLongClick(View v) { + return UiUtils.pickAccountForCompose(getActivity(), accountID, '#'+hashtag+' '); } - private void onFabClick(View v){ + @Override + protected void onFabClick(View v){ Bundle args=new Bundle(); args.putString("account", accountID); args.putString("prefilledText", '#'+hashtag+' '); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index 4f3fd7c6c..60203b167 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -32,11 +32,16 @@ import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; import me.grishka.appkit.utils.V; -public class HomeTimelineFragment extends FabStatusListFragment { +public class HomeTimelineFragment extends StatusListFragment { private HomeTabFragment parent; private String maxID; private String lastSavedMarkerID; + @Override + protected boolean withComposeButton() { + return true; + } + @Override public void onAttach(Activity activity){ super.onAttach(activity); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java index 0bd9fec60..79422cbb7 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java @@ -42,10 +42,10 @@ public class ListTimelineFragment extends PinnableStatusListFragment { private String listTitle; @Nullable private ListTimeline.RepliesPolicy repliesPolicy; - private ImageButton fab; - public ListTimelineFragment() { - setListLayoutId(R.layout.recycler_fragment_with_fab); + @Override + protected boolean withComposeButton() { + return true; } @Override @@ -152,14 +152,7 @@ public class ListTimelineFragment extends PinnableStatusListFragment { } @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - fab=view.findViewById(R.id.fab); - fab.setOnClickListener(this::onFabClick); - fab.setOnLongClickListener(v -> UiUtils.pickAccountForCompose(getActivity(), accountID)); - } - - private void onFabClick(View v){ + protected void onFabClick(View v){ Bundle args=new Bundle(); args.putString("account", accountID); Nav.go(getActivity(), ComposeFragment.class, args); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java index a4b71f61c..3516efaed 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java @@ -48,6 +48,11 @@ public class NotificationsListFragment extends BaseStatusListFragment { private String nextMaxID; - private ImageButton fab; private static final int SCHEDULED_STATUS_LIST_OPENED = 161; - public ScheduledStatusListFragment() { - setListLayoutId(R.layout.recycler_fragment_with_fab); + @Override + protected boolean withComposeButton() { + return true; } @Override @@ -56,14 +56,24 @@ public class ScheduledStatusListFragment extends BaseStatusListFragment Nav.go(getActivity(), ComposeFragment.class, args)); - fab.setOnLongClickListener(v -> UiUtils.pickAccountForCompose(getActivity(), accountID, args)); + Nav.go(getActivity(), ComposeFragment.class, args); + } + + @Override + protected boolean onFabLongClick(View v) { + Bundle args=new Bundle(); + args.putString("account", accountID); + args.putSerializable("scheduledAt", CreateStatus.getDraftInstant()); + return UiUtils.pickAccountForCompose(getActivity(), accountID, args); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); if (getArguments().getBoolean("hide_fab", false)) fab.setVisibility(View.GONE); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java index 33fbca69a..7cefb5ab6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java @@ -5,7 +5,6 @@ import android.view.View; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline; -import org.joinmastodon.android.fragments.FabStatusListFragment; import org.joinmastodon.android.fragments.StatusListFragment; import org.joinmastodon.android.model.Filter; import org.joinmastodon.android.model.Status; @@ -17,10 +16,16 @@ import java.util.stream.Collectors; import me.grishka.appkit.api.SimpleCallback; -public class FederatedTimelineFragment extends FabStatusListFragment { +public class FederatedTimelineFragment extends StatusListFragment { private DiscoverInfoBannerHelper bannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.FEDERATED_TIMELINE); private String maxID; + @Override + protected boolean withComposeButton() { + return true; + } + + @Override protected void doLoadData(int offset, int count){ currentRequest=new GetPublicTimeline(false, false, refreshing ? null : maxID, count) 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 index 25eabd942..dc2dff4c9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java @@ -3,9 +3,7 @@ package org.joinmastodon.android.fragments.discover; import android.os.Bundle; import android.view.View; -import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline; -import org.joinmastodon.android.fragments.FabStatusListFragment; import org.joinmastodon.android.fragments.StatusListFragment; import org.joinmastodon.android.model.Filter; import org.joinmastodon.android.model.Status; @@ -17,10 +15,16 @@ import java.util.stream.Collectors; import me.grishka.appkit.api.SimpleCallback; -public class LocalTimelineFragment extends FabStatusListFragment { +public class LocalTimelineFragment extends StatusListFragment { private DiscoverInfoBannerHelper bannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.LOCAL_TIMELINE); private String maxID; + @Override + protected boolean withComposeButton() { + return true; + } + + @Override protected void doLoadData(int offset, int count){ currentRequest=new GetPublicTimeline(true, false, refreshing ? null : maxID, count) diff --git a/mastodon/src/main/res/layout/compose_fab.xml b/mastodon/src/main/res/layout/compose_fab.xml new file mode 100644 index 000000000..e2017ac5c --- /dev/null +++ b/mastodon/src/main/res/layout/compose_fab.xml @@ -0,0 +1,5 @@ + + diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index 957eb5e57..5141e8c8d 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -359,7 +359,7 @@ - + \ No newline at end of file diff --git a/mastodon/src/main/res/layout/recycler_fragment_with_fab.xml b/mastodon/src/main/res/layout/recycler_fragment_with_fab.xml index 1ed27ed70..cf8845e83 100644 --- a/mastodon/src/main/res/layout/recycler_fragment_with_fab.xml +++ b/mastodon/src/main/res/layout/recycler_fragment_with_fab.xml @@ -20,6 +20,6 @@ android:layout_height="match_parent" android:id="@+id/empty"/> - + \ No newline at end of file