diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DiscoveryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DiscoveryFragment.java index a6db1e46b..c87a43a9c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DiscoveryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DiscoveryFragment.java @@ -24,6 +24,7 @@ import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.textfield.MaterialAutoCompleteTextView; import com.google.android.material.textfield.TextInputLayout; +import de.danoeh.antennapod.core.BuildConfig; import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; @@ -69,6 +70,7 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli private Disposable disposable; private String countryCode = "US"; private boolean hidden; + private boolean needsConfirm; private MaterialToolbar toolbar; public DiscoveryFragment() { @@ -102,6 +104,7 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli prefs = getActivity().getSharedPreferences(ItunesTopListLoader.PREFS, Context.MODE_PRIVATE); countryCode = prefs.getString(ItunesTopListLoader.PREF_KEY_COUNTRY_CODE, Locale.getDefault().getCountry()); hidden = prefs.getBoolean(ItunesTopListLoader.PREF_KEY_HIDDEN_DISCOVERY_COUNTRY, false); + needsConfirm = prefs.getBoolean(ItunesTopListLoader.PREF_KEY_NEEDS_CONFIRM, true); } @Override @@ -156,6 +159,7 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli gridView.setVisibility(View.GONE); txtvError.setVisibility(View.GONE); butRetry.setVisibility(View.GONE); + butRetry.setText(R.string.retry_label); txtvEmpty.setVisibility(View.GONE); progressBar.setVisibility(View.VISIBLE); @@ -166,22 +170,38 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli butRetry.setVisibility(View.GONE); txtvEmpty.setVisibility(View.GONE); progressBar.setVisibility(View.GONE); - } else { - ItunesTopListLoader loader = new ItunesTopListLoader(getContext()); - disposable = loader.loadToplist(country, 25).subscribe( - podcasts -> { - progressBar.setVisibility(View.GONE); - topList = podcasts; - updateData(topList); - }, error -> { - Log.e(TAG, Log.getStackTraceString(error)); - progressBar.setVisibility(View.GONE); - txtvError.setText(error.getMessage()); - txtvError.setVisibility(View.VISIBLE); - butRetry.setOnClickListener(v -> loadToplist(country)); - butRetry.setVisibility(View.VISIBLE); - }); + return; } + //noinspection ConstantConditions + if (BuildConfig.FLAVOR.equals("free") && needsConfirm) { + txtvError.setVisibility(View.VISIBLE); + txtvError.setText(""); + butRetry.setVisibility(View.VISIBLE); + butRetry.setText(R.string.discover_confirm); + butRetry.setOnClickListener(v -> { + prefs.edit().putBoolean(ItunesTopListLoader.PREF_KEY_NEEDS_CONFIRM, false).apply(); + needsConfirm = false; + loadToplist(country); + }); + txtvEmpty.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); + return; + } + + ItunesTopListLoader loader = new ItunesTopListLoader(getContext()); + disposable = loader.loadToplist(country, 25).subscribe( + podcasts -> { + progressBar.setVisibility(View.GONE); + topList = podcasts; + updateData(topList); + }, error -> { + Log.e(TAG, Log.getStackTraceString(error)); + progressBar.setVisibility(View.GONE); + txtvError.setText(error.getMessage()); + txtvError.setVisibility(View.VISIBLE); + butRetry.setOnClickListener(v -> loadToplist(country)); + butRetry.setVisibility(View.VISIBLE); + }); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QuickFeedDiscoveryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QuickFeedDiscoveryFragment.java index 37bdc3c9e..acdd1e1c7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QuickFeedDiscoveryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QuickFeedDiscoveryFragment.java @@ -17,6 +17,7 @@ import android.widget.GridView; import android.widget.LinearLayout; import android.widget.TextView; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.net.discovery.ItunesTopListLoader; import de.danoeh.antennapod.net.discovery.PodcastSearchResult; import org.greenrobot.eventbus.EventBus; @@ -61,7 +62,6 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView. errorView = root.findViewById(R.id.discover_error); errorTextView = root.findViewById(R.id.discover_error_txtV); errorRetry = root.findViewById(R.id.discover_error_retry_btn); - errorRetry.setOnClickListener((listener) -> loadToplist()); poweredByTextView = root.findViewById(R.id.discover_powered_by_itunes); adapter = new FeedDiscoverAdapter((MainActivity) getActivity()); @@ -108,14 +108,14 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView. private void loadToplist() { errorView.setVisibility(View.GONE); errorRetry.setVisibility(View.INVISIBLE); + errorRetry.setText(R.string.retry_label); poweredByTextView.setVisibility(View.VISIBLE); ItunesTopListLoader loader = new ItunesTopListLoader(getContext()); SharedPreferences prefs = getActivity().getSharedPreferences(ItunesTopListLoader.PREFS, MODE_PRIVATE); String countryCode = prefs.getString(ItunesTopListLoader.PREF_KEY_COUNTRY_CODE, Locale.getDefault().getCountry()); - boolean hidden = prefs.getBoolean(ItunesTopListLoader.PREF_KEY_HIDDEN_DISCOVERY_COUNTRY, false); - if (hidden) { + if (prefs.getBoolean(ItunesTopListLoader.PREF_KEY_HIDDEN_DISCOVERY_COUNTRY, false)) { errorTextView.setText(R.string.discover_is_hidden); errorView.setVisibility(View.VISIBLE); discoverGridLayout.setVisibility(View.GONE); @@ -123,6 +123,20 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView. poweredByTextView.setVisibility(View.GONE); return; } + //noinspection ConstantConditions + if (BuildConfig.FLAVOR.equals("free") && prefs.getBoolean(ItunesTopListLoader.PREF_KEY_NEEDS_CONFIRM, true)) { + errorTextView.setText(""); + errorView.setVisibility(View.VISIBLE); + discoverGridLayout.setVisibility(View.VISIBLE); + errorRetry.setVisibility(View.VISIBLE); + errorRetry.setText(R.string.discover_confirm); + poweredByTextView.setVisibility(View.VISIBLE); + errorRetry.setOnClickListener(v -> { + prefs.edit().putBoolean(ItunesTopListLoader.PREF_KEY_NEEDS_CONFIRM, false).apply(); + loadToplist(); + }); + return; + } disposable = loader.loadToplist(countryCode, NUM_SUGGESTIONS) .subscribe( @@ -142,6 +156,7 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView. errorView.setVisibility(View.VISIBLE); discoverGridLayout.setVisibility(View.INVISIBLE); errorRetry.setVisibility(View.VISIBLE); + errorRetry.setOnClickListener((listener) -> loadToplist()); }); } diff --git a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java index 3dddf763c..53ea00235 100644 --- a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java +++ b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java @@ -27,6 +27,7 @@ public class ItunesTopListLoader { private final Context context; public static final String PREF_KEY_COUNTRY_CODE = "country_code"; public static final String PREF_KEY_HIDDEN_DISCOVERY_COUNTRY = "hidden_discovery_country"; + public static final String PREF_KEY_NEEDS_CONFIRM = "needs_confirm"; public static final String PREFS = "CountryRegionPrefs"; public static final String COUNTRY_CODE_UNSET = "99"; diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml index ffb2da237..f6213f9d4 100644 --- a/ui/i18n/src/main/res/values/strings.xml +++ b/ui/i18n/src/main/res/values/strings.xml @@ -724,6 +724,7 @@ You selected to hide suggestions. more ยป Suggestions by iTunes + Show suggestions Results by %1$s Country