Skip to main content

Photo Cleaner

Photo Cleaner works in collaboration with Photo SDK to find and clear local media files that are duplicated in the cloud storage.

important

Before you start working with this module, connect and initialize the photo library in the main module of your project as described in this manual, and also make sure that there is internet connection is available during the operation.

Analysis#

The following code example demonstrates how to use the analysis operation:

// Get the photo cleaner through the cleaner managerval photoCleaner = CleanerManagerFactory.cleanerManager.getCleaner(CleanerType.PHOTO)
// Get coroutine scope to call cleaner library functionsval cleanerScope = CleanerManagerFactory.cleanerManager.scope
// Run all operations related to libraries only in the cleaner librarycleanerScope.launch {        // Start the analysis process with the following call    photoCleaner.analyze(        isFullRefresh = true    )}

The cleaner is represented by an object that implements the interface Cleaner, the method analyze which takes isFullRefresh: Boolean:

  • true - when analyzing, the cleaner scans the system again;
  • false - the method returns the cached result of the parsing (only non-deleted items).

Cleaning#

Use the following code example to clear items.

// Get the photo cleaner through the cleaner managerval photoCleaner = CleanerManagerFactory.cleanerManager.getCleaner(CleanerType.PHOTO)
// Get coroutine scope to call cleaner library functionsval cleanerScope = CleanerManagerFactory.cleanerManager.scope
// Get a list of items to removeval trashItemList: List<TrashItem>
// Run all operations related to libraries only in the cleaner librarycleanerScope.launch {    // Start the analysis process with the following call    photoCleaner.clean(        content = trashItemList    )}

A cleaner is represented by an object that implements the Cleaner interface, whose clean method accepts content: List<TrashItem> (list of items to remove)

Getting results#

In order to get the state of the cleaner and the results of its work, you need to subscribe to its state as follows:

// Get the photo cleaner through the cleaner managerval photoCleaner = CleanerManagerFactory.cleanerManager.getCleaner(CleanerType.PHOTO)
// Get coroutine scope to call cleaner library functionsval cleanerScope = CleanerManagerFactory.cleanerManager.scope
// Run all operations related to libraries only in the cleaner librarycleanerScope.launch {    // Subscribe to the states of the photo cleaner    photoCleaner.stateFlow.collect { cleanerState -> // cleanerState: CleanerState        // Do something...    }}

Photo cleaner inherits Cleaner interface that provides stateFlow: StateFlow (StateFlow) which emits CleanerState objects containing information about the condition of the cleaner. Here are the following possible states of the cleaner:

Inactive - this is the initial state of the cleaner before starting work.

Analyzing - this state indicates that the cleaner is in the process of analyzing data. It includes the following fields:

  • itemCount: Int - number of items found
  • size: Long - size of found elements in bits

Analysed - this state indicates that the cleaner has finished analyzing the data. It includes the following fields:

  • items: List<PhotoItem> - list of found items
  • error: Trowable? - an error occurred during the analysis process

Cleaning -this state indicates that the cleaner is in the process of deleting data. It includes the following fields:

  • itemCount: Int - number of items found
  • size: Long - size of found elements in bits

Cleaned - this state indicates that the cleaner has completed the data cleaning process. It includes the following fields:

  • items: List<PhotoItem> - list of deleted items
  • error: Trowable? - an error occurred during the cleaning process

Links - CleanerState, PhotoItem, Cleaner.