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.dialog.RenameFeedDialog;
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.view.EmptyViewHandler;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
@ -63,6 +64,7 @@ public class SubscriptionFragment extends Fragment {
private DBReader.NavDrawerData navDrawerData;
private SubscriptionsAdapter subscriptionAdapter;
private FloatingActionButton subscriptionAddButton;
private EmptyViewHandler emptyView;
private int mPosition = -1;
private boolean isUpdatingFeeds = false;
@ -87,6 +89,7 @@ public class SubscriptionFragment extends Fragment {
subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, 3));
registerForContextMenu(subscriptionGridLayout);
subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
setupEmptyView();
return root;
}
@ -136,9 +139,18 @@ public class SubscriptionFragment extends Fragment {
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
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
subscriptionAdapter = new SubscriptionsAdapter((MainActivity) getActivity(), itemAccess);
subscriptionGridLayout.setAdapter(subscriptionAdapter);
subscriptionGridLayout.setOnItemClickListener(subscriptionAdapter);
@ -174,12 +186,14 @@ public class SubscriptionFragment extends Fragment {
if(disposable != null) {
disposable.dispose();
}
emptyView.hide();
disposable = Observable.fromCallable(DBReader::getNavDrawerData)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
navDrawerData = result;
subscriptionAdapter.notifyDataSetChanged();
emptyView.updateVisibility();
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.view;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.AbsListView;
import androidx.annotation.AttrRes;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
@ -9,7 +10,6 @@ import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -54,25 +54,28 @@ public class EmptyViewHandler {
emptyView.setVisibility(View.GONE);
}
public void attachToListView(ListView listView) {
public void attachToListView(AbsListView listView) {
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;
((ViewGroup) listView.getParent()).addView(emptyView);
listView.setEmptyView(emptyView);
}
public void attachToRecyclerView(RecyclerView recyclerView) {
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;
this.recyclerView = recyclerView;
ViewGroup parent = ((ViewGroup) recyclerView.getParent());
parent.addView(emptyView);
updateAdapter(recyclerView.getAdapter());
}
private void addToParentView(View view) {
ViewGroup parent = ((ViewGroup) view.getParent());
parent.addView(emptyView);
if (parent instanceof RelativeLayout) {
RelativeLayout.LayoutParams layoutParams =
(RelativeLayout.LayoutParams) emptyView.getLayoutParams();
@ -99,7 +102,7 @@ public class EmptyViewHandler {
}
};
private void updateVisibility() {
public void updateVisibility() {
boolean empty;
if (adapter == null) {
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_chapters_head_label">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 -->
<string name="storage_pref">Storage</string>