Commit f6f530b7 authored by wutao's avatar wutao Committed by Commit Bot

ambient: Select album by id

The album's name could be duplicate, so it cannot be used as an
identifier to select an album.
This patch changes the logic to use album id to select albums.

Bug: b/161081423
Test: manual
Change-Id: Ia6e6f07751f9ab6f4c9b12f7d333a63e7625ec6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2296861
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789780}
parent 7cbaa671
......@@ -35,6 +35,9 @@ struct ASH_PUBLIC_EXPORT ArtSetting {
int setting_id = 0;
// Album ID for Art category, used in Settings UI to select Art categories.
std::string album_id;
// Whether the setting is enabled in the Art gallery topic source.
bool enabled = false;
......@@ -75,9 +78,6 @@ struct ASH_PUBLIC_EXPORT PersonalAlbum {
// ID of this album.
std::string album_id;
// Whether the album is selected in the Google Photos topic source.
bool selected = false;
// UTF-8 encoded.
std::string album_name;
......@@ -86,9 +86,6 @@ struct ASH_PUBLIC_EXPORT PersonalAlbum {
// Preview image of this album.
std::string banner_image_url;
// Preview images if this is a live album.
std::vector<std::string> preview_image_urls;
};
struct ASH_PUBLIC_EXPORT PersonalAlbums {
......
......@@ -25,6 +25,7 @@
<cr-checkbox class="list-item"
checked="[[item.checked]]"
on-change="onCheckboxChange_"
data-id="[[item.albumId]]"
label="[[item.title]]">
[[item.title]]
</cr-checkbox>
......
......@@ -100,7 +100,7 @@ Polymer({
const containers = [];
checkboxes.forEach((checkbox) => {
if (checkbox.checked && !checkbox.hidden) {
containers.push(checkbox.label);
containers.push(checkbox.dataset.id);
}
});
this.browserProxy_.setSelectedPhotosContainers(
......
......@@ -124,10 +124,12 @@ void AmbientModeHandler::HandleSetSelectedPhotosContainers(
// of selected albums.
settings_->selected_album_ids.clear();
for (const auto& value : containers->GetList()) {
std::string name = value.GetString();
auto it = std::find_if(
personal_albums_.albums.begin(), personal_albums_.albums.end(),
[name](const auto& album) { return album.album_name == name; });
const std::string& album_id = value.GetString();
auto it = std::find_if(personal_albums_.albums.begin(),
personal_albums_.albums.end(),
[&album_id](const auto& album) {
return album.album_id == album_id;
});
CHECK(it != personal_albums_.albums.end());
settings_->selected_album_ids.emplace_back(it->album_id);
}
......@@ -136,10 +138,12 @@ void AmbientModeHandler::HandleSetSelectedPhotosContainers(
// For Art gallery, we set the corresponding setting to be enabled or not
// based on the selections.
for (auto& art_setting : settings_->art_settings) {
std::string title = art_setting.title;
auto it = std::find_if(
containers->GetList().begin(), containers->GetList().end(),
[title](const auto& value) { return value.GetString() == title; });
const std::string& album_id = art_setting.album_id;
auto it = std::find_if(containers->GetList().begin(),
containers->GetList().end(),
[&album_id](const auto& value) {
return value.GetString() == album_id;
});
const bool checked = it != containers->GetList().end();
art_setting.enabled = checked;
}
......@@ -182,6 +186,7 @@ void AmbientModeHandler::SendPhotosContainers(
case ash::AmbientModeTopicSource::kGooglePhotos:
for (const auto& album : personal_albums_.albums) {
base::Value value(base::Value::Type::DICTIONARY);
value.SetKey("albumId", base::Value(album.album_id));
value.SetKey("title", base::Value(album.album_name));
value.SetKey("checked",
base::Value(base::Contains(settings_->selected_album_ids,
......@@ -192,6 +197,7 @@ void AmbientModeHandler::SendPhotosContainers(
case ash::AmbientModeTopicSource::kArtGallery:
for (const auto& setting : settings_->art_settings) {
base::Value value(base::Value::Type::DICTIONARY);
value.SetKey("albumId", base::Value(setting.album_id));
value.SetKey("title", base::Value(setting.title));
value.SetKey("checked", base::Value(setting.enabled));
containers.Append(std::move(value));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment