1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_MEDIALIBRARY_ALBUM_CHANGE_INFO_H 17 #define OHOS_MEDIALIBRARY_ALBUM_CHANGE_INFO_H 18 19 #include <string> 20 #include <vector> 21 #include <unordered_set> 22 23 #include "photo_album_column.h" 24 #include "photo_asset_change_info.h" 25 #include "result_set.h" 26 #include "medialibrary_type_const.h" 27 #include "values_bucket.h" 28 #include "album_accurate_refresh_manager.h" 29 30 namespace OHOS { 31 namespace Media::AccurateRefresh { 32 #define EXPORT __attribute__ ((visibility ("default"))) 33 34 class EXPORT AlbumChangeInfo : public Parcelable { 35 public: AlbumChangeInfo()36 AlbumChangeInfo() {} AlbumChangeInfo(int32_t albumId,std::string lpath,int32_t imageCount,int32_t videoCount,int32_t albumType,int32_t albumSubType,std::string albumName,std::string albumUri,int32_t count,std::string coverUri,int32_t hiddenCount,std::string hiddenCoverUri,bool isCoverChange,bool isHiddenCoverChange,int64_t dateTimeForCover,int64_t dateTimeForHiddenCover,int32_t dirty,int32_t albumOrder,int32_t orderSection)37 AlbumChangeInfo(int32_t albumId, std::string lpath, int32_t imageCount, int32_t videoCount, int32_t albumType, 38 int32_t albumSubType, std::string albumName, std::string albumUri, int32_t count, std::string coverUri, 39 int32_t hiddenCount, std::string hiddenCoverUri, bool isCoverChange, 40 bool isHiddenCoverChange, int64_t dateTimeForCover, int64_t dateTimeForHiddenCover, int32_t dirty, 41 int32_t albumOrder, int32_t orderSection) : albumId_(albumId), lpath_(lpath), imageCount_(imageCount), 42 videoCount_(videoCount), albumType_(albumType), albumSubType_(albumSubType), albumName_(albumName), 43 albumUri_(albumUri), count_(count), coverUri_(coverUri), hiddenCount_(hiddenCount), 44 hiddenCoverUri_(hiddenCoverUri), isCoverChange_(isCoverChange), isHiddenCoverChange_(isHiddenCoverChange), 45 coverDateTime_(dateTimeForCover), hiddenCoverDateTime_(dateTimeForHiddenCover), dirty_(dirty), 46 albumOrder_(albumOrder), orderSection_(orderSection) {} 47 48 int32_t albumId_ = INVALID_INT32_VALUE; 49 std::string lpath_ = EMPTY_STR; 50 int32_t imageCount_ = INVALID_INT32_VALUE; 51 int32_t videoCount_ = INVALID_INT32_VALUE; 52 int32_t albumType_ = INVALID_INT32_VALUE; 53 int32_t albumSubType_ = INVALID_INT32_VALUE; 54 std::string albumName_ = EMPTY_STR; 55 std::string albumUri_ = EMPTY_STR; 56 int32_t count_ = INVALID_INT32_VALUE; 57 std::string coverUri_ = EMPTY_STR; 58 int32_t hiddenCount_ = INVALID_INT32_VALUE; 59 std::string hiddenCoverUri_ = EMPTY_STR; 60 bool isCoverChange_ = false; 61 PhotoAssetChangeInfo coverInfo_; 62 bool isHiddenCoverChange_ = false; 63 PhotoAssetChangeInfo hiddenCoverInfo_; 64 int64_t coverDateTime_ = INVALID_INT64_VALUE; 65 int64_t hiddenCoverDateTime_ = INVALID_INT64_VALUE; 66 int32_t dirty_ = INVALID_INT32_VALUE; 67 int32_t coverUriSource_ = 0; 68 int32_t albumOrder_ = INVALID_INT32_VALUE; 69 int32_t orderSection_ = INVALID_INT32_VALUE; 70 71 NativeRdb::ValuesBucket GetUpdateValues(const AlbumChangeInfo &oldAlbumInfo, NotifyType &type); 72 std::string ToString(bool isDetail = false) const; 73 string GetDataDiff(const AlbumChangeInfo &compare); 74 75 bool Marshalling(Parcel &parcel) const override; 76 bool Marshalling(Parcel &parcel, bool isSystem) const; 77 bool ReadFromParcel(Parcel &parcel); 78 static std::shared_ptr<AlbumChangeInfo> Unmarshalling(Parcel &parcel); 79 80 static const std::vector<std::string>& GetAlbumInfoColumns(); 81 static std::vector<AlbumChangeInfo> GetInfoFromResult(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, 82 const std::vector<std::string> &columns); 83 static ResultSetDataType GetDataType(const std::string &column); 84 private: 85 std::string GetAlbumDiff(const AlbumChangeInfo &album, const AlbumChangeInfo &compare); 86 87 private: 88 static const std::vector<std::string> albumInfoColumns_; 89 static const std::map<std::string, ResultSetDataType> albumInfoCloumnTypes_; 90 bool isSystem_ = false; 91 }; 92 93 class AlbumChangeData : public AccurateRefreshChangeData<AlbumChangeInfo> { 94 public: 95 static std::shared_ptr<AlbumChangeData> Unmarshalling(Parcel &parcel); 96 bool IsAlbumInfoChange(); 97 bool IsAlbumHiddenInfoChange(); 98 }; 99 100 class AlbumRefreshInfo { 101 public: 102 int32_t deltaCount_ = 0; 103 int32_t deltaVideoCount_ = 0; 104 int32_t deltaHiddenCount_ = 0; 105 PhotoAssetChangeInfo deltaAddCover_; 106 PhotoAssetChangeInfo deltaAddHiddenCover_; 107 std::unordered_set<int32_t> removeFileIds; 108 std::unordered_set<int32_t> removeHiddenFileIds; 109 int32_t assetModifiedCnt_ = 0; 110 int32_t hiddenAssetModifiedCnt_ = 0; 111 bool isForceRefresh_ = false; 112 bool isHiddenForceRefresh_ = false; 113 AlbumRefreshTimestamp albumRefreshTimestamp_; 114 AlbumRefreshTimestamp albumHiddenRefreshTimestamp_; 115 116 std::string ToString() const; IsAlbumInfoRefresh()117 bool IsAlbumInfoRefresh() const 118 { 119 return assetModifiedCnt_ > 0; 120 } IsAlbumHiddenInfoRefresh()121 bool IsAlbumHiddenInfoRefresh() const 122 { 123 return hiddenAssetModifiedCnt_ > 0; 124 } 125 }; 126 127 } // namespace Media 128 } // namespace OHOS 129 130 #endif