Skip to content
Snippets Groups Projects
Commit c5ff71c6 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais
Browse files

Allow adding a directory to scanned ones from the browser

parent f2e3f20f
No related branches found
No related tags found
1 merge request!252Allow adding a directory to scanned ones from the browser
Showing
with 162 additions and 2 deletions
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="48" height="48"
id="svg4682" version="1.1" inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="ic_menu_scan.svg"
inkscape:export-filename="/home/corbax/Dev/android/Icons/Test 1/ic_play_normal.png"
inkscape:export-xdpi="90" inkscape:export-ydpi="90">
<defs id="defs4684" />
<sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0"
inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="15.839192"
inkscape:cx="16.249969" inkscape:cy="21.90058" inkscape:document-units="px"
inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1920"
inkscape:window-height="1053" inkscape:window-x="0" inkscape:window-y="27"
inkscape:window-maximized="1" inkscape:snap-grids="true" inkscape:snap-bbox="true"
inkscape:bbox-paths="true" inkscape:bbox-nodes="true"
inkscape:snap-bbox-edge-midpoints="true" inkscape:snap-bbox-midpoints="true"
inkscape:object-paths="true" inkscape:snap-intersection-paths="true"
inkscape:object-nodes="true" inkscape:snap-smooth-nodes="true"
inkscape:snap-midpoints="true" inkscape:snap-object-midpoints="true"
inkscape:snap-center="true" showguides="true" inkscape:guide-bbox="true">
<inkscape:grid type="xygrid" id="grid3002" />
<sodipodi:guide position="-10,24" orientation="0,1" id="guide814" inkscape:locked="false"
inkscape:label="" inkscape:color="rgb(0,0,255)" />
</sodipodi:namedview>
<metadata id="metadata4687">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1"
transform="translate(0,-1004.3622)">
<path style="fill:#ffffff;fill-opacity:1;stroke-width:2.00000525"
d="m 19.734319,1012.3621 c -0.380001,0 -0.805182,0.046 -1.109383,0.2734 -0.601602,0.4504 -0.843322,1.173 -1.367184,2.7345 -0.523861,1.5614 -0.546881,1.6405 -0.546881,1.6405 2.188106,1.0941 3.77507,1.1964 6.042976,0 0,0 -0.025,-0.086 -0.546862,-1.6405 -0.521841,-1.5554 -0.761982,-2.2732 -1.367203,-2.7345 -0.302241,-0.2302 -0.725462,-0.2734 -1.105463,-0.2734 z m -4.937513,10.3906 -2.187506,6.5665 -0.004,0.02 c 0.01,0 0.018,0 0.0274,0 2.042825,1.7706 4.558712,2.6566 7.078139,2.664 a 14.000037,14.000037 0 0 1 5.601574,-7.3125 l -0.640621,-1.9218 h -0.004 c -3.318249,2.4776 -6.588957,2.458 -9.871106,0 z m 18.203168,3.6095 a 10.000026,10.000026 0 0 0 -10.000027,10.0001 10.000026,10.000026 0 0 0 10.000027,10 10.000026,10.000026 0 0 0 9.789085,-8 h -3.082028 a 7.0000184,7.0000184 0 0 1 -6.707057,5 7.0000184,7.0000184 0 0 1 -7.000019,-7 7.0000184,7.0000184 0 0 1 7.000019,-7 7.0000184,7.0000184 0 0 1 4.945333,2.0545 l -2.945328,2.9455 H 39.703111 42.796879 43 v -8.0001 l -2.933608,2.9337 a 10.000026,10.000026 0 0 0 -7.066418,-2.9337 z m -23.7930224,6.2383 c -0.7272619,0 -1.4046637,0.5488 -1.6172043,1.2735 l -1.2734433,4.3359 c -0.4162811,1.4222 -0.8278822,2.8317 -1.2460833,4.2618 -0.1750005,0.5976 -0.00108,1.04 0.2812407,1.3438 0.1748005,0.188 0.3911211,0.3234 0.5898416,0.414 0.1988005,0.088 0.3355409,0.132 0.4922013,0.132 0.3652009,0 6.7433377,0 13.3008147,0 0.884222,0 0.929622,-2e-4 1.792964,0 a 14.000037,14.000037 0 0 1 -2.277345,-5.4062 c -3.180529,-0.098 -6.288897,-1.132 -8.261742,-3.0626 -0.412581,-0.4036 -0.273621,-0.82 0,-1.6406 0.1824,-0.547 0.527341,-1.6484 0.527341,-1.6484 H 9.2069516 Z"
id="path6982" inkscape:connector-curvature="0" inkscape:transform-center-y="1" />
</g>
</svg>
<!--
~ *************************************************************************
~ ic_ctx_scan.xml
~ **************************************************************************
~ Copyright © 2019 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<vector android:height="38dp"
android:viewportHeight="48"
android:viewportWidth="48"
android:width="38dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillAlpha="1"
android:fillColor="#000000"
android:pathData="m19.7343,7.9999c-0.38,0 -0.8052,0.046 -1.1094,0.2734 -0.6016,0.4504 -0.8433,1.173 -1.3672,2.7345 -0.5239,1.5614 -0.5469,1.6405 -0.5469,1.6405 2.1881,1.0941 3.7751,1.1964 6.043,0 0,0 -0.025,-0.086 -0.5469,-1.6405 -0.5218,-1.5554 -0.762,-2.2732 -1.3672,-2.7345 -0.3022,-0.2302 -0.7255,-0.2734 -1.1055,-0.2734zM14.7968,18.3906 L12.6093,24.957 12.6053,24.9771c0.01,0 0.018,0 0.0274,0 2.0428,1.7706 4.5587,2.6566 7.0781,2.664a14,14 0,0 1,5.6016 -7.3125l-0.6406,-1.9218h-0.004c-3.3182,2.4776 -6.589,2.458 -9.8711,0zM33,22.0001a10,10 0,0 0,-10 10.0001,10 10,0 0,0 10,10 10,10 0,0 0,9.7891 -8h-3.082a7,7 0,0 1,-6.7071 5,7 7,0 0,1 -7,-7 7,7 0,0 1,7 -7,7 7,0 0,1 4.9453,2.0545l-2.9453,2.9455L39.7031,30.0002 42.7969,30.0002 43,30.0002v-8.0001l-2.9336,2.9337a10,10 0,0 0,-7.0664 -2.9337zM9.207,28.2384c-0.7273,0 -1.4047,0.5488 -1.6172,1.2735l-1.2734,4.3359c-0.4163,1.4222 -0.8279,2.8317 -1.2461,4.2618 -0.175,0.5976 -0.0011,1.04 0.2812,1.3438 0.1748,0.188 0.3911,0.3234 0.5898,0.414 0.1988,0.088 0.3355,0.132 0.4922,0.132 0.3652,0 6.7433,0 13.3008,0 0.8842,0 0.9296,-0.0002 1.793,0a14,14 0,0 1,-2.2773 -5.4062c-3.1805,-0.098 -6.2889,-1.132 -8.2617,-3.0626 -0.4126,-0.4036 -0.2736,-0.82 0,-1.6406 0.1824,-0.547 0.5273,-1.6484 0.5273,-1.6484L9.207,28.2415Z"
android:strokeWidth="2.00000525" />
</vector>
<!--
~ *************************************************************************
~ ic_menu_scan.xml
~ **************************************************************************
~ Copyright © 2019 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="m19.7343,7.9999c-0.38,0 -0.8052,0.046 -1.1094,0.2734 -0.6016,0.4504 -0.8433,1.173 -1.3672,2.7345 -0.5239,1.5614 -0.5469,1.6405 -0.5469,1.6405 2.1881,1.0941 3.7751,1.1964 6.043,0 0,0 -0.025,-0.086 -0.5469,-1.6405 -0.5218,-1.5554 -0.762,-2.2732 -1.3672,-2.7345 -0.3022,-0.2302 -0.7255,-0.2734 -1.1055,-0.2734zM14.7968,18.3906 L12.6093,24.957 12.6053,24.9771c0.01,0 0.018,0 0.0274,0 2.0428,1.7706 4.5587,2.6566 7.0781,2.664a14,14 0,0 1,5.6016 -7.3125l-0.6406,-1.9218h-0.004c-3.3182,2.4776 -6.589,2.458 -9.8711,0zM33,22.0001a10,10 0,0 0,-10 10.0001,10 10,0 0,0 10,10 10,10 0,0 0,9.7891 -8h-3.082a7,7 0,0 1,-6.7071 5,7 7,0 0,1 -7,-7 7,7 0,0 1,7 -7,7 7,0 0,1 4.9453,2.0545l-2.9453,2.9455L39.7031,30.0002 42.7969,30.0002 43,30.0002v-8.0001l-2.9336,2.9337a10,10 0,0 0,-7.0664 -2.9337zM9.207,28.2384c-0.7273,0 -1.4047,0.5488 -1.6172,1.2735l-1.2734,4.3359c-0.4163,1.4222 -0.8279,2.8317 -1.2461,4.2618 -0.175,0.5976 -0.0011,1.04 0.2812,1.3438 0.1748,0.188 0.3911,0.3234 0.5898,0.414 0.1988,0.088 0.3355,0.132 0.4922,0.132 0.3652,0 6.7433,0 13.3008,0 0.8842,0 0.9296,-0.0002 1.793,0a14,14 0,0 1,-2.2773 -5.4062c-3.1805,-0.098 -6.2889,-1.132 -8.2617,-3.0626 -0.4126,-0.4036 -0.2736,-0.82 0,-1.6406 0.1824,-0.547 0.5273,-1.6484 0.5273,-1.6484L9.207,28.2415Z"
android:strokeWidth="2.00000525"
android:fillColor="#ffffff"
android:fillAlpha="1" />
</vector>
......@@ -38,6 +38,13 @@
vlc:showAsAction="ifRoom|collapseActionView"
android:icon="@drawable/ic_view_grid"
android:visible="false"/>
<item
android:orderInCategory="3"
android:id="@+id/ml_menu_scan"
android:title="@string/add_to_scanned"
vlc:showAsAction="ifRoom|collapseActionView"
android:icon="@drawable/ic_menu_scan"
android:visible="false" />
<item
android:orderInCategory="2"
android:title="@string/sortby"
......
......@@ -731,6 +731,8 @@
<string name="report_a_crash">Report a crash</string>
<string name="describe_crash">Please describe how this crash happened</string>
<string name="favorite">Favorite</string>
<string name="add_to_scanned">Scan this folder</string>
<string name="scanned_directory_added">%s added to your scanned folders</string>
<string name="directory_not_scanned">This directory is not scanned</string>
<string name="scanned_directory_added">%s added to your scanned directories</string>
<string name="video_group_size_dialog_text">Number of characters used to group by name</string>
......
......@@ -37,6 +37,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -50,6 +51,7 @@ import org.videolan.vlc.gui.MainActivity
import org.videolan.vlc.gui.dialogs.CtxActionReceiver
import org.videolan.vlc.gui.dialogs.SavePlaylistDialog
import org.videolan.vlc.gui.dialogs.showContext
import org.videolan.vlc.gui.helpers.MedialibraryUtils
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.hf.OTG_SCHEME
import org.videolan.vlc.gui.view.VLCDividerItemDecoration
......@@ -394,10 +396,22 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
viewModel.updateShowHiddenFiles(item.isChecked)
true
}
R.id.ml_menu_scan -> {
currentMedia?.let { media ->
addToScannedFolders(media)
item.isVisible = false
}
true
}
else -> super.onOptionsItemSelected(item)
}
}
private fun addToScannedFolders(mw: AbstractMediaWrapper) {
MedialibraryUtils.addDir(mw.uri.toString(), requireActivity().applicationContext)
Snackbar.make(binding.root, getString(R.string.scanned_directory_added, Uri.parse(mw.uri.toString()).lastPathSegment), Snackbar.LENGTH_LONG).show()
}
private fun toggleFavorite() = launch {
val mw = currentMedia ?: return@launch
withContext(Dispatchers.IO) {
......@@ -456,6 +470,9 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
else flags or CTX_FAV_REMOVE
} else flags or CTX_FAV_ADD
}
if (isFileBrowser && !isRootDirectory && !MedialibraryUtils.isScanned(item.uri.toString())) {
flags = flags or CTX_ADD_SCANNED
}
} else {
val isVideo = mw.type == AbstractMediaWrapper.TYPE_VIDEO
val isAudio = mw.type == AbstractMediaWrapper.TYPE_AUDIO
......@@ -487,6 +504,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
CTX_ADD_TO_PLAYLIST -> UiTools.addToPlaylist(requireActivity(), mw.tracks, SavePlaylistDialog.KEY_NEW_TRACKS)
CTX_DOWNLOAD_SUBTITLES -> MediaUtils.getSubs(requireActivity(), mw)
CTX_FAV_REMOVE -> launch(Dispatchers.IO) { browserFavRepository.deleteBrowserFav(mw.uri) }
CTX_ADD_SCANNED -> addToScannedFolders(mw)
}
}
......
......@@ -40,6 +40,7 @@ import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.ExternalMonitor
import org.videolan.vlc.R
import org.videolan.vlc.gui.helpers.MedialibraryUtils
import org.videolan.vlc.gui.helpers.hf.OtgAccess
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.browser.BrowserModel
......@@ -142,7 +143,7 @@ open class FileBrowserFragment : BaseBrowserFragment() {
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
if (!(this is FilePickerFragment || this is StorageBrowserFragment))
inflater!!.inflate(R.menu.fragment_option_network, menu)
inflater.inflate(R.menu.fragment_option_network, menu)
super.onCreateOptionsMenu(menu, inflater)
}
......@@ -150,6 +151,9 @@ open class FileBrowserFragment : BaseBrowserFragment() {
super.onPrepareOptionsMenu(menu)
val item = menu.findItem(R.id.ml_menu_save) ?: return
item.isVisible = !isRootDirectory && mrl!!.startsWith("file")
mrl?.let {
menu.findItem(R.id.ml_menu_scan)?.isVisible = !isRootDirectory && mrl!!.startsWith("file") && !MedialibraryUtils.isScanned(it)
}
runIO(Runnable {
val isFavorite = mrl != null && browserFavRepository.browserFavExists(Uri.parse(mrl))
launch {
......
......@@ -102,6 +102,7 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
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_ctx_fav_add_normal))
if (flags and CTX_ADD_SCANNED != 0) add(Simple(CTX_ADD_SCANNED, getString(R.string.add_to_scanned), R.drawable.ic_ctx_scan))
if (flags and CTX_FAV_EDIT != 0) add(Simple(CTX_FAV_EDIT, getString(R.string.favorites_edit), R.drawable.ic_ctx_fav_edit_normal))
if (flags and CTX_FAV_REMOVE != 0) add(Simple(CTX_FAV_REMOVE, getString(R.string.favorites_remove), R.drawable.ic_ctx_fav_remove_normal))
if (flags and CTX_REMOVE_FROM_PLAYLIST != 0) add(Simple(CTX_REMOVE_FROM_PLAYLIST, getString(R.string.remove), R.drawable.ic_ctx_remove_from_playlist_normal))
......
......@@ -3,6 +3,7 @@ package org.videolan.vlc.gui.helpers
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.core.content.ContextCompat
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.vlc.MediaParsingService
......@@ -30,4 +31,16 @@ object MedialibraryUtils {
intent.putExtra(EXTRA_PATH, path)
ContextCompat.startForegroundService(context, intent)
}
fun isScanned(path: String): Boolean {
//scheme is supported => test if the parent is scanned
var isScanned = false
AbstractMedialibrary.getInstance().foldersList.forEach search@{
if (path.startsWith(Uri.parse(it).toString())) {
isScanned = true
return@search
}
}
return isScanned
}
}
......@@ -134,7 +134,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
val miscHeader = HeaderItem(HEADER_MISC, getString(R.string.other))
otherAdapter.add(GenericCardItem(ID_SETTINGS, getString(R.string.preferences), "", R.drawable.ic_menu_preferences_big, R.color.tv_card_content_dark))
otherAdapter.add(GenericCardItem(ID_REFRESH, getString(R.string.refresh), "", R.drawable.ic_menu_scan, R.color.tv_card_content_dark))
otherAdapter.add(GenericCardItem(ID_REFRESH, getString(R.string.refresh), "", R.drawable.ic_menu_tv_scan, R.color.tv_card_content_dark))
otherAdapter.add(GenericCardItem(ID_ABOUT_TV, getString(R.string.about), "${getString(R.string.app_name_full)} ${BuildConfig.VERSION_NAME}", R.drawable.ic_menu_info_big, R.color.tv_card_content_dark))
otherAdapter.add(GenericCardItem(ID_LICENCE, getString(R.string.licence), "", R.drawable.ic_menu_open_source, R.color.tv_card_content_dark))
miscRow = ListRow(miscHeader, otherAdapter)
......
......@@ -164,6 +164,7 @@ const val CTX_SUBS_TRACK = 1 shl 21
const val CTX_PICK_SUBS = 1 shl 22
const val CTX_VIDEO_TRACK = 1 shl 23
const val CTX_DOWNLOAD_SUBTITLES_PLAYER = 1 shl 24
const val CTX_ADD_SCANNED = 1 shl 25
const val CTX_COPY = 1 shl 25
const val CTX_VIDEO_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_DOWNLOAD_SUBTITLES or CTX_INFORMATION or CTX_PLAY_ALL or CTX_PLAY_AS_AUDIO or CTX_ADD_TO_PLAYLIST
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment