diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-11-05 23:39:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-05 23:39:02 +0100 |
commit | af3cebbd08c8408e8a6a4595949d3b29e9a34e0c (patch) | |
tree | affe0d8a78796ec37e65c0f855369a444f6a02b6 | |
parent | 562391c7d9ad8e119f83a729027ddbf2893ce634 (diff) | |
parent | cbc4e9dc36faf680828d1b97cae2a93c34e6e7e1 (diff) | |
download | AntennaPod-af3cebbd08c8408e8a6a4595949d3b29e9a34e0c.zip |
Merge pull request #3582 from ByteHamster/empty-view-subscriptions
Added empty view to subscription list
3 files changed, 28 insertions, 9 deletions
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 da0c50d03..aa6d80bb0 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -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))); } diff --git a/app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java b/app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java index 1516c4eb6..0bfd0247f 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java @@ -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,28 +54,31 @@ 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();
+ (RelativeLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
emptyView.setLayoutParams(layoutParams);
}
@@ -99,7 +102,7 @@ public class EmptyViewHandler { }
};
- private void updateVisibility() {
+ public void updateVisibility() {
boolean empty;
if (adapter == null) {
empty = true;
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index b8187a404..53f9a0810 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -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> |