From c870e9c2e3102e93a240ef3ddfde853a56583697 Mon Sep 17 00:00:00 2001 From: Vishal Nehra Date: Mon, 24 Jul 2023 02:00:25 +0530 Subject: [PATCH] Update readme --- README.md | 68 ++++++++++++++----- .../main/java/com/amaze/trashbin/TrashBin.kt | 6 +- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index fcf8dc7..c59e4ca 100644 --- a/README.md +++ b/README.md @@ -3,40 +3,72 @@ Amaze Trash Bin library Library responsible to manage files deleted, from filesystem, keep it in for some time and delete once the provided configurations are met -*Notes* -trash bin config. -Deleted files will be at baseDir/TrashBinFiles/ +Usage +--- +` +implementation 'com.github.TeamAmaze:AmazeTrashBin:x.y.z' +` + +Overview +--- +Helper methods to +- move files to bin +- restore files from bin +- empty bin +- delete permanently +- list files in bin +- trigger cleanup +- trigger deletion of rogue files (not present in metadata) + +Library maintains metadata as you call either methods in an external directory. +Make sure the directory is not in app's cache as it might get removed as user re-installs the app. + +Documentation +--- +**trash bin config.** +Deleted files will be at baseDir/TrashBinFiles/ Suggested to keep baseDir as a directory starting with a dot (.) so that it's hidden -- baseStorageDir / TrashBinFiles / (deleted files) // warning: avoid using app cache directory as base storage dir because if user uninstall your app they'll lose all their files +- baseStorageDir // warning: avoid using app cache directory as base storage dir because if user uninstall your app they'll lose all their files - retentionDays - days to keep the files in the deleted directory - retentionBytes - bytes to keep till we start deleting the oldest files +- retentionNumOfFiles - num of files to keep till we start deleting the oldest files - deleteRogueFiles - whether to delete files which aren't recorded in the metadata -trash bin metadata -- located at baseDir / TrashBinFiles / metadata.json -struct: +**trash bin metadata** +- located at baseDir / metadata.json - trashbin config - total size of files in trash - list of files -trashBinFile -defines a file structure in the bin. All the contracts require you to enclose file in a trashBinFile object. +**trashBinFile** +defines a file structure in the bin. All the contracts require you to enclose file in a trashBinFile object. You'll be returned a list of path files that you should utilize to show list to user and to allow various operations to be performed. - fileName - name of file (can be utilized to show to user in list of files in the bin) - isDirectory - whether the file is a directory - path - original path of file where it can be restored - sizeBytes - size of file -- deletedPath - deleted path of file - deleteTime - time at which file was deleted -contract -- deletePermanently - deletes the files permanently -- moveToBin - deletes file temporarily -- triggerCleanup - triggers a cleanup manually based on the criteria defined in config -- emptyBin - deletes all files permanently -- restore - restore set of files back to their original location Note: allowing to rename files in recycle bin is discouraged. It'll break the file and will be considered as rogue file (volunteer to be deleted in next cleanup cycle) -- + Library initializes by creating an object of TrashBin providing it a trashBinConfig object -As soon as it's initalized it creates the necessary directories / config files \ No newline at end of file +As soon as it's initalized it creates the necessary directories / config files + + +### License: + + Copyright 2023 Arpit Khurana , Vishal Nehra , + Emmanuel Messulam, Raymond Lai and Contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/trashbin/src/main/java/com/amaze/trashbin/TrashBin.kt b/trashbin/src/main/java/com/amaze/trashbin/TrashBin.kt index 782c094..13c11a7 100644 --- a/trashbin/src/main/java/com/amaze/trashbin/TrashBin.kt +++ b/trashbin/src/main/java/com/amaze/trashbin/TrashBin.kt @@ -35,7 +35,7 @@ typealias ListTrashBinFilesCallback = suspend (parentTrashBinPath: String) -> Li * @param deletePermanentlyCallback - callback to invoke for cleanup automatically when any bin action is performed. * Pass null if you want to invoke cleanup manually through triggerCleanup. This will be executed in the same thread where your bin functions are executed. */ -class TrashBin private constructor( +class TrashBin constructor( var trashConfig: TrashBinConfig, var deletePermanentlyCallback: DeletePermanentlyCallback?, var listTrashBinFilesCallback: @@ -44,10 +44,6 @@ class TrashBin private constructor( private var metadata: TrashBinMetadata? = null - companion object : - SingletonSingleArgHolder(::TrashBin) - init { trashConfig.getTrashBinFilesDirectory() metadata = getTrashBinMetadata()