Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalNehra committed Jul 23, 2023
1 parent d6cf43b commit c870e9c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 23 deletions.
68 changes: 50 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
As soon as it's initalized it creates the necessary directories / config files


### License:

Copyright 2023 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> 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.
6 changes: 1 addition & 5 deletions trashbin/src/main/java/com/amaze/trashbin/TrashBin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -44,10 +44,6 @@ class TrashBin private constructor(

private var metadata: TrashBinMetadata? = null

companion object :
SingletonSingleArgHolder<TrashBin, TrashBinConfig, DeletePermanentlyCallback,
ListTrashBinFilesCallback>(::TrashBin)

init {
trashConfig.getTrashBinFilesDirectory()
metadata = getTrashBinMetadata()
Expand Down

0 comments on commit c870e9c

Please sign in to comment.