summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2023-10-13 17:31:09 +0200
committerGitHub <noreply@github.com>2023-10-13 17:31:09 +0200
commit58484d5790cd8410368f989e1ce3390a666a4346 (patch)
tree9a4ff81c81e6d2626e712da2a111014b8def9320
parent2ee2cb67029c27200324884127f556d89e2e9460 (diff)
downloadAntennaPod-58484d5790cd8410368f989e1ce3390a666a4346.zip
Add 'Search online' button if local search has no results (#6681)
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/HorizontalFeedListAdapter.java27
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java19
-rw-r--r--app/src/main/res/layout/horizontal_feed_item.xml8
-rw-r--r--ui/i18n/src/main/res/values/strings.xml1
4 files changed, 53 insertions, 2 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/HorizontalFeedListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/HorizontalFeedListAdapter.java
index 9a578da6a..304bf9f64 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/HorizontalFeedListAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/HorizontalFeedListAdapter.java
@@ -2,7 +2,10 @@ package de.danoeh.antennapod.adapter;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
import androidx.annotation.NonNull;
+import androidx.annotation.StringRes;
+import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
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 int dummyViews = 0;
private Feed longPressedItem;
-
+ private @StringRes int endButtonText = 0;
+ private Runnable endButtonAction = null;
public HorizontalFeedListAdapter(MainActivity mainActivity) {
this.mainActivityRef = new WeakReference<>(mainActivity);
@@ -51,6 +55,15 @@ public class HorizontalFeedListAdapter extends RecyclerView.Adapter<HorizontalFe
@Override
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()) {
holder.itemView.setAlpha(0.1f);
Glide.with(mainActivityRef.get()).clear(holder.imageView);
@@ -95,7 +108,7 @@ public class HorizontalFeedListAdapter extends RecyclerView.Adapter<HorizontalFe
@Override
public int getItemCount() {
- return dummyViews + data.size();
+ return dummyViews + data.size() + ((endButtonAction == null) ? 0 : 1);
}
@Override
@@ -108,13 +121,23 @@ public class HorizontalFeedListAdapter extends RecyclerView.Adapter<HorizontalFe
contextMenu.setHeaderTitle(longPressedItem.getTitle());
}
+ public void setEndButton(@StringRes int text, Runnable action) {
+ endButtonAction = action;
+ endButtonText = text;
+ notifyDataSetChanged();
+ }
+
static class Holder extends RecyclerView.ViewHolder {
SquareImageView imageView;
+ CardView cardView;
+ Button actionButton;
public Holder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.discovery_cover);
imageView.setDirection(SquareImageView.DIRECTION_HEIGHT);
+ actionButton = itemView.findViewById(R.id.actionButton);
+ cardView = itemView.findViewById(R.id.cardView);
}
}
}
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java
index b85e34e7d..307ef0af1 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java
@@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -26,6 +27,7 @@ import com.google.android.material.chip.Chip;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
+import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.adapter.EpisodeItemListAdapter;
import de.danoeh.antennapod.adapter.HorizontalFeedListAdapter;
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.util.FeedItemUtil;
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
+import de.danoeh.antennapod.net.discovery.CombinedSearcher;
import de.danoeh.antennapod.view.EmptyViewHandler;
import de.danoeh.antennapod.view.EpisodeItemListRecyclerView;
import de.danoeh.antennapod.view.LiftOnScrollListener;
@@ -334,6 +337,7 @@ public class SearchFragment extends Fragment {
if (disposable != null) {
disposable.dispose();
}
+ adapterFeeds.setEndButton(R.string.search_online, this::searchOnline);
chip.setVisibility((getArguments().getLong(ARG_FEED, 0) == 0) ? View.GONE : View.VISIBLE);
disposable = Observable.fromCallable(this::performSearch)
.subscribeOn(Schedulers.io())
@@ -374,4 +378,19 @@ public class SearchFragment extends Fragment {
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));
+ }
}
diff --git a/app/src/main/res/layout/horizontal_feed_item.xml b/app/src/main/res/layout/horizontal_feed_item.xml
index faadd0766..9182e78e1 100644
--- a/app/src/main/res/layout/horizontal_feed_item.xml
+++ b/app/src/main/res/layout/horizontal_feed_item.xml
@@ -11,6 +11,7 @@
android:clipChildren="false">
<androidx.cardview.widget.CardView
+ android:id="@+id/cardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/non_square_icon_background"
@@ -30,4 +31,11 @@
</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>
diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml
index a83ada10a..6091afcc4 100644
--- a/ui/i18n/src/main/res/values/strings.xml
+++ b/ui/i18n/src/main/res/values/strings.xml
@@ -545,6 +545,7 @@
<string name="type_to_search">Type a query to search</string>
<string name="search_label">Search</string>
<string name="no_results_for_query">No results were found for \"%1$s\"</string>
+ <string name="search_online">Search online</string>
<!-- Synchronization -->
<string name="sync_status_started">Sync started</string>