1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.storagemanager.deletionhelper; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import androidx.annotation.IntDef; 22 23 /** 24 * Helper for the Deletion Helper which can query, clear out, and visualize deletable data. 25 * This could represent a helper for deleting photos, downloads, movies, etc. 26 */ 27 public interface DeletionType { 28 29 @IntDef({LoadingStatus.LOADING, LoadingStatus.COMPLETE, LoadingStatus.EMPTY}) 30 @interface LoadingStatus { 31 /** Loading is still in progress. */ 32 int LOADING = 0; 33 /** Loading was completed and deletable content was found. */ 34 int COMPLETE = 1; 35 /** Loading was completed and no deletable content was found. */ 36 int EMPTY = 2; 37 } 38 39 /** 40 * Registers a callback to call when the amount of freeable space is updated. 41 * @param listener A callback. 42 */ registerFreeableChangedListener(FreeableChangedListener listener)43 void registerFreeableChangedListener(FreeableChangedListener listener); 44 45 /** 46 * Resumes an operation, intended to be called when the deletion fragment resumes. 47 */ onResume()48 void onResume(); 49 50 /** 51 * Pauses the feature's operations, intended to be called when the deletion fragment is paused. 52 */ onPause()53 void onPause(); 54 onSaveInstanceStateBundle(Bundle savedInstanceState)55 void onSaveInstanceStateBundle(Bundle savedInstanceState); 56 57 /** 58 * Asynchronously free up the freeable information for the feature. 59 */ clearFreeableData(Activity activity)60 void clearFreeableData(Activity activity); 61 62 /** @return The number of items found that are available for deletion. */ getContentCount()63 int getContentCount(); 64 65 /** @return The loading status of this deletion type. Can be any of {@link LoadingStatus}. */ 66 @LoadingStatus getLoadingStatus()67 int getLoadingStatus(); 68 69 /** 70 * Convenience method for checking if the loading status is {@link LoadingStatus#COMPLETE}. 71 * 72 * @return Whether the loading status is currently {@link LoadingStatus#COMPLETE} as a boolean. 73 */ isComplete()74 default boolean isComplete() { 75 return getLoadingStatus() == LoadingStatus.COMPLETE; 76 } 77 78 /** 79 * Convenience method for checking if the loading status is {@link LoadingStatus#EMPTY}. 80 * 81 * @return Whether the loading status is currently {@link LoadingStatus#EMPTY} as a boolean. 82 */ isEmpty()83 default boolean isEmpty() { 84 return getLoadingStatus() == LoadingStatus.EMPTY; 85 } 86 87 /** 88 * @param loadingStatus The state to set the deletion type to. Can be any of {@link 89 * LoadingStatus}. 90 */ setLoadingStatus(@oadingStatus int loadingStatus)91 void setLoadingStatus(@LoadingStatus int loadingStatus); 92 93 /** 94 * Callback interface to listen for when a deletion feature's amount of freeable space updates. 95 */ 96 interface FreeableChangedListener { onFreeableChanged(int numItems, long bytesFreeable)97 void onFreeableChanged(int numItems, long bytesFreeable); 98 } 99 100 /** 101 * Updates the loading status of the deletion type based on whether content is available to 102 * delete or not. 103 */ updateLoadingStatus()104 default void updateLoadingStatus() { 105 if (getContentCount() == 0) { 106 setLoadingStatus(LoadingStatus.EMPTY); 107 } else { 108 setLoadingStatus(LoadingStatus.COMPLETE); 109 } 110 } 111 } 112