Merge pull request #6181 from ByteHamster/hide-suggestions-fdroid

Hide iTunes suggestions by default in F-Droid version
This commit is contained in:
ByteHamster 2022-11-10 21:35:29 +01:00 committed by GitHub
commit 085147723e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 18 deletions

View File

@ -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

View File

@ -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());
});
}

View File

@ -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";

View File

@ -724,6 +724,7 @@
<string name="discover_is_hidden">You selected to hide suggestions.</string>
<string name="discover_more">more »</string>
<string name="discover_powered_by_itunes">Suggestions by iTunes</string>
<string name="discover_confirm">Show suggestions</string>
<string name="search_powered_by">Results by %1$s</string>
<string name="country">Country</string>