From adbeff11d460c4e43dd83b3076447d907b994b6e Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Wed, 26 Apr 2017 16:32:20 -0300 Subject: [PATCH] Minor improvements --- app/build.gradle | 14 ++++---- app/src/main/java/org/schabi/newpipe/App.java | 3 ++ .../org/schabi/newpipe/ReCaptchaActivity.java | 12 +++++-- .../newpipe/player/BackgroundPlayer.java | 2 +- .../newpipe/player/MainVideoPlayer.java | 10 +++--- .../newpipe/player/PopupVideoPlayer.java | 3 +- .../schabi/newpipe/player/VideoPlayer.java | 2 +- .../schabi/newpipe/report/ErrorActivity.java | 13 +++---- .../org/schabi/newpipe/util/Constants.java | 4 +++ .../schabi/newpipe/util/NavigationHelper.java | 13 ++++++- .../org/schabi/newpipe/util/ThemeHelper.java | 36 +++++++++++-------- 11 files changed, 74 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dcc662279..f8b61d1cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,14 +39,16 @@ dependencies { compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:design:25.3.1' compile 'com.android.support:recyclerview-v7:25.3.1' + + compile 'com.google.code.gson:gson:2.7' compile 'org.jsoup:jsoup:1.8.3' compile 'org.mozilla:rhino:1.7.7' - compile 'info.guardianproject.netcipher:netcipher:1.2' - compile 'de.hdodenhof:circleimageview:2.0.0' - compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' - compile 'com.github.nirhart:parallaxscroll:1.0' - compile 'com.google.code.gson:gson:2.7' - compile 'com.nononsenseapps:filepicker:3.0.0' compile 'ch.acra:acra:4.9.0' + compile 'info.guardianproject.netcipher:netcipher:1.2' + + compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' + compile 'de.hdodenhof:circleimageview:2.0.0' + compile 'com.github.nirhart:parallaxscroll:1.0' + compile 'com.nononsenseapps:filepicker:3.0.0' compile 'com.google.android.exoplayer:exoplayer:r2.3.1' } diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index cb4dce3ea..e2bdc9f68 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -15,6 +15,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.report.AcraReportSenderFactory; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.settings.SettingsActivity; +import org.schabi.newpipe.util.ThemeHelper; import info.guardianproject.netcipher.NetCipher; import info.guardianproject.netcipher.proxy.OrbotHelper; @@ -82,6 +83,8 @@ public class App extends Application { // DO NOT REMOVE THIS FUNCTION!!! // Otherwise downloadPathPreference has invalid value. SettingsActivity.initSettings(this); + + ThemeHelper.setTheme(getApplicationContext()); } /** diff --git a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java index 45c4dfeb8..b97e0566d 100644 --- a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java @@ -8,6 +8,7 @@ import android.os.Bundle; import android.support.v4.app.NavUtils; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.webkit.CookieManager; import android.webkit.ValueCallback; @@ -48,10 +49,15 @@ public class ReCaptchaActivity extends AppCompatActivity { // Set return to Cancel by default setResult(RESULT_CANCELED); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setTitle(R.string.reCaptcha_title); - actionBar.setDisplayShowTitleEnabled(true); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setTitle(R.string.reCaptcha_title); + actionBar.setDisplayShowTitleEnabled(true); + } WebView myWebView = (WebView) findViewById(R.id.reCaptchaWebView); diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 8c9c80a3d..cbf4f2bf6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -78,7 +78,7 @@ public class BackgroundPlayer extends Service { powerManager = ((PowerManager) getSystemService(POWER_SERVICE)); wifiManager = ((WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE)); - ThemeHelper.setTheme(this, false); + ThemeHelper.setTheme(this); basePlayerImpl = new BasePlayerImpl(this); basePlayerImpl.setup(); } diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index c5f0b2d3b..ce3525f17 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -55,7 +55,7 @@ public class MainVideoPlayer extends Activity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); - ThemeHelper.setTheme(this, false); + ThemeHelper.setTheme(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.BLACK); setVolumeControlStream(AudioManager.STREAM_MUSIC); audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); @@ -67,7 +67,7 @@ public class MainVideoPlayer extends Activity { } showSystemUi(); - setContentView(R.layout.activity_exo_player); + setContentView(R.layout.activity_main_player); playerImpl = new VideoPlayerImpl(); playerImpl.setup(findViewById(android.R.id.content)); playerImpl.handleIntent(getIntent()); @@ -474,7 +474,7 @@ public class MainVideoPlayer extends Activity { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { //noinspection PointlessBooleanExpression - if (DEBUG && true) Log.d(TAG, "MainVideoPlayer.onScroll = " + + if (DEBUG && false) Log.d(TAG, "MainVideoPlayer.onScroll = " + ", e1.getRaw = [" + e1.getRawX() + ", " + e1.getRawY() + "]" + ", e2.getRaw = [" + e2.getRawX() + ", " + e2.getRawY() + "]" + ", distanceXy = [" + distanceX + ", " + distanceY + "]"); @@ -531,12 +531,14 @@ public class MainVideoPlayer extends Activity { if (playerImpl.getBrightnessTextView().getVisibility() == View.VISIBLE) playerImpl.animateView(playerImpl.getBrightnessTextView(), false, 200, 200); if (playerImpl.isControlsVisible() && playerImpl.getCurrentState() == BasePlayer.STATE_PLAYING) { - playerImpl.animateView(playerImpl.getControlsRoot(), false, 300, VideoPlayer.DEFAULT_CONTROLS_HIDE_TIME); + playerImpl.animateView(playerImpl.getControlsRoot(), false, 300, VideoPlayer.DEFAULT_CONTROLS_HIDE_TIME, true); } } @Override public boolean onTouch(View v, MotionEvent event) { + //noinspection PointlessBooleanExpression + if (DEBUG && false) Log.d(TAG, "onTouch() called with: v = [" + v + "], event = [" + event + "]"); gestureDetector.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_UP && isMoving) { isMoving = false; diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 170e2f6aa..ded6f34f9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -89,7 +89,7 @@ public class PopupVideoPlayer extends Service { notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); playerImpl = new VideoPlayerImpl(); - ThemeHelper.setTheme(this, false); + ThemeHelper.setTheme(this); } @Override @@ -124,7 +124,6 @@ public class PopupVideoPlayer extends Service { playerImpl.destroy(); if (playerImpl.getRootView() != null) windowManager.removeView(playerImpl.getRootView()); } - if (imageLoader != null) imageLoader.clearMemoryCache(); if (notificationManager != null) notificationManager.cancel(NOTIFICATION_ID); if (currentExtractorWorker != null) { currentExtractorWorker.cancel(); diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 3e0976242..d64e60747 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -125,7 +125,7 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. this.aspectRatioFrameLayout = (AspectRatioFrameLayout) rootView.findViewById(R.id.aspectRatioLayout); this.surfaceView = (SurfaceView) rootView.findViewById(R.id.surfaceView); this.surfaceForeground = rootView.findViewById(R.id.surfaceForeground); - this.loadingPanel = rootView.findViewById(R.id.loadingPanel); + this.loadingPanel = rootView.findViewById(R.id.loading_panel); this.endScreen = (ImageView) rootView.findViewById(R.id.endScreen); this.controlAnimationView = (ImageView) rootView.findViewById(R.id.controlAnimationView); this.controlsRoot = rootView.findViewById(R.id.playbackControlRoot); diff --git a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java index 14c72c561..23ee471b3 100644 --- a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java @@ -15,6 +15,7 @@ import android.support.design.widget.Snackbar; import android.support.v4.app.NavUtils; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -205,19 +206,19 @@ public class ErrorActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ThemeHelper.setTheme(this, true); + ThemeHelper.setTheme(this); setContentView(R.layout.activity_error); Intent intent = getIntent(); - try { - ActionBar actionBar = getSupportActionBar(); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(R.string.error_report_title); actionBar.setDisplayShowTitleEnabled(true); - } catch (Throwable e) { - Log.e(TAG, "Error turing exception handling"); - e.printStackTrace(); } reportButton = (Button) findViewById(R.id.errorReportButton); diff --git a/app/src/main/java/org/schabi/newpipe/util/Constants.java b/app/src/main/java/org/schabi/newpipe/util/Constants.java index 9f94729ae..f9329b0be 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Constants.java +++ b/app/src/main/java/org/schabi/newpipe/util/Constants.java @@ -5,4 +5,8 @@ public class Constants { public static final String KEY_URL = "key_url"; public static final String KEY_TITLE = "key_title"; public static final String KEY_LINK_TYPE = "key_link_type"; + public static final String KEY_OPEN_SEARCH = "key_open_search"; + public static final String KEY_QUERY = "key_query"; + + public static final String KEY_THEME_CHANGE = "key_theme_change"; } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 52a4eca1d..129adb5c2 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -19,6 +19,10 @@ import org.schabi.newpipe.player.VideoPlayer; @SuppressWarnings({"unused", "WeakerAccess"}) public class NavigationHelper { + /*////////////////////////////////////////////////////////////////////////// + // Players + //////////////////////////////////////////////////////////////////////////*/ + public static Intent getOpenVideoPlayerIntent(Context context, Class targetClazz, StreamInfo info, int selectedStreamIndex) { Intent mIntent = new Intent(context, targetClazz) .putExtra(BasePlayer.VIDEO_TITLE, info.title) @@ -61,7 +65,6 @@ public class NavigationHelper { return mIntent; } - /*////////////////////////////////////////////////////////////////////////// // Through Interface (faster) //////////////////////////////////////////////////////////////////////////*/ @@ -115,6 +118,14 @@ public class NavigationHelper { context.startActivity(mIntent); } + public static void openSearch(Context context, int serviceId, String query) { + Intent mIntent = new Intent(context, MainActivity.class); + mIntent.putExtra(Constants.KEY_SERVICE_ID, serviceId); + mIntent.putExtra(Constants.KEY_QUERY, query); + mIntent.putExtra(Constants.KEY_OPEN_SEARCH, true); + context.startActivity(mIntent); + } + private static Intent getOpenIntent(Context context, String url, int serviceId, StreamingService.LinkType type) { Intent mIntent = new Intent(context, MainActivity.class); mIntent.putExtra(Constants.KEY_SERVICE_ID, serviceId); diff --git a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java index 8021a0972..4f3be4a0d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java @@ -10,25 +10,33 @@ public class ThemeHelper { /** * Apply the selected theme (on NewPipe settings) in the context * - * @param context context that the theme will be applied - * @param useActionbarTheme whether to use an action bar theme or not + * @param context context that the theme will be applied */ - public static void setTheme(Context context, boolean useActionbarTheme) { + public static void setTheme(Context context) { + String themeKey = context.getString(R.string.theme_key); String darkTheme = context.getResources().getString(R.string.dark_theme_title); String blackTheme = context.getResources().getString(R.string.black_theme_title); - String sp = PreferenceManager.getDefaultSharedPreferences(context) - .getString(themeKey, context.getResources().getString(R.string.light_theme_title)); + String sp = PreferenceManager.getDefaultSharedPreferences(context).getString(themeKey, context.getResources().getString(R.string.light_theme_title)); - if (useActionbarTheme) { - if (sp.equals(darkTheme)) context.setTheme(R.style.DarkTheme); - else if (sp.equals(blackTheme)) context.setTheme(R.style.BlackTheme); - else context.setTheme(R.style.AppTheme); - } else { - if (sp.equals(darkTheme)) context.setTheme(R.style.DarkTheme_NoActionBar); - else if (sp.equals(blackTheme)) context.setTheme(R.style.BlackTheme_NoActionBar); - else context.setTheme(R.style.AppTheme_NoActionBar); - } + if (sp.equals(darkTheme)) context.setTheme(R.style.DarkTheme); + else if (sp.equals(blackTheme)) context.setTheme(R.style.BlackTheme); + else context.setTheme(R.style.AppTheme); + } + + /** + * Return true if the selected theme (on NewPipe settings) is the Light theme + * + * @param context context to get the preference + */ + public static boolean isLightThemeSelected(Context context) { + String themeKey = context.getString(R.string.theme_key); + String darkTheme = context.getResources().getString(R.string.dark_theme_title); + String blackTheme = context.getResources().getString(R.string.black_theme_title); + + String sp = PreferenceManager.getDefaultSharedPreferences(context).getString(themeKey, context.getResources().getString(R.string.light_theme_title)); + + return !(sp.equals(darkTheme) || sp.equals(blackTheme)); } }