Add 'Search online' button if local search has no results (#6681)

This commit is contained in:
ByteHamster 2023-10-13 17:31:09 +02:00 committed by GitHub
parent 2ee2cb6702
commit 58484d5790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 2 deletions

View File

@ -2,7 +2,10 @@ package de.danoeh.antennapod.adapter;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
@ -26,7 +29,8 @@ public class HorizontalFeedListAdapter extends RecyclerView.Adapter<HorizontalFe
private final List<Feed> data = new ArrayList<>(); private final List<Feed> data = new ArrayList<>();
private int dummyViews = 0; private int dummyViews = 0;
private Feed longPressedItem; private Feed longPressedItem;
private @StringRes int endButtonText = 0;
private Runnable endButtonAction = null;
public HorizontalFeedListAdapter(MainActivity mainActivity) { public HorizontalFeedListAdapter(MainActivity mainActivity) {
this.mainActivityRef = new WeakReference<>(mainActivity); this.mainActivityRef = new WeakReference<>(mainActivity);
@ -51,6 +55,15 @@ public class HorizontalFeedListAdapter extends RecyclerView.Adapter<HorizontalFe
@Override @Override
public void onBindViewHolder(@NonNull Holder holder, int position) { public void onBindViewHolder(@NonNull Holder holder, int position) {
if (position == getItemCount() - 1 && endButtonAction != null) {
holder.cardView.setVisibility(View.GONE);
holder.actionButton.setVisibility(View.VISIBLE);
holder.actionButton.setText(endButtonText);
holder.actionButton.setOnClickListener(v -> endButtonAction.run());
return;
}
holder.cardView.setVisibility(View.VISIBLE);
holder.actionButton.setVisibility(View.GONE);
if (position >= data.size()) { if (position >= data.size()) {
holder.itemView.setAlpha(0.1f); holder.itemView.setAlpha(0.1f);
Glide.with(mainActivityRef.get()).clear(holder.imageView); Glide.with(mainActivityRef.get()).clear(holder.imageView);
@ -95,7 +108,7 @@ public class HorizontalFeedListAdapter extends RecyclerView.Adapter<HorizontalFe
@Override @Override
public int getItemCount() { public int getItemCount() {
return dummyViews + data.size(); return dummyViews + data.size() + ((endButtonAction == null) ? 0 : 1);
} }
@Override @Override
@ -108,13 +121,23 @@ public class HorizontalFeedListAdapter extends RecyclerView.Adapter<HorizontalFe
contextMenu.setHeaderTitle(longPressedItem.getTitle()); contextMenu.setHeaderTitle(longPressedItem.getTitle());
} }
public void setEndButton(@StringRes int text, Runnable action) {
endButtonAction = action;
endButtonText = text;
notifyDataSetChanged();
}
static class Holder extends RecyclerView.ViewHolder { static class Holder extends RecyclerView.ViewHolder {
SquareImageView imageView; SquareImageView imageView;
CardView cardView;
Button actionButton;
public Holder(@NonNull View itemView) { public Holder(@NonNull View itemView) {
super(itemView); super(itemView);
imageView = itemView.findViewById(R.id.discovery_cover); imageView = itemView.findViewById(R.id.discovery_cover);
imageView.setDirection(SquareImageView.DIRECTION_HEIGHT); imageView.setDirection(SquareImageView.DIRECTION_HEIGHT);
actionButton = itemView.findViewById(R.id.actionButton);
cardView = itemView.findViewById(R.id.cardView);
} }
} }
} }

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -26,6 +27,7 @@ import com.google.android.material.chip.Chip;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.adapter.EpisodeItemListAdapter; import de.danoeh.antennapod.adapter.EpisodeItemListAdapter;
import de.danoeh.antennapod.adapter.HorizontalFeedListAdapter; import de.danoeh.antennapod.adapter.HorizontalFeedListAdapter;
import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; import de.danoeh.antennapod.core.menuhandler.MenuItemUtils;
@ -39,6 +41,7 @@ import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.core.storage.FeedSearcher; import de.danoeh.antennapod.core.storage.FeedSearcher;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.net.discovery.CombinedSearcher;
import de.danoeh.antennapod.view.EmptyViewHandler; import de.danoeh.antennapod.view.EmptyViewHandler;
import de.danoeh.antennapod.view.EpisodeItemListRecyclerView; import de.danoeh.antennapod.view.EpisodeItemListRecyclerView;
import de.danoeh.antennapod.view.LiftOnScrollListener; import de.danoeh.antennapod.view.LiftOnScrollListener;
@ -334,6 +337,7 @@ public class SearchFragment extends Fragment {
if (disposable != null) { if (disposable != null) {
disposable.dispose(); disposable.dispose();
} }
adapterFeeds.setEndButton(R.string.search_online, this::searchOnline);
chip.setVisibility((getArguments().getLong(ARG_FEED, 0) == 0) ? View.GONE : View.VISIBLE); chip.setVisibility((getArguments().getLong(ARG_FEED, 0) == 0) ? View.GONE : View.VISIBLE);
disposable = Observable.fromCallable(this::performSearch) disposable = Observable.fromCallable(this::performSearch)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -374,4 +378,19 @@ public class SearchFragment extends Fragment {
imm.showSoftInput(view, 0); imm.showSoftInput(view, 0);
} }
} }
private void searchOnline() {
searchView.clearFocus();
InputMethodManager in = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
String query = searchView.getQuery().toString();
if (query.matches("http[s]?://.*")) {
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, query);
startActivity(intent);
return;
}
((MainActivity) getActivity()).loadChildFragment(
OnlineSearchFragment.newInstance(CombinedSearcher.class, query));
}
} }

View File

@ -11,6 +11,7 @@
android:clipChildren="false"> android:clipChildren="false">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardBackgroundColor="@color/non_square_icon_background" app:cardBackgroundColor="@color/non_square_icon_background"
@ -30,4 +31,11 @@
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<Button
android:id="@+id/actionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
style="@style/Widget.Material3.Button.OutlinedButton" />
</LinearLayout> </LinearLayout>

View File

@ -545,6 +545,7 @@
<string name="type_to_search">Type a query to search</string> <string name="type_to_search">Type a query to search</string>
<string name="search_label">Search</string> <string name="search_label">Search</string>
<string name="no_results_for_query">No results were found for \"%1$s\"</string> <string name="no_results_for_query">No results were found for \"%1$s\"</string>
<string name="search_online">Search online</string>
<!-- Synchronization --> <!-- Synchronization -->
<string name="sync_status_started">Sync started</string> <string name="sync_status_started">Sync started</string>