Merge pull request #3501 from xgouchet/feature/3475_add_icon

Implement a FAB to add podcast on the Subscriptions screen
This commit is contained in:
H. Lehmann 2019-10-08 10:44:33 +02:00 committed by GitHub
commit b22b1b3237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 45 deletions

View File

@ -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<MainActivity> 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,13 +105,9 @@ 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);
}
}
static class Holder {
public TextView feedTitle;

View File

@ -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;
}
@ -141,6 +145,12 @@ public class SubscriptionFragment extends Fragment {
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);
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -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">
</GridView>
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/subscriptions_add"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_margin="16dp"
android:layout_gravity="bottom|end"
android:contentDescription="@string/add_feed_label"
android:src="@drawable/ic_add_white_24dp"
/>
</FrameLayout>