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 #define MLOG_TAG "AccurateRefresh::SystemAlbumInfoCalculation"
17
18 #include "system_album_info_calculation.h"
19 #include "album_asset_helper.h"
20 #include "album_accurate_refresh_manager.h"
21
22 #include "accurate_debug_log.h"
23
24 using namespace std;
25
26 namespace OHOS {
27 namespace Media::AccurateRefresh {
28
CalAlbumRefreshInfo(const PhotoAssetChangeData & assetChangeData,AlbumRefreshInfo & refreshInfo,int32_t albumId)29 bool SystemAlbumInfoCalculation::CalAlbumRefreshInfo(const PhotoAssetChangeData &assetChangeData,
30 AlbumRefreshInfo &refreshInfo, int32_t albumId)
31 {
32 bool ret = false;
33 AlbumRefreshTimestamp assetTimestamp(assetChangeData.infoBeforeChange_.timestamp_,
34 assetChangeData.infoAfterChange_.timestamp_);
35 // 普通信息变化
36 if (IsSystemAlbumInfoChange(assetChangeData, isSystemAsset_)) {
37 std::function<bool(AlbumRefreshInfo &)> calRefreshInfoFunc = [this, &assetChangeData]
38 (AlbumRefreshInfo &refreshInfo) -> bool {
39 return this->UpdateRefreshNormalInfo(assetChangeData, refreshInfo);
40 };
41 ret = AlbumAssetHelper::CalAlbumRefreshInfo(calRefreshInfoFunc, refreshInfo, albumId, false, assetTimestamp);
42 }
43
44 // 隐藏相册不需要计算
45 if (subType_ == PhotoAlbumSubType::HIDDEN) {
46 return ret;
47 }
48
49 // 隐藏信息变化
50 if (IsSystemAlbumInfoChange(assetChangeData, isHiddenSystemAsset_)) {
51 std::function<bool(AlbumRefreshInfo &)> calHiddenRefreshInfoFunc = [this, &assetChangeData]
52 (AlbumRefreshInfo &refreshInfo) -> bool {
53 return this->UpdateRefreshHiddenInfo(assetChangeData, refreshInfo);
54 };
55 ret = AlbumAssetHelper::CalAlbumRefreshInfo(calHiddenRefreshInfoFunc, refreshInfo, albumId, true,
56 assetTimestamp) || ret;
57 }
58
59 return ret;
60 }
61
UpdateCover(const PhotoAssetChangeData & assetChangeData,std::function<bool (const PhotoAssetChangeInfo &)> isSystemAsset,std::function<bool (const PhotoAssetChangeInfo &,const PhotoAssetChangeInfo &)> isNewerAsset,PhotoAssetChangeInfo & addCover,unordered_set<int32_t> & removeFileIds)62 bool SystemAlbumInfoCalculation::UpdateCover(const PhotoAssetChangeData &assetChangeData,
63 std::function<bool(const PhotoAssetChangeInfo&)> isSystemAsset,
64 std::function<bool(const PhotoAssetChangeInfo&, const PhotoAssetChangeInfo&)> isNewerAsset,
65 PhotoAssetChangeInfo &addCover, unordered_set<int32_t> &removeFileIds)
66 {
67 return AlbumAssetHelper::UpdateCover(assetChangeData, isSystemAsset, isNewerAsset, addCover, removeFileIds);
68 }
69
UpdateCount(const PhotoAssetChangeData & assetChangeData,std::function<bool (PhotoAssetChangeInfo)> isSystemAsset,int32_t & count)70 bool SystemAlbumInfoCalculation::UpdateCount(const PhotoAssetChangeData &assetChangeData,
71 std::function<bool(PhotoAssetChangeInfo)> isSystemAsset, int32_t &count)
72 {
73 return AlbumAssetHelper::UpdateCount(assetChangeData, isSystemAsset, count);
74 }
75
UpdateRefreshNormalInfo(const PhotoAssetChangeData & assetChangeData,AlbumRefreshInfo & refreshInfo)76 bool SystemAlbumInfoCalculation::UpdateRefreshNormalInfo(const PhotoAssetChangeData &assetChangeData,
77 AlbumRefreshInfo& refreshInfo)
78 {
79 bool ret = false;
80 // count更新
81 if (UpdateCount(assetChangeData, isSystemAsset_, refreshInfo.deltaCount_)) {
82 refreshInfo.assetModifiedCnt_++;
83 ret = true;
84 }
85
86 // video countvideo count更新
87 if (UpdateCount(assetChangeData, isVideoAsset_, refreshInfo.deltaVideoCount_)) {
88 ret = true;
89 }
90
91 // cover更新
92 if (UpdateCover(assetChangeData, isSystemAsset_, isNewerAsset_, refreshInfo.deltaAddCover_,
93 refreshInfo.removeFileIds)) {
94 ret = true;
95 }
96 return ret;
97 }
98
UpdateRefreshHiddenInfo(const PhotoAssetChangeData & assetChangeData,AlbumRefreshInfo & refreshInfo)99 bool SystemAlbumInfoCalculation::UpdateRefreshHiddenInfo(const PhotoAssetChangeData &assetChangeData,
100 AlbumRefreshInfo& refreshInfo)
101 {
102 bool ret = false;
103 // hidden count
104 if (this->UpdateCount(assetChangeData, this->isHiddenSystemAsset_, refreshInfo.deltaHiddenCount_)) {
105 refreshInfo.hiddenAssetModifiedCnt_++;
106 ret = true;
107 }
108 // hidden cover更新
109 if (this->UpdateCover(assetChangeData, this->isHiddenSystemAsset_, this->isNewerHiddenAsset_,
110 refreshInfo.deltaAddHiddenCover_, refreshInfo.removeHiddenFileIds)) {
111 ret = true;
112 }
113 return ret;
114 }
115
IsSystemAlbumInfoChange(const PhotoAssetChangeData & assetChangeData,std::function<bool (PhotoAssetChangeInfo)> isAlbumAsset)116 bool SystemAlbumInfoCalculation::IsSystemAlbumInfoChange(const PhotoAssetChangeData &assetChangeData,
117 std::function<bool(PhotoAssetChangeInfo)> isAlbumAsset)
118 {
119 return isAlbumAsset(assetChangeData.infoBeforeChange_) != isAlbumAsset(assetChangeData.infoAfterChange_);
120 }
121 } // namespace Media
122 } // namespace OHOS