1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.android.storagemanager.deletionhelper; 18 19 import android.view.View; 20 21 /** Handles whether or not to hide/show the loading progress spinner. */ 22 public class LoadingSpinnerController { 23 private boolean mHasLoadedACategory; 24 private View mListView; 25 private DeletionHelperActivity mParentActivity; 26 27 /** 28 * Initializes the spinner with an activity that contains both a content view and a loading 29 * view. 30 */ LoadingSpinnerController(DeletionHelperActivity activity)31 public LoadingSpinnerController(DeletionHelperActivity activity) { 32 mParentActivity = activity; 33 } 34 35 /** 36 * Initializes the loading progress bar. 37 * 38 * @param listView A content view to potentially swap in for the loading screen. 39 */ initializeLoading(View listView)40 public void initializeLoading(View listView) { 41 mListView = listView; 42 if (!mHasLoadedACategory) { 43 setLoading(true); 44 } 45 } 46 47 /** If a category loads, we should hide the loading progress bar. This hides the loading. */ onCategoryLoad()48 public void onCategoryLoad() { 49 mHasLoadedACategory = true; 50 setLoading(false); 51 } 52 setLoading(boolean isLoading)53 private void setLoading(boolean isLoading) { 54 if (mListView != null && mParentActivity.isLoadingVisible() != isLoading) { 55 mParentActivity.setLoading(mListView, isLoading, true); 56 } 57 } 58 } 59