From 2adae86108c1afe2a7fd5b9bab6c07cccf1bb48e Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 30 Aug 2018 14:07:25 -0400 Subject: [PATCH] fixed everything wrong with why fdroid wasnt building and then some, updated gradle wrapper using git, optimized code for java 1.8 (including converting anonymous java expressions to lambdas), reduced minSdkVersion to 14, bumped version to 1.2, blah blah blah (#106) Signed-off-by: TacoTheDank --- .gitignore | 53 +------------ app/.gitignore | 1 - app/build.gradle | 24 ++++-- app/proguard-rules.pro | 4 +- app/src/main/AndroidManifest.xml | 9 ++- .../webtube/BackgroundPlayHelper.java | 27 +++---- .../cz/martykan/webtube/BookmarkManager.java | 10 +-- .../webtube/BookmarkSelectedListener.java | 35 ++++----- .../java/cz/martykan/webtube/Downloader.java | 1 - .../cz/martykan/webtube/HeadSetReceiver.java | 1 - .../cz/martykan/webtube/MainActivity.java | 70 +++++------------- .../webtube/MediaButtonIntentReceiver.java | 4 +- .../java/cz/martykan/webtube/MenuHelper.java | 58 +++++---------- .../martykan/webtube/NotificationCloser.java | 6 +- .../java/cz/martykan/webtube/TorHelper.java | 7 +- .../martykan/webtube/WebTubeChromeClient.java | 35 ++++----- .../webtube/WebTubeWebViewClient.java | 15 ++-- app/src/main/res/layout/activity_main.xml | 6 +- app/src/main/res/menu/bookmarks.xml | 3 +- app/src/main/res/menu/menu_main.xml | 1 - app/src/main/res/values-w820dp/dimens.xml | 3 - build.gradle | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin 56190 -> 56172 bytes gradle/wrapper/gradle-wrapper.properties | 3 +- gradlew | 2 +- gradlew.bat | 2 +- 26 files changed, 128 insertions(+), 254 deletions(-) delete mode 100644 app/.gitignore diff --git a/.gitignore b/.gitignore index 379cc7c..e5677cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,54 +1,5 @@ -*~ - -# Gradle .gradle/ -.gradle build/ -/*/build/ - -# User-specific configurations local.properties - -.idea -.idea/libraries/ -.idea/runConfigurations.xml -.idea/gradle.xml -.idea/workspace.xml -.idea/tasks.xml -.idea/.name -.idea/compiler.xml -.idea/copyright/profiles_settings.xml -.idea/encodings.xml -.idea/misc.xml -.idea/modules.xml -.idea/scopes/scope_settings.xml -.idea/vcs.xml -*.iml - -# OS-specific files -.DS_Store -.DS_Store? -._* -.Trashes -ehthumbs.db -Thumbs.db - -# Built application files -*.apk -*.ap_ - -# Files for the Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ - -local.properties -proguard/ -*.log -.navigation/ - +.idea/ +*.iml \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/app/build.gradle b/app/build.gradle index 24a6d13..a6c8327 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,17 +2,21 @@ apply plugin: 'com.android.application' android { compileSdkVersion 28 - buildToolsVersion '28.0.1' + buildToolsVersion '28.0.2' defaultConfig { applicationId "cz.martykan.webtube" - minSdkVersion 15 + minSdkVersion 14 targetSdkVersion 28 - versionCode 16 - versionName "1.1.3" + versionCode 17 + versionName "1.2" } lintOptions { disable 'MissingTranslation' + checkReleaseBuilds false + // Or, if you prefer, you can continue to check for errors in release builds, + // but continue the build even when errors are found: + abortOnError false } compileOptions { @@ -22,16 +26,20 @@ android { buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + debug { + zipAlignEnabled true + } } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'junit:junit:4.12' - implementation 'com.android.support:appcompat-v7:28.0.0-beta01' - implementation 'com.android.support:design:28.0.0-beta01' - implementation 'info.guardianproject.netcipher:netcipher:2.0.0-alpha1' + implementation 'com.android.support:design:28.0.0-rc01' + implementation 'com.android.support:appcompat-v7:28.0.0-rc01' + implementation 'info.guardianproject.netcipher:netcipher:2.0.0-beta1' + implementation 'info.guardianproject.netcipher:netcipher-webkit:2.0.0-alpha1' } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 68c73af..79cd440 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,11 +1,11 @@ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified -# in /home/tomas/Android/Sdk/tools/proguard/proguard-android.txt +# in C:/Users/$USER/AppData/Local/Android/Sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html +# https://developer.android.com/studio/build/shrink-code.html # Add any project specific keep options here: diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ee6c9d2..6b0d0ee 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + package="cz.martykan.webtube" + android:installLocation="auto"> @@ -70,7 +71,11 @@ - + diff --git a/app/src/main/java/cz/martykan/webtube/BackgroundPlayHelper.java b/app/src/main/java/cz/martykan/webtube/BackgroundPlayHelper.java index 671110b..9af7303 100644 --- a/app/src/main/java/cz/martykan/webtube/BackgroundPlayHelper.java +++ b/app/src/main/java/cz/martykan/webtube/BackgroundPlayHelper.java @@ -11,7 +11,6 @@ import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.util.Log; -import android.webkit.ValueCallback; import android.webkit.WebView; public class BackgroundPlayHelper { @@ -32,13 +31,13 @@ public BackgroundPlayHelper (Context context, WebView webView) { public void enableBackgroundPlay() { SharedPreferences.Editor spedit = sp.edit(); spedit.putBoolean(PREF_BACKGROUND_PLAY_ENABLED, true); - spedit.commit(); + spedit.apply(); } public void disableBackgroundPlay() { SharedPreferences.Editor spedit = sp.edit(); spedit.putBoolean(PREF_BACKGROUND_PLAY_ENABLED, false); - spedit.commit(); + spedit.apply(); } public boolean isBackgroundPlayEnabled() { @@ -49,15 +48,12 @@ public void playInBackground() { try { if (webView.getUrl().contains("/watch")) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - webView.evaluateJavascript("(function() { if(document.getElementsByTagName('video')[0].paused == false) { return 'playing'; } else { return 'stopped'; } })();", new ValueCallback() { - @Override - public void onReceiveValue(String value) { - Log.i("VALUE", value); - if (value.equals("\"playing\"")) { - showBackgroundPlaybackNotification(); - } - } - }); + webView.evaluateJavascript("(function() { if(document.getElementsByTagName('video')[0].paused == false) { return 'playing'; } else { return 'stopped'; } })();", value -> { + Log.i("VALUE", value); + if (value.equals("\"playing\"")) { + showBackgroundPlaybackNotification(); + } + }); } else { showBackgroundPlaybackNotification(); } @@ -77,20 +73,19 @@ public void showBackgroundPlaybackNotification() { .setContentTitle(context.getString(R.string.app_name)) .setContentText(webView.getTitle().replace(" - YouTube", "")) .setAutoCancel(true) - .setContentIntent( - PendingIntent.getActivity( + .setContentIntent(PendingIntent.getActivity( context, NOTIFICATION_ID, new Intent(context, MainActivity.class) .setAction(Intent.ACTION_VIEW) .setData(Uri.parse(webView.getUrl())), PendingIntent.FLAG_UPDATE_CURRENT)); - NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); + NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ID, builder.build()); } public void hideBackgroundPlaybackNotification() { - NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); + NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.cancel(NOTIFICATION_ID); } } diff --git a/app/src/main/java/cz/martykan/webtube/BookmarkManager.java b/app/src/main/java/cz/martykan/webtube/BookmarkManager.java index 89a00ab..508663a 100644 --- a/app/src/main/java/cz/martykan/webtube/BookmarkManager.java +++ b/app/src/main/java/cz/martykan/webtube/BookmarkManager.java @@ -32,7 +32,7 @@ public BookmarkManager(Context context, WebView webView) { sp = PreferenceManager.getDefaultSharedPreferences(context); } - public void initalizeBookmarks(NavigationView navigationView) { + public void initializeBookmarks(NavigationView navigationView) { this.navigationView = navigationView; bookmarkUrls = new ArrayList<>(); bookmarkTimelessUrls = new ArrayList<>(); @@ -86,11 +86,11 @@ public void addBookmark(String title, String url) { bookmarksArray.put(new JSONObject("{'title':'" + title.replace("'", "\\'") + "','url':'" + url + "'}")); SharedPreferences.Editor editor = sp.edit(); editor.putString("bookmarks", bookmarksArray.toString()); - editor.commit(); + editor.apply(); } catch (JSONException e) { e.printStackTrace(); } - initalizeBookmarks(navigationView); + initializeBookmarks(navigationView); } public void removeBookmark(String title) { @@ -110,11 +110,11 @@ public void removeBookmark(String title) { } SharedPreferences.Editor editor = sp.edit(); editor.putString("bookmarks", bookmarksArray.toString()); - editor.commit(); + editor.apply(); } catch (JSONException e) { e.printStackTrace(); } - initalizeBookmarks(navigationView); + initializeBookmarks(navigationView); } public String getUrl(String title) { diff --git a/app/src/main/java/cz/martykan/webtube/BookmarkSelectedListener.java b/app/src/main/java/cz/martykan/webtube/BookmarkSelectedListener.java index f754d4d..74f1427 100644 --- a/app/src/main/java/cz/martykan/webtube/BookmarkSelectedListener.java +++ b/app/src/main/java/cz/martykan/webtube/BookmarkSelectedListener.java @@ -6,7 +6,6 @@ import android.support.v4.widget.DrawerLayout; import android.util.Log; import android.view.MenuItem; -import android.webkit.ValueCallback; import android.webkit.WebView; import java.io.UnsupportedEncodingException; @@ -33,24 +32,21 @@ public boolean onNavigationItemSelected(final MenuItem menuItem) { if (!webView.getTitle().equals("YouTube")) { if (webView.getUrl().contains("/watch") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { time = "0"; - webView.evaluateJavascript("(function() { return document.getElementsByTagName('video')[0].currentTime; })();", new ValueCallback() { - @Override - public void onReceiveValue(String value) { - Log.i("VALUE", value); - time = value; - String url = webView.getUrl(); - try { - time = time.substring(0, time.indexOf(".")); - } catch (Exception e) { - e.printStackTrace(); - time = "0"; - } - if (url.contains("&t=")) { - url = url.substring(0, url.indexOf("&t=")); - } - bookmarkManager.addBookmark(webView.getTitle().replace(" - YouTube", ""), url + "&t=" + time); - } - }); + webView.evaluateJavascript("(function() { return document.getElementsByTagName('video')[0].currentTime; })();", value -> { + Log.i("VALUE", value); + time = value; + String url = webView.getUrl(); + try { + time = time.substring(0, time.indexOf(".")); + } catch (Exception e) { + e.printStackTrace(); + time = "0"; + } + if (url.contains("&t=")) { + url = url.substring(0, url.indexOf("&t=")); + } + bookmarkManager.addBookmark(webView.getTitle().replace(" - YouTube", ""), url + "&t=" + time); + }); } else { bookmarkManager.addBookmark(webView.getTitle().replace(" - YouTube", ""), webView.getUrl()); } @@ -90,5 +86,4 @@ public void onReceiveValue(String value) { } return true; } - } diff --git a/app/src/main/java/cz/martykan/webtube/Downloader.java b/app/src/main/java/cz/martykan/webtube/Downloader.java index aab90b4..55e8e57 100644 --- a/app/src/main/java/cz/martykan/webtube/Downloader.java +++ b/app/src/main/java/cz/martykan/webtube/Downloader.java @@ -23,6 +23,5 @@ public void download(String url) { e.printStackTrace(); } context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.ytbmp4.com/search?q=" + encodedURL))); - } } diff --git a/app/src/main/java/cz/martykan/webtube/HeadSetReceiver.java b/app/src/main/java/cz/martykan/webtube/HeadSetReceiver.java index 301f928..5514818 100644 --- a/app/src/main/java/cz/martykan/webtube/HeadSetReceiver.java +++ b/app/src/main/java/cz/martykan/webtube/HeadSetReceiver.java @@ -29,5 +29,4 @@ public void onReceive(Context context, Intent intent) { } } } - } diff --git a/app/src/main/java/cz/martykan/webtube/MainActivity.java b/app/src/main/java/cz/martykan/webtube/MainActivity.java index c56033a..8b4d064 100644 --- a/app/src/main/java/cz/martykan/webtube/MainActivity.java +++ b/app/src/main/java/cz/martykan/webtube/MainActivity.java @@ -1,58 +1,27 @@ package cz.martykan.webtube; -import android.animation.Animator; -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import android.app.AlarmManager; -import android.app.NotificationManager; -import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.content.pm.PackageManager; import android.graphics.Color; import android.media.AudioManager; -import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.design.widget.NavigationView; -import android.support.design.widget.Snackbar; -import android.support.v4.app.NotificationCompat; import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.ActionMenuView; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.view.WindowManager; -import android.webkit.CookieManager; -import android.webkit.ValueCallback; import android.webkit.WebSettings; import android.webkit.WebView; -import android.widget.ArrayAdapter; import android.widget.FrameLayout; import android.widget.ProgressBar; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.List; - -import info.guardianproject.netcipher.proxy.OrbotHelper; -import info.guardianproject.netcipher.web.WebkitProxy; - - public class MainActivity extends AppCompatActivity { private static final String LOG_TAG = "webTube"; @@ -82,16 +51,13 @@ public void onClick(View v) { public static void toggleVideo() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webView.evaluateJavascript("(function() { return document.getElementsByTagName('video')[0].paused; })();", - new ValueCallback() { - @Override - public void onReceiveValue(String value) { - if (value.equals("true")) { - playVideo(); - } else { - pauseVideo(); - } - } - }); + value -> { + if (value.equals("true")) { + playVideo(); + } else { + pauseVideo(); + } + }); } else { pauseVideo(); } @@ -116,16 +82,16 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - webView = (WebView) findViewById(R.id.webView); + webView = findViewById(R.id.webView); appWindow = findViewById(R.id.appWindow); - progress = (ProgressBar) findViewById(R.id.progress); - customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer); + progress = findViewById(R.id.progress); + customViewContainer = findViewById(R.id.customViewContainer); sp = PreferenceManager.getDefaultSharedPreferences(this); - drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - navigationView = (NavigationView) findViewById(R.id.bookmarks_panel); + drawerLayout = findViewById(R.id.drawer_layout); + navigationView = findViewById(R.id.bookmarks_panel); - // Set up media button reciever + // Set up media button receiver ((AudioManager) getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); @@ -140,16 +106,16 @@ protected void onCreate(Bundle savedInstanceState) { // Initialize bookmarks panel bookmarkManager = new BookmarkManager(this, webView); - bookmarkManager.initalizeBookmarks(navigationView); + bookmarkManager.initializeBookmarks(navigationView); drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { - bookmarkManager.initalizeBookmarks(navigationView); + bookmarkManager.initializeBookmarks(navigationView); } @Override public void onDrawerOpened(View drawerView) { - bookmarkManager.initalizeBookmarks(navigationView); + bookmarkManager.initializeBookmarks(navigationView); } @Override @@ -172,7 +138,7 @@ public void onDrawerStateChanged(int newState) { backgroundPlayHelper = new BackgroundPlayHelper(mApplicationContext, webView); // Menu helper - ActionMenuView actionMenu = (ActionMenuView) findViewById(R.id.menu_main); + ActionMenuView actionMenu = findViewById(R.id.menu_main); menuHelper = new MenuHelper(this, webView, torHelper, backgroundPlayHelper, appWindow); getMenuInflater().inflate(R.menu.menu_main, actionMenu.getMenu()); menuHelper.setUpMenu(actionMenu, drawerLayout, findViewById(R.id.bookmarks_panel)); @@ -264,7 +230,6 @@ public void setUpWebview() { webView.setBackgroundColor(Color.WHITE); webView.setScrollbarFadingEnabled(true); webView.setNetworkAvailable(true); - } @Override @@ -274,6 +239,5 @@ public void onBackPressed() { } else { finish(); } - } } diff --git a/app/src/main/java/cz/martykan/webtube/MediaButtonIntentReceiver.java b/app/src/main/java/cz/martykan/webtube/MediaButtonIntentReceiver.java index a1c56e4..6059240 100644 --- a/app/src/main/java/cz/martykan/webtube/MediaButtonIntentReceiver.java +++ b/app/src/main/java/cz/martykan/webtube/MediaButtonIntentReceiver.java @@ -18,7 +18,7 @@ public void onReceive(Context context, Intent intent) { if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { return; } - KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); + KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); Log.i("Key", event.getKeyCode() + " pressed"); int action = event.getAction(); @@ -33,4 +33,4 @@ public void onReceive(Context context, Intent intent) { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/cz/martykan/webtube/MenuHelper.java b/app/src/main/java/cz/martykan/webtube/MenuHelper.java index e124808..bcd6d38 100644 --- a/app/src/main/java/cz/martykan/webtube/MenuHelper.java +++ b/app/src/main/java/cz/martykan/webtube/MenuHelper.java @@ -1,8 +1,5 @@ package cz.martykan.webtube; -import android.animation.Animator; -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -19,7 +16,6 @@ import android.view.MenuItem; import android.view.View; import android.webkit.WebView; -import android.widget.ArrayAdapter; import info.guardianproject.netcipher.proxy.OrbotHelper; @@ -53,19 +49,16 @@ public void homepageTutorial() { dialog.setMessage(context.getString(R.string.homePageHelp)); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int buttonId) { - dialog.dismiss(); - SharedPreferences.Editor editor = sp.edit(); - editor.putBoolean("homepageLearned", true); - editor.commit(); - } - }); + (dialog1, buttonId) -> { + dialog1.dismiss(); + SharedPreferences.Editor editor = sp.edit(); + editor.putBoolean("homepageLearned", true); + editor.apply(); + }); dialog.show(); } } - public void setUpMenu(final ActionMenuView actionMenu, final DrawerLayout drawerLayout, final View bookmarksPanel ) { this.drawerLayout = drawerLayout; this.bookmarksPanel = bookmarksPanel; @@ -101,11 +94,7 @@ private void show_noVideo_dialog() { dialog.setMessage(context.getString(R.string.error_select_video_and_retry)); dialog.setCancelable(true); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok).toUpperCase(), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int buttonId) { - dialog.dismiss(); - } - }); + (dialog1, buttonId) -> dialog1.dismiss()); dialog.show(); } @@ -129,7 +118,7 @@ public boolean onMenuItemClick(final MenuItem item) { Snackbar.make(appWindow, context.getString(R.string.homePageSet), Snackbar.LENGTH_LONG).show(); SharedPreferences.Editor editor = sp.edit(); editor.putString("homepage", webView.getUrl()); - editor.commit(); + editor.apply(); return true; case R.id.action_bookmarks: @@ -153,15 +142,15 @@ public boolean onMenuItemClick(final MenuItem item) { show_noVideo_dialog(); } else { try { - /* The following code is based on an extract from the source code of NewPipe (v0.7.2) (https://github.com/theScrabi/NewPipe), - which is also licenced under version 3 of the GNU General Public License as published by the Free Software Foundation. - The copyright owner of the original code is Christian Schabesberger . - All modifications were made on 06-Jan-2016 */ + /* The following code is based on an extract from the source code of NewPipe (v0.7.2) (https://github.com/theScrabi/NewPipe), + which is also licenced under version 3 of the GNU General Public License as published by the Free Software Foundation. + The copyright owner of the original code is Christian Schabesberger . + All modifications were made on 06-Jan-2016 */ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setPackage("org.xbmc.kore"); intent.setData(Uri.parse(webView.getUrl().replace("https", "http"))); context.startActivity(intent); - /* End of the modified NewPipe code extract */ + /* End of the modified NewPipe code extract */ } catch (Exception e) { e.printStackTrace(); } @@ -191,19 +180,13 @@ public boolean onMenuItemClick(final MenuItem item) { alert.setMessage(context.getString(R.string.torWarning)); alert.setCancelable(false); alert.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.enable), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int buttonId) { - torHelper.torEnable(); - item.setChecked(true); - cookieItem.setChecked(false).setEnabled(false); - } - }); + (dialog, buttonId) -> { + torHelper.torEnable(); + item.setChecked(true); + cookieItem.setChecked(false).setEnabled(false); + }); alert.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int buttonId) { - item.setChecked(false); - } - }); + (dialog, buttonId) -> item.setChecked(false)); alert.show(); } } @@ -231,10 +214,9 @@ public void onClick(DialogInterface dialog, int buttonId) { } SharedPreferences.Editor spEdit = sp.edit(); spEdit.putBoolean(PREF_COOKIES_ENABLED,!sp.getBoolean(PREF_COOKIES_ENABLED,true)); - spEdit.commit(); + spEdit.apply(); return true; } - return false; } } diff --git a/app/src/main/java/cz/martykan/webtube/NotificationCloser.java b/app/src/main/java/cz/martykan/webtube/NotificationCloser.java index 9c01a5f..19c791f 100644 --- a/app/src/main/java/cz/martykan/webtube/NotificationCloser.java +++ b/app/src/main/java/cz/martykan/webtube/NotificationCloser.java @@ -31,8 +31,6 @@ public static PendingIntent getDismissIntent(int notificationId, Context context Intent intent = new Intent(context, NotificationCloser.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(NOTIFICATION_ID, notificationId); - PendingIntent dismissIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); - return dismissIntent; + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); } - -} \ No newline at end of file +} diff --git a/app/src/main/java/cz/martykan/webtube/TorHelper.java b/app/src/main/java/cz/martykan/webtube/TorHelper.java index 69c6997..cadb6bc 100644 --- a/app/src/main/java/cz/martykan/webtube/TorHelper.java +++ b/app/src/main/java/cz/martykan/webtube/TorHelper.java @@ -10,7 +10,7 @@ import android.webkit.WebView; import info.guardianproject.netcipher.proxy.OrbotHelper; -import info.guardianproject.netcipher.web.WebkitProxy; +import info.guardianproject.netcipher.webkit.WebkitProxy; public class TorHelper { public static final String PREF_TOR_ENABLED = "torEnabled"; @@ -47,7 +47,7 @@ public void torEnable() { WebkitProxy.setProxy(MainActivity.class.getName(), mApplicationContext, null, "localhost", PORT_TOR); SharedPreferences.Editor spEdit = sp.edit(); spEdit.putBoolean(PREF_TOR_ENABLED, true); - spEdit.commit(); + spEdit.apply(); } catch (Exception e) { e.printStackTrace(); } @@ -63,7 +63,7 @@ public void torDisable() { WebkitProxy.resetProxy(MainActivity.class.getName(), mApplicationContext); SharedPreferences.Editor spEdit = sp.edit(); spEdit.putBoolean(PREF_TOR_ENABLED, false); - spEdit.commit(); + spEdit.apply(); CookieHelper.acceptCookies(webView, true); } catch (Exception e) { e.printStackTrace(); @@ -76,5 +76,4 @@ public void torDisable() { mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); } - } diff --git a/app/src/main/java/cz/martykan/webtube/WebTubeChromeClient.java b/app/src/main/java/cz/martykan/webtube/WebTubeChromeClient.java index 9cdd504..0cf1740 100644 --- a/app/src/main/java/cz/martykan/webtube/WebTubeChromeClient.java +++ b/app/src/main/java/cz/martykan/webtube/WebTubeChromeClient.java @@ -1,12 +1,8 @@ package cz.martykan.webtube; -import android.content.Context; import android.os.Build; import android.support.v4.widget.DrawerLayout; -import android.util.Log; import android.view.View; -import android.view.Window; -import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.widget.FrameLayout; @@ -43,9 +39,11 @@ public void onShowCustomView(View view, CustomViewCallback callback) { customViewContainer.setVisibility(View.VISIBLE); customViewContainer.addView(view); - // Hide the status bar. - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + // Hide the status bar + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); } } @@ -74,26 +72,21 @@ public void onProgressChanged(WebView view, int percentage) { progress.setVisibility(View.VISIBLE); progress.setProgress(percentage); - // For more advnaced loading status + // For more advanced loading status if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { progress.setIndeterminate(percentage == 100); view.evaluateJavascript("(function() { return document.readyState == \"complete\"; })();", - new ValueCallback() { - @Override - public void onReceiveValue(String value) { - if (value.equals("true")) { - progress.setVisibility(View.INVISIBLE); - } else { - onProgressChanged(webView, 100); - } - } - }); + value -> { + if (value.equals("true")) { + progress.setVisibility(View.INVISIBLE); + } else { + onProgressChanged(webView, 100); + } + }); } else { if (percentage == 100) { progress.setVisibility(View.GONE); } } } - - -} \ No newline at end of file +} diff --git a/app/src/main/java/cz/martykan/webtube/WebTubeWebViewClient.java b/app/src/main/java/cz/martykan/webtube/WebTubeWebViewClient.java index 3565523..99974e6 100644 --- a/app/src/main/java/cz/martykan/webtube/WebTubeWebViewClient.java +++ b/app/src/main/java/cz/martykan/webtube/WebTubeWebViewClient.java @@ -8,7 +8,6 @@ import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; import android.view.View; -import android.webkit.ValueCallback; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -69,14 +68,11 @@ public void onLoadResource(WebView view, String url) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { statusBarSpace.setVisibility(View.VISIBLE); view.evaluateJavascript("(function() { if(document.getElementById('player').style.visibility == 'hidden' || document.getElementById('player').innerHTML == '') { return 'not_video'; } else { return 'video'; } })();", - new ValueCallback() { - @Override - public void onReceiveValue(final String value) { - int colorId = value.contains("not_video") ? R.color.colorPrimary : R.color.colorWatch; - statusBarSpace.setBackgroundColor(ContextCompat.getColor(context, colorId)); - bottomBar.setBackgroundColor(ContextCompat.getColor(context, colorId)); - } - }); + value -> { + int colorId = value.contains("not_video") ? R.color.colorPrimary : R.color.colorWatch; + statusBarSpace.setBackgroundColor(ContextCompat.getColor(context, colorId)); + bottomBar.setBackgroundColor(ContextCompat.getColor(context, colorId)); + }); } } } @@ -94,5 +90,4 @@ public void onReceivedError(WebView view, int errorCode, String description, Str setAction(context.getString(R.string.refresh), clickListener).show(); } } - } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f2353d2..32058d6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,7 +1,6 @@ + android:backgroundTint="@android:color/transparent" + tools:targetApi="lollipop" /> - - - - + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 49fb5ac..8bf63b5 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -3,7 +3,6 @@ xmlns:tools="http://schemas.android.com/tools" tools:context="cz.martykan.webtube.MainActivity"> - - 64dp diff --git a/build.gradle b/build.gradle index 5214d43..9e7a982 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { maven { url "https://jitpack.io" } } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.1.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index a384ae8b3aa315094a2731238f25f71ce86f261a..28861d273a5d270fd8f65dd74570c17c9c507736 100644 GIT binary patch delta 58 zcmeyjjrq+s<_%9z3NbJQc(Ze`wC_(6VPIeYav3JSJtebQ^%SolCtP&0^=(_W?18tpCWZiSc8>S9E6%AgFff4dWXFp# Xn}tvD3Ub0lCu`oeW#c>rlw<$^LC+YY diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7d754af..f73107d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip -distributionSha256Sum=39e2d5803bbd5eaf6c8efe07067b0e5a00235e8c71318642b2ed262920b27721 diff --git a/gradlew b/gradlew index 450358c..cccdd3d 100755 --- a/gradlew +++ b/gradlew @@ -28,7 +28,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="-Xmx128m -Dfile.encoding=UTF-8" +DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/gradlew.bat b/gradlew.bat index cdd00df..e95643d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS=-Xmx128m -Dfile.encoding=UTF-8 +set DEFAULT_JVM_OPTS= @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome