1 /* 2 * Copyright (C) 2023 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.providers.media.photopicker.data; 18 19 import static com.android.providers.media.photopicker.data.CloudProviderQueryExtras.isMergedAlbum; 20 21 import android.os.Bundle; 22 import android.provider.MediaStore; 23 import android.text.TextUtils; 24 25 import androidx.annotation.NonNull; 26 import androidx.annotation.Nullable; 27 28 import java.util.Objects; 29 30 /** 31 * Encapsulate all picker sync request arguments related logic. 32 */ 33 public class PickerSyncRequestExtras { 34 @Nullable 35 private final String mAlbumId; 36 @Nullable 37 private final String mAlbumAuthority; 38 private final boolean mInitLocalOnlyData; PickerSyncRequestExtras(@ullable String albumId, @Nullable String albumAuthority, boolean initLocalOnlyData)39 public PickerSyncRequestExtras(@Nullable String albumId, 40 @Nullable String albumAuthority, 41 boolean initLocalOnlyData) { 42 mAlbumId = albumId; 43 mAlbumAuthority = albumAuthority; 44 mInitLocalOnlyData = initLocalOnlyData; 45 } 46 47 /** 48 * Create a {@link PickerSyncRequestExtras} object from an input bundle. 49 */ fromBundle(@onNull Bundle extras)50 public static PickerSyncRequestExtras fromBundle(@NonNull Bundle extras) { 51 Objects.requireNonNull(extras); 52 53 final String albumId = extras.getString(MediaStore.EXTRA_ALBUM_ID); 54 final String albumAuthority = extras.getString(MediaStore.EXTRA_ALBUM_AUTHORITY); 55 final boolean initLocalOnlyData = 56 extras.getBoolean(MediaStore.EXTRA_LOCAL_ONLY); 57 return new PickerSyncRequestExtras(albumId, albumAuthority, initLocalOnlyData); 58 } 59 60 /** 61 * Returns true when media data should be synced. 62 */ shouldSyncMediaData()63 public boolean shouldSyncMediaData() { 64 return TextUtils.isEmpty(mAlbumId); 65 } 66 67 /** 68 * Returns true when only local data needs to be synced. 69 */ shouldSyncLocalOnlyData()70 public boolean shouldSyncLocalOnlyData() { 71 return mInitLocalOnlyData; 72 } 73 74 /** 75 * Returns true when the sync request is for a merged album. 76 */ shouldSyncMergedAlbum()77 public boolean shouldSyncMergedAlbum() { 78 return isMergedAlbum(mAlbumId); 79 } 80 81 /** 82 * Return album id for the sync request. 83 */ 84 @Nullable getAlbumId()85 public String getAlbumId() { 86 return mAlbumId; 87 } 88 89 /** 90 * Return album authority for the sync request. 91 */ 92 @Nullable getAlbumAuthority()93 public String getAlbumAuthority() { 94 return mAlbumAuthority; 95 } 96 } 97