[Android] Allow editing a network favorite on Android TV
Nicolas Pomepuy
git at videolan.org
Wed Feb 9 14:56:38 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jan 18 09:01:28 2022 +0100| [8242233ab827c7e306b2dc9f163ee2eef4772bbc] | committer: Nicolas Pomepuy
Allow editing a network favorite on Android TV
Fixes #2325
> https://code.videolan.org/videolan/vlc-android/commit/8242233ab827c7e306b2dc9f163ee2eef4772bbc
---
.../org/videolan/television/ui/MediaItemDetailsFragment.kt | 12 ++++++++++++
.../vlc-android/src/org/videolan/vlc/gui/DialogActivity.kt | 10 ++++++++--
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
index 373eb60e5..621f51650 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
@@ -56,6 +56,8 @@ import org.videolan.tools.HttpImageLoader
import org.videolan.tools.retrieveParent
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
+import org.videolan.vlc.gui.DialogActivity
+import org.videolan.vlc.gui.DialogActivity.Companion.EXTRA_MEDIA
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.UiTools.addToPlaylist
@@ -64,6 +66,7 @@ import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.FileUtils
import org.videolan.vlc.util.getScreenWidth
+import org.videolan.vlc.util.isSchemeNetwork
private const val TAG = "MediaItemDetailsFragment"
private const val ID_PLAY = 1
@@ -79,6 +82,7 @@ private const val ID_GET_INFO = 10
private const val ID_FAVORITE = 11
private const val ID_REMOVE_FROM_HISTORY = 12
private const val ID_NAVIGATE_PARENT = 13
+private const val ID_FAVORITE_EDIT = 14
const val EXTRA_FROM_HISTORY = "from_history"
@ExperimentalCoroutinesApi
@@ -293,6 +297,7 @@ class MediaItemDetailsFragment : DetailsSupportFragment(), CoroutineScope by Mai
val activity = requireActivity()
detailsOverview = DetailsOverviewRow(viewModel.mediaItemDetails)
val actionAdd = Action(ID_FAVORITE_ADD.toLong(), getString(R.string.favorites_add))
+ val actionEdit = Action(ID_FAVORITE_EDIT.toLong(), getString(R.string.favorites_edit))
val actionDelete = Action(ID_FAVORITE_DELETE.toLong(), getString(R.string.favorites_remove))
rowPresenter.backgroundColor = ContextCompat.getColor(activity, R.color.orange500)
@@ -341,6 +346,11 @@ class MediaItemDetailsFragment : DetailsSupportFragment(), CoroutineScope by Mai
rowsAdapter.notifyArrayItemRangeChanged(0, rowsAdapter.size())
Toast.makeText(activity, R.string.favorite_added, Toast.LENGTH_SHORT).show()
}
+ ID_FAVORITE_EDIT -> {
+ requireActivity().startActivity(Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_SERVER).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).apply {
+ putExtra(EXTRA_MEDIA, viewModel.media)
+ })
+ }
ID_FAVORITE_DELETE -> {
lifecycleScope.launch { browserFavRepository.deleteBrowserFav(viewModel.mediaItemDetails.location!!.toUri()) }
actionsAdapter.set(ID_FAVORITE, actionAdd)
@@ -374,6 +384,7 @@ class MediaItemDetailsFragment : DetailsSupportFragment(), CoroutineScope by Mai
val isDir = viewModel.media.type == MediaWrapper.TYPE_DIR
val canSave = isDir && withContext(Dispatchers.IO) { FileUtils.canSave(viewModel.media) }
if (activity.isFinishing) return at launchWhenStarted
+ val isNetwork = viewModel.media.uri.scheme.isSchemeNetwork()
val res = resources
if (isDir) {
detailsOverview.imageDrawable = ContextCompat.getDrawable(activity, if (viewModel.media.uri.scheme == "file")
@@ -383,6 +394,7 @@ class MediaItemDetailsFragment : DetailsSupportFragment(), CoroutineScope by Mai
detailsOverview.isImageScaleUpAllowed = true
actionsAdapter.set(ID_BROWSE, Action(ID_BROWSE.toLong(), res.getString(R.string.browse_folder)))
if (canSave) actionsAdapter.set(ID_FAVORITE, if (browserFavExists) actionDelete else actionAdd)
+ if (isDir && isNetwork && browserFavExists) actionsAdapter.set(ID_FAVORITE_EDIT, actionEdit)
} else if (viewModel.media.type == MediaWrapper.TYPE_AUDIO) {
// Add images and action buttons to the details view
if (cover == null) {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/DialogActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/DialogActivity.kt
index f2ced2332..8986f03e0 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/DialogActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/DialogActivity.kt
@@ -29,6 +29,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.libvlc.Dialog
import org.videolan.medialibrary.interfaces.media.MediaWrapper
+import org.videolan.resources.AppContextProvider
import org.videolan.vlc.R
import org.videolan.vlc.gui.dialogs.DeviceDialog
import org.videolan.vlc.gui.dialogs.NetworkServerDialog
@@ -71,7 +72,11 @@ class DialogActivity : BaseActivity() {
private fun setupServerDialog() {
- NetworkServerDialog().show(supportFragmentManager, "fragment_mrl")
+ val networkServerDialog = NetworkServerDialog()
+ intent.getParcelableExtra<MediaWrapper>(EXTRA_MEDIA)?.let {
+ networkServerDialog.setServer(it)
+ }
+ networkServerDialog.show(supportFragmentManager, "fragment_edit_network")
}
@ObsoleteCoroutinesApi
@@ -91,7 +96,8 @@ class DialogActivity : BaseActivity() {
const val KEY_DEVICE = "deviceDialog"
const val KEY_DIALOG = "vlcDialog"
- const val EXTRA_MEDIALIST = "extra_media"
+ const val EXTRA_MEDIALIST = "extra_media_list"
+ const val EXTRA_MEDIA = "extra_media"
const val EXTRA_PATH = "extra_path"
const val EXTRA_UUID = "extra_uuid"
const val EXTRA_SCAN = "extra_scan"
More information about the Android
mailing list