From 839cd7d1c7798dcf08457d31ef22ca8d91503068 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 5 Mar 2016 16:24:47 +0100 Subject: [PATCH] some small fixes --- .../schabi/newpipe/VideoItemListActivity.java | 19 ++++++++++--------- .../schabi/newpipe/extractor/ServiceList.java | 9 +++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java index d3062fdd3..0d879149d 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java @@ -68,7 +68,6 @@ public class VideoItemListActivity extends AppCompatActivity private Menu menu = null; private SuggestionListAdapter suggestionListAdapter; - private StreamingService streamingService; private SuggestionSearchRunnable suggestionSearchRunnable; private Thread searchThread; @@ -152,12 +151,12 @@ public class VideoItemListActivity extends AppCompatActivity } private class SuggestionSearchRunnable implements Runnable{ - private final SearchEngine engine; + private final int serviceId; private final String query; final Handler h = new Handler(); private Context context; - private SuggestionSearchRunnable(SearchEngine engine, String query) { - this.engine = engine; + private SuggestionSearchRunnable(int serviceId, String query) { + this.serviceId = serviceId; this.query = query; context = VideoItemListActivity.this; } @@ -165,6 +164,8 @@ public class VideoItemListActivity extends AppCompatActivity @Override public void run() { try { + SearchEngine engine = + ServiceList.getService(serviceId).getSearchEngineInstance(new Downloader()); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); String searchLanguageKey = context.getString(R.string.search_language_key); String searchLanguage = sp.getString(searchLanguageKey, @@ -174,7 +175,7 @@ public class VideoItemListActivity extends AppCompatActivity } catch (ExtractionException e) { ErrorActivity.reportError(h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, - /* todo: this shoudl not be assigned static */ "Youtube", query, R.string.parsing_error)); + ServiceList.getNameOfService(serviceId), query, R.string.parsing_error)); e.printStackTrace(); } catch (IOException e) { postNewErrorToast(h, R.string.network_error); @@ -182,7 +183,7 @@ public class VideoItemListActivity extends AppCompatActivity } catch (Exception e) { ErrorActivity.reportError(h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, - /* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error)); + ServiceList.getNameOfService(serviceId), query, R.string.general_error)); } } } @@ -196,6 +197,7 @@ public class VideoItemListActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_videoitem_list); + StreamingService streamingService = null; try { //------ todo: remove this line when multiservice support is implemented ------ @@ -205,7 +207,7 @@ public class VideoItemListActivity extends AppCompatActivity e.printStackTrace(); ErrorActivity.reportError(VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, - /* todo: this shoudl not be assigned static */ "Youtube", "", R.string.general_error)); + ServiceList.getNameOfService(currentStreamingServiceId), "", R.string.general_error)); } //----------------------------------------------------------------------------- //to solve issue 38 @@ -365,8 +367,7 @@ public class VideoItemListActivity extends AppCompatActivity private void searchSuggestions(String query) { suggestionSearchRunnable = - new SuggestionSearchRunnable(streamingService.getSearchEngineInstance(new Downloader()), - query); + new SuggestionSearchRunnable(currentStreamingServiceId, query); searchThread = new Thread(suggestionSearchRunnable); searchThread.start(); diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ServiceList.java b/app/src/main/java/org/schabi/newpipe/extractor/ServiceList.java index 9d57225a7..2305f2d1c 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ServiceList.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/ServiceList.java @@ -47,6 +47,15 @@ public class ServiceList { public static StreamingService getService(String serviceName) throws ExtractionException { return services[getIdOfService(serviceName)]; } + public static String getNameOfService(int id) { + try { + return getService(id).getServiceInfo().name; + } catch (Exception e) { + System.err.println("Service id not known"); + e.printStackTrace(); + return ""; + } + } public static int getIdOfService(String serviceName) throws ExtractionException { for(int i = 0; i < services.length; i++) { if(services[i].getServiceInfo().name.equals(serviceName)) {