[Android] Move classnames to fields in Constants.kt

Geoffrey Métais git at videolan.org
Thu Jan 30 09:55:00 CET 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 29 16:46:17 2020 +0100| [2fbcabc6482fa09fb8644bb5342d3447ed80f6ae] | committer: Geoffrey Métais

Move classnames to fields in Constants.kt

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

 .../src/main/java/org/videolan/resources/Constants.kt   | 14 ++++++++++++--
 .../main/java/org/videolan/resources/util/Extensions.kt |  9 ++-------
 .../vlc-android/src/org/videolan/vlc/StartActivity.kt   | 17 +++++++++--------
 .../org/videolan/vlc/gui/browser/BaseBrowserFragment.kt |  2 +-
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt |  2 +-
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.kt   |  2 +-
 6 files changed, 26 insertions(+), 20 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 77ebd39cd..badb70c6b 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -194,5 +194,15 @@ const val CRASH_ML_MSG = "crash_ml_msg"
 
 fun String.buildPkgString() = "${BuildConfig.APP_ID}.$this"
 
-// Activity names
-const val COMPATERROR_ACTIVITY = "org.videolan.vlc.gui.CompatErrorActivity"
\ No newline at end of file
+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 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"
+const val TV_MAIN_ACTIVITY = "org.videolan.television.ui.MainTvActivity"
+const val MOBILE_MAIN_ACTIVITY = "org.videolan.vlc.gui.MainActivity"
+const val MOVIEPEDIA_ACTIVITY = "org.videolan.moviepedia.ui.MoviepediaActivity"
+const val TV_AUDIOPLAYER_ACTIVITY = "org.videolan.television.ui.audioplayer.AudioPlayerActivity"
+const val MEDIAPARSING_SERVICE = "org.videolan.vlc.MediaParsingService"
\ No newline at end of file
diff --git a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
index 561091d5d..b580905b8 100644
--- a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
+++ b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
@@ -1,15 +1,11 @@
 package org.videolan.resources.util
 
-import android.content.ComponentName
 import android.content.Context
 import android.content.Intent
 import androidx.core.content.ContextCompat
 import kotlinx.coroutines.*
 import org.videolan.medialibrary.interfaces.Medialibrary
-import org.videolan.resources.ACTION_INIT
-import org.videolan.resources.EXTRA_FIRST_RUN
-import org.videolan.resources.EXTRA_PARSE
-import org.videolan.resources.EXTRA_UPGRADE
+import org.videolan.resources.*
 import org.videolan.tools.*
 import java.io.File
 import kotlin.coroutines.resume
@@ -47,8 +43,7 @@ fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = fals
     if (parse && scanOpt == -1) {
         if (dbExists(coroutineContextProvider)) prefs.edit().putInt(KEY_MEDIALIBRARY_SCAN, ML_SCAN_ON).apply()
     }
