GithubHelp home page GithubHelp logo

00mjk / filepreloaderlibrary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from teamamaze/filepreloaderlibrary

0.0 0.0 0.0 3.04 MB

Loading takes time, catching takes space, preloading takes neither

License: GNU General Public License v3.0

Kotlin 100.00%

filepreloaderlibrary's Introduction

File Preloader Library

Loading takes time,
Caching takes space,
Preloading takes neither!

The aim of this library is to preload entire folders the user might access, so that they load instantly should the user open them.

Installation

Requirements

dependencies {
    ...
    implementation 'com.github.TeamAmaze:FilePreloaderLibrary:master-SNAPSHOT' //Folder preloading
}

Usage

Kotlin:

fun preload(externalDir: File) =
        FilePreloader.with(::FileMetadata).preloadFrom(externalDir.absolutePath)

fun load() = FilePreloader.with(::FileMetadata).load(externalDir.absolutePath) {
            //Do something with the data
            show(it) //it: List<FileMetadata>
        }

class FileMetadata(path: String): DataContainer(path) {
    private val name: String
    private val filePath: String
    private val extension: String
    private val isDirectory: Boolean

    init {
        val file = File(path)
        name = file.name
        filePath = file.absolutePath
        extension = file.extension
        isDirectory = file.isDirectory
    }

    override fun toString(): String {
        return "'$name': {'$filePath', $isDirectory, *.$extension}"
    }
}

Java:

private static final FilePreloader FILE_PRELOADER = FilePreloader.INSTANCE;

public void preload(File externalDir) {
    FILE_PRELOADER.with(FileMetadata.class).preloadFrom(externalDir.getAbsolutePath());
}

public void load(File externalDir) {
    FILE_PRELOADER.with(FileMetadata.class).load(externalDir.getAbsolutePath(), (fileMetadatas) -> {
        show(fileMetadatas); //Do something with the data
    });
}

private static class FileMetadata extends DataContainer {
    private final String name;
    private final String filePath;
    private final String extension;
    private final boolean isDirectory;


    public FileMetadata(@NonNull String path){
        super(path);
        File file = new File(path);
        name = file.getName();
        filePath = file.getAbsolutePath();
        extension = name.substring(name.lastIndexOf('.'));
        isDirectory = file.isDirectory();
    }

    @Override
    public String toString() {
        return "'" + name + "': {'" + filePath + "', " + isDirectory + ", *." + extension + "}";
    }
}

Development

Just import to Android Studio as normal!

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Authors

  • Emmanuel Messulam
  • README made with makeareadme by Danny Guo | 郭亚东.

License:

Copyright (C) 2018 Emmanuel Messulam <[email protected]>
This file is part of Amaze File Manager.
Amaze File Manager 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 <http://www.gnu.org/licenses/>.

filepreloaderlibrary's People

Contributors

emmanuelmess avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.