From f1b63e92f0882379848d6a286f6cef108860ba80 Mon Sep 17 00:00:00 2001 From: Xavier Gouchet Date: Mon, 7 Oct 2019 10:20:34 +0200 Subject: [PATCH] Implement a FAB to add podcast on the Subscriptions screen Fixes #3475 --- .../adapter/SubscriptionsAdapter.java | 46 ++----------------- .../fragment/SubscriptionFragment.java | 12 ++++- .../res/layout/fragment_subscriptions.xml | 18 ++++++-- 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java index 230b7ee31..5d52eb263 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -30,7 +30,6 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI public static final Object ADD_ITEM_OBJ = new Object(); /** the position in the view that holds the add item; 0 is the first, -1 is the last position */ - private static final int ADD_POSITION = -1; private static final String TAG = "SubscriptionsAdapter"; private final WeakReference mainActivityRef; @@ -41,28 +40,14 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI this.itemAccess = itemAccess; } - private int getAddTilePosition() { - if(ADD_POSITION < 0) { - return ADD_POSITION + getCount(); - } - return ADD_POSITION; - } - - private int getAdjustedPosition(int origPosition) { - return origPosition < getAddTilePosition() ? origPosition : origPosition - 1; - } - @Override public int getCount() { - return 1 + itemAccess.getCount(); + return itemAccess.getCount(); } @Override public Object getItem(int position) { - if (position == getAddTilePosition()) { - return ADD_ITEM_OBJ; - } - return itemAccess.getItem(getAdjustedPosition(position)); + return itemAccess.getItem(position); } @Override @@ -72,10 +57,7 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI @Override public long getItemId(int position) { - if (position == getAddTilePosition()) { - return 0; - } - return itemAccess.getItem(getAdjustedPosition(position)).getId(); + return itemAccess.getItem(position).getId(); } @Override @@ -98,20 +80,6 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI holder = (Holder) convertView.getTag(); } - if (position == getAddTilePosition()) { - holder.feedTitle.setText("{md-add 500%}\n\n" + mainActivityRef.get().getString(R.string.add_feed_label)); - holder.feedTitle.setVisibility(View.VISIBLE); - // prevent any accidental re-use of old values (not sure how that would happen...) - holder.count.setPrimaryText(""); - // make it go away, we don't need it for add feed - holder.count.setVisibility(View.INVISIBLE); - - // when this holder is reused, we could else end up with a cover image - Glide.with(mainActivityRef.get()).clear(holder.imageView); - - return convertView; - } - final Feed feed = (Feed) getItem(position); if (feed == null) return null; @@ -137,12 +105,8 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (position == getAddTilePosition()) { - mainActivityRef.get().loadChildFragment(new AddFeedFragment()); - } else { - Fragment fragment = FeedItemlistFragment.newInstance(getItemId(position)); - mainActivityRef.get().loadChildFragment(fragment); - } + Fragment fragment = FeedItemlistFragment.newInstance(getItemId(position)); + mainActivityRef.get().loadChildFragment(fragment); } static class Holder { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index 21c744727..253c99c4e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -18,6 +18,8 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.GridView; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + import java.util.concurrent.Callable; import de.danoeh.antennapod.R; @@ -62,6 +64,7 @@ public class SubscriptionFragment extends Fragment { private GridView subscriptionGridLayout; private DBReader.NavDrawerData navDrawerData; private SubscriptionsAdapter subscriptionAdapter; + private FloatingActionButton subscriptionAddButton; private int mPosition = -1; private boolean isUpdatingFeeds = false; @@ -85,6 +88,7 @@ public class SubscriptionFragment extends Fragment { subscriptionGridLayout = root.findViewById(R.id.subscriptions_grid); subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, 3)); registerForContextMenu(subscriptionGridLayout); + subscriptionAddButton = root.findViewById(R.id.subscriptions_add); return root; } @@ -137,10 +141,16 @@ public class SubscriptionFragment extends Fragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - subscriptionAdapter = new SubscriptionsAdapter((MainActivity)getActivity(), itemAccess); + subscriptionAdapter = new SubscriptionsAdapter((MainActivity) getActivity(), itemAccess); subscriptionGridLayout.setAdapter(subscriptionAdapter); subscriptionGridLayout.setOnItemClickListener(subscriptionAdapter); + subscriptionAddButton.setOnClickListener(view -> { + if (getActivity() instanceof MainActivity) { + ((MainActivity) getActivity()).loadChildFragment(new AddFeedFragment()); + } + }); + if (getActivity() instanceof MainActivity) { ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.subscriptions_label); } diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml index a716cecb6..69eee04ce 100644 --- a/app/src/main/res/layout/fragment_subscriptions.xml +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -1,5 +1,5 @@ - @@ -11,6 +11,18 @@ android:horizontalSpacing="2dp" android:verticalSpacing="2dp" android:layout_height="match_parent" - android:layout_gravity="center_horizontal"> + android:layout_gravity="center_horizontal" + android:paddingBottom="88dp" + android:clipToPadding="false"> - + + +