switch languageCode to content country

This commit is contained in:
Christian Schabesberger 2018-01-09 12:25:40 +01:00
parent 28a9855fd2
commit 33d75fd2fb
7 changed files with 36 additions and 22 deletions

View file

@ -143,8 +143,8 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
public Single<KioskInfo> loadResult(boolean forceReload) {
String contentCountry = PreferenceManager
.getDefaultSharedPreferences(activity)
.getString(getString(R.string.search_language_key),
getString(R.string.default_language_value));
.getString(getString(R.string.content_country_key),
getString(R.string.default_country_value));
return ExtractorHelper.getKioskInfo(serviceId, url, contentCountry, forceReload);
}
@ -152,8 +152,8 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
public Single<ListExtractor.NextItemsResult> loadMoreItemsLogic() {
String contentCountry = PreferenceManager
.getDefaultSharedPreferences(activity)
.getString(getString(R.string.search_language_key),
getString(R.string.default_language_value));
.getString(getString(R.string.content_country_key),
getString(R.string.default_country_value));
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextItemsUrl, contentCountry);
}

View file

@ -111,7 +111,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
private int currentPage = 0;
private int currentNextPage = 0;
private String searchLanguage;
private String contentCountry;
private boolean isSuggestionsEnabled = true;
private boolean isSearchHistoryEnabled = true;
@ -176,7 +176,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
isSuggestionsEnabled = preferences.getBoolean(getString(R.string.show_search_suggestions_key), true);
searchLanguage = preferences.getString(getString(R.string.search_language_key), getString(R.string.default_language_value));
contentCountry = preferences.getString(getString(R.string.content_country_key), getString(R.string.default_country_value));
}
@Override
@ -619,7 +619,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
return local.materialize();
}
final Observable<List<SuggestionItem>> network = ExtractorHelper.suggestionsFor(serviceId, query, searchLanguage).toObservable()
final Observable<List<SuggestionItem>> network = ExtractorHelper.suggestionsFor(serviceId, query, contentCountry).toObservable()
.map(new Function<List<String>, List<SuggestionItem>>() {
@Override
public List<SuggestionItem> apply(@io.reactivex.annotations.NonNull List<String> strings) throws Exception {
@ -731,7 +731,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
super.startLoading(forceLoad);
if (disposables != null) disposables.clear();
if (searchDisposable != null) searchDisposable.dispose();
searchDisposable = ExtractorHelper.searchFor(serviceId, searchQuery, currentPage, searchLanguage, filter)
searchDisposable = ExtractorHelper.searchFor(serviceId, searchQuery, currentPage, contentCountry, filter)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<SearchResult>() {
@ -755,7 +755,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
showListFooter(true);
if (searchDisposable != null) searchDisposable.dispose();
currentNextPage = currentPage + 1;
searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, searchQuery, currentNextPage, searchLanguage, filter)
searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, searchQuery, currentNextPage, contentCountry, filter)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ListExtractor.NextItemsResult>() {

View file

@ -382,7 +382,7 @@ public class ErrorActivity extends AppCompatActivity {
private String getContentLangString() {
return PreferenceManager.getDefaultSharedPreferences(this)
.getString(this.getString(R.string.search_language_key), "none");
.getString(this.getString(R.string.content_country_key), "none");
}
private String getOsString() {

View file

@ -57,13 +57,13 @@ public final class ExtractorHelper {
}
}
public static Single<SearchResult> searchFor(final int serviceId, final String query, final int pageNumber, final String searchLanguage, final SearchEngine.Filter filter) {
public static Single<SearchResult> searchFor(final int serviceId, final String query, final int pageNumber, final String contentCountry, final SearchEngine.Filter filter) {
checkServiceId(serviceId);
return Single.fromCallable(new Callable<SearchResult>() {
@Override
public SearchResult call() throws Exception {
return SearchResult.getSearchResult(NewPipe.getService(serviceId).getSearchEngine(),
query, pageNumber, searchLanguage, filter);
query, pageNumber, contentCountry, filter);
}
});
}
@ -79,12 +79,12 @@ public final class ExtractorHelper {
});
}
public static Single<List<String>> suggestionsFor(final int serviceId, final String query, final String searchLanguage) {
public static Single<List<String>> suggestionsFor(final int serviceId, final String query, final String contentCountry) {
checkServiceId(serviceId);
return Single.fromCallable(new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
return NewPipe.getService(serviceId).getSuggestionExtractor().suggestionList(query, searchLanguage);
return NewPipe.getService(serviceId).getSuggestionExtractor().suggestionList(query, contentCountry);
}
});
}
@ -143,7 +143,8 @@ public final class ExtractorHelper {
return checkCache(forceLoad, serviceId, url, Single.fromCallable(new Callable<KioskInfo>() {
@Override
public KioskInfo call() throws Exception {
return KioskInfo.getInfo(NewPipe.getService(serviceId), url, toUpperCase(contentCountry));
Log.e("---------", contentCountry);
return KioskInfo.getInfo(NewPipe.getService(serviceId), url, contentCountry);
}
}));
}
@ -152,7 +153,7 @@ public final class ExtractorHelper {
return Single.fromCallable(new Callable<NextItemsResult>() {
@Override
public NextItemsResult call() throws Exception {
return KioskInfo.getMoreItems(NewPipe.getService(serviceId), url, nextStreamsUrl, toUpperCase(contentCountry));
return KioskInfo.getMoreItems(NewPipe.getService(serviceId), url, nextStreamsUrl, contentCountry);
}
});
}

View file

@ -100,7 +100,9 @@
<string name="show_next_video_key" translatable="false">show_next_video</string>
<string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string>
<string name="default_language_value">en</string>
<string name="default_country_value">GB</string>
<string name="search_language_key" translatable="false">search_language</string>
<string name="content_country_key" translatable="false">content_country</string>
<string name="show_age_restricted_content" translatable="false">show_age_restricted_content</string>
<string name="use_tor_key" translatable="false">use_tor</string>
<string name="enable_search_history_key" translatable="false">enable_search_history</string>
@ -518,7 +520,7 @@
<item>Sweden</item>
<item>Switzerland</item>
<item>Syrian ArabRepublic(Syria)</item>
<item>Taiwan,RepublicofChina</item>
<item>Taiwan, Republicof China</item>
<item>Tajikistan</item>
<item>Tanzania</item>
<item>Thailand</item>
@ -534,10 +536,10 @@
<item>Tuvalu</item>
<item>Uganda</item>
<item>Ukraine</item>
<item>UnitedArabEmirates</item>
<item>UnitedKingdom</item>
<item>United Arab Emirates</item>
<item>United Kingdom</item>
<item>USA</item>
<item>MinorOutlyingIslands</item>
<item>Minor Outlying Islands</item>
<item>Uruguay</item>
<item>Uzbekistan</item>
<item>Vanuatu</item>

View file

@ -83,7 +83,8 @@
<string name="show_hold_to_append_title">Show Hold to Append Tip</string>
<string name="show_hold_to_append_summary">Show tip when background or popup button is pressed on video details page</string>
<string name="url_not_supported_toast">URL not supported</string>
<string name="default_content_country_title">Default content country.</string>
<string name="default_content_country_title">Default content country</string>
<string name="search_language_title">Default content language</string>
<string name="settings_category_player_title">Player</string>
<string name="settings_category_player_behavior_title">Behavior</string>
<string name="settings_category_video_audio_title">Video &amp; Audio</string>

View file

@ -3,13 +3,23 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/content">
<ListPreference
android:defaultValue="@string/default_country_value"
android:entries="@array/country_names"
android:entryValues="@array/country_codes"
android:key="@string/content_country_key"
android:summary="%s"
android:title="@string/default_content_country_title"/>
<!-- TODO: add support for this within code
<ListPreference
android:defaultValue="@string/default_language_value"
android:entries="@array/language_names"
android:entryValues="@array/language_codes"
android:key="@string/search_language_key"
android:summary="%s"
android:title="@string/default_content_country_title"/>
android:title="@string/search_language_title"/>
-->
<SwitchPreference
android:defaultValue="false"