From c79997ebe36a8ef46d5e402e2f649ae16347e883 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 15 Aug 2020 23:45:23 +0200 Subject: [PATCH] Show hourglass icon when buffering --- .../newpipe/player/NotificationUtil.java | 72 +++++++++--------- .../ic_hourglass_top_white_24dp.png | Bin 0 -> 302 bytes .../ic_hourglass_top_white_24dp.png | Bin 0 -> 246 bytes .../ic_hourglass_top_white_24dp.png | Bin 0 -> 413 bytes .../ic_hourglass_top_white_24dp.png | Bin 0 -> 614 bytes .../ic_hourglass_top_white_24dp.png | Bin 0 -> 777 bytes 6 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_hourglass_top_white_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_hourglass_top_white_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_hourglass_top_white_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_hourglass_top_white_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_hourglass_top_white_24dp.png diff --git a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java index 32dd93bd4..3b7e2ac3d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java @@ -94,12 +94,7 @@ public final class NotificationUtil { } else { notificationBuilder.setLargeIcon(player.getThumbnail()); } - - setAction(player, notificationSlot0, 0); - setAction(player, notificationSlot1, 1); - setAction(player, notificationSlot2, 2); - setAction(player, notificationSlot3, 3); - setAction(player, notificationSlot4, 4); + updateActions(notificationBuilder, player); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } @@ -122,7 +117,7 @@ public final class NotificationUtil { private NotificationCompat.Builder createNotification(final VideoPlayerImpl player) { notificationManager = (NotificationManager) player.context.getSystemService(NOTIFICATION_SERVICE); - NotificationCompat.Builder builder = new NotificationCompat.Builder(player.context, + final NotificationCompat.Builder builder = new NotificationCompat.Builder(player.context, player.context.getString(R.string.notification_channel_id)); final String compactView = player.sharedPreferences.getString(player.context.getString( @@ -165,6 +160,7 @@ public final class NotificationUtil { new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT)) .setColor(ContextCompat.getColor(player.context, R.color.gray)) .setPriority(NotificationCompat.PRIORITY_HIGH); + final boolean scaleImageToSquareAspectRatio = player.sharedPreferences.getBoolean( player.context.getString(R.string.scale_to_square_image_in_notifications_key), false); @@ -174,22 +170,8 @@ public final class NotificationUtil { builder.setLargeIcon(player.getThumbnail()); } - notificationSlot0 = player.sharedPreferences.getString( - player.context.getString(R.string.notification_slot_0_key), notificationSlot0); - notificationSlot1 = player.sharedPreferences.getString( - player.context.getString(R.string.notification_slot_1_key), notificationSlot1); - notificationSlot2 = player.sharedPreferences.getString( - player.context.getString(R.string.notification_slot_2_key), notificationSlot2); - notificationSlot3 = player.sharedPreferences.getString( - player.context.getString(R.string.notification_slot_3_key), notificationSlot3); - notificationSlot4 = player.sharedPreferences.getString( - player.context.getString(R.string.notification_slot_4_key), notificationSlot4); - - addAction(builder, player, notificationSlot0); - addAction(builder, player, notificationSlot1); - addAction(builder, player, notificationSlot2); - addAction(builder, player, notificationSlot3); - addAction(builder, player, notificationSlot4); + initializeNotificationSlots(player); + updateActions(builder, player); return builder; } @@ -224,32 +206,50 @@ public final class NotificationUtil { // ACTIONS ///////////////////////////////////////////////////// - private void addAction(final NotificationCompat.Builder builder, - final VideoPlayerImpl player, - final String slot) { - builder.addAction(getAction(builder, player, slot)); + private void initializeNotificationSlots(final VideoPlayerImpl player) { + notificationSlot0 = player.sharedPreferences.getString( + player.context.getString(R.string.notification_slot_0_key), notificationSlot0); + notificationSlot1 = player.sharedPreferences.getString( + player.context.getString(R.string.notification_slot_1_key), notificationSlot1); + notificationSlot2 = player.sharedPreferences.getString( + player.context.getString(R.string.notification_slot_2_key), notificationSlot2); + notificationSlot3 = player.sharedPreferences.getString( + player.context.getString(R.string.notification_slot_3_key), notificationSlot3); + notificationSlot4 = player.sharedPreferences.getString( + player.context.getString(R.string.notification_slot_4_key), notificationSlot4); } @SuppressLint("RestrictedApi") - private void setAction(final VideoPlayerImpl player, - final String slot, - final int slotNumber) { - notificationBuilder.mActions.set(slotNumber, getAction(notificationBuilder, player, slot)); + private void updateActions(final NotificationCompat.Builder builder, + final VideoPlayerImpl player) { + builder.mActions.clear(); + addAction(builder, player, notificationSlot0); + addAction(builder, player, notificationSlot1); + addAction(builder, player, notificationSlot2); + addAction(builder, player, notificationSlot3); + addAction(builder, player, notificationSlot4); } - private NotificationCompat.Action getAction(final NotificationCompat.Builder builder, - final VideoPlayerImpl player, + private void addAction(final NotificationCompat.Builder builder, + final VideoPlayerImpl player, + final String slot) { + final NotificationCompat.Action action = getAction(player, slot); + if (action != null) { + builder.addAction(action); + } + } + + @Nullable + private NotificationCompat.Action getAction(final VideoPlayerImpl player, final String slot) { switch (slot) { case "play_pause_buffering": if (player.getCurrentState() == BasePlayer.STATE_PREFLIGHT || player.getCurrentState() == BasePlayer.STATE_BLOCKED || player.getCurrentState() == BasePlayer.STATE_BUFFERING) { - builder.setSmallIcon(android.R.drawable.stat_sys_download); - return getAction(player, R.drawable.ic_file_download_white_24dp, + return getAction(player, R.drawable.ic_hourglass_top_white_24dp, "Buffering", ACTION_BUFFERING); } else { - builder.setSmallIcon(R.drawable.ic_newpipe_triangle_white); return getAction(player, player.isPlaying() ? R.drawable.exo_notification_pause : R.drawable.exo_notification_play, diff --git a/app/src/main/res/drawable-hdpi/ic_hourglass_top_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_hourglass_top_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..13050da089b68bb561b1b88c72a2f23b7a018abf GIT binary patch literal 302 zcmV+}0nz@6P)Nkl%kOb+SFg8yf4J1JA4k(RzB1HQTxKi^J_m z=)PuW{QLo9{cWs9n}O7q&!^F!#XbS_4xm0ZND8`wMg+KnZum6#-uly6KMrp1a^B9PMKK<0)2JsR0Z$Rg|+q0d;Uf;&U3R@|(^8f$<07*qoM6N<$f{e0+ Ak^lez literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_hourglass_top_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_hourglass_top_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..2343e8cb9e297af98a685569a634ee2fe2a422d7 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`Gjdp%toLn>}1CrE62@c;k+MGk9x zRm4<}H?{pg(%crv-L{PNpTnQ29ETmV{+!&{AlPxa;Rm% zW05+kz--6#(N*D^)1=EyU9~N%5><{f@hkk}G4+t{-eVTRx8zv!q#m(ucV8XTq9P4B u(}m85nvxy%aIxE&t>Cu46*kiu=!^C3ukHU_nkEbM2!p4qpUXO@geCyZ!C@@` literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_hourglass_top_white_24dp.png b/app/src/main/res/drawable-xhdpi/ic_hourglass_top_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..bdf88fb3b6228c30f5d7dec80785280edab4f951 GIT binary patch literal 413 zcmV;O0b>4%P)O7Aq9@TonZ1cVp_@8>K<>;J^DzwVmC38< z1LtD=zN+(ktciUv|18=ma~ILOXrb~JICfEaJFJaew~aP`7QKnmj{Fqo&IW}2cEZ4# zZF7RbWzV`La!wuX6xsyHjDc;h{A$43RmYuZYGpP73Zv(HuYAv)&@)lE+R%J;_56Su zDb_mQk!?oQ*${vL1aJ?q9r00P%lASAcu;`H{>aB*F#L%hbZ+LFA=;ok00000NkvXX Hu0mjf8wtON literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_hourglass_top_white_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_hourglass_top_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..f9a097f4de3976b2b71e70580fdd791fd281ca8d GIT binary patch literal 614 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@Zgyv2VAAz;aSW-r^>(&l-XRAOmz5he zHZbu%=U~#364rK-|KAp?`=@>T(7mG}{@|2&8;jy! zt+OoKd@en>*HJFnbaUY|h3_+qRabOY=-Q<+Ja35-zCCXy?@>p#hAqb~9Bc0?ed1d1 z*vBey&9xQNb3_z)KMLMldS;I4v0I$SCwR^lX)wE%>c_NTV#QRZ3Gb|b@h7Z$B$xMY zn<0n&4Y@~Omu|bUE_t=t;g=oHA2ll`PuubP+efQ;f$TkRBRDzJ>+8-gwSG9wA^S_t znK>5>iu-=-`k+^)_pN+GZe#5uW6do}lb<$aDNG*)EF|P6HvpDckwDj1G?-?tMo%@Rf87m*1*9rS46sEPcJ$%c|$BODohp%cm z?AxK4wM#-+VqKnKRprk4o+sv*oy$tuaX#`9*V8)zw-4S}`p{0(>3rEbW6p(^)lW{v zAM#rIE$^x1h4}tjyCY|Lewzedp7lJb${}C!TcxwFHG}O2d6WqHD4zC*Qw}V2VQ<5a i{D+`ebq$>MLi|jkkK9kjrLMsA!{F)a=d#Wzp$Pz@f(ADL literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_hourglass_top_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_hourglass_top_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..7a099dabfe78a342fb0ab8821a1344cbdc805c18 GIT binary patch literal 777 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7Ro>V7lPx;uunK>+RhASxk-s?e7_N zm@+RdHCocWv|r(6@F~$s21l0p3QN8Swk+`$R%+VntMfLOd843C^VFNF`zO?|+v$9M z_wB!R1`6}cH=EzT^Uji6%9TU0MZgJ6{L9=MXFug+4NHI)BhXHwK!6&9bMj-MC-?da zUnn=s+qheZVMFqppBxX4+-TJ+h`DfT|78h(C3#g2TVHqA%K^!sjeqWUxKgrlGLuT( zqK#J;1*GVGyAyH!#(^7$ZfLb1Suaw(VB;M3g(qW5oUfXnW<21tQ95wNr4SM6>L8~u z_EmpoCLMG1wT*T-vg+7TMg|=b?Y;~B)(aQ@teEt%$vQwstDd=I-6~`4$osKId;h*% zG0pLIlFt0C3iHdjE^Pa-d2c||w$}e|Tbs7)9?H~DVR&#O;&enkJ45YH3$?{BC)cOF zxprf*@=kBt%lcocCd)m2%){}LVat>q_2SoBxVL@1s_64X!O8i3mh~%MZR51N z_2|9F{LI&Le6tVDPP(gIW}3oK8v3|ozO*{0dDXJ6SpKh>%UAxac(>xu(!TO7C&Ge$ ztbZ}5uSQ3<{7}sC*^aidnXfW)BMZK7Dx6fXIDN^+5ND5?OWzK~{r<-JUGh&}^pYI? z8!fT#4Zm%zX}i76<8s`I0-lH4bT4fYHzBe6Gzc(!aL+@ex1X