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

Correctly navigate to parent even if it's not in backstack

parent e9f587d5
No related branches found
No related tags found
1 merge request!242Breadcrumb backstack
Pipeline #9943 failed with stage
in 3 minutes and 10 seconds
......@@ -42,6 +42,7 @@ import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.tools.MultiSelectHelper
import org.videolan.tools.isStarted
import org.videolan.vlc.BuildConfig
......@@ -59,7 +60,9 @@ import org.videolan.vlc.gui.helpers.hf.OTG_SCHEME
import org.videolan.vlc.gui.view.VLCDividerItemDecoration
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.interfaces.IRefreshable
import org.videolan.vlc.media.MediaSessionBrowser.browse
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.media.MediaUtils.playAll
import org.videolan.vlc.media.PlaylistManager
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.*
......@@ -168,7 +171,20 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
}
override fun backTo(tag: String) {
requireActivity().supportFragmentManager.popBackStack(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE)
val supportFragmentManager = requireActivity().supportFragmentManager
var poped = false
for (i in 0 until supportFragmentManager.backStackEntryCount) {
if (tag == supportFragmentManager.getBackStackEntryAt(i).name) {
supportFragmentManager.popBackStack(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE)
poped = true
break
}
}
if (!poped) {
viewModel.setDestination(MediaWrapper(Uri.parse(tag)))
supportFragmentManager.popBackStackImmediate()
}
}
override fun currentContext() = requireContext()
......@@ -189,6 +205,9 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
override fun onResume() {
super.onResume()
if (goBack) goBack()
viewModel.getAndRemoveDestination()?.let {
browse(it, true)
}
}
override fun onStop() {
......
......@@ -77,7 +77,7 @@ class PathAdapter(val browser: PathAdapterListener, media: AbstractMediaWrapper)
val pathParts = string.split('/').filter { it.isNotEmpty() }
for (index in pathParts.indices) {
//start creating the Uri
val currentPathUri = Uri.Builder().scheme(uri.scheme).authority(uri.authority)
val currentPathUri = Uri.Builder().scheme(uri.scheme).encodedAuthority(uri.authority)
//append all the previous paths and the current one
for (i in 0..index) pathOperationDelegate.appendPathToUri(pathParts[i], currentPathUri)
list.add(currentPathUri.toString())
......
......@@ -2,6 +2,7 @@ package org.videolan.vlc.gui.tv.browser
import android.content.Context
import android.graphics.Rect
import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
......@@ -170,7 +171,22 @@ class FileBrowserTvFragment : BaseBrowserTvFragment(), PathAdapterListener {
requireActivity().finish()
return
}
requireActivity().supportFragmentManager.popBackStack(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE)
val supportFragmentManager = requireActivity().supportFragmentManager
var poped = false
for (i in 0 until supportFragmentManager.backStackEntryCount) {
if (tag == supportFragmentManager.getBackStackEntryAt(i).name) {
supportFragmentManager.popBackStack(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE)
poped = true
break
}
}
if (!poped) {
if (supportFragmentManager.backStackEntryCount == 0) browse(MediaWrapper(Uri.parse(tag)), false)
else {
(viewModel as IPathOperationDelegate).setDestination(MediaWrapper(Uri.parse(tag)))
supportFragmentManager.popBackStack()
}
}
}
override fun currentContext(): Context = requireActivity()
......@@ -215,6 +231,9 @@ class FileBrowserTvFragment : BaseBrowserTvFragment(), PathAdapterListener {
super.onResume()
if (item == null) (viewModel.provider as BrowserProvider).browseRoot()
else refresh()
(viewModel as IPathOperationDelegate).getAndRemoveDestination()?.let {
browse(it, true)
}
}
override fun onSaveInstanceState(outState: Bundle) {
......
......@@ -3,34 +3,35 @@ package org.videolan.vlc.viewmodels.browser
import android.net.Uri
import android.util.Base64
import androidx.collection.SimpleArrayMap
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
interface IPathOperationDelegate {
// fun getBackstack(from: String, to: String): SimpleArrayMap<String, Uri>
fun appendPathToUri(path: String, uri: Uri.Builder)
fun replaceStoragePath(path: String): String
fun makePathSafe(path: String): String
fun retrieveSafePath(encoded: String): String
fun setDestination(media: AbstractMediaWrapper?)
fun getAndRemoveDestination(): AbstractMediaWrapper?
}
class PathOperationDelegate : IPathOperationDelegate {
override fun setDestination(media: AbstractMediaWrapper?) {
privateDestination = media
}
override fun getAndRemoveDestination(): AbstractMediaWrapper? {
val destination = privateDestination
privateDestination = null
return destination
}
companion object {
val storages = SimpleArrayMap<String, String>()
private var privateDestination: AbstractMediaWrapper? = null
}
// override fun getBackstack(from: String, to: String): SimpleArrayMap<String, Uri> {
// val result = SimpleArrayMap<String, Uri>()
// val fromUri = if (from == "root") null else Uri.parse(from)
// val toUri = Uri.parse(to)
// if (BuildConfig.DEBUG) Log.d(this::class.java.simpleName, "PathAdapter From: $fromUri")
// if (BuildConfig.DEBUG) Log.d(this::class.java.simpleName, "PathAdapter To: $toUri")
//
//
//
// return result
// }
/**
* Append a path to the Uri from a String
......
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