@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, getString(R.string.default_language_value)); ArrayList<String> suggestions = engine.suggestionList(query, searchLanguage, new Downloader()); h.post(new SuggestionResultRunnable(suggestions)); } catch (ExtractionException e) { ErrorActivity.reportError( h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list), ErrorActivity.ErrorInfo.make( ErrorActivity.SEARCHED, ServiceList.getNameOfService(serviceId), query, R.string.parsing_error)); e.printStackTrace(); } catch (IOException e) { postNewErrorToast(h, R.string.network_error); e.printStackTrace(); } catch (Exception e) { ErrorActivity.reportError( h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list), ErrorActivity.ErrorInfo.make( ErrorActivity.SEARCHED, ServiceList.getNameOfService(serviceId), query, R.string.general_error)); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: { Intent intent = new Intent(this, VideoItemListActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); NavUtils.navigateUpTo(this, intent); return true; } case R.id.action_settings: { Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); return true; } case R.id.action_report_error: { ErrorActivity.reportError( VideoItemListActivity.this, new Vector<Exception>(), null, null, ErrorActivity.ErrorInfo.make( ErrorActivity.USER_REPORT, ServiceList.getNameOfService(currentStreamingServiceId), "user_report", R.string.user_report)); return true; } case R.id.action_show_downloads: { Intent intent = new Intent(this, org.schabi.newpipe.download.MainActivity.class); startActivity(intent); return true; } default: return videoFragment.onOptionsItemSelected(item) || super.onOptionsItemSelected(item); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_videoitem_list); StreamingService streamingService = null; View bg = findViewById(R.id.mainBG); bg.setVisibility(View.VISIBLE); try { // ------ todo: remove this line when multiservice support is implemented ------ currentStreamingServiceId = ServiceList.getIdOfService("Youtube"); streamingService = ServiceList.getService(currentStreamingServiceId); } catch (Exception e) { e.printStackTrace(); ErrorActivity.reportError( VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list), ErrorActivity.ErrorInfo.make( ErrorActivity.SEARCHED, ServiceList.getNameOfService(currentStreamingServiceId), "", R.string.general_error)); } setVolumeControlStream(AudioManager.STREAM_MUSIC); listFragment = (VideoItemListFragment) getSupportFragmentManager().findFragmentById(R.id.videoitem_list); listFragment.setStreamingService(streamingService); if (savedInstanceState != null && mode != PRESENT_VIDEOS_MODE) { searchQuery = savedInstanceState.getString(QUERY); currentStreamingServiceId = savedInstanceState.getInt(STREAMING_SERVICE); if (!searchQuery.isEmpty()) { listFragment.search(searchQuery); } } if (findViewById(R.id.videoitem_detail_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; // In two-pane mode, list items should be given the // 'activated' state when touched. ((VideoItemListFragment) getSupportFragmentManager().findFragmentById(R.id.videoitem_list)) .setActivateOnItemClick(true); SearchView searchView = (SearchView) findViewById(R.id.searchViewTablet); if (mode != PRESENT_VIDEOS_MODE) { // Somehow the seticonifiedbydefault property set by the layout xml is not working on // the support version on SearchView, so it needs to be set programmatically. searchView.setIconifiedByDefault(false); searchView.setIconified(false); if (!searchQuery.isEmpty()) { searchView.setQuery(searchQuery, false); } searchView.setOnQueryTextListener(new SearchVideoQueryListener()); suggestionListAdapter = new SuggestionListAdapter(this); searchView.setSuggestionsAdapter(suggestionListAdapter); searchView.setOnSuggestionListener(new SearchSuggestionListener(searchView)); } else { searchView.setVisibility(View.GONE); } } PreferenceManager.setDefaultValues(this, R.xml.settings, false); }