-    val intent = Intent.makeMainActivity(ComponentName(applicationContext, "org.videolan.vlc.MediaParsingService"))
-    intent.action = ACTION_INIT
+    val intent = Intent(ACTION_INIT).setClassName(applicationContext, MEDIAPARSING_SERVICE)
     ContextCompat.startForegroundService(this at startMedialibrary, intent
             .putExtra(EXTRA_FIRST_RUN, firstRun)
             .putExtra(EXTRA_UPGRADE, upgrade)
diff --git a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
index 97749e44b..34f1dffe0 100644
--- a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
@@ -108,7 +108,7 @@ class StartActivity : FragmentActivity() {
         val intent = intent
         val action = intent?.action
 
-        if ((Intent.ACTION_VIEW == action || "org.chromium.arc.intent.action.VIEW" == action)
+        if ((Intent.ACTION_VIEW == action || ACTION_VIEW_ARC == action)
                 && TV_CHANNEL_SCHEME != intent.data?.scheme) {
             startPlaybackFromApp(intent)
             return
@@ -144,8 +144,8 @@ class StartActivity : FragmentActivity() {
         val tv = showTvUi()
         if (upgrade && (tv || !firstRun)) settings.edit().putInt(PREF_FIRST_RUN, currentVersionNumber).apply()
         // Route search query
-        if (Intent.ACTION_SEARCH == action || "com.google.android.gms.actions.SEARCH_ACTION" == action) {
-            intent.setClassName(applicationContext, if (tv) "org.videolan.television.ui.SearchActivity" else "org.videolan.vlc.gui.SearchActivity")
+        if (Intent.ACTION_SEARCH == action || ACTION_SEARCH_GMS == action) {
+            intent.setClassName(applicationContext, if (tv) TV_SEARCH_ACTIVITY else MOBILE_SEARCH_ACTIVITY)
             startActivity(intent)
             finish()
             return
@@ -195,15 +195,16 @@ class StartActivity : FragmentActivity() {
                         return at launch
                     }
                     this at StartActivity.startMedialibrary(firstRun, upgrade, true)
-                    if (onboarding)  settings.edit().putBoolean(ONBOARDING_DONE_KEY, true).apply()
+                    if (onboarding) settings.edit().putBoolean(ONBOARDING_DONE_KEY, true).apply()
                 }
             }.start()
-            val intent = Intent().apply { setClassName(applicationContext, if (tv) "org.videolan.television.ui.MainTvActivity" else "org.videolan.vlc.gui.MainActivity") }
+            val mainIntent = Intent(Intent.ACTION_VIEW)
+                    .setClassName(applicationContext, if (tv) TV_MAIN_ACTIVITY else MOBILE_MAIN_ACTIVITY)
                     .putExtra(EXTRA_FIRST_RUN, firstRun)
                     .putExtra(EXTRA_UPGRADE, upgrade)
-            if (tv && getIntent().hasExtra(EXTRA_PATH)) intent.putExtra(EXTRA_PATH, getIntent().getStringExtra(EXTRA_PATH))
-            if (target != 0) intent.putExtra(EXTRA_TARGET, target)
-            startActivity(intent)
+            if (tv && intent.hasExtra(EXTRA_PATH)) mainIntent.putExtra(EXTRA_PATH, intent.getStringExtra(EXTRA_PATH))
+            if (target != 0) mainIntent.putExtra(EXTRA_TARGET, target)
+            startActivity(mainIntent)
         } else {
             startOnboarding()
         }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index c857a25a3..0a12bdfba 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -533,7 +533,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
             CTX_ADD_SCANNED -> addToScannedFolders(mw)
             CTX_FIND_METADATA -> {
                 val intent = Intent().apply {
-                    setClassName(requireContext().applicationContext, "org.videolan.moviepedia.ui.MoviepediaActivity")
+                    setClassName(requireContext().applicationContext, MOVIEPEDIA_ACTIVITY)
                     putExtra(MOVIEPEDIA_MEDIA, mw)
                 }
                 startActivity(intent)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 2760b467e..a035e4470 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -403,7 +403,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                 CTX_ADD_TO_PLAYLIST -> UiTools.addToPlaylist(requireActivity(), media.tracks, SavePlaylistDialog.KEY_NEW_TRACKS)
                 CTX_FIND_METADATA -> {
                     val intent = Intent().apply {
-                        setClassName(requireContext().applicationContext, "org.videolan.moviepedia.ui.MoviepediaActivity")
+                        setClassName(requireContext().applicationContext, MOVIEPEDIA_ACTIVITY)
                         apply { putExtra(MOVIEPEDIA_MEDIA, media) }
                     }
                     startActivity(intent)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index c2c6fecbd..2af4d9c60 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -1611,7 +1611,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
         // Show the MainActivity if it is not in background.
         if (showUI) {
             val i = Intent().apply {
-                setClassName(applicationContext, if (isTv) "org.videolan.television.ui.audioplayer.AudioPlayerActivity" else "org.videolan.vlc.gui.MainActivity")
+                setClassName(applicationContext, if (isTv) TV_AUDIOPLAYER_ACTIVITY else MOBILE_MAIN_ACTIVITY)
             }
             startActivity(i)
         }



More information about the Android mailing list