Commit dfd00737 authored by Habib Kazemi's avatar Habib Kazemi Committed by Geoffrey Métais

Convert Constants to kotlin

Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 0e4fcb70
......@@ -35,7 +35,7 @@ import org.videolan.vlc.database.helpers.*
import org.videolan.vlc.database.models.BrowserFav
import org.videolan.vlc.database.models.ExternalSub
import org.videolan.vlc.database.models.Slave
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.TYPE_NETWORK_FAV
@RunWith(AndroidJUnit4::class)
class MigrationTest {
......@@ -89,7 +89,7 @@ class MigrationTest {
assertEquals(fav.uri, favUri)
assertEquals(fav.title, favTitle)
assertEquals(fav.iconUrl, null)
assertEquals(fav.type, Constants.TYPE_NETWORK_FAV)
assertEquals(fav.type, TYPE_NETWORK_FAV)
clearDatabase(sqliteTestDbOpenHelper)
}
......
......@@ -91,8 +91,8 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
medialibrary = Medialibrary.getInstance()
medialibrary.addDeviceDiscoveryCb(this@MediaParsingService)
val filter = IntentFilter()
filter.addAction(Constants.ACTION_PAUSE_SCAN)
filter.addAction(Constants.ACTION_RESUME_SCAN)
filter.addAction(ACTION_PAUSE_SCAN)
filter.addAction(ACTION_RESUME_SCAN)
registerReceiver(receiver, filter)
localBroadcastManager.registerReceiver(receiver, IntentFilter(Medialibrary.ACTION_IDLE))
val pm = applicationContext.getSystemService(Context.POWER_SERVICE) as PowerManager
......@@ -117,15 +117,15 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
if (AndroidUtil.isOOrLater && lastNotificationTime == 0L) forceForeground()
else if (lastNotificationTime <= 0L) lastNotificationTime = System.currentTimeMillis()
when (intent.action) {
Constants.ACTION_INIT -> {
val upgrade = intent.getBooleanExtra(Constants.EXTRA_UPGRADE, false)
val parse = intent.getBooleanExtra(Constants.EXTRA_PARSE, true)
ACTION_INIT -> {
val upgrade = intent.getBooleanExtra(EXTRA_UPGRADE, false)
val parse = intent.getBooleanExtra(EXTRA_PARSE, true)
setupMedialibrary(upgrade, parse)
}
Constants.ACTION_RELOAD -> reload(intent.getStringExtra(Constants.EXTRA_PATH))
Constants.ACTION_DISCOVER -> discover(intent.getStringExtra(Constants.EXTRA_PATH))
Constants.ACTION_DISCOVER_DEVICE -> discoverStorage(intent.getStringExtra(Constants.EXTRA_PATH))
Constants.ACTION_CHECK_STORAGES -> if (scanActivated) actions.offer(UpdateStorages) else exitCommand()
ACTION_RELOAD -> reload(intent.getStringExtra(EXTRA_PATH))
ACTION_DISCOVER -> discover(intent.getStringExtra(EXTRA_PATH))
ACTION_DISCOVER_DEVICE -> discoverStorage(intent.getStringExtra(EXTRA_PATH))
ACTION_CHECK_STORAGES -> if (scanActivated) actions.offer(UpdateStorages) else exitCommand()
else -> {
exitCommand()
return Service.START_NOT_STICKY
......@@ -379,12 +379,12 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
Constants.ACTION_PAUSE_SCAN -> {
ACTION_PAUSE_SCAN -> {
if (wakeLock.isHeld) wakeLock.release()
scanPaused = true
medialibrary.pauseBackgroundOperations()
}
Constants.ACTION_RESUME_SCAN -> {
ACTION_RESUME_SCAN -> {
if (!wakeLock.isHeld) wakeLock.acquire()
medialibrary.resumeBackgroundOperations()
scanPaused = false
......@@ -410,15 +410,15 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
data class ScanProgress(val parsing: Int, val discovery: String)
fun reload(ctx: Context) {
ContextCompat.startForegroundService(ctx, Intent(Constants.ACTION_RELOAD, null, ctx, MediaParsingService::class.java))
ContextCompat.startForegroundService(ctx, Intent(ACTION_RELOAD, null, ctx, MediaParsingService::class.java))
}
fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = false, parse: Boolean = true) = launch(UI.immediate) {
if (Medialibrary.getInstance().isStarted || !Permissions.canReadStorage(this@startMedialibrary)) return@launch
val prefs = withContext(VLCIO) { Settings.getInstance(this@startMedialibrary) }
val scanOpt = if (VLCApplication.showTvUi()) Constants.ML_SCAN_ON else prefs.getInt(Constants.KEY_MEDIALIBRARY_SCAN, -1)
val scanOpt = if (VLCApplication.showTvUi()) ML_SCAN_ON else prefs.getInt(KEY_MEDIALIBRARY_SCAN, -1)
if (parse && scanOpt == -1) {
if (dbExists(this@startMedialibrary)) prefs.edit().putInt(Constants.KEY_MEDIALIBRARY_SCAN, Constants.ML_SCAN_ON).apply()
if (dbExists(this@startMedialibrary)) prefs.edit().putInt(KEY_MEDIALIBRARY_SCAN, ML_SCAN_ON).apply()
else {
if (MediaParsingService.wizardShowing) return@launch
MediaParsingService.wizardShowing = true
......@@ -426,11 +426,11 @@ fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = fals
return@launch
}
}
val intent = Intent(Constants.ACTION_INIT, null, this@startMedialibrary, MediaParsingService::class.java)
val intent = Intent(ACTION_INIT, null, this@startMedialibrary, MediaParsingService::class.java)
ContextCompat.startForegroundService(this@startMedialibrary, intent
.putExtra(Constants.EXTRA_FIRST_RUN, firstRun)
.putExtra(Constants.EXTRA_UPGRADE, upgrade)
.putExtra(Constants.EXTRA_PARSE, parse && scanOpt == Constants.ML_SCAN_ON))
.putExtra(EXTRA_FIRST_RUN, firstRun)
.putExtra(EXTRA_UPGRADE, upgrade)
.putExtra(EXTRA_PARSE, parse && scanOpt == ML_SCAN_ON))
}
private suspend fun dbExists(context: Context) = withContext(VLCIO) {
......
......@@ -13,10 +13,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.extensions.ExtensionsManager
import org.videolan.vlc.media.BrowserProvider
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.VoiceSearchParams
import org.videolan.vlc.util.registerMedialibrary
import org.videolan.vlc.util.*
private const val TAG = "VLC/MediaSessionCallback"
......@@ -44,10 +41,10 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
when (action) {
"shuffle" -> playbackService.shuffle()
"repeat" -> playbackService.repeatType = when (playbackService.repeatType) {
Constants.REPEAT_NONE -> Constants.REPEAT_ALL
Constants.REPEAT_ALL -> Constants.REPEAT_ONE
Constants.REPEAT_ONE -> Constants.REPEAT_NONE
else -> Constants.REPEAT_NONE
REPEAT_NONE -> REPEAT_ALL
REPEAT_ALL -> REPEAT_ONE
REPEAT_ONE -> REPEAT_NONE
else -> REPEAT_NONE
}
}
}
......
......@@ -112,7 +112,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
/*
* Launch the activity if needed
*/
if (action.startsWith(Constants.ACTION_REMOTE_GENERIC) && !isPlaying && !playlistManager.hasCurrentMedia()) {
if (action.startsWith(ACTION_REMOTE_GENERIC) && !isPlaying && !playlistManager.hasCurrentMedia()) {
packageManager.getLaunchIntentForPackage(packageName)?.let { context.startActivity(it) }
}
......@@ -120,20 +120,20 @@ class PlaybackService : MediaBrowserServiceCompat() {
* Remote / headset control events
*/
when (action) {
Constants.ACTION_REMOTE_PLAYPAUSE -> {
ACTION_REMOTE_PLAYPAUSE -> {
if (!playlistManager.hasCurrentMedia()) loadLastAudioPlaylist()
else if (isPlaying) pause()
else play()
}
Constants.ACTION_REMOTE_PLAY -> if (!isPlaying && playlistManager.hasCurrentMedia()) play()
Constants.ACTION_REMOTE_PAUSE -> if (playlistManager.hasCurrentMedia()) pause()
Constants.ACTION_REMOTE_BACKWARD -> previous(false)
Constants.ACTION_REMOTE_STOP,
ACTION_REMOTE_PLAY -> if (!isPlaying && playlistManager.hasCurrentMedia()) play()
ACTION_REMOTE_PAUSE -> if (playlistManager.hasCurrentMedia()) pause()
ACTION_REMOTE_BACKWARD -> previous(false)
ACTION_REMOTE_STOP,
VLCApplication.SLEEP_INTENT -> stop()
Constants.ACTION_REMOTE_FORWARD -> next()
Constants.ACTION_REMOTE_LAST_PLAYLIST -> loadLastAudioPlaylist()
Constants.ACTION_REMOTE_LAST_VIDEO_PLAYLIST -> playlistManager.loadLastPlaylist(Constants.PLAYLIST_TYPE_VIDEO)
Constants.ACTION_REMOTE_SWITCH_VIDEO -> {
ACTION_REMOTE_FORWARD -> next()
ACTION_REMOTE_LAST_PLAYLIST -> loadLastAudioPlaylist()
ACTION_REMOTE_LAST_VIDEO_PLAYLIST -> playlistManager.loadLastPlaylist(PLAYLIST_TYPE_VIDEO)
ACTION_REMOTE_SWITCH_VIDEO -> {
removePopup()
if (hasMedia()) {
currentMediaWrapper!!.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
......@@ -142,7 +142,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
}
VLCAppWidgetProvider.ACTION_WIDGET_INIT -> updateWidget()
VLCAppWidgetProvider.ACTION_WIDGET_ENABLED , VLCAppWidgetProvider.ACTION_WIDGET_DISABLED -> updateHasWidget()
Constants.ACTION_CAR_MODE_EXIT -> BrowserProvider.unbindExtensionConnection()
ACTION_CAR_MODE_EXIT -> BrowserProvider.unbindExtensionConnection()
AudioManager.ACTION_AUDIO_BECOMING_NOISY -> if (detectHeadset) {
if (BuildConfig.DEBUG) Log.i(TAG, "Becoming noisy")
wasPlaying = isPlaying
......@@ -206,7 +206,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
}
playlistManager.videoBackground || canSwitchToVideo() && !currentMediaHasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) -> {//resume video playback
/* Resume VideoPlayerActivity from ACTION_REMOTE_SWITCH_VIDEO intent */
val notificationIntent = Intent(Constants.ACTION_REMOTE_SWITCH_VIDEO)
val notificationIntent = Intent(ACTION_REMOTE_SWITCH_VIDEO)
PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
}
else -> { /* Show audio player */
......@@ -467,22 +467,22 @@ class PlaybackService : MediaBrowserServiceCompat() {
val filter = IntentFilter().apply {
priority = Integer.MAX_VALUE
addAction(Constants.ACTION_REMOTE_BACKWARD)
addAction(Constants.ACTION_REMOTE_PLAYPAUSE)
addAction(Constants.ACTION_REMOTE_PLAY)
addAction(Constants.ACTION_REMOTE_PAUSE)
addAction(Constants.ACTION_REMOTE_STOP)
addAction(Constants.ACTION_REMOTE_FORWARD)
addAction(Constants.ACTION_REMOTE_LAST_PLAYLIST)
addAction(Constants.ACTION_REMOTE_LAST_VIDEO_PLAYLIST)
addAction(Constants.ACTION_REMOTE_SWITCH_VIDEO)
addAction(ACTION_REMOTE_BACKWARD)
addAction(ACTION_REMOTE_PLAYPAUSE)
addAction(ACTION_REMOTE_PLAY)
addAction(ACTION_REMOTE_PAUSE)
addAction(ACTION_REMOTE_STOP)
addAction(ACTION_REMOTE_FORWARD)
addAction(ACTION_REMOTE_LAST_PLAYLIST)
addAction(ACTION_REMOTE_LAST_VIDEO_PLAYLIST)
addAction(ACTION_REMOTE_SWITCH_VIDEO)
addAction(VLCAppWidgetProvider.ACTION_WIDGET_INIT)
addAction(VLCAppWidgetProvider.ACTION_WIDGET_ENABLED)
addAction(VLCAppWidgetProvider.ACTION_WIDGET_DISABLED)
addAction(Intent.ACTION_HEADSET_PLUG)
addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY)
addAction(VLCApplication.SLEEP_INTENT)
addAction(Constants.ACTION_CAR_MODE_EXIT)
addAction(ACTION_CAR_MODE_EXIT)
}
registerReceiver(receiver, filter)
......@@ -504,15 +504,15 @@ class PlaybackService : MediaBrowserServiceCompat() {
Intent.ACTION_MEDIA_BUTTON -> {
if (AndroidDevices.hasTsp || AndroidDevices.hasPlayServices) MediaButtonReceiver.handleIntent(mediaSession, intent)
}
Constants.ACTION_REMOTE_PLAYPAUSE,
Constants.ACTION_REMOTE_PLAY,
Constants.ACTION_REMOTE_LAST_PLAYLIST -> {
ACTION_REMOTE_PLAYPAUSE,
ACTION_REMOTE_PLAY,
ACTION_REMOTE_LAST_PLAYLIST -> {
if (playlistManager.hasCurrentMedia()) play()
else loadLastAudioPlaylist()
}
Constants.ACTION_PLAY_FROM_SEARCH -> {
ACTION_PLAY_FROM_SEARCH -> {
if (!this::mediaSession.isInitialized) initMediaSession()
val extras = intent!!.getBundleExtra(Constants.EXTRA_SEARCH_BUNDLE)
val extras = intent!!.getBundleExtra(EXTRA_SEARCH_BUNDLE)
mediaSession.controller.transportControls
.playFromSearch(extras.getString(SearchManager.QUERY), extras)
}
......@@ -801,15 +801,15 @@ class PlaybackService : MediaBrowserServiceCompat() {
}
pscb.setState(state, time, playlistManager.player.getRate())
val repeatType = playlistManager.repeating
if (repeatType != Constants.REPEAT_NONE || hasNext())
if (repeatType != REPEAT_NONE || hasNext())
actions = actions or PlaybackStateCompat.ACTION_SKIP_TO_NEXT
if (repeatType != Constants.REPEAT_NONE || hasPrevious() || isSeekable)
if (repeatType != REPEAT_NONE || hasPrevious() || isSeekable)
actions = actions or PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
if (isSeekable)
actions = actions or PlaybackStateCompat.ACTION_FAST_FORWARD or PlaybackStateCompat.ACTION_REWIND or PlaybackStateCompat.ACTION_SEEK_TO
actions = actions or PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM
pscb.setActions(actions)
val repeatResId = if (repeatType == Constants.REPEAT_ALL) R.drawable.ic_auto_repeat_pressed else if (repeatType == Constants.REPEAT_ONE) R.drawable.ic_auto_repeat_one_pressed else R.drawable.ic_auto_repeat_normal
val repeatResId = if (repeatType == REPEAT_ALL) R.drawable.ic_auto_repeat_pressed else if (repeatType == REPEAT_ONE) R.drawable.ic_auto_repeat_one_pressed else R.drawable.ic_auto_repeat_normal
if (playlistManager.hasPlaylist())
pscb.addCustomAction("shuffle", getString(R.string.shuffle_title), if (isShuffling) R.drawable.ic_auto_shuffle_pressed else R.drawable.ic_auto_shuffle_normal)
pscb.addCustomAction("repeat", getString(R.string.repeat_title), repeatResId)
......@@ -1316,7 +1316,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
}
fun loadLastAudio(context: Context) {
val i = PlaybackService.Client.getServiceIntent(context).apply { action = Constants.ACTION_REMOTE_LAST_PLAYLIST }
val i = PlaybackService.Client.getServiceIntent(context).apply { action = ACTION_REMOTE_LAST_PLAYLIST }
ContextCompat.startForegroundService(context, i)
}
......
......@@ -37,7 +37,6 @@ import kotlinx.coroutines.experimental.withContext
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.gui.helpers.BitmapUtil
import org.videolan.vlc.gui.video.VideoPlayerActivity
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.Util
import org.videolan.vlc.util.*
......@@ -81,10 +80,10 @@ class RecommendationsService : IntentService("RecommendationService") {
private fun buildPendingIntent(mw: MediaWrapper, id: Int): PendingIntent {
val intent = Intent(this@RecommendationsService, VideoPlayerActivity::class.java)
intent.action = Constants.PLAY_FROM_VIDEOGRID
intent.putExtra(Constants.PLAY_EXTRA_ITEM_LOCATION, mw.uri)
intent.putExtra(Constants.PLAY_EXTRA_ITEM_TITLE, mw.title)
intent.putExtra(Constants.PLAY_EXTRA_FROM_START, false)
intent.action = PLAY_FROM_VIDEOGRID
intent.putExtra(PLAY_EXTRA_ITEM_LOCATION, mw.uri)
intent.putExtra(PLAY_EXTRA_ITEM_TITLE, mw.title)
intent.putExtra(PLAY_EXTRA_FROM_START, false)
return PendingIntent.getActivity(this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
......
......@@ -70,8 +70,7 @@ import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.gui.video.VideoPlayerActivity
import org.videolan.vlc.gui.view.AudioMediaSwitcher.AudioMediaSwitcherListener
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.VLCIO
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.PlaybackProgress
import org.videolan.vlc.viewmodels.PlaylistModel
......@@ -167,12 +166,12 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
private val ctxReceiver : CtxActionReceiver = object : CtxActionReceiver {
override fun onCtxAction(position: Int, option: Int) {
when(option) {
Constants.CTX_SET_RINGTONE -> AudioUtil.setRingtone(playlistAdapter.getItem(position), activity)
Constants.CTX_ADD_TO_PLAYLIST -> {
CTX_SET_RINGTONE -> AudioUtil.setRingtone(playlistAdapter.getItem(position), activity)
CTX_ADD_TO_PLAYLIST -> {
val mw = playlistAdapter.getItem(position)
UiTools.addToPlaylist(requireActivity(), listOf(mw))
}
Constants.CTX_REMOVE -> view?.let {
CTX_REMOVE -> view?.let {
val mw = playlistAdapter.getItem(position)
val cancelAction = Runnable { service?.insertItem(position, mw) }
val message = String.format(VLCApplication.getAppResources().getString(R.string.remove_playlist_item), mw.title)
......@@ -186,7 +185,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
override fun onPopupMenu(anchor: View, position: Int, media: MediaWrapper) {
val activity = activity
if (activity === null || position >= playlistAdapter.itemCount) return
val flags = Constants.CTX_REMOVE or Constants.CTX_SET_RINGTONE or Constants.CTX_ADD_TO_PLAYLIST
val flags = CTX_REMOVE or CTX_SET_RINGTONE or CTX_ADD_TO_PLAYLIST
showContext(activity, ctxReceiver, position, media.title, flags)
}
......@@ -234,11 +233,11 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
private fun updateRepeatMode() {
when (service?.repeatType) {
Constants.REPEAT_ONE -> {
REPEAT_ONE -> {
binding.repeat.setImageResource(UiTools.getResourceFromAttribute(activity, R.attr.ic_repeat_one))
binding.repeat.contentDescription = resources.getString(R.string.repeat_single)
}
Constants.REPEAT_ALL -> {
REPEAT_ALL -> {
binding.repeat.setImageResource(UiTools.getResourceFromAttribute(activity, R.attr.ic_repeat_all))
binding.repeat.contentDescription = resources.getString(R.string.repeat_all)
}
......@@ -338,9 +337,9 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
fun onRepeatClick(view: View) {
if (service === null) return
when (service?.repeatType) {
Constants.REPEAT_NONE -> service?.repeatType = Constants.REPEAT_ALL
Constants.REPEAT_ALL -> service?.repeatType = Constants.REPEAT_ONE
else -> service?.repeatType = Constants.REPEAT_NONE
REPEAT_NONE -> service?.repeatType = REPEAT_ALL
REPEAT_ALL -> service?.repeatType = REPEAT_ONE
else -> service?.repeatType = REPEAT_NONE
}
updateRepeatMode()
}
......@@ -539,7 +538,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
private fun showPlaylistTips() {
val activity = activity as? AudioPlayerContainerActivity
activity?.showTipViewIfNeeded(R.id.audio_playlist_tips, Constants.PREF_PLAYLIST_TIPS_SHOWN)
activity?.showTipViewIfNeeded(R.id.audio_playlist_tips, PREF_PLAYLIST_TIPS_SHOWN)
}
fun onStateChanged(newState: Int) {
......
......@@ -57,7 +57,7 @@ import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.media.PlaylistManager
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.*
import org.videolan.vlc.util.Constants.KEY_MRL
import org.videolan.vlc.util.KEY_MRL
import org.videolan.vlc.viewmodels.browser.BrowserModel
import java.util.*
......@@ -416,27 +416,27 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
if (mActionMode == null && item.itemType == MediaLibraryItem.TYPE_MEDIA) launch(UI.immediate) {
val mw = item as MediaWrapper
if (mw.uri.scheme == "content" || mw.uri.scheme == OTG_SCHEME) return@launch
var flags = if (!isRootDirectory && this@BaseBrowserFragment is FileBrowserFragment) Constants.CTX_DELETE else 0
if (!isRootDirectory && this is FileBrowserFragment) flags = flags or Constants.CTX_DELETE
var flags = if (!isRootDirectory && this@BaseBrowserFragment is FileBrowserFragment) CTX_DELETE else 0
if (!isRootDirectory && this is FileBrowserFragment) flags = flags or CTX_DELETE
if (mw.type == MediaWrapper.TYPE_DIR) {
val isEmpty = viewModel.isFolderEmpty(mw)
if (!isEmpty) flags = flags or Constants.CTX_PLAY
if (!isEmpty) flags = flags or CTX_PLAY
val isFileBrowser = this@BaseBrowserFragment is FileBrowserFragment && item.uri.scheme == "file"
val isNetworkBrowser = this@BaseBrowserFragment is NetworkBrowserFragment
if (isFileBrowser || isNetworkBrowser) {
val favExists = withContext(VLCIO) { browserFavRepository.browserFavExists(mw.uri) }
flags = if (favExists) {
if (isNetworkBrowser) flags or Constants.CTX_FAV_EDIT or Constants.CTX_FAV_REMOVE
else flags or Constants.CTX_FAV_REMOVE
} else flags or Constants.CTX_FAV_ADD
if (isNetworkBrowser) flags or CTX_FAV_EDIT or CTX_FAV_REMOVE
else flags or CTX_FAV_REMOVE
} else flags or CTX_FAV_ADD
}
} else {
val isVideo = mw.type == MediaWrapper.TYPE_VIDEO
val isAudio = mw.type == MediaWrapper.TYPE_AUDIO
val isMedia = isVideo || isAudio
if (isMedia) flags = flags or Constants.CTX_PLAY_ALL or Constants.CTX_APPEND or Constants.CTX_INFORMATION
flags = if (!isAudio) flags or Constants.CTX_PLAY_AS_AUDIO else flags or Constants.CTX_ADD_TO_PLAYLIST
if (isVideo) flags = flags or Constants.CTX_DOWNLOAD_SUBTITLES
if (isMedia) flags = flags or CTX_PLAY_ALL or CTX_APPEND or CTX_INFORMATION
flags = if (!isAudio) flags or CTX_PLAY_AS_AUDIO else flags or CTX_ADD_TO_PLAYLIST
if (isVideo) flags = flags or CTX_DOWNLOAD_SUBTITLES
}
if (flags != 0) showContext(requireActivity(), this@BaseBrowserFragment, position, item.getTitle(), flags)
}
......@@ -446,22 +446,22 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
if (adapter.getItem(position) !is MediaWrapper) return
val mw = adapter.getItem(position) as MediaWrapper
when (option) {
Constants.CTX_PLAY -> MediaUtils.openMedia(activity, mw)
Constants.CTX_PLAY_ALL -> {
CTX_PLAY -> MediaUtils.openMedia(activity, mw)
CTX_PLAY_ALL -> {
mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
playAll(mw)
}
Constants.CTX_APPEND -> MediaUtils.appendMedia(activity, mw)
Constants.CTX_DELETE -> if (checkWritePermission(mw) { removeMedia(mw) })
CTX_APPEND -> MediaUtils.appendMedia(activity, mw)
CTX_DELETE -> if (checkWritePermission(mw) { removeMedia(mw) })
removeMedia(mw)
Constants.CTX_INFORMATION -> showMediaInfo(mw)
Constants.CTX_PLAY_AS_AUDIO -> {
CTX_INFORMATION -> showMediaInfo(mw)
CTX_PLAY_AS_AUDIO -> {
mw.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
MediaUtils.openMedia(activity, mw)
}
Constants.CTX_ADD_TO_PLAYLIST -> UiTools.addToPlaylist(requireActivity(), mw.tracks, SavePlaylistDialog.KEY_NEW_TRACKS)
Constants.CTX_DOWNLOAD_SUBTITLES -> MediaUtils.getSubs(requireActivity(), mw)
Constants.CTX_FAV_REMOVE -> launch(VLCIO) { browserFavRepository.deleteBrowserFav(mw.uri) }
CTX_ADD_TO_PLAYLIST -> UiTools.addToPlaylist(requireActivity(), mw.tracks, SavePlaylistDialog.KEY_NEW_TRACKS)
CTX_DOWNLOAD_SUBTITLES -> MediaUtils.getSubs(requireActivity(), mw)
CTX_FAV_REMOVE -> launch(VLCIO) { browserFavRepository.deleteBrowserFav(mw.uri) }
}
}
......
......@@ -33,8 +33,7 @@ import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.launch
import org.videolan.vlc.R
import org.videolan.vlc.databinding.ContextItemBinding
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.*
const val CTX_TITLE_KEY = "CTX_TITLE_KEY"
const val CTX_POSITION_KEY = "CTX_POSITION_KEY"
......@@ -80,22 +79,22 @@ class ContextSheet : BottomSheetDialogFragment() {
}
private fun populateOptions(flags: Int) = mutableListOf<CtxOption>().apply {
if (flags and Constants.CTX_PLAY != 0) add(Simple(Constants.CTX_PLAY, getString(R.string.play), R.drawable.ic_ctx_play_normal))
if (flags and Constants.CTX_PLAY_FROM_START != 0) add(Simple(Constants.CTX_PLAY_FROM_START, getString(R.string.play_from_start), R.drawable.ic_ctx_play_from_start_normal))
if (flags and Constants.CTX_PLAY_ALL != 0) add(Simple(Constants.CTX_PLAY_ALL, getString(R.string.play_all), R.drawable.ic_ctx_play_all_normal))
if (flags and Constants.CTX_PLAY_AS_AUDIO != 0) add(Simple(Constants.CTX_PLAY_AS_AUDIO, getString(R.string.play_as_audio), R.drawable.ic_ctx_play_as_audio_normal))
if (flags and Constants.CTX_PLAY_GROUP != 0) add(Simple(Constants.CTX_PLAY_GROUP, getString(R.string.play), R.drawable.ic_ctx_play_normal))
if (flags and Constants.CTX_APPEND != 0) add(Simple(Constants.CTX_APPEND, getString(R.string.append), R.drawable.ic_ctx_append_normal))
if (flags and Constants.CTX_INFORMATION != 0) add(Simple(Constants.CTX_INFORMATION, getString(R.string.info), R.drawable.ic_ctx_information_normal))
if (flags and Constants.CTX_DELETE != 0) add(Simple(Constants.CTX_DELETE, getString(R.string.delete), R.drawable.ic_ctx_delete_normal))
if (flags and Constants.CTX_DOWNLOAD_SUBTITLES != 0) add(Simple(Constants.CTX_DOWNLOAD_SUBTITLES, getString(R.string.download_subtitles), R.drawable.ic_ctx_download_subtitles_normal))
if (flags and Constants.CTX_PLAY_NEXT != 0) add(Simple(Constants.CTX_PLAY_NEXT, getString(R.string.insert_next), R.drawable.ic_ctx_play_next_normal))
if (flags and Constants.CTX_ADD_TO_PLAYLIST != 0) add(Simple(Constants.CTX_ADD_TO_PLAYLIST, getString(R.string.add_to_playlist), R.drawable.ic_ctx_add_to_playlist_normal))
if (flags and Constants.CTX_SET_RINGTONE != 0 && AndroidDevices.isPhone) add(Simple(Constants.CTX_SET_RINGTONE, getString(R.string.set_song), R.drawable.ic_ctx_set_ringtone_normal))
if (flags and Constants.CTX_FAV_ADD != 0) add(Simple(Constants.CTX_FAV_ADD, getString(R.string.favorites_add), R.drawable.ic_menu_network))
if (flags and Constants.CTX_FAV_EDIT != 0) add(Simple(Constants.CTX_FAV_EDIT, getString(R.string.favorites_edit), R.drawable.ic_menu_network))
if (flags and Constants.CTX_FAV_REMOVE != 0) add(Simple(Constants.CTX_FAV_REMOVE, getString(R.string.favorites_remove), R.drawable.ic_menu_network))
if (flags and Constants.CTX_REMOVE != 0) add(Simple(Constants.CTX_REMOVE, getString(R.string.remove), R.drawable.ic_ctx_delete_normal))
if (flags and CTX_PLAY != 0) add(Simple(CTX_PLAY, getString(R.string.play), R.drawable.ic_ctx_play_normal))
if (flags and CTX_PLAY_FROM_START != 0) add(Simple(CTX_PLAY_FROM_START, getString(R.string.play_from_start), R.drawable.ic_ctx_play_from_start_normal))
if (flags and CTX_PLAY_ALL != 0) add(Simple(CTX_PLAY_ALL, getString(R.string.play_all), R.drawable.ic_ctx_play_all_normal))
if (flags and CTX_PLAY_AS_AUDIO != 0) add(Simple(CTX_PLAY_AS_AUDIO, getString(R.string.play_as_audio), R.drawable.ic_ctx_play_as_audio_normal))
if (flags and CTX_PLAY_GROUP != 0) add(Simple(CTX_PLAY_GROUP, getString(R.string.play), R.drawable.ic_ctx_play_normal))
if (flags and CTX_APPEND != 0) add(Simple(CTX_APPEND, getString(R.string.append), R.drawable.ic_ctx_append_normal))
if (flags and CTX_INFORMATION != 0) add(Simple(CTX_INFORMATION, getString(R.string.info), R.drawable.ic_ctx_information_normal))
if (flags and CTX_DELETE != 0) add(Simple(CTX_DELETE, getString(R.string.delete), R.drawable.ic_ctx_delete_normal))
if (flags and CTX_DOWNLOAD_SUBTITLES != 0) add(Simple(CTX_DOWNLOAD_SUBTITLES, getString(R.string.download_subtitles), R.drawable.ic_ctx_download_subtitles_normal))
if (flags and CTX_PLAY_NEXT != 0) add(Simple(CTX_PLAY_NEXT, getString(R.string.insert_next), R.drawable.ic_ctx_play_next_normal))
if (flags and CTX_ADD_TO_PLAYLIST != 0) add(Simple(CTX_ADD_TO_PLAYLIST, getString(R.string.add_to_playlist), R.drawable.ic_ctx_add_to_playlist_normal))
if (flags and CTX_SET_RINGTONE != 0 && AndroidDevices.isPhone) add(Simple(CTX_SET_RINGTONE, getString(R.string.set_song), R.drawable.ic_ctx_set_ringtone_normal))
if (flags and CTX_FAV_ADD != 0) add(Simple(CTX_FAV_ADD, getString(R.string.favorites_add), R.drawable.ic_menu_network))
if (flags and CTX_FAV_EDIT != 0) add(Simple(CTX_FAV_EDIT, getString(R.string.favorites_edit), R.drawable.ic_menu_network))
if (flags and CTX_FAV_REMOVE != 0) add(Simple(CTX_FAV_REMOVE, getString(R.string.favorites_remove), R.drawable.ic_menu_network))
if (flags and CTX_REMOVE != 0) add(Simple(CTX_REMOVE, getString(R.string.remove), R.drawable.ic_ctx_delete_normal))
}
inner class ContextAdapter : RecyclerView.Adapter<ContextAdapter.ViewHolder>() {
......
......@@ -46,7 +46,7 @@ import org.videolan.vlc.gui.browser.*
import org.videolan.vlc.gui.network.MRLPanelFragment
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.gui.video.VideoGridFragment
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.*
import java.lang.ref.WeakReference
private const val TAG = "Navigator"
......@@ -57,7 +57,7 @@ class Navigator(private val activity: MainActivity,
): NavigationView.OnNavigationItemSelectedListener, LifecycleObserver {
private val fragmentsStack = SimpleArrayMap<String, WeakReference<Fragment>>()
private val defaultFragmentId inline get() = if (settings.getInt(Constants.KEY_MEDIALIBRARY_SCAN, Constants.ML_SCAN_OFF) == Constants.ML_SCAN_ON) R.id.nav_video else R.id.nav_directories
private val defaultFragmentId inline get() = if (settings.getInt(KEY_MEDIALIBRARY_SCAN, ML_SCAN_OFF) == ML_SCAN_ON) R.id.nav_video else R.id.nav_directories
var currentFragmentId = 0
var currentFragment: Fragment? = null
private set
......@@ -156,15 +156,15 @@ class Navigator(private val activity: MainActivity,
}
private fun getTag(id: Int) = when (id) {
R.id.nav_about -> Constants.ID_ABOUT
R.id.nav_settings -> Constants.ID_PREFERENCES
R.id.nav_audio -> Constants.ID_AUDIO
R.id.nav_directories -> Constants.ID_DIRECTORIES
R.id.nav_history -> Constants.ID_HISTORY
R.id.nav_mrl -> Constants.ID_MRL
R.id.nav_network -> Constants.ID_NETWORK
R.id.nav_video -> Constants.ID_VIDEO
else -> if (defaultFragmentId == R.id.nav_video) Constants.ID_VIDEO else Constants.ID_DIRECTORIES
R.id.nav_about -> ID_ABOUT
R.id.nav_settings -> ID_PREFERENCES
R.id.nav_audio -> ID_AUDIO
R.id.nav_directories -> ID_DIRECTORIES
R.id.nav_history -> ID_HISTORY
R.id.nav_mrl -> ID_MRL
R.id.nav_network -> ID_NETWORK
R.id.nav_video -> ID_VIDEO
else -> if (defaultFragmentId == R.id.nav_video) ID_VIDEO else ID_DIRECTORIES
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
......@@ -195,7 +195,7 @@ class Navigator(private val activity: MainActivity,
}
} else when (id) {
R.id.nav_about -> showSecondaryFragment(SecondaryActivity.ABOUT)
R.id.nav_settings -> activity.startActivityForResult(Intent(activity, PreferencesActivity::class.java), Constants.ACTIVITY_RESULT_PREFERENCES)
R.id.nav_settings -> activity.startActivityForResult(Intent(activity, PreferencesActivity::class.java), ACTIVITY_RESULT_PREFERENCES)
R.id.nav_mrl -> MRLPanelFragment().show(activity.supportFragmentManager, "fragment_mrl")
else -> {
activity.slideDownAudioPlayer()
......
......@@ -33,7 +33,8 @@ import android.support.v4.app.FragmentActivity
import kotlinx.coroutines.experimental.channels.Channel
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.vlc.startMedialibrary
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.EXTRA_FIRST_RUN
import org.videolan.vlc.util.EXTRA_UPGRADE
import org.videolan.vlc.util.Permissions
import org.videolan.vlc.util.Permissions.canReadStorage
......@@ -51,11 +52,11 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val intent = if (mActivity == null) null else mActivity!!.intent
if (intent !== null && intent.getBooleanExtra(Constants.EXTRA_UPGRADE, false)) {
if (intent !== null && intent.getBooleanExtra(EXTRA_UPGRADE, false)) {
mUpgrade = true
mFirstRun = intent.getBooleanExtra(Constants.EXTRA_FIRST_RUN, false)
intent.removeExtra(Constants.EXTRA_UPGRADE)
intent.removeExtra(Constants.EXTRA_FIRST_RUN)
mFirstRun = intent.getBooleanExtra(EXTRA_FIRST_RUN, false)
intent.removeExtra(EXTRA_UPGRADE)
intent.removeExtra(EXTRA_FIRST_RUN)
}
mWrite = arguments?.getBoolean("write") ?: false
if (AndroidUtil.isMarshMallowOrLater && !canReadStorage(activity!!)) {
......
......@@ -51,8 +51,7 @@ import org.videolan.vlc.gui.tv.TvUtil.diffCallback
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity
import org.videolan.vlc.gui.tv.browser.VerticalGridActivity
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.HistoryModel
import org.videolan.vlc.viewmodels.VideosModel
......@@ -128,7 +127,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
rowsAdapter.add(videoRow)
// Audio
categoriesAdapter = ArrayObjectAdapter(CardPresenter(ctx))
val musicHeader = HeaderItem(Constants.HEADER_CATEGORIES, getString(R.string.audio))
val musicHeader = HeaderItem(HEADER_CATEGORIES, getString(R.string.audio))
updateAudioCategories()
audioRow = ListRow(musicHeader, categoriesAdapter)
rowsAdapter.add(audioRow)
......@@ -136,17 +135,17 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
//Browser section
browserAdapter = ArrayObjectAdapter(CardPresenter(ctx))
val browserHeader = HeaderItem(Constants.HEADER_NETWORK, getString(R.string.browsing))
val browserHeader = HeaderItem(HEADER_NETWORK, getString(R.string.browsing))
updateBrowsers()
browsersRow = ListRow(browserHeader, browserAdapter)
rowsAdapter.add(browsersRow)
//Misc. section
otherAdapter = ArrayObjectAdapter(CardPresenter(ctx))
val miscHeader = HeaderItem(Constants.HEADER_MISC, getString(R.string.other))
val miscHeader = HeaderItem(HEADER_MISC, getString(R.string.other))
otherAdapter.add(DummyItem(Constants.ID_SETTINGS, getString(R.string.preferences), ""))
otherAdapter.add(DummyItem(Constants.ID_ABOUT_TV, getString(R.string.about), "${getString(R.string.app_name_full)} ${BuildConfig.VERSION_NAME}"))
otherAdapter.add(DummyItem(Constants.ID_LICENCE, getString(R.string.licence), ""))
otherAdapter.add(DummyItem(ID_SETTINGS, getString(R.string.preferences), ""))
otherAdapter.add(DummyItem(ID_ABOUT_TV, getString(R.string.about), "${getString(R.string.app_name_full)} ${BuildConfig.VERSION_NAME}"))
otherAdapter.add(DummyItem(ID_LICENCE, getString(R.string.licence), ""))
miscRow = ListRow(miscHeader, otherAdapter)
rowsAdapter.add(miscRow)
......@@ -163,10 +162,10 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
fun updateAudioCategories(current: DummyItem? = null) {
val list = mutableListOf<MediaLibraryItem>(
DummyItem(Constants.CATEGORY_ARTISTS, getString(R.string.artists), ""),
DummyItem(Constants.CATEGORY_ALBUMS, getString(R.string.albums), ""),
DummyItem(Constants.CATEGORY_GENRES, getString(R.string.genres), ""),
DummyItem(Constants.CATEGORY_SONGS, getString(R.string.tracks), "")
DummyItem(CATEGORY_ARTISTS, getString(R.string.artists), ""),
DummyItem(CATEGORY_ALBUMS, getString(R.string.albums), ""),
DummyItem(CATEGORY_GENRES, getString(R.string.genres), ""),
DummyItem(CATEGORY_SONGS, getString(R.string.tracks), "")