Ruan625Br / FilePickerSphere

Material Design file selection library for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FilePickerSphere

FilePickerSphere, a customizable and modern file selection library


What is FilePickerSphere?

Screenshot 1 Screenshot 2 Screenshot 3
View More Screenshots
Screenshot 4 Screenshot 5 Screenshot 6

FilePickerSphere is a powerful file selection library crafted to streamline and enhance your interaction with documents, media, and various file formats. Built on the foundation of FileManagerSphere, it focuses on simplifying the process of selecting files, optimizing your experience in managing and choosing documents and media files effortlessly.


Features

  • Open-source: Lightweight, clean, and secure.
  • Material Design: Follows Material Design guidelines, with attention to detail.
  • Themes: Customizable user interface colors, along with optional true black dark mode.
  • Well-implemented: Built on the right foundations, including Java NIO File API and LiveData.

Integration

implementation("com.github.Ruan625Br:FilePickerSphere:1.0.0")

Usage

To use FilePickerSphereManager, create an instance of the class by providing the necessary parameters. You can then customize its behavior using various builder methods before calling the picker() method to initiate the file picking process.

Constructor

class FilePickerSphereManager(
    private val context: Context,
    private val bottomSheetViewMode: Boolean = true,
    private val filePickerCallbacks: FilePickerCallbacks? = null,
    private val filePickerModel: FilePickerModel? = null,
    @IdRes private val containerViewId: Int? = null
)

Parameters

Parameter Description Default Value
context The context in which the file picker will be used. -
bottomSheetViewMode A boolean flag indicating whether the file picker should be displayed as a bottom sheet. true
filePickerCallbacks Optional callbacks for handling file picker events. null
filePickerModel Optional configuration model for file picking behavior. null
containerViewId Optional container view ID for non-dialog mode. null

Builder Methods

callbacks(callbacks: FilePickerCallbacks): FilePickerSphereManager

Sets the file picker callbacks.

model(model: FilePickerModel): FilePickerSphereManager

Sets the file picker configuration model.

container(@IdRes containerViewId: Int): FilePickerSphereManager

Sets the container view ID for non-dialog mode.

File Picking

To initiate the file picking process, call the picker() method

This method checks for necessary configurations and displays the file picker accordingly.

Notes

  • Ensure that the required configurations (callbacks and model) are set before calling the picker() method.
  • For non-dialog mode, provide a valid containerViewId using the container() method and set the bottomSheetViewModel to false

Example

    // Define file picking options
    val options = PickOptions(
        mimeType = listOf(MimeType.IMAGE_PNG, MimeType.IMAGE_JPEG, MimeType.DIRECTORY, MimeType("value here")),
        localOnly = false,
        rootPath = "/storage/emulated/0/",
        maxSelection = 8
    )

     // Create and configure FilePickerSphereManager
    FilePickerSphereManager(this, true).callbacks(object : FilePickerCallbacks {
        override fun onFileSelectionChanged(file: FileModel, selected: Boolean) {
            Log.i("FilePickerSphere", "File clicked: ${file.name}\n Selected: $selected")
        }

        override fun onOpenFile(file: FileModel) {
            Log.i("FilePickerSphere", "Open file: ${file.name}")
        }

        override fun onSelectedFilesChanged(files: List<FileModel>) {
            // Handle selected files change
        }

        override fun onAllFilesSelected(files: List<FileModel>) {
            // Handle all files selected
        }
    }).container(R.id.fragment_container)
        .model(FilePickerModel(options))
        .picker()

Authors


Love my work?

Buy Me a Coffee at ko-fi.com


License

Copyright (C) 2023 Juan Nscimento

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 3 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, see <https://www.gnu.org/licenses/>.