Home | History | Annotate | Download | only in test
      1 /*
      2  * Copyright 2018 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 androidx.loader.app.test;
     18 
     19 import android.content.Context;
     20 import android.os.Bundle;
     21 
     22 import androidx.annotation.NonNull;
     23 import androidx.loader.app.LoaderManager;
     24 import androidx.loader.content.Loader;
     25 
     26 import java.util.concurrent.CountDownLatch;
     27 
     28 public class DelayLoaderCallbacks implements LoaderManager.LoaderCallbacks<Boolean> {
     29     private final Context mContext;
     30     private final CountDownLatch mDeliverResultLatch;
     31 
     32     public Loader<Boolean> mLoader;
     33     public boolean mOnLoadFinished;
     34     public boolean mOnLoaderReset;
     35 
     36     public DelayLoaderCallbacks(Context context, CountDownLatch deliverResultLatch) {
     37         mContext = context;
     38         mDeliverResultLatch = deliverResultLatch;
     39     }
     40 
     41     @NonNull
     42     @Override
     43     public Loader<Boolean> onCreateLoader(int id, Bundle args) {
     44         mLoader = new DelayLoader(mContext, mDeliverResultLatch);
     45         return mLoader;
     46     }
     47 
     48     @Override
     49     public void onLoadFinished(@NonNull Loader<Boolean> loader, Boolean data) {
     50         mOnLoadFinished = true;
     51     }
     52 
     53     @Override
     54     public void onLoaderReset(@NonNull Loader<Boolean> loader) {
     55         mOnLoaderReset = true;
     56     }
     57 }
     58