parent
0e614f96e9
commit
f1b63e92f0
|
@ -30,7 +30,6 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
public static final Object ADD_ITEM_OBJ = new Object();
|
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 */
|
/** 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 static final String TAG = "SubscriptionsAdapter";
|
||||||
|
|
||||||
private final WeakReference<MainActivity> mainActivityRef;
|
private final WeakReference<MainActivity> mainActivityRef;
|
||||||
|
@ -41,28 +40,14 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
this.itemAccess = itemAccess;
|
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
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return 1 + itemAccess.getCount();
|
return itemAccess.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
if (position == getAddTilePosition()) {
|
return itemAccess.getItem(position);
|
||||||
return ADD_ITEM_OBJ;
|
|
||||||
}
|
|
||||||
return itemAccess.getItem(getAdjustedPosition(position));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,10 +57,7 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
if (position == getAddTilePosition()) {
|
return itemAccess.getItem(position).getId();
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return itemAccess.getItem(getAdjustedPosition(position)).getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,20 +80,6 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
holder = (Holder) convertView.getTag();
|
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);
|
final Feed feed = (Feed) getItem(position);
|
||||||
if (feed == null) return null;
|
if (feed == null) return null;
|
||||||
|
|
||||||
|
@ -137,12 +105,8 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if (position == getAddTilePosition()) {
|
Fragment fragment = FeedItemlistFragment.newInstance(getItemId(position));
|
||||||
mainActivityRef.get().loadChildFragment(new AddFeedFragment());
|
mainActivityRef.get().loadChildFragment(fragment);
|
||||||
} else {
|
|
||||||
Fragment fragment = FeedItemlistFragment.newInstance(getItemId(position));
|
|
||||||
mainActivityRef.get().loadChildFragment(fragment);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Holder {
|
static class Holder {
|
||||||
|
|
|
@ -18,6 +18,8 @@ import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
@ -62,6 +64,7 @@ public class SubscriptionFragment extends Fragment {
|
||||||
private GridView subscriptionGridLayout;
|
private GridView subscriptionGridLayout;
|
||||||
private DBReader.NavDrawerData navDrawerData;
|
private DBReader.NavDrawerData navDrawerData;
|
||||||
private SubscriptionsAdapter subscriptionAdapter;
|
private SubscriptionsAdapter subscriptionAdapter;
|
||||||
|
private FloatingActionButton subscriptionAddButton;
|
||||||
|
|
||||||
private int mPosition = -1;
|
private int mPosition = -1;
|
||||||
private boolean isUpdatingFeeds = false;
|
private boolean isUpdatingFeeds = false;
|
||||||
|
@ -85,6 +88,7 @@ public class SubscriptionFragment extends Fragment {
|
||||||
subscriptionGridLayout = root.findViewById(R.id.subscriptions_grid);
|
subscriptionGridLayout = root.findViewById(R.id.subscriptions_grid);
|
||||||
subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, 3));
|
subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, 3));
|
||||||
registerForContextMenu(subscriptionGridLayout);
|
registerForContextMenu(subscriptionGridLayout);
|
||||||
|
subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,10 +141,16 @@ public class SubscriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
subscriptionAdapter = new SubscriptionsAdapter((MainActivity)getActivity(), itemAccess);
|
subscriptionAdapter = new SubscriptionsAdapter((MainActivity) getActivity(), itemAccess);
|
||||||
subscriptionGridLayout.setAdapter(subscriptionAdapter);
|
subscriptionGridLayout.setAdapter(subscriptionAdapter);
|
||||||
subscriptionGridLayout.setOnItemClickListener(subscriptionAdapter);
|
subscriptionGridLayout.setOnItemClickListener(subscriptionAdapter);
|
||||||
|
|
||||||
|
subscriptionAddButton.setOnClickListener(view -> {
|
||||||
|
if (getActivity() instanceof MainActivity) {
|
||||||
|
((MainActivity) getActivity()).loadChildFragment(new AddFeedFragment());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (getActivity() instanceof MainActivity) {
|
if (getActivity() instanceof MainActivity) {
|
||||||
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.subscriptions_label);
|
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.subscriptions_label);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
@ -11,6 +11,18 @@
|
||||||
android:horizontalSpacing="2dp"
|
android:horizontalSpacing="2dp"
|
||||||
android:verticalSpacing="2dp"
|
android:verticalSpacing="2dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center_horizontal">
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:paddingBottom="88dp"
|
||||||
|
android:clipToPadding="false">
|
||||||
</GridView>
|
</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>
|
||||||
|
|
Loading…
Reference in New Issue