1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-23 03:22:37 +01:00

Added country language param to the suggestionList method in search engine

This commit is contained in:
madiyar 2016-02-23 16:22:49 +06:00
parent c7679bec87
commit 8fc113cc52
5 changed files with 12 additions and 15 deletions

View File

@ -40,7 +40,7 @@ public class YoutubeSearchEngineTest extends AndroidTestCase {
result = engine.search("https://www.youtube.com/results?search_query=bla",
0, "de", new Downloader());
suggestionReply = engine.suggestionList("hello", new Downloader());
suggestionReply = engine.suggestionList("hello","de",new Downloader());
}
public void testIfNoErrorOccur() {

View File

@ -16,20 +16,10 @@ import java.util.ArrayList;
*/
public class SuggestionListAdapter extends CursorAdapter {
private ArrayList<String> suggestions;
private String[] columns = new String[]{"_id", "title"};
public SuggestionListAdapter(Context context) {
super(context, null, false);
}
public ArrayList<String> getSuggestions() {
return suggestions;
}
public void setSuggestions(ArrayList<String> suggestions) {
this.suggestions = suggestions;
}
@Override

View File

@ -2,6 +2,7 @@ package org.schabi.newpipe;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
@ -150,16 +151,21 @@ public class VideoItemListActivity extends AppCompatActivity
private final SearchEngine engine;
private final String query;
final Handler h = new Handler();
private Context context;
private SuggestionSearchRunnable(SearchEngine engine, String query) {
this.engine = engine;
this.query = query;
context = VideoItemListActivity.this;
}
@Override
public void run() {
try {
ArrayList<String>suggestions = engine.suggestionList(query,new Downloader());
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String searchLanguageKey = context.getString(R.string.search_language_key);
String searchLanguage = sp.getString(searchLanguageKey,
getString(R.string.default_language_value));
ArrayList<String>suggestions = engine.suggestionList(query,searchLanguage,new Downloader());
h.post(new SuggestionResultRunnable(suggestions));
} catch (ExtractionException e) {
e.printStackTrace();

View File

@ -33,7 +33,7 @@ public interface SearchEngine {
public final List<VideoPreviewInfo> resultList = new Vector<>();
}
ArrayList<String> suggestionList(String query, Downloader dl)
ArrayList<String> suggestionList(String query,String contentCountry, Downloader dl)
throws ExtractionException, IOException;
//Result search(String query, int page);

View File

@ -147,7 +147,7 @@ public class YoutubeSearchEngine implements SearchEngine {
}
@Override
public ArrayList<String> suggestionList(String query, Downloader dl)
public ArrayList<String> suggestionList(String query,String contentCountry, Downloader dl)
throws IOException, ParsingException {
ArrayList<String> suggestions = new ArrayList<>();
@ -160,6 +160,7 @@ public class YoutubeSearchEngine implements SearchEngine {
.appendQueryParameter("client", "")
.appendQueryParameter("output", "toolbar")
.appendQueryParameter("ds", "yt")
.appendQueryParameter("hl",contentCountry)
.appendQueryParameter("q", query);
String url = builder.build().toString();