diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java
index 4f28b606d..94d79514d 100644
--- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java
+++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java
@@ -6,7 +6,6 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
@@ -36,7 +35,8 @@ import android.widget.ArrayAdapter;
* along with NewPipe. If not, see .
*/
-public class ActionBarHandler {
+
+class ActionBarHandler {
private static final String TAG = ActionBarHandler.class.toString();
private static final String KORE_PACKET = "org.xbmc.kore";
@@ -47,10 +47,11 @@ public class ActionBarHandler {
private int selectedStream = -1;
private String videoTitle = "";
- SharedPreferences defaultPreferences = null;
+ private SharedPreferences defaultPreferences = null;
private int startPosition;
- class FormatItemSelectListener implements ActionBar.OnNavigationListener {
+ @SuppressWarnings("deprecation")
+ private class FormatItemSelectListener implements ActionBar.OnNavigationListener {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
selectFormatItem((int)itemId);
@@ -62,11 +63,17 @@ public class ActionBarHandler {
this.activity = activity;
}
+ @SuppressWarnings({"deprecation", "ConstantConditions"})
public void setupNavMenu(AppCompatActivity activity) {
this.activity = activity;
- activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ try {
+ activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ } catch(NullPointerException e) {
+ e.printStackTrace();
+ }
}
+ @SuppressWarnings("deprecation")
public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStream[] audioStreams) {
this.videoStreams = videoStreams;
selectedStream = 0;
@@ -84,12 +91,14 @@ public class ActionBarHandler {
}
}
- ArrayAdapter itemAdapter = new ArrayAdapter(activity.getBaseContext(),
+ ArrayAdapter itemAdapter = new ArrayAdapter<>(activity.getBaseContext(),
android.R.layout.simple_spinner_dropdown_item, itemArray);
if(activity != null) {
ActionBar ab = activity.getSupportActionBar();
- ab.setListNavigationCallbacks(itemAdapter
- ,new FormatItemSelectListener());
+ assert ab != null : "Could not get actionbar";
+ ab.setListNavigationCallbacks(itemAdapter
+ , new FormatItemSelectListener());
+
ab.setSelectedNavigationItem(defaultResolutionPos);
}
@@ -117,7 +126,7 @@ public class ActionBarHandler {
selectedStream = i;
}
- public boolean setupMenu(Menu menu, MenuInflater inflater) {
+ public void setupMenu(Menu menu, MenuInflater inflater) {
// CAUTION set item properties programmatically otherwise it would not be accepted by
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);
@@ -128,8 +137,6 @@ public class ActionBarHandler {
castItem.setVisible(defaultPreferences
.getBoolean(activity.getString(R.string.showPlayWidthKodiPreference), false));
-
- return true;
}
public boolean onItemSelected(MenuItem item) {
@@ -229,7 +236,7 @@ public class ActionBarHandler {
this.startPosition = startPositionSeconds;
}
- public void downloadVideo() {
+ private void downloadVideo() {
if(!videoTitle.isEmpty()) {
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
@@ -245,7 +252,7 @@ public class ActionBarHandler {
}
}
- public void openInBrowser() {
+ private void openInBrowser() {
if(!videoTitle.isEmpty()) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
@@ -255,7 +262,7 @@ public class ActionBarHandler {
}
}
- public void playWithKodi() {
+ private void playWithKodi() {
if(!videoTitle.isEmpty()) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -286,7 +293,7 @@ public class ActionBarHandler {
}
}
- public void playAudio() {
+ private void playAudio() {
Intent intent = new Intent();
try {
intent.setAction(Intent.ACTION_VIEW);
diff --git a/app/src/main/java/org/schabi/newpipe/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/DownloadDialog.java
index 01479b642..fa79e5f82 100644
--- a/app/src/main/java/org/schabi/newpipe/DownloadDialog.java
+++ b/app/src/main/java/org/schabi/newpipe/DownloadDialog.java
@@ -8,6 +8,7 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.util.Log;
@@ -42,8 +43,9 @@ public class DownloadDialog extends DialogFragment {
public static final String FILE_SUFFIX_VIDEO = "file_suffix_video";
public static final String AUDIO_URL = "audio_url";
public static final String VIDEO_URL = "video_url";
- Bundle arguments;
+ private Bundle arguments;
+ @NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
arguments = getArguments();
diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java
index 9c2fa2948..f0a19cfc5 100644
--- a/app/src/main/java/org/schabi/newpipe/Downloader.java
+++ b/app/src/main/java/org/schabi/newpipe/Downloader.java
@@ -50,8 +50,8 @@ public class Downloader {
return ret;
}
/**Common functionality between download(String url) and download(String url, String language)*/
- private static String dl(HttpURLConnection con) {
- StringBuffer response = new StringBuffer();
+ private static String dl(HttpURLConnection con) throws IOException {
+ StringBuilder response = new StringBuilder();
try {
con.setRequestMethod("GET");
@@ -71,9 +71,7 @@ public class Downloader {
uhe.printStackTrace();
//Toast.makeText(getActivity(), uhe.getMessage(), Toast.LENGTH_LONG).show();
}
- catch (Exception e) {
- e.printStackTrace();
- }
+
return response.toString();
}
diff --git a/app/src/main/java/org/schabi/newpipe/MediaFormat.java b/app/src/main/java/org/schabi/newpipe/MediaFormat.java
index c9af7b8b7..f3f6348f0 100644
--- a/app/src/main/java/org/schabi/newpipe/MediaFormat.java
+++ b/app/src/main/java/org/schabi/newpipe/MediaFormat.java
@@ -23,6 +23,7 @@ package org.schabi.newpipe;
*/
/**Static data about various media formats support by Newpipe, eg mime type, extension*/
+
public enum MediaFormat {
// id name suffix mime type
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
@@ -32,7 +33,9 @@ public enum MediaFormat {
WEBMA (0x4, "WebM", "webm", "audio/webm");
public final int id;
+ @SuppressWarnings("WeakerAccess")
public final String name;
+ @SuppressWarnings("WeakerAccess")
public final String suffix;
public final String mimeType;
diff --git a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java
index 33a4b0b72..825f69949 100644
--- a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java
@@ -84,6 +84,7 @@ public class PlayVideoActivity extends AppCompatActivity {
hasSoftKeys = checkIfHasSoftKeys();
actionBar = getSupportActionBar();
+ assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
if(mediaController == null) {
@@ -291,11 +292,9 @@ public class PlayVideoActivity extends AppCompatActivity {
}
private boolean checkIfHasSoftKeys(){
- if(Build.VERSION.SDK_INT >= 17) {
- return getNavigationBarHeight() != 0 || getNavigationBarWidth() != 0;
- } else {
- return true;
- }
+ return Build.VERSION.SDK_INT >= 17 ||
+ getNavigationBarHeight() != 0 ||
+ getNavigationBarWidth() != 0;
}
private int getNavigationBarHeight() {
@@ -332,7 +331,7 @@ public class PlayVideoActivity extends AppCompatActivity {
}
}
- public boolean checkIfLandscape() {
+ private boolean checkIfLandscape() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels < displayMetrics.widthPixels;
diff --git a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
index 11313124d..b434b53d8 100644
--- a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
@@ -9,10 +9,9 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
-import android.support.annotation.Nullable;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
-import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
@@ -70,14 +69,11 @@ public class SettingsActivity extends PreferenceActivity {
getDelegate().onPostCreate(savedInstanceState);
}
- public ActionBar getSupportActionBar() {
+ private ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}
- public void setSupportActionBar(@Nullable Toolbar toolbar) {
- getDelegate().setSupportActionBar(toolbar);
- }
-
+ @NonNull
@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/VideoInfo.java
index 80e5d3861..c7c051945 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoInfo.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoInfo.java
@@ -58,6 +58,7 @@ public class VideoInfo extends AbstractVideoInfo {
/**Creates a new VideoInfo object from an existing AbstractVideoInfo.
* All the shared properties are copied to the new VideoInfo.*/
+ @SuppressWarnings("WeakerAccess")
public VideoInfo(AbstractVideoInfo avi) {
this.id = avi.id;
this.title = avi.title;
@@ -76,7 +77,6 @@ public class VideoInfo extends AbstractVideoInfo {
int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length()));
this.duration = (minutes*60)+seconds;
}
-
}
public static class VideoStream {
diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java
index 07cd09e3c..efd752788 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java
@@ -26,10 +26,10 @@ import android.widget.TextView;
* along with NewPipe. If not, see .
*/
-public class VideoInfoItemViewCreator {
+class VideoInfoItemViewCreator {
private static final String TAG = VideoInfoItemViewCreator.class.toString();
- LayoutInflater inflater;
+ private final LayoutInflater inflater;
public VideoInfoItemViewCreator(LayoutInflater inflater) {
this.inflater = inflater;
diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java
index e5b224222..4a553241f 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java
@@ -5,11 +5,11 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
-import org.schabi.newpipe.services.VideoExtractor;
import org.schabi.newpipe.services.ServiceList;
import org.schabi.newpipe.services.StreamingService;
@@ -36,7 +36,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
private static final String TAG = VideoItemDetailActivity.class.toString();
- VideoItemDetailFragment fragment;
+ private VideoItemDetailFragment fragment;
private String videoUrl;
private int currentStreamingService = -1;
@@ -46,7 +46,13 @@ public class VideoItemDetailActivity extends AppCompatActivity {
setContentView(R.layout.activity_videoitem_detail);
// Show the Up button in the action bar.
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ try {
+ //noinspection ConstantConditions
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ } catch(Exception e) {
+ Log.d(TAG, "Could not get SupportActionBar");
+ e.printStackTrace();
+ }
// savedInstanceState is non-null when there is fragment state
// saved from previous configurations of this activity
@@ -64,7 +70,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
if (getIntent().getData() != null) {
videoUrl = getIntent().getData().toString();
StreamingService[] serviceList = ServiceList.getServices();
- VideoExtractor videoExtractor = null;
+ //VideoExtractor videoExtractor = null;
for (int i = 0; i < serviceList.length; i++) {
if (serviceList[i].acceptUrl(videoUrl)) {
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i);
diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java
index 8c244cff0..84009069a 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java
@@ -81,7 +81,6 @@ public class VideoItemDetailFragment extends Fragment {
private ActionBarHandler actionBarHandler;
private boolean autoPlayEnabled = false;
- private Thread videoExtractorThread = null;
private VideoInfo currentVideoInfo = null;
private boolean showNextVideoItem = false;
@@ -92,12 +91,12 @@ public class VideoItemDetailFragment extends Fragment {
private OnInvokeCreateOptionsMenuListener onInvokeCreateOptionsMenuListener = null;
private class VideoExtractorRunnable implements Runnable {
- private Handler h = new Handler();
+ private final Handler h = new Handler();
private VideoExtractor videoExtractor;
- private StreamingService service;
- private String videoUrl;
+ private final StreamingService service;
+ private final String videoUrl;
- public VideoExtractorRunnable(String videoUrl, StreamingService service, VideoItemDetailFragment f) {
+ public VideoExtractorRunnable(String videoUrl, StreamingService service) {
this.service = service;
this.videoUrl = videoUrl;
}
@@ -137,7 +136,7 @@ public class VideoItemDetailFragment extends Fragment {
}
private class VideoResultReturnedRunnable implements Runnable {
- private VideoInfo videoInfo;
+ private final VideoInfo videoInfo;
public VideoResultReturnedRunnable(VideoInfo videoInfo) {
this.videoInfo = videoInfo;
}
@@ -153,8 +152,8 @@ public class VideoItemDetailFragment extends Fragment {
public static final int VIDEO_THUMBNAIL = 1;
public static final int CHANNEL_THUMBNAIL = 2;
public static final int NEXT_VIDEO_THUMBNAIL = 3;
- private Bitmap thumbnail;
- private int thumbnailId;
+ private final Bitmap thumbnail;
+ private final int thumbnailId;
public SetThumbnailRunnable(Bitmap thumbnail, int id) {
this.thumbnail = thumbnail;
this.thumbnailId = id;
@@ -165,9 +164,9 @@ public class VideoItemDetailFragment extends Fragment {
}
}
- public void updateThumbnail(Bitmap thumbnail, int id) {
+ private void updateThumbnail(Bitmap thumbnail, int id) {
Activity a = getActivity();
- ImageView thumbnailView = null;
+ ImageView thumbnailView;
try {
switch (id) {
case SetThumbnailRunnable.VIDEO_THUMBNAIL:
@@ -196,7 +195,7 @@ public class VideoItemDetailFragment extends Fragment {
}
}
- public void updateInfo(VideoInfo info) {
+ private void updateInfo(VideoInfo info) {
currentVideoInfo = info;
Resources res = activity.getResources();
try {
@@ -330,8 +329,6 @@ public class VideoItemDetailFragment extends Fragment {
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
- public VideoItemDetailFragment() {
- }
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -367,8 +364,8 @@ public class VideoItemDetailFragment extends Fragment {
try {
StreamingService streamingService = ServiceList.getService(
getArguments().getInt(STREAMING_SERVICE));
- videoExtractorThread = new Thread(new VideoExtractorRunnable(
- getArguments().getString(VIDEO_URL), streamingService, this));
+ Thread videoExtractorThread = new Thread(new VideoExtractorRunnable(
+ getArguments().getString(VIDEO_URL), streamingService));
autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
videoExtractorThread.start();
@@ -416,10 +413,12 @@ public class VideoItemDetailFragment extends Fragment {
/**Returns the java.util.Locale object which corresponds to the locale set in NewPipe's preferences.
* Currently not affected by the device's locale.*/
- public Locale getPreferredLocale() {
+ private Locale getPreferredLocale() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
String languageKey = getContext().getString(R.string.searchLanguage);
- String languageCode = "en";//i know the following line defaults languageCode to "en", but java is picky about uninitialised values
+ //i know the following line defaults languageCode to "en", but java is picky about uninitialised values
+ // Schabi: well lint tels me the value is redundant. I'll suppress it for now.
+ @SuppressWarnings("UnusedAssignment") String languageCode = "en";
languageCode = sp.getString(languageKey, "en");
if(languageCode.length() == 2) {
@@ -433,7 +432,7 @@ public class VideoItemDetailFragment extends Fragment {
return Locale.getDefault();
}
- public boolean checkIfLandscape() {
+ private boolean checkIfLandscape() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels < displayMetrics.widthPixels;
diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java
index 7a89682f3..37bf67333 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java
@@ -6,6 +6,7 @@ import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -56,9 +57,9 @@ public class VideoItemListActivity extends AppCompatActivity
private VideoItemListFragment listFragment;
private VideoItemDetailFragment videoFragment = null;
- Menu menu = null;
+ private Menu menu = null;
- public class SearchVideoQueryListener implements SearchView.OnQueryTextListener {
+ private class SearchVideoQueryListener implements SearchView.OnQueryTextListener {
@Override
public boolean onQueryTextSubmit(String query) {
@@ -69,8 +70,14 @@ public class VideoItemListActivity extends AppCompatActivity
// hide virtual keyboard
InputMethodManager inputManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- inputManager.hideSoftInputFromWindow(
- getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
+ try {
+ //noinspection ConstantConditions
+ inputManager.hideSoftInputFromWindow(
+ getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
+ } catch(NullPointerException e) {
+ Log.e(TAG, "Could not get widget with focus");
+ e.printStackTrace();
+ }
// clear focus
// 1. to not open up the keyboard after switching back to this
// 2. It's a workaround to a seeming bug by the Android OS it self, causing
@@ -116,7 +123,13 @@ public class VideoItemListActivity extends AppCompatActivity
ArrayList p = arguments.getParcelableArrayList(VIDEO_INFO_ITEMS);
if(p != null) {
mode = PRESENT_VIDEOS_MODE;
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ try {
+ //noinspection ConstantConditions
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Could not get SupportActionBar");
+ e.printStackTrace();
+ }
listFragment.present(p);
}
diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java
index 2c8cb6de9..fb2ba14a7 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java
@@ -64,8 +64,8 @@ public class VideoItemListFragment extends ListFragment {
private ListView list;
private class ResultRunnable implements Runnable {
- private SearchEngine.Result result;
- private int requestId;
+ private final SearchEngine.Result result;
+ private final int requestId;
public ResultRunnable(SearchEngine.Result result, int requestId) {
this.result = result;
this.requestId = requestId;
@@ -77,12 +77,12 @@ public class VideoItemListFragment extends ListFragment {
}
private class SearchRunnable implements Runnable {
- private SearchEngine engine;
- private String query;
- private int page;
- Handler h = new Handler();
+ private final SearchEngine engine;
+ private final String query;
+ private final int page;
+ final Handler h = new Handler();
private volatile boolean run = true;
- private int requestId;
+ private final int requestId;
public SearchRunnable(SearchEngine engine, String query, int page, int requestId) {
this.engine = engine;
this.query = query;
@@ -116,11 +116,11 @@ public class VideoItemListFragment extends ListFragment {
}
private class LoadThumbsRunnable implements Runnable {
- private Vector thumbnailUrlList = new Vector<>();
- private Vector downloadedList;
- Handler h = new Handler();
+ private final Vector thumbnailUrlList = new Vector<>();
+ private final Vector downloadedList;
+ final Handler h = new Handler();
private volatile boolean run = true;
- private int requestId;
+ private final int requestId;
public LoadThumbsRunnable(Vector videoList,
Vector downloadedList, int requestId) {
for(VideoPreviewInfo item : videoList) {
@@ -139,7 +139,7 @@ public class VideoItemListFragment extends ListFragment {
public void run() {
for(int i = 0; i < thumbnailUrlList.size() && run; i++) {
if(!downloadedList.get(i)) {
- Bitmap thumbnail = null;
+ Bitmap thumbnail;
try {
thumbnail = BitmapFactory.decodeStream(
new URL(thumbnailUrlList.get(i)).openConnection().getInputStream());
@@ -153,9 +153,9 @@ public class VideoItemListFragment extends ListFragment {
}
private class SetThumbnailRunnable implements Runnable {
- private int index;
- private Bitmap thumbnail;
- private int requestId;
+ private final int index;
+ private final Bitmap thumbnail;
+ private final int requestId;
public SetThumbnailRunnable(int index, Bitmap thumbnail, int requestId) {
this.index = index;
this.thumbnail = thumbnail;
@@ -164,7 +164,7 @@ public class VideoItemListFragment extends ListFragment {
@Override
public void run() {
if(requestId == currentRequestId) {
- videoListAdapter.updateDownloadedThumbnailList(index, true);
+ videoListAdapter.updateDownloadedThumbnailList(index);
videoListAdapter.setThumbnail(index, thumbnail);
}
}
@@ -188,7 +188,7 @@ public class VideoItemListFragment extends ListFragment {
getListView().smoothScrollToPosition(0);
}
- public void nextPage() {
+ private void nextPage() {
lastPage++;
Log.d(TAG, getString(R.string.searchPage) + Integer.toString(lastPage));
startSearch(query, lastPage);
@@ -207,7 +207,7 @@ public class VideoItemListFragment extends ListFragment {
this.streamingService = streamingService;
}
- public void updateListOnResult(SearchEngine.Result result, int requestId) {
+ private void updateListOnResult(SearchEngine.Result result, int requestId) {
if(requestId == currentRequestId) {
setListShown(true);
if (result.resultList.isEmpty()) {
@@ -237,7 +237,7 @@ public class VideoItemListFragment extends ListFragment {
}
}
- public void terminateThreads() {
+ private void terminateThreads() {
if(loadThumbsRunnable != null && loadThumbsRunnable.isRunning()) {
loadThumbsRunnable.terminate();
try {
@@ -276,12 +276,7 @@ public class VideoItemListFragment extends ListFragment {
void onItemSelected(String id);
}
- Callbacks mCallbacks = null;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
+ private Callbacks mCallbacks = null;
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
@@ -333,11 +328,6 @@ public class VideoItemListFragment extends ListFragment {
mCallbacks = (Callbacks) context;
}
- @Override
- public void onDetach() {
- super.onDetach();
- }
-
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
@@ -345,22 +335,11 @@ public class VideoItemListFragment extends ListFragment {
mCallbacks.onItemSelected(Long.toString(id));
}
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- /*
- if (mActivatedPosition != ListView.INVALID_POSITION) {
- // Serialize and persist the activated item position.
- outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
- }
- */
- }
-
/**
* Turns on activate-on-click mode. When this mode is on, list items will be
* given the 'activated' state when touched.
*/
- public void setActivateOnItemClick(boolean activateOnItemClick) {
+ public void setActivateOnItemClick(@SuppressWarnings("SameParameterValue") boolean activateOnItemClick) {
// When setting CHOICE_MODE_SINGLE, ListView will automatically
// give items the 'activated' state when touched.
getListView().setChoiceMode(activateOnItemClick
diff --git a/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java b/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java
index 6f20a92db..6f06430d3 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java
@@ -32,19 +32,17 @@ import java.util.Vector;
* along with NewPipe. If not, see .
*/
-public class VideoListAdapter extends BaseAdapter {
+class VideoListAdapter extends BaseAdapter {
private static final String TAG = VideoListAdapter.class.toString();
- private Context context;
- private VideoInfoItemViewCreator viewCreator;
+ private final Context context;
+ private final VideoInfoItemViewCreator viewCreator;
private Vector videoList = new Vector<>();
private Vector downloadedThumbnailList = new Vector<>();
- VideoItemListFragment videoListFragment;
- ListView listView;
+ private final ListView listView;
public VideoListAdapter(Context context, VideoItemListFragment videoListFragment) {
viewCreator = new VideoInfoItemViewCreator(LayoutInflater.from(context));
- this.videoListFragment = videoListFragment;
this.listView = videoListFragment.getListView();
this.context = context;
}
@@ -67,8 +65,8 @@ public class VideoListAdapter extends BaseAdapter {
return videoList;
}
- public void updateDownloadedThumbnailList(int index, boolean val) {
- downloadedThumbnailList.set(index, val);
+ public void updateDownloadedThumbnailList(int index) {
+ downloadedThumbnailList.set(index, true);
}
public Vector getDownloadedThumbnailList() {
diff --git a/app/src/main/java/org/schabi/newpipe/VideoPreviewInfo.java b/app/src/main/java/org/schabi/newpipe/VideoPreviewInfo.java
index 1e2f96891..0832114e0 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoPreviewInfo.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoPreviewInfo.java
@@ -29,6 +29,7 @@ import org.schabi.newpipe.services.AbstractVideoInfo;
/**Info object for previews of unopened videos, eg search results, related videos*/
public class VideoPreviewInfo extends AbstractVideoInfo implements Parcelable {
public String duration = "";
+ @SuppressWarnings("WeakerAccess")
protected VideoPreviewInfo(Parcel in) {
id = in.readString();
title = in.readString();
diff --git a/app/src/main/java/org/schabi/newpipe/services/SearchEngine.java b/app/src/main/java/org/schabi/newpipe/services/SearchEngine.java
index 4feda4edc..42b0fed6c 100644
--- a/app/src/main/java/org/schabi/newpipe/services/SearchEngine.java
+++ b/app/src/main/java/org/schabi/newpipe/services/SearchEngine.java
@@ -31,7 +31,7 @@ public interface SearchEngine {
class Result {
public String errorMessage = "";
public String suggestion = "";
- public Vector resultList = new Vector<>();
+ public final Vector resultList = new Vector<>();
}
ArrayList suggestionList(String query);
diff --git a/app/src/main/java/org/schabi/newpipe/services/ServiceList.java b/app/src/main/java/org/schabi/newpipe/services/ServiceList.java
index f0522a9cd..53bba3ffb 100644
--- a/app/src/main/java/org/schabi/newpipe/services/ServiceList.java
+++ b/app/src/main/java/org/schabi/newpipe/services/ServiceList.java
@@ -42,7 +42,7 @@ public class ServiceList {
}
public static int getIdOfService(String serviceName) {
for(int i = 0; i < services.length; i++) {
- if(services[i].getServiceInfo().name == serviceName) {
+ if(services[i].getServiceInfo().name.equals(serviceName)) {
return i;
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java b/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java
index 5aefc35d7..01ff361ef 100644
--- a/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java
+++ b/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java
@@ -24,9 +24,10 @@ import org.schabi.newpipe.VideoInfo;
/**Scrapes information from a video streaming service (eg, YouTube).*/
public abstract class VideoExtractor {
- public String pageUrl;
- public VideoInfo videoInfo;
+ protected final String pageUrl;
+ protected VideoInfo videoInfo;
+ @SuppressWarnings("WeakerAccess")
public VideoExtractor(String url) {
this.pageUrl = url;
}
@@ -99,17 +100,17 @@ public abstract class VideoExtractor {
return videoInfo;
}
- public abstract String getVideoUrl(String videoId);
- public abstract String getVideoId(String siteUrl);
- public abstract int getTimeStamp();
- public abstract String getTitle();
- public abstract String getDescription();
- public abstract String getUploader();
- public abstract int getLength();
- public abstract int getViews();
- public abstract String getUploadDate();
- public abstract String getThumbnailUrl();
- public abstract String getUploaderThumbnailUrl();
- public abstract VideoInfo.AudioStream[] getAudioStreams();
- public abstract VideoInfo.VideoStream[] getVideoStreams();
+ protected abstract String getVideoUrl(String videoId);
+ protected abstract String getVideoId(String siteUrl);
+ protected abstract int getTimeStamp();
+ protected abstract String getTitle();
+ protected abstract String getDescription();
+ protected abstract String getUploader();
+ protected abstract int getLength();
+ protected abstract int getViews();
+ protected abstract String getUploadDate();
+ protected abstract String getThumbnailUrl();
+ protected abstract String getUploaderThumbnailUrl();
+ protected abstract VideoInfo.AudioStream[] getAudioStreams();
+ protected abstract VideoInfo.VideoStream[] getVideoStreams();
}
diff --git a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeSearchEngine.java b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeSearchEngine.java
index 9074e4724..a6d6e31c3 100644
--- a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeSearchEngine.java
+++ b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeSearchEngine.java
@@ -95,20 +95,18 @@ public class YoutubeSearchEngine implements SearchEngine {
// both types of spell correction item
if(!((el = item.select("div[class*=\"spell-correction\"]").first()) == null)) {
result.suggestion = el.select("a").first().text();
- // search message item
+ // search message item
} else if(!((el = item.select("div[class*=\"search-message\"]").first()) == null)) {
result.errorMessage = el.text();
- // video item type
+ // video item type
} else if(!((el = item.select("div[class*=\"yt-lockup-video\"").first()) == null)) {
- //todo: de-duplicate this with YoutubeVideoExtractor.getVideoPreviewInfo()
VideoPreviewInfo resultItem = new VideoPreviewInfo();
Element dl = el.select("h3").first().select("a").first();
resultItem.webpage_url = dl.attr("abs:href");
try {
Pattern p = Pattern.compile("v=([0-9a-zA-Z-]*)");
Matcher m = p.matcher(resultItem.webpage_url);
- m.find();
resultItem.id=m.group(1);
} catch (Exception e) {
e.printStackTrace();
@@ -134,6 +132,7 @@ public class YoutubeSearchEngine implements SearchEngine {
}
result.resultList.add(resultItem);
} else {
+ //noinspection ConstantConditions
Log.e(TAG, "unexpected element found:\""+el+"\"");
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java
index 2ff272bad..7d9363ea7 100644
--- a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java
+++ b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java
@@ -50,8 +50,7 @@ import java.util.regex.Pattern;
public class YoutubeVideoExtractor extends VideoExtractor {
private static final String TAG = YoutubeVideoExtractor.class.toString();
- private String pageContents;
- private Document doc;
+ private final Document doc;
private JSONObject jsonObj;
private JSONObject playerArgs;
@@ -64,7 +63,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
public YoutubeVideoExtractor(String pageUrl) {
super(pageUrl);//most common videoInfo fields are now set in our superclass, for all services
- pageContents = Downloader.download(cleanUrl(pageUrl));
+ String pageContents = Downloader.download(cleanUrl(pageUrl));
doc = Jsoup.parse(pageContents, pageUrl);
//attempt to load the youtube js player JSON arguments
@@ -266,6 +265,8 @@ public class YoutubeVideoExtractor extends VideoExtractor {
/**These lists only contain itag formats that are supported by the common Android Video player.
However if you are looking for a list showing all itag formats, look at
https://github.com/rg3/youtube-dl/issues/1687 */
+
+ @SuppressWarnings("WeakerAccess")
public static int resolveFormat(int itag) {
switch(itag) {
// video
@@ -285,6 +286,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
}
}
+ @SuppressWarnings("WeakerAccess")
public static String resolveResolutionString(int itag) {
switch(itag) {
case 17: return "144p";
@@ -303,6 +305,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
}
}
+ @SuppressWarnings("WeakerAccess")
@Override
public String getVideoId(String url) {
String id;
@@ -327,6 +330,7 @@ public class YoutubeVideoExtractor extends VideoExtractor {
return "";
}
+ @SuppressWarnings("WeakerAccess")
@Override
public String getVideoUrl(String videoId) {
return "https://www.youtube.com/watch?v=" + videoId;
@@ -579,7 +583,10 @@ public class YoutubeVideoExtractor extends VideoExtractor {
e.printStackTrace();
}
Context.exit();
- return result.toString();
+ if(result != null)
+ return result.toString();
+ else
+ return "";
}
private String cleanUrl(String complexUrl) {
diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml
index de60976d7..f1cd7ebaf 100644
--- a/app/src/main/res/values/settings_keys.xml
+++ b/app/src/main/res/values/settings_keys.xml
@@ -1,5 +1,5 @@
-
+
settings_categoery_video_audio
settings_category_video_info
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index e38ea093b..a6ca5f74d 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -15,7 +15,7 @@
- @color/primaryColorYoutube
-