From 3e762ab8d4ce987c08425a64d8050342e290fe42 Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Tue, 14 Feb 2023 23:08:04 +0100 Subject: [PATCH] [MOS-28] Change alarm sounds and ringtones preview behavior Change of the behavior of alarm sounds and ringtones preview, so that it matches with the design. Additionally fixed lack of ringtones list looping. --- .../widgets/AlarmMusicOptionsItem.cpp | 16 ++--- .../models/apps/SoundsModel.cpp | 63 ++++++++++--------- .../windows/apps/SoundSelectWindow.cpp | 3 +- pure_changelog.md | 1 + 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/module-apps/application-alarm-clock/widgets/AlarmMusicOptionsItem.cpp b/module-apps/application-alarm-clock/widgets/AlarmMusicOptionsItem.cpp index 46f82a947ba6906ad8d4c4fa42e96739d5914bd3..a4931377c4064975015472beceb0d5aa7719c3e6 100644 --- a/module-apps/application-alarm-clock/widgets/AlarmMusicOptionsItem.cpp +++ b/module-apps/application-alarm-clock/widgets/AlarmMusicOptionsItem.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AlarmMusicOptionsItem.hpp" @@ -47,17 +47,13 @@ namespace gui if (player->isInState(SoundsPlayer::State::Playing) && event.isShortRelease(gui::KeyCode::KEY_RF)) { player->stop(); } - auto res = optionSpinner->onInput(event); - if (res && player->previouslyPlayed(getFilePath(optionSpinner->getCurrentValue())) && - player->isInState(SoundsPlayer::State::Playing)) { - this->navBarTemporaryMode(utils::translate(style::strings::common::pause)); + const auto actionHandled = optionSpinner->onInput(event); + if (actionHandled && player->isInState(SoundsPlayer::State::Playing)) { + player->play(getFilePath(optionSpinner->getCurrentValue()), + [=]() { this->navBarTemporaryMode(utils::translate(style::strings::common::play)); }); } - else if (res) { - this->navBarTemporaryMode(utils::translate(style::strings::common::play)); - } - - return res; + return actionHandled; }; focusChangedCallback = [=](Item &item) { diff --git a/module-apps/application-settings/models/apps/SoundsModel.cpp b/module-apps/application-settings/models/apps/SoundsModel.cpp index 726a5475d51197a62afde401669cdb3a1974d3e3..37c87a17e2d9a3daa548fc82a2fcb91ea3125d91 100644 --- a/module-apps/application-settings/models/apps/SoundsModel.cpp +++ b/module-apps/application-settings/models/apps/SoundsModel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "SoundsModel.hpp" @@ -9,7 +9,6 @@ #include #include -#include #include SoundsModel::SoundsModel(std::shared_ptr soundsPlayer) : soundsPlayer{std::move(soundsPlayer)} @@ -42,7 +41,7 @@ void SoundsModel::createData(app::ApplicationCommon *app, audio_settings::Abstra assert(app); // configure according to type - std::filesystem::path folder = getSoundPath(model); + const auto folder = getSoundPath(model); // iterate through selected folder and collect all sounds names std::vector sounds; @@ -54,8 +53,9 @@ void SoundsModel::createData(app::ApplicationCommon *app, audio_settings::Abstra } const auto &filePath = entry.path(); - if (filePath.extension() == ".mp3") + if (filePath.extension() == ".mp3") { sounds.push_back(filePath); + } } LOG_INFO("Found %d sounds in folder %s", static_cast(sounds.size()), folder.c_str()); } @@ -97,7 +97,7 @@ void SoundsModel::applyItems(const std::vector &sounds, auto currentItemIndex = 0; auto selectedItemIndex = 0; - std::string selectedSound = purefs::dir::getAssetsDirPath() / model->getSound(); + const auto selectedSound = purefs::dir::getAssetsDirPath() / model->getSound(); for (const auto &sound : sounds) { bool isSelected = false; @@ -122,7 +122,7 @@ void SoundsModel::applyItems(const std::vector &sounds, case audio::PlaybackType::TextMessageRingtone: case audio::PlaybackType::Notifications: item->activatedCallback = [=](gui::Item &) { - auto fileRelativePath = sound.lexically_relative(purefs::dir::getSystemDiskPath()); + const auto fileRelativePath = sound.lexically_relative(purefs::dir::getSystemDiskPath()); LOG_INFO("Setting sound to %s", fileRelativePath.c_str()); model->setSound(fileRelativePath); soundsPlayer->stop(); @@ -132,28 +132,34 @@ void SoundsModel::applyItems(const std::vector &sounds, // callback to handle preview of the sound item->inputCallback = [=](gui::Item &item, const gui::InputEvent &event) { - auto fileRelativePath = sound.lexically_relative(purefs::dir::getSystemDiskPath()); + const auto fileRelativePath = sound.lexically_relative(purefs::dir::getSystemDiskPath()); if (event.isShortRelease(gui::KeyCode::KEY_RF)) { soundsPlayer->stop(); + return false; } - else if (event.isShortRelease(gui::KeyCode::KEY_LF)) { + + if (event.isShortRelease(gui::KeyCode::KEY_LF)) { + const auto window = app->getCurrentWindow(); + if (!soundsPlayer->previouslyPlayed(fileRelativePath) || soundsPlayer->isInState(AbstractSoundsPlayer::State::Stopped)) { - app->getCurrentWindow()->navBarTemporaryMode( + window->navBarTemporaryMode( utils::translate(style::strings::common::pause), gui::nav_bar::Side::Left, false); return soundsPlayer->play(fileRelativePath, [=]() { - app->getCurrentWindow()->navBarTemporaryMode( + window->navBarTemporaryMode( utils::translate(style::strings::common::play), gui::nav_bar::Side::Left, false); }); } - else if (soundsPlayer->isInState(AbstractSoundsPlayer::State::Playing)) { - app->getCurrentWindow()->navBarTemporaryMode( + + if (soundsPlayer->isInState(AbstractSoundsPlayer::State::Playing)) { + window->navBarTemporaryMode( utils::translate(style::strings::common::play), gui::nav_bar::Side::Left, false); return soundsPlayer->pause(); } - else if (soundsPlayer->isInState(AbstractSoundsPlayer::State::Paused)) { - app->getCurrentWindow()->navBarTemporaryMode( + + if (soundsPlayer->isInState(AbstractSoundsPlayer::State::Paused)) { + window->navBarTemporaryMode( utils::translate(style::strings::common::pause), gui::nav_bar::Side::Left, false); return soundsPlayer->resume(); } @@ -163,29 +169,26 @@ void SoundsModel::applyItems(const std::vector &sounds, }; item->focusChangedCallback = [=](gui::Item &item) { + const auto window = app->getCurrentWindow(); if (!item.focus) { - app->getCurrentWindow()->navBarRestoreFromTemporaryMode(); + window->navBarRestoreFromTemporaryMode(); return true; } - auto fileRelativePath = sound.lexically_relative(purefs::dir::getSystemDiskPath()); - if (!soundsPlayer->previouslyPlayed(fileRelativePath)) { - app->getCurrentWindow()->navBarTemporaryMode( - utils::translate(style::strings::common::play), gui::nav_bar::Side::Left, false); - return true; - } - - if (soundsPlayer->isInState(AbstractSoundsPlayer::State::Playing)) { - app->getCurrentWindow()->navBarTemporaryMode( + const auto fileRelativePath = sound.lexically_relative(purefs::dir::getSystemDiskPath()); + if (!soundsPlayer->previouslyPlayed(fileRelativePath) && + soundsPlayer->isInState(AbstractSoundsPlayer::State::Playing)) { + window->navBarTemporaryMode( utils::translate(style::strings::common::pause), gui::nav_bar::Side::Left, false); - return true; + return soundsPlayer->play(fileRelativePath, [=]() { + window->navBarTemporaryMode( + utils::translate(style::strings::common::play), gui::nav_bar::Side::Left, false); + }); } - else { - app->getCurrentWindow()->navBarTemporaryMode( - utils::translate(style::strings::common::play), gui::nav_bar::Side::Left, false); - return true; - } + window->navBarTemporaryMode( + utils::translate(style::strings::common::play), gui::nav_bar::Side::Left, false); + return true; }; break; diff --git a/module-apps/application-settings/windows/apps/SoundSelectWindow.cpp b/module-apps/application-settings/windows/apps/SoundSelectWindow.cpp index 41e5f6e8bb7580cba2a7d6aa1f820a612f657522..16f8cf5db4fc45418f7976346a84c45187cf297e 100644 --- a/module-apps/application-settings/windows/apps/SoundSelectWindow.cpp +++ b/module-apps/application-settings/windows/apps/SoundSelectWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "SoundSelectWindow.hpp" @@ -39,6 +39,7 @@ namespace gui style::nav_bar::height + style::margins::small, mSoundsModel, listview::ScrollBarType::Proportional); + mSoundsList->setBoundaries(Boundaries::Continuous); setFocusItem(mSoundsList); } diff --git a/pure_changelog.md b/pure_changelog.md index 954f4e56b8a4d57061d6fc032fea63c134fe84ce..d4d515bf65a0bdeafc630045436ce89e9f599463 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -78,6 +78,7 @@ * Fixed going back to wrong window after confirming or cancelling creation of new contact from call log * Fixed misleading popup on SMS send when modem is rebooting * Fixed window redirection when clicking SMS icon +* Fixed navigation through the ringtone preview list to automatically switch playback to the currently selected option ## [1.5.0 2022-12-20]