1135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount/*
2135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * Copyright (C) 2013 The Android Open Source Project
3135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount *
4135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * Licensed under the Apache License, Version 2.0 (the "License");
5135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * you may not use this file except in compliance with the License.
6135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * You may obtain a copy of the License at
7135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount *
8135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount *      http://www.apache.org/licenses/LICENSE-2.0
9135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount *
10135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * Unless required by applicable law or agreed to in writing, software
11135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * distributed under the License is distributed on an "AS IS" BASIS,
12135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * See the License for the specific language governing permissions and
14135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * limitations under the License.
15135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount */
16135c2e576f3dfea954ba628942c55adcb35a7cf6George Mountpackage com.android.photos.data;
17135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
18135c2e576f3dfea954ba628942c55adcb35a7cf6George Mountimport android.net.Uri;
19135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
20135c2e576f3dfea954ba628942c55adcb35a7cf6George Mountimport com.android.photos.data.PhotoProvider.ChangeNotification;
21135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
225139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mountimport java.util.ArrayList;
23135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
24135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount/**
25135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * Used for capturing notifications from PhotoProvider without relying on
26135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * ContentResolver. MockContentResolver does not allow sending notification to
27135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount * ContentObservers, so PhotoProvider allows this alternative for testing.
28135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount */
29135c2e576f3dfea954ba628942c55adcb35a7cf6George Mountpublic class NotificationWatcher implements ChangeNotification {
305139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount    private ArrayList<Uri> mUris = new ArrayList<Uri>();
315139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount    private boolean mSyncToNetwork = false;
32135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
33135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    @Override
345139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount    public void notifyChange(Uri uri, boolean syncToNetwork) {
35135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount        mUris.add(uri);
365139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount        mSyncToNetwork = mSyncToNetwork || syncToNetwork;
37135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    }
38135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
39135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    public boolean isNotified(Uri uri) {
40135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount        return mUris.contains(uri);
41135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    }
42135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
43135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    public int notificationCount() {
44135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount        return mUris.size();
45135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    }
46135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount
475139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount    public boolean syncToNetwork() {
485139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount        return mSyncToNetwork;
495139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount    }
505139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount
51135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    public void reset() {
52135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount        mUris.clear();
535139ee00d28c3f694df74f0ccf13cec402707aeaGeorge Mount        mSyncToNetwork = false;
54135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount    }
55135c2e576f3dfea954ba628942c55adcb35a7cf6George Mount}
56