From bdf7bf68449d514abae81fbc7cbaa06694092cd2 Mon Sep 17 00:00:00 2001 From: Jatin Kumar Date: Wed, 27 Mar 2019 04:16:06 -0400 Subject: [PATCH] Fixes #3052: Added empty views to the Playback History, Queue, Downloads and Episodes --- .../fragment/AllEpisodesFragment.java | 14 +++++ .../fragment/CompletedDownloadsFragment.java | 11 ++-- .../fragment/DownloadLogFragment.java | 11 ++-- .../fragment/FavoriteEpisodesFragment.java | 9 ++- .../fragment/NewEpisodesFragment.java | 8 ++- .../fragment/PlaybackHistoryFragment.java | 11 ++-- .../antennapod/fragment/QueueFragment.java | 21 +++---- .../fragment/RunningDownloadsFragment.java | 11 ++-- .../antennapod/view/EmptyViewHandler.java | 59 +++++++++++++++++++ .../main/res/layout/all_episodes_fragment.xml | 35 +++++++++++ .../layout/completed_downloads_empty_view.xml | 27 --------- .../res/layout/download_log_empty_view.xml | 27 --------- ...y_empty_view.xml => empty_view_layout.xml} | 6 +- app/src/main/res/layout/queue_fragment.xml | 20 +++++-- .../layout/running_downloads_empty_view.xml | 27 --------- core/src/main/res/values/strings.xml | 7 ++- 16 files changed, 178 insertions(+), 126 deletions(-) create mode 100644 app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java delete mode 100644 app/src/main/res/layout/completed_downloads_empty_view.xml delete mode 100644 app/src/main/res/layout/download_log_empty_view.xml rename app/src/main/res/layout/{playback_history_empty_view.xml => empty_view_layout.xml} (81%) delete mode 100644 app/src/main/res/layout/running_downloads_empty_view.xml diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index beca6ab5c..497e5f18b 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -19,6 +19,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.Toast; @@ -74,6 +75,7 @@ public class AllEpisodesFragment extends Fragment { RecyclerView recyclerView; AllEpisodesRecycleAdapter listAdapter; private ProgressBar progLoading; + private LinearLayout layoutEmpty; List episodes; private List downloaderList; @@ -331,6 +333,9 @@ public class AllEpisodesFragment extends Fragment { onFragmentLoaded(); } + layoutEmpty = (LinearLayout) root.findViewById(R.id.llEmpty); + layoutEmpty.setVisibility(View.GONE); + return root; } @@ -342,6 +347,14 @@ public class AllEpisodesFragment extends Fragment { listAdapter.setHasStableIds(true); recyclerView.setAdapter(listAdapter); } + if(episodes == null || episodes.size() == 0) { + recyclerView.setVisibility(View.GONE); + layoutEmpty.setVisibility(View.VISIBLE); + } else { + layoutEmpty.setVisibility(View.GONE); + recyclerView.setVisibility(View.VISIBLE); + } + listAdapter.notifyDataSetChanged(); restoreScrollPosition(); getActivity().supportInvalidateOptionsMenu(); @@ -473,6 +486,7 @@ public class AllEpisodesFragment extends Fragment { } if (viewsCreated && !itemsLoaded) { recyclerView.setVisibility(View.GONE); + layoutEmpty.setVisibility(View.GONE); progLoading.setVisibility(View.VISIBLE); } disposable = Observable.fromCallable(this::loadData) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index 966c31296..ddf9044ab 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -8,7 +8,6 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.ListView; import java.util.List; @@ -22,6 +21,7 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; +import de.danoeh.antennapod.view.EmptyViewHandler; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -108,11 +108,10 @@ public class CompletedDownloadsFragment extends ListFragment { onFragmentLoaded(); } - //empty view - View emptyView = getActivity().getLayoutInflater().inflate(R.layout.completed_downloads_empty_view, null); - ((ViewGroup)getListView().getParent()).addView(emptyView); - getListView().setEmptyView(emptyView); - + EmptyViewHandler emptyView = new EmptyViewHandler(getActivity()); + emptyView.setTitle(R.string.no_comp_downloads_head_label); + emptyView.setMessage(R.string.no_comp_downloads_label); + emptyView.attachToListView(getListView()); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java index 3338b2b0b..973772049 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java @@ -11,7 +11,6 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.ListView; import android.widget.TextView; @@ -25,6 +24,7 @@ import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.view.EmptyViewHandler; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -77,10 +77,11 @@ public class DownloadLogFragment extends ListFragment { onFragmentLoaded(); } - //empty view - View emptyView = getActivity().getLayoutInflater().inflate(R.layout.download_log_empty_view, null); - ((ViewGroup)getListView().getParent()).addView(emptyView); - getListView().setEmptyView(emptyView); + EmptyViewHandler emptyView = new EmptyViewHandler(getActivity()); + emptyView.setTitle(R.string.no_log_downloads_head_label); + emptyView.setMessage(R.string.no_log_downloads_label); + emptyView.attachToListView(getListView()); + } private void onFragmentLoaded() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java index 70f82c2ec..80a0ef455 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java @@ -8,6 +8,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import java.util.List; @@ -30,6 +31,9 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment { private static final String PREF_NAME = "PrefFavoriteEpisodesFragment"; + private TextView tvHeader; + private TextView tvEmpty; + @Override protected boolean showOnlyNewEpisodes() { return true; } @@ -50,7 +54,10 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = super.onCreateViewHelper(inflater, container, savedInstanceState, R.layout.all_episodes_fragment); - + tvHeader = root.findViewById(R.id.emptyHeader); + tvHeader.setText(R.string.no_fav_episodes_head_label); + tvEmpty = root.findViewById(R.id.empty); + tvEmpty.setText(R.string.no_fav_episodes_label); ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java index 335ee224b..1a9035a5d 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java @@ -7,6 +7,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import java.util.List; @@ -29,6 +30,8 @@ public class NewEpisodesFragment extends AllEpisodesFragment { private static final String PREF_NAME = "PrefNewEpisodesFragment"; + private TextView tvHeader; + private TextView tvEmpty; @Override protected boolean showOnlyNewEpisodes() { return true; } @@ -49,7 +52,10 @@ public class NewEpisodesFragment extends AllEpisodesFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = super.onCreateViewHelper(inflater, container, savedInstanceState, R.layout.all_episodes_fragment); - + tvHeader = root.findViewById(R.id.emptyHeader); + tvHeader.setText(R.string.no_new_episodes_head_label); + tvEmpty = root.findViewById(R.id.empty); + tvEmpty.setText(R.string.no_new_episodes_label); ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index 73763b470..bd4a43f83 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -10,7 +10,6 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.ListView; import java.util.List; @@ -30,6 +29,7 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.LongList; +import de.danoeh.antennapod.view.EmptyViewHandler; import de.greenrobot.event.EventBus; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -83,10 +83,11 @@ public class PlaybackHistoryFragment extends ListFragment { onFragmentLoaded(); } - //empty view - View emptyView = getActivity().getLayoutInflater().inflate(R.layout.playback_history_empty_view, null); - ((ViewGroup)getListView().getParent()).addView(emptyView); - getListView().setEmptyView(emptyView); + EmptyViewHandler emptyView = new EmptyViewHandler(getActivity()); + emptyView.setTitle(R.string.no_history_head_label); + emptyView.setMessage(R.string.no_history_label); + emptyView.attachToListView(getListView()); + } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 2a22c3b8a..5a5e80681 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -19,6 +19,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; @@ -72,8 +73,7 @@ public class QueueFragment extends Fragment { private TextView infoBar; private RecyclerView recyclerView; private QueueRecyclerAdapter recyclerAdapter; - private TextView txtvEmpty; - private TextView txtvHeadEmpty; + private LinearLayout layoutEmpty; private ProgressBar progLoading; private List queue; @@ -494,11 +494,9 @@ public class QueueFragment extends Fragment { } ); itemTouchHelper.attachToRecyclerView(recyclerView); - - txtvEmpty = root.findViewById(android.R.id.empty); - txtvEmpty.setVisibility(View.GONE); - txtvHeadEmpty = root.findViewById(R.id.emptyQueueHeader); - txtvHeadEmpty.setVisibility(View.GONE); + //empty view + layoutEmpty = (LinearLayout) root.findViewById(R.id.llEmpty); + layoutEmpty.setVisibility(View.GONE); progLoading = root.findViewById(R.id.progLoading); progLoading.setVisibility(View.VISIBLE); @@ -516,12 +514,10 @@ public class QueueFragment extends Fragment { } if(queue == null || queue.size() == 0) { recyclerView.setVisibility(View.GONE); - txtvEmpty.setVisibility(View.VISIBLE); - txtvHeadEmpty.setVisibility(View.VISIBLE); + layoutEmpty.setVisibility(View.VISIBLE); } else { - txtvEmpty.setVisibility(View.GONE); + layoutEmpty.setVisibility(View.GONE); recyclerView.setVisibility(View.VISIBLE); - txtvHeadEmpty.setVisibility(View.GONE); } if (restoreScrollPosition) { @@ -634,8 +630,7 @@ public class QueueFragment extends Fragment { } if (queue == null) { recyclerView.setVisibility(View.GONE); - txtvEmpty.setVisibility(View.GONE); - txtvHeadEmpty.setVisibility(View.GONE); + layoutEmpty.setVisibility(View.GONE); progLoading.setVisibility(View.VISIBLE); } disposable = Observable.fromCallable(DBReader::getQueue) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java index 9940152b2..3c40b542c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java @@ -4,7 +4,6 @@ import android.os.Bundle; import android.support.v4.app.ListFragment; import android.util.Log; import android.view.View; -import android.view.ViewGroup; import android.widget.ListView; import android.widget.Toast; @@ -21,6 +20,7 @@ import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequester; +import de.danoeh.antennapod.view.EmptyViewHandler; import de.greenrobot.event.EventBus; /** @@ -46,10 +46,11 @@ public class RunningDownloadsFragment extends ListFragment { adapter = new DownloadlistAdapter(getActivity(), itemAccess); setListAdapter(adapter); - //empty view - View emptyView = getActivity().getLayoutInflater().inflate(R.layout.running_downloads_empty_view, null); - ((ViewGroup)getListView().getParent()).addView(emptyView); - getListView().setEmptyView(emptyView); + EmptyViewHandler emptyView = new EmptyViewHandler(getActivity()); + emptyView.setTitle(R.string.no_run_downloads_head_label); + emptyView.setMessage(R.string.no_run_downloads_label); + emptyView.attachToListView(getListView()); + } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java b/app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java new file mode 100644 index 000000000..5bd92687d --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/view/EmptyViewHandler.java @@ -0,0 +1,59 @@ +package de.danoeh.antennapod.view; + +import android.app.Activity; +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; +import android.widget.TextView; + +import de.danoeh.antennapod.R; + +public class EmptyViewHandler extends View { + private Activity activity; + private int title; + private int message; + + public EmptyViewHandler(Context context) { + super(context); + this.setActivity((Activity) context); + } + + public int getTitle() { + return title; + } + + public void setTitle(int title) { + this.title = title; + } + + public int getMessage() { + return message; + } + + public void setMessage(int message) { + this.message = message; + } + + public void attachToListView(ListView listView){ + + View emptyView = getActivity().getLayoutInflater().inflate(R.layout.empty_view_layout, null); + ((ViewGroup) listView.getParent()).addView(emptyView); + listView.setEmptyView(emptyView); + + TextView tvTitle = (TextView) emptyView.findViewById(R.id.txtvtitle); + tvTitle.setText(title); + + TextView tvMessage = (TextView) emptyView.findViewById(R.id.txtvmessage); + tvMessage.setText(message); + + } + + public Activity getActivity() { + return activity; + } + + public void setActivity(Activity activity) { + this.activity = activity; + } +} diff --git a/app/src/main/res/layout/all_episodes_fragment.xml b/app/src/main/res/layout/all_episodes_fragment.xml index 89f900a1f..b313e86f0 100644 --- a/app/src/main/res/layout/all_episodes_fragment.xml +++ b/app/src/main/res/layout/all_episodes_fragment.xml @@ -17,6 +17,41 @@ tools:itemCount="13" tools:listitem="@layout/new_episodes_listitem" /> + + + + + + + + - - - - - - - diff --git a/app/src/main/res/layout/download_log_empty_view.xml b/app/src/main/res/layout/download_log_empty_view.xml deleted file mode 100644 index f11ee2722..000000000 --- a/app/src/main/res/layout/download_log_empty_view.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/playback_history_empty_view.xml b/app/src/main/res/layout/empty_view_layout.xml similarity index 81% rename from app/src/main/res/layout/playback_history_empty_view.xml rename to app/src/main/res/layout/empty_view_layout.xml index 36136d661..45889bcf9 100644 --- a/app/src/main/res/layout/playback_history_empty_view.xml +++ b/app/src/main/res/layout/empty_view_layout.xml @@ -6,20 +6,22 @@ android:gravity="center"> diff --git a/app/src/main/res/layout/queue_fragment.xml b/app/src/main/res/layout/queue_fragment.xml index e0abc8175..897a72669 100644 --- a/app/src/main/res/layout/queue_fragment.xml +++ b/app/src/main/res/layout/queue_fragment.xml @@ -27,14 +27,21 @@ android:layout_below="@id/divider" android:scrollbars="vertical"/> - + + + - - - - - - - diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index f35e07e34..0f906f433 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -327,7 +327,12 @@ Download logs will appear here when available. No History After you listen to an episode, it will appear here. - + No Episodes + When you add a podcast, the episodes will be shown here. + No new episodes + When new episodes arrive, they will be shown here. + No favourite episodes + You can add episodes to the favourites by long-pressing them. Storage