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.PickerDbFacade.QueryFilterBuilder.INT_DEFAULT; 20 21 /** 22 * Holder for parameters required for pagination of photos and category items grid recyclerView in 23 * photoPicker. 24 */ 25 public class PaginationParameters { 26 private int mPageSize = INT_DEFAULT; 27 private long mDateBeforeMs = Long.MIN_VALUE; 28 private int mRowId = INT_DEFAULT; 29 public static final int PAGINATION_PAGE_SIZE_ITEMS = 600; 30 31 public static final int PAGINATION_PAGE_SIZE_ALBUM_ITEMS = 600; 32 33 /** 34 * Instantiates UI pagination parameters for photoPicker. Use this when all the fields needs to 35 * be set to default, i.e. to return complete list of items. 36 */ PaginationParameters()37 public PaginationParameters() { 38 } 39 40 /** 41 * Instantiates UI pagination parameters for photoPicker. 42 * 43 * <p>The parameters will be used similar to this sample query : 44 * {@code SELECT * FROM TABLE_NAME WHERE (column_date_before_ms < dateBeforeMs 45 * OR ( column_date_before_ms = dateBeforeMs AND column_row_id < rowID)) LIMIT pageSize;} 46 * 47 * @param pageSize used to represent the upper limit of the number of rows that should be 48 * returned by the query. Set as -1 to ignore this parameter in the query. 49 * @param dateBeforeMs when set items with date less that this will be returned. Set as -1 to 50 * ignore this parameter in the query. 51 * @param rowId when set items with id less than this will be returned. Set as -1 to 52 * ignore this parameter in the query. 53 */ PaginationParameters(int pageSize, long dateBeforeMs, int rowId)54 public PaginationParameters(int pageSize, long dateBeforeMs, int rowId) { 55 mPageSize = pageSize; 56 mDateBeforeMs = dateBeforeMs; 57 mRowId = rowId; 58 } 59 60 /** 61 * Instantiates UI pagination parameters for photoPicker. 62 * 63 * <p>When using this constructor the value for pageSize will be the default value i.e. -1.</p> 64 * 65 * @param dateBeforeMs when set items with date less that this will be returned. Set as -1 to 66 * ignore this parameter in the query. 67 * @param rowId when set items with id less than this will be returned. Set as -1 to 68 * ignore this parameter in the query. 69 */ PaginationParameters(long dateBeforeMs, int rowId)70 public PaginationParameters(long dateBeforeMs, int rowId) { 71 this(PAGINATION_PAGE_SIZE_ITEMS, dateBeforeMs, rowId); 72 } 73 74 /** 75 * @return page size for pagination. It is used as the LIMIT clause in the query to database. 76 */ getPageSize()77 public int getPageSize() { 78 return mPageSize; 79 } 80 81 /** 82 * @return date in ms which can be used as the parameter in the query to load items. 83 * 84 * <p>This is combination with row id is used to find the next page of data.</p> 85 * 86 * <b>Note: This parameter is only used in the query if the row id is set. Else it is 87 * ignored.</b> 88 */ getDateBeforeMs()89 public Long getDateBeforeMs() { 90 return mDateBeforeMs; 91 } 92 93 /** 94 * @return row id which can be used as the parameter in the query to load items. 95 * 96 * <p>This is combination with date_taken_before_ms is used to find the next page of data.</p> 97 * 98 * <p>When the {@link PaginationParameters#mDateBeforeMs} for two rows is same, this 99 * parameter is used to figure out which row to return.</p> 100 */ getRowId()101 public int getRowId() { 102 return mRowId; 103 } 104 } 105