Show message for empty home sections (#7221)

This commit is contained in:
flofriday 2024-09-08 16:05:36 +02:00 committed by GitHub
parent 5ac3185605
commit 60f6e175a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 94 additions and 59 deletions

View File

@ -6,36 +6,39 @@ import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemListAdapter;
import de.danoeh.antennapod.event.DownloadLogEvent;
import de.danoeh.antennapod.ui.MenuItemUtils;
import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.event.FeedItemEvent;
import de.danoeh.antennapod.event.PlayerStatusEvent;
import de.danoeh.antennapod.event.playback.PlaybackPositionEvent;
import de.danoeh.antennapod.ui.screen.download.CompletedDownloadsFragment;
import de.danoeh.antennapod.ui.swipeactions.SwipeActions;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.screen.home.HomeSection;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemViewHolder;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.event.DownloadLogEvent;
import de.danoeh.antennapod.event.FeedItemEvent;
import de.danoeh.antennapod.event.PlayerStatusEvent;
import de.danoeh.antennapod.event.playback.PlaybackPositionEvent;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.MenuItemUtils;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemListAdapter;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemViewHolder;
import de.danoeh.antennapod.ui.screen.download.CompletedDownloadsFragment;
import de.danoeh.antennapod.ui.screen.home.HomeSection;
import de.danoeh.antennapod.ui.swipeactions.SwipeActions;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
public class DownloadsSection extends HomeSection {
public static final String TAG = "DownloadsSection";
private static final int NUM_EPISODES = 2;
@ -63,6 +66,7 @@ public class DownloadsSection extends HomeSection {
};
adapter.setDummyViews(NUM_EPISODES);
viewBinding.recyclerView.setAdapter(adapter);
viewBinding.emptyLabel.setText(R.string.home_downloads_empty_text);
SwipeActions swipeActions = new SwipeActions(this, CompletedDownloadsFragment.TAG);
swipeActions.attachTo(viewBinding.recyclerView);
@ -133,6 +137,7 @@ public class DownloadsSection extends HomeSection {
items = downloads;
adapter.setDummyViews(0);
adapter.updateItems(items);
viewBinding.emptyLabel.setVisibility(items.isEmpty() ? View.VISIBLE : View.GONE);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
}

View File

@ -6,27 +6,12 @@ import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.ui.episodeslist.HorizontalItemListAdapter;
import de.danoeh.antennapod.ui.MenuItemUtils;
import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.event.EpisodeDownloadEvent;
import de.danoeh.antennapod.event.FeedItemEvent;
import de.danoeh.antennapod.event.PlayerStatusEvent;
import de.danoeh.antennapod.event.playback.PlaybackPositionEvent;
import de.danoeh.antennapod.ui.screen.AllEpisodesFragment;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.ui.screen.home.HomeSection;
import de.danoeh.antennapod.ui.episodeslist.HorizontalItemViewHolder;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@ -34,6 +19,24 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.event.EpisodeDownloadEvent;
import de.danoeh.antennapod.event.FeedItemEvent;
import de.danoeh.antennapod.event.PlayerStatusEvent;
import de.danoeh.antennapod.event.playback.PlaybackPositionEvent;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.ui.MenuItemUtils;
import de.danoeh.antennapod.ui.episodeslist.HorizontalItemListAdapter;
import de.danoeh.antennapod.ui.episodeslist.HorizontalItemViewHolder;
import de.danoeh.antennapod.ui.screen.AllEpisodesFragment;
import de.danoeh.antennapod.ui.screen.home.HomeSection;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
public class EpisodesSurpriseSection extends HomeSection {
public static final String TAG = "EpisodesSurpriseSection";
private static final int NUM_EPISODES = 8;
@ -69,6 +72,7 @@ public class EpisodesSurpriseSection extends HomeSection {
if (seed == 0) {
seed = new Random().nextInt();
}
viewBinding.emptyLabel.setText(R.string.home_no_recent_unplayed_episodes_text);
return view;
}
@ -149,6 +153,11 @@ public class EpisodesSurpriseSection extends HomeSection {
this.episodes = episodes;
listAdapter.setDummyViews(0);
listAdapter.updateData(episodes);
boolean isShuffleable = !episodes.isEmpty();
viewBinding.shuffleButton.setVisibility(isShuffleable ? View.VISIBLE : View.GONE);
viewBinding.recyclerView.setVisibility(isShuffleable ? View.VISIBLE : View.GONE);
viewBinding.emptyLabel.setVisibility(!isShuffleable ? View.VISIBLE : View.GONE);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
}

View File

@ -6,30 +6,13 @@ import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemListAdapter;
import de.danoeh.antennapod.ui.MenuItemUtils;
import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.event.EpisodeDownloadEvent;
import de.danoeh.antennapod.event.FeedItemEvent;
import de.danoeh.antennapod.event.FeedListUpdateEvent;
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.ui.screen.InboxFragment;
import de.danoeh.antennapod.ui.swipeactions.SwipeActions;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.screen.home.HomeSection;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@ -37,6 +20,26 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.event.EpisodeDownloadEvent;
import de.danoeh.antennapod.event.FeedItemEvent;
import de.danoeh.antennapod.event.FeedListUpdateEvent;
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.MenuItemUtils;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemListAdapter;
import de.danoeh.antennapod.ui.screen.InboxFragment;
import de.danoeh.antennapod.ui.screen.home.HomeSection;
import de.danoeh.antennapod.ui.swipeactions.SwipeActions;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
public class InboxSection extends HomeSection {
public static final String TAG = "InboxSection";
private static final int NUM_EPISODES = 2;
@ -53,7 +56,7 @@ public class InboxSection extends HomeSection {
viewBinding.recyclerView.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);
viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
viewBinding.recyclerView.setRecycledViewPool(((MainActivity) requireActivity()).getRecycledViewPool());
adapter = new EpisodeItemListAdapter((MainActivity) requireActivity()) {
adapter = new EpisodeItemListAdapter(requireActivity()) {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
@ -62,6 +65,7 @@ public class InboxSection extends HomeSection {
};
adapter.setDummyViews(NUM_EPISODES);
viewBinding.recyclerView.setAdapter(adapter);
viewBinding.emptyLabel.setText(R.string.home_new_empty_text);
SwipeActions swipeActions = new SwipeActions(this, InboxFragment.TAG);
swipeActions.attachTo(viewBinding.recyclerView);
@ -129,7 +133,8 @@ public class InboxSection extends HomeSection {
items = data.first;
adapter.setDummyViews(0);
adapter.updateItems(items);
viewBinding.numNewItemsLabel.setVisibility(View.VISIBLE);
viewBinding.emptyLabel.setVisibility(items.isEmpty() ? View.VISIBLE : View.GONE);
viewBinding.numNewItemsLabel.setVisibility(!items.isEmpty() ? View.VISIBLE : View.GONE);
if (data.second >= 100) {
viewBinding.numNewItemsLabel.setText(String.format(Locale.getDefault(), "%d+", 99));
} else {

View File

@ -59,6 +59,7 @@ public class QueueSection extends HomeSection {
viewBinding.recyclerView.setAdapter(listAdapter);
int paddingHorizontal = (int) (12 * getResources().getDisplayMetrics().density);
viewBinding.recyclerView.setPadding(paddingHorizontal, 0, paddingHorizontal, 0);
viewBinding.emptyLabel.setText(R.string.home_continue_empty_text);
return view;
}
@ -156,6 +157,7 @@ public class QueueSection extends HomeSection {
this.queue = queue;
listAdapter.setDummyViews(0);
listAdapter.updateData(queue);
viewBinding.emptyLabel.setVisibility(queue.isEmpty() ? View.VISIBLE : View.GONE);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}

View File

@ -106,4 +106,14 @@
tools:listitem="@layout/horizontal_itemlist_item"
tools:itemCount="1" />
<TextView
android:id="@+id/emptyLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingHorizontal="32dp"
android:paddingVertical="8dp"
android:textAlignment="center"
app:layout_constraintTop_toBottomOf="@id/barrier" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -61,6 +61,10 @@
<string name="home_continue_title">Continue listening</string>
<string name="home_new_title">See what\'s new</string>
<string name="home_downloads_title">Manage downloads</string>
<string name="home_no_recent_unplayed_episodes_text">You already played all recent episodes. Nothing to be surprised here ;)</string>
<string name="home_continue_empty_text">You can add episodes by downloading them or long-pressing them and selecting \"Add to queue\".</string>
<string name="home_new_empty_text">New episodes will show up here. You can then decide whether you are interested in them.</string>
<string name="home_downloads_empty_text">You can download any episode to listen to it offline.</string>
<string name="home_welcome_title">Welcome to AntennaPod!</string>
<string name="home_welcome_text">You are not subscribed to any podcasts yet. Open the side menu to add a podcast.</string>
<string name="notification_permission_text">AntennaPod needs your permission to show notifications. By default, AntennaPod only shows notifications while something is being downloaded or when something goes wrong.</string>