Skip to content

Android: Allow listContentURI to list content of a subfolder#6246

Open
MaxGyver83 wants to merge 1 commit intofyne-io:developfrom
MaxGyver83:android-list-subfolder-content
Open

Android: Allow listContentURI to list content of a subfolder#6246
MaxGyver83 wants to merge 1 commit intofyne-io:developfrom
MaxGyver83:android-list-subfolder-content

Conversation

@MaxGyver83
Copy link
Copy Markdown
Contributor

Description:

Assume this file structure, p.e. in /sdcard/Download/:

folder
├── a
└── subfolder
    └── b

When you list the content of folder, you get a and subfolder (as expected). But when you then try to list the content of folder/subfolder, you get a and subfolder again instead of b.

This pull request fixes this.

Test program:

package main

import (
	"fmt"
	"net/url"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/dialog"
	"fyne.io/fyne/v2/storage"
	"fyne.io/fyne/v2/widget"
)

var w fyne.Window

func main() {
	a := app.New()
	w = a.NewWindow("List content of subdirectory")
	btn := widget.NewButton("Open folder", selectFolder)
	w.SetContent(container.NewVBox(btn))
	w.ShowAndRun()
}

func selectFolder() {
	dialog.ShowFolderOpen(func(u fyne.ListableURI, err error) {
		if err != nil || u == nil {
			return
		}
		openFolder(u)
	}, w)
}

func openFolder(u fyne.URI) {
	fmt.Println("Open folder", u.String())
	filelist, err := storage.List(u)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, file := range filelist {
		name, _ := url.PathUnescape(file.Name())
		fmt.Println("-", name)
		if isdir, err := storage.CanList(file); err == nil && isdir {
			filelist, err := storage.List(file)
			if err == nil {
				for _, file := range filelist {
					name, _ = url.PathUnescape(file.Name())
					fmt.Println("  -", name)
				}
			}
		}
	}
}

Output on develop:

04-03 15:09:22.286 23985 25311 I Fyne    : - primary:Download/folder/a
04-03 15:09:22.299 23985 25311 I Fyne    : - primary:Download/folder/subfolder
04-03 15:09:22.327 23985 25311 I Fyne    :   - primary:Download/folder/a
04-03 15:09:22.327 23985 25311 I Fyne    :   - primary:Download/folder/subfolder

With this PR:

04-03 15:11:02.795 24825 25891 I Fyne    : - primary:Download/folder/a
04-03 15:11:02.803 24825 25891 I Fyne    : - primary:Download/folder/subfolder
04-03 15:11:02.826 24825 25891 I Fyne    :   - primary:Download/folder/subfolder/b

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant