From ee0696714f4fca5f355935f8a712a3c540f1bb17 Mon Sep 17 00:00:00 2001 From: Klearchos-K <32612550+Klearchos-K@users.noreply.github.com> Date: Mon, 24 Dec 2018 20:11:21 +0200 Subject: [PATCH 1/5] Update RouterActivity.java Add dunction handleText() for #1951 issue --- .../java/org/schabi/newpipe/RouterActivity.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index b8941670f..d7bf07675 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -42,6 +42,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; +import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.NavigationHelper; @@ -94,7 +95,7 @@ public class RouterActivity extends AppCompatActivity { currentUrl = getUrl(getIntent()); if (TextUtils.isEmpty(currentUrl)) { - Toast.makeText(this, R.string.invalid_url_toast, Toast.LENGTH_LONG).show(); + handleText(); finish(); } } @@ -112,7 +113,7 @@ public class RouterActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - + handleUrl(currentUrl); } @@ -353,6 +354,15 @@ public class RouterActivity extends AppCompatActivity { positiveButton.setEnabled(state); } + private void handleText(){ + String searchString = getIntent().getStringExtra(Intent.EXTRA_TEXT); + int serviceId = getIntent().getIntExtra(Constants.KEY_SERVICE_ID, 0); + Intent intent = new Intent(getThemeWrapperContext(), MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + NavigationHelper.openSearch(getThemeWrapperContext(),serviceId,searchString); + } + private void handleChoice(final String selectedChoiceKey) { final List validChoicesList = Arrays.asList(getResources().getStringArray(R.array.preferred_open_action_values_list)); if (validChoicesList.contains(selectedChoiceKey)) { From 100197d1a92d03155fc2a8aa7a91dca198386fd0 Mon Sep 17 00:00:00 2001 From: Redirion Date: Mon, 4 Mar 2019 10:24:08 +0100 Subject: [PATCH 2/5] Cache duration String to improve performance In VideoPlayer the Duration String is cached effectively by setting it to the playbackSeekBar. As the playbackSeekBar doesn't exist in BackgroundPlayer, using two addition variables will reduce performance impact of notification updates by almost 50% and thus perform similar to VideoPlayer. This addresses issue #2170 --- .../java/org/schabi/newpipe/player/BackgroundPlayer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 94b401f09..83ac85b06 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -275,6 +275,8 @@ public final class BackgroundPlayer extends Service { protected class BasePlayerImpl extends BasePlayer { @NonNull final private AudioPlaybackResolver resolver; + private int cachedDuration; + private String cachedDurationString; BasePlayerImpl(Context context) { super(context); @@ -351,8 +353,12 @@ public final class BackgroundPlayer extends Service { resetNotification(); if(Build.VERSION.SDK_INT >= 26 /*Oreo*/) updateNotificationThumbnail(); if (bigNotRemoteView != null) { + if(cachedDuration != duration) { + cachedDuration = duration; + cachedDurationString = getTimeString(duration); + } bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false); - bigNotRemoteView.setTextViewText(R.id.notificationTime, getTimeString(currentProgress) + " / " + getTimeString(duration)); + bigNotRemoteView.setTextViewText(R.id.notificationTime, getTimeString(currentProgress) + " / " + cachedDurationString); } if (notRemoteView != null) { notRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false); From 38d7dc714060fb312fe2d7a2652d7cf95ea54776 Mon Sep 17 00:00:00 2001 From: Redirion Date: Mon, 4 Mar 2019 15:45:59 +0100 Subject: [PATCH 3/5] Improved performance of getTimeString This pull requests complements pull request #2178 by reducing general computational time for the method getTimeString. On my local machine (Desktop PC with Java) my tests with a sample size of 10000 calls to the method with param 86400001 showed a performance improvement of about 50%. See sample code below to reproduce: private static final StringBuilder stringBuilder = new StringBuilder(); private static final Formatter stringFormatter = new Formatter(stringBuilder, Locale.getDefault()); public static String getTimeString(int milliSeconds) { int seconds = (milliSeconds % 60000) / 1000; int minutes = (milliSeconds % 3600000) / 60000; int hours = (milliSeconds % 86400000) / 3600000; int days = (milliSeconds % (86400000 * 7)) / 86400000; stringBuilder.setLength(0); return days > 0 ? stringFormatter.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds).toString() : hours > 0 ? stringFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString() : stringFormatter.format("%02d:%02d", minutes, seconds).toString(); } public static String getTimeStringL(int milliSeconds) { long seconds = (milliSeconds % 60000L) / 1000L; long minutes = (milliSeconds % 3600000L) / 60000L; long hours = (milliSeconds % 86400000L) / 3600000L; long days = (milliSeconds % (86400000L * 7L)) / 86400000L; stringBuilder.setLength(0); return days > 0 ? stringFormatter.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds).toString() : hours > 0 ? stringFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString() : stringFormatter.format("%02d:%02d", minutes, seconds).toString(); } public static void main(String[] args) throws Exception { final int SAMPLE_SIZE = 25000; long[] results = new long[SAMPLE_SIZE]; for(int i = 0; i < SAMPLE_SIZE; i++) { long now = System.nanoTime(); getTimeString(86400001); results[i] = System.nanoTime() - now; } long sum = 0; for(int i = 0; i < SAMPLE_SIZE; i++) { sum += results[i]; } System.out.println("Average execution time: " + (sum/SAMPLE_SIZE)); results = new long[SAMPLE_SIZE]; for(int i = 0; i < SAMPLE_SIZE; i++) { long now = System.nanoTime(); getTimeStringL(86400001); results[i] = System.nanoTime() - now; } sum = 0; for(int i = 0; i < SAMPLE_SIZE; i++) { sum += results[i]; } System.out.println("Average execution time: " + (sum/SAMPLE_SIZE)); --- .../org/schabi/newpipe/player/helper/PlayerHelper.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index e1960247e..7752295d7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -70,10 +70,10 @@ public class PlayerHelper { //////////////////////////////////////////////////////////////////////////// public static String getTimeString(int milliSeconds) { - long seconds = (milliSeconds % 60000L) / 1000L; - long minutes = (milliSeconds % 3600000L) / 60000L; - long hours = (milliSeconds % 86400000L) / 3600000L; - long days = (milliSeconds % (86400000L * 7L)) / 86400000L; + int seconds = (milliSeconds % 60000) / 1000; + int minutes = (milliSeconds % 3600000) / 60000; + int hours = (milliSeconds % 86400000) / 3600000; + int days = (milliSeconds % (86400000 * 7)) / 86400000; stringBuilder.setLength(0); return days > 0 ? stringFormatter.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds).toString() From ed1746c9f8dbe6c5b16d89d747563aecc4180b80 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 5 Mar 2019 18:01:11 +0100 Subject: [PATCH 4/5] delete unused files --- app/src/main/res/layout/activity_history.xml | 49 ------------------- .../main/res/layout/activity_play_video.xml | 27 ---------- app/src/main/res/layout/fragment_history.xml | 30 ------------ 3 files changed, 106 deletions(-) delete mode 100644 app/src/main/res/layout/activity_history.xml delete mode 100644 app/src/main/res/layout/activity_play_video.xml delete mode 100644 app/src/main/res/layout/fragment_history.xml diff --git a/app/src/main/res/layout/activity_history.xml b/app/src/main/res/layout/activity_history.xml deleted file mode 100644 index e53b9bff9..000000000 --- a/app/src/main/res/layout/activity_history.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_play_video.xml b/app/src/main/res/layout/activity_play_video.xml deleted file mode 100644 index bc37184a4..000000000 --- a/app/src/main/res/layout/activity_play_video.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - -