1 /* 2 * Copyright (C) 2024 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.v2.model; 18 19 import android.os.Bundle; 20 21 import androidx.annotation.NonNull; 22 23 import com.android.providers.media.util.MimeUtils; 24 25 import java.util.ArrayList; 26 27 /** 28 * This is a convenience class for Videos album related SQL queries performed on the Picker 29 * Database. 30 */ 31 public class VideoMediaQuery extends MediaQuery { VideoMediaQuery(@onNull Bundle queryArgs, int pageSize)32 public VideoMediaQuery(@NonNull Bundle queryArgs, int pageSize) { 33 this(queryArgs); 34 35 mPageSize = pageSize; 36 } 37 VideoMediaQuery(@onNull Bundle queryArgs)38 public VideoMediaQuery(@NonNull Bundle queryArgs) { 39 super(queryArgs); 40 41 if (mMimeTypes == null) { 42 // If there are no MIME type filters applied, add all videos MIME type filter. 43 mMimeTypes = new ArrayList<String>(); 44 mMimeTypes.add("video/*"); 45 } else { 46 // If there are MIME type filters applied, only keep videos MIME type filters. 47 mMimeTypes.removeIf(mimeType -> !MimeUtils.isVideoMimeType(mimeType)); 48 } 49 } 50 51 /** 52 * @return true if any videos can be displayed after applying the input MIME type filters, 53 * otherwise return false. 54 */ shouldDisplayVideosAlbum()55 public boolean shouldDisplayVideosAlbum() { 56 // Only display Videos album when at least one valid Videos filter is applied. 57 if (mMimeTypes != null && mMimeTypes.isEmpty()) { 58 return false; 59 } 60 return true; 61 } 62 } 63