[Android] Move some utils to resources/

Geoffrey Métais git at videolan.org
Tue Feb 4 15:36:09 CET 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sat Feb  1 11:27:06 2020 +0100| [e62953abbe86a241a78407094ae8d18785367a1b] | committer: Nicolas Pomepuy

Move some utils to resources/

> https://code.videolan.org/videolan/vlc-android/commit/e62953abbe86a241a78407094ae8d18785367a1b
---

 .../src/main/java/org/videolan/resources/Constants.kt       |  1 +
 application/tools/src/main/java/org/videolan/tools/Util.kt  | 11 +++++++++++
 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt     |  7 ++-----
 .../src/org/videolan/vlc/gui/helpers/NotificationHelper.kt  | 13 +++++--------
 application/vlc-android/src/org/videolan/vlc/util/Util.kt   | 10 ----------
 5 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/Constants.kt b/application/resources/src/main/java/org/videolan/resources/Constants.kt
index badb70c6b..2e97d4cf7 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -198,6 +198,7 @@ const val ACTION_VIEW_ARC = "org.chromium.arc.intent.action.VIEW"
 const val ACTION_SEARCH_GMS = "com.google.android.gms.actions.SEARCH_ACTION"
 
 // Class names
+const val START_ACTIVITY = "org.videolan.vlc.StartActivity"
 const val COMPATERROR_ACTIVITY = "org.videolan.vlc.gui.CompatErrorActivity"
 const val TV_SEARCH_ACTIVITY = "org.videolan.television.ui.SearchActivity"
 const val MOBILE_SEARCH_ACTIVITY = "org.videolan.vlc.gui.SearchActivity"
diff --git a/application/tools/src/main/java/org/videolan/tools/Util.kt b/application/tools/src/main/java/org/videolan/tools/Util.kt
new file mode 100644
index 000000000..550ad180f
--- /dev/null
+++ b/application/tools/src/main/java/org/videolan/tools/Util.kt
@@ -0,0 +1,11 @@
+package org.videolan.tools
+
+fun getMediaDescription(artist: String?, album: String?): String {
+    val hasArtist = !artist.isNullOrEmpty()
+    val hasAlbum = !album.isNullOrEmpty()
+    if (!hasAlbum && !hasArtist) return ""
+    val contentBuilder = StringBuilder(if (hasArtist) artist!! else "")
+    if (hasArtist && hasAlbum) contentBuilder.append(" - ")
+    if (hasAlbum) contentBuilder.append(album)
+    return contentBuilder.toString()
+}
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 6b4771cc7..cd0681aa0 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -60,10 +60,7 @@ import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.resources.*
-import org.videolan.tools.Settings
-import org.videolan.tools.WeakHandler
-import org.videolan.tools.getContextWithLocale
-import org.videolan.tools.safeOffer
+import org.videolan.tools.*
 import org.videolan.vlc.gui.helpers.AudioUtil
 import org.videolan.vlc.gui.helpers.BitmapUtil
 import org.videolan.vlc.gui.helpers.NotificationHelper
@@ -1079,7 +1076,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                     val title: String = media.nowPlaying ?: media.title
                     val builder = MediaDescriptionCompat.Builder()
                     builder.setTitle(title)
-                            .setDescription(Util.getMediaDescription(MediaUtils.getMediaArtist(ctx, media), MediaUtils.getMediaAlbum(ctx, media)))
+                            .setDescription(getMediaDescription(MediaUtils.getMediaArtist(ctx, media), MediaUtils.getMediaAlbum(ctx, media)))
                             .setIconBitmap(BitmapUtil.getPictureFromCache(media))
                             .setMediaUri(media.uri)
                             .setMediaId(MediaSessionBrowser.generateMediaId(media))
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
index 9986b8cd6..e449cfd90 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
@@ -34,14 +34,10 @@ import androidx.annotation.RequiresApi
 import androidx.core.app.NotificationCompat
 import androidx.media.session.MediaButtonReceiver
 import org.videolan.libvlc.util.AndroidUtil
-import org.videolan.resources.ACTION_PAUSE_SCAN
-import org.videolan.resources.ACTION_RESUME_SCAN
-import org.videolan.resources.AndroidDevices
-import org.videolan.resources.AppContextProvider
+import org.videolan.resources.*
 import org.videolan.tools.getContextWithLocale
+import org.videolan.tools.getMediaDescription
 import org.videolan.vlc.R
-import org.videolan.vlc.StartActivity
-import org.videolan.vlc.util.Util
 
 private const val MEDIALIBRRARY_CHANNEL_ID = "vlc_medialibrary"
 private const val PLAYBACK_SERVICE_CHANNEL_ID = "vlc_playback"
@@ -68,7 +64,7 @@ object NotificationHelper {
         builder.setSmallIcon(if (video) R.drawable.ic_notif_video else R.drawable.ic_notif_audio)
                 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                 .setContentTitle(title)
-                .setContentText(Util.getMediaDescription(artist, album))
+                .setContentText(getMediaDescription(artist, album))
                 .setLargeIcon(cover)
                 .setTicker(sb.toString())
                 .setAutoCancel(!playing)
@@ -109,8 +105,9 @@ object NotificationHelper {
     }
 
     fun createScanNotification(ctx: Context, progressText: String, paused: Boolean): Notification {
+        val intent = Intent(Intent.ACTION_VIEW).setClassName(ctx, START_ACTIVITY)
         val scanCompatBuilder = NotificationCompat.Builder(ctx, MEDIALIBRRARY_CHANNEL_ID)
-                .setContentIntent(PendingIntent.getActivity(ctx, 0, Intent(ctx, StartActivity::class.java), PendingIntent.FLAG_UPDATE_CURRENT))
+                .setContentIntent(PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
                 .setSmallIcon(R.drawable.ic_notif_scan)
                 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                 .setContentTitle(ctx.getString(R.string.ml_scanning))
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Util.kt b/application/vlc-android/src/org/videolan/vlc/util/Util.kt
index 248f9fa68..d4d3f9280 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Util.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Util.kt
@@ -68,16 +68,6 @@ object Util {
         }
     }
 
-    fun getMediaDescription(artist: String, album: String): String {
-        val hasArtist = !TextUtils.isEmpty(artist)
-        val hasAlbum = !TextUtils.isEmpty(album)
-        if (!hasAlbum && !hasArtist) return ""
-        val contentBuilder = StringBuilder(if (hasArtist) artist else "")
-        if (hasArtist && hasAlbum) contentBuilder.append(" - ")
-        if (hasAlbum) contentBuilder.append(album)
-        return contentBuilder.toString()
-    }
-
     fun checkCpuCompatibility(ctx: Context) {
         runBackground(Runnable {
             if (!VLCInstance.testCompatibleCPU(ctx))



More information about the Android mailing list