Merge pull request #3582 from ByteHamster/empty-view-subscriptions

Added empty view to subscription list
This commit is contained in:
H. Lehmann 2019-11-05 23:39:02 +01:00 committed by GitHub
commit af3cebbd08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 9 deletions

View File

@ -42,6 +42,7 @@ import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.download.AutoUpdateManager; import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
import de.danoeh.antennapod.dialog.RenameFeedDialog; import de.danoeh.antennapod.dialog.RenameFeedDialog;
import de.danoeh.antennapod.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.view.EmptyViewHandler;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
@ -63,6 +64,7 @@ public class SubscriptionFragment extends Fragment {
private DBReader.NavDrawerData navDrawerData; private DBReader.NavDrawerData navDrawerData;
private SubscriptionsAdapter subscriptionAdapter; private SubscriptionsAdapter subscriptionAdapter;
private FloatingActionButton subscriptionAddButton; private FloatingActionButton subscriptionAddButton;
private EmptyViewHandler emptyView;
private int mPosition = -1; private int mPosition = -1;
private boolean isUpdatingFeeds = false; private boolean isUpdatingFeeds = false;
@ -87,6 +89,7 @@ public class SubscriptionFragment extends Fragment {
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); subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
setupEmptyView();
return root; return root;
} }
@ -136,9 +139,18 @@ public class SubscriptionFragment extends Fragment {
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
} }
private void setupEmptyView() {
emptyView = new EmptyViewHandler(getContext());
emptyView.setIcon(R.attr.ic_folder);
emptyView.setTitle(R.string.no_subscriptions_head_label);
emptyView.setMessage(R.string.no_subscriptions_label);
emptyView.attachToListView(subscriptionGridLayout);
}
@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);
@ -174,12 +186,14 @@ public class SubscriptionFragment extends Fragment {
if(disposable != null) { if(disposable != null) {
disposable.dispose(); disposable.dispose();
} }
emptyView.hide();
disposable = Observable.fromCallable(DBReader::getNavDrawerData) disposable = Observable.fromCallable(DBReader::getNavDrawerData)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
navDrawerData = result; navDrawerData = result;
subscriptionAdapter.notifyDataSetChanged(); subscriptionAdapter.notifyDataSetChanged();
emptyView.updateVisibility();
}, error -> Log.e(TAG, Log.getStackTraceString(error))); }, error -> Log.e(TAG, Log.getStackTraceString(error)));
} }

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.view;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.widget.AbsListView;
import androidx.annotation.AttrRes; import androidx.annotation.AttrRes;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -9,7 +10,6 @@ import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
@ -54,28 +54,31 @@ public class EmptyViewHandler {
emptyView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE);
} }
public void attachToListView(ListView listView) { public void attachToListView(AbsListView listView) {
if (layoutAdded) { if (layoutAdded) {
throw new IllegalStateException("Can not attach to ListView multiple times"); throw new IllegalStateException("Can not attach EmptyView multiple times");
} }
addToParentView(listView);
layoutAdded = true; layoutAdded = true;
((ViewGroup) listView.getParent()).addView(emptyView);
listView.setEmptyView(emptyView); listView.setEmptyView(emptyView);
} }
public void attachToRecyclerView(RecyclerView recyclerView) { public void attachToRecyclerView(RecyclerView recyclerView) {
if (layoutAdded) { if (layoutAdded) {
throw new IllegalStateException("Can not attach to ListView multiple times"); throw new IllegalStateException("Can not attach EmptyView multiple times");
} }
addToParentView(recyclerView);
layoutAdded = true; layoutAdded = true;
this.recyclerView = recyclerView; this.recyclerView = recyclerView;
ViewGroup parent = ((ViewGroup) recyclerView.getParent());
parent.addView(emptyView);
updateAdapter(recyclerView.getAdapter()); updateAdapter(recyclerView.getAdapter());
}
private void addToParentView(View view) {
ViewGroup parent = ((ViewGroup) view.getParent());
parent.addView(emptyView);
if (parent instanceof RelativeLayout) { if (parent instanceof RelativeLayout) {
RelativeLayout.LayoutParams layoutParams = RelativeLayout.LayoutParams layoutParams =
(RelativeLayout.LayoutParams)emptyView.getLayoutParams(); (RelativeLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
emptyView.setLayoutParams(layoutParams); emptyView.setLayoutParams(layoutParams);
} }
@ -99,7 +102,7 @@ public class EmptyViewHandler {
} }
}; };
private void updateVisibility() { public void updateVisibility() {
boolean empty; boolean empty;
if (adapter == null) { if (adapter == null) {
empty = true; empty = true;

View File

@ -325,6 +325,8 @@
<string name="no_fav_episodes_label">You can add episodes to the favorites by long-pressing them.</string> <string name="no_fav_episodes_label">You can add episodes to the favorites by long-pressing them.</string>
<string name="no_chapters_head_label">No chapters</string> <string name="no_chapters_head_label">No chapters</string>
<string name="no_chapters_label">This episode has no chapters.</string> <string name="no_chapters_label">This episode has no chapters.</string>
<string name="no_subscriptions_head_label">No subscriptions</string>
<string name="no_subscriptions_label">To subscribe to a podcast, press the plus icon below.</string>
<!-- Preferences --> <!-- Preferences -->
<string name="storage_pref">Storage</string> <string name="storage_pref">Storage</string>