From: 罗正yun <1732036298@qq.com> Date: Thu, 4 Jan 2024 02:44:39 +0000 (+0800) Subject: 播放器歌单,删除歌曲视图完成,还差最后删除歌曲功能 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=1ed7344ce89aaa6c1b62d437b6c362aaa81d0209;p=mirrors%2FFD230.git 播放器歌单,删除歌曲视图完成,还差最后删除歌曲功能 --- diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index e0ac53590..5da5f5987 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -154,6 +154,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/player/src/PlayersModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/player/src/PlayersCaseListAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/player/src/PlayerListitemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/player/src/PlayerListDelSongView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/activity/src/MainActivityView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/activity/src/ActivityWeekView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/activity/src/ActivityPresenter.cpp diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListDelSongView.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListDelSongView.h new file mode 100644 index 000000000..6c5ff7a84 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayerListDelSongView.h @@ -0,0 +1,34 @@ +#ifndef PLAYER_LIST_DEL_SONG_VIEW_H +#define PLAYER_LIST_DEL_SONG_VIEW_H + +#include "BaseView.h" +#include "string" +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_button.h" + +namespace OHOS +{ + class PlayerListDelSongView + { + + public: + PlayerListDelSongView(); + virtual ~PlayerListDelSongView(); + static PlayerListDelSongView *GetInstance(void); + UIScrollView * InitDelSongView(); + void DeInitView(void); + void SetTheSongLabelStyle(const char * songName); + private: + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *songNameLabel = nullptr; + UIButton *button3_ = nullptr; + UILabel *label2_ = nullptr; + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + bool viewInitStatus{false}; +}; +} +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h index 9c15544ab..678b33588 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h @@ -13,6 +13,7 @@ #include "components/abstract_adapter.h" #include "components/ui_label.h" #include "components/ui_label_button.h" +#include "components/ui_scroll_view.h" #include "UiConfig.h" namespace OHOS { @@ -25,8 +26,10 @@ public: void SetButtonAndLabel(UILabel *label,UIButton *button,int index,UIView::OnClickListener *listener) { m_label[index] = label; + m_label[index]->SetTouchable(true); + m_label[index]->SetOnClickListener(listener); m_button[index] = button; - //m_button[index]->SetOnClickListener(listener); + m_button[index]->SetOnClickListener(listener); } void SongClick(PlayersCaseListAdapter *P_PlayersCaseListAdapter,int index); void SongNotClick(PlayersCaseListAdapter *P_PlayersCaseListAdapter,int index); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h index cffd0fc11..52f1237e7 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h @@ -186,7 +186,7 @@ public: TIPSSUCCMESSAGEVIEW, // 连接成功 TIPSCONNFAILMESSAGEVIEW, // 连接失败 TIPSFAILMESSAGEVIEW, - BLUETOOTHEVIEW, // 设置界面 + BLUETOOTHEVIEW, // 蓝牙视图 BLUETOOTHEJUMP_MAX, }; JumpView(); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h index bc9b0c171..314fb2c6a 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h @@ -26,6 +26,7 @@ #include "components/ui_card_page.h" #include "PlayersPresenter.h" #include "components/ui_scroll_view.h" +#include "PlayerListDelSongView.h" namespace OHOS { #define PLAY_PROGRESS_MIN 0 #define PLAY_PROGRESS_MAX 100 @@ -67,6 +68,12 @@ public: void CreateJumpView(void); void CreatePlayersPresenter(void); void CreatePlayerOnDragListener(void); + void ShowUpDelSongView(void); + void SetPlayerDelSongViewStatus(bool status); + PlayerListDelSongView *GetDelSongView() + { + return p_PlayerListDelSongView; + } private: bool InitBackGround(void); void TearDownView(); @@ -101,6 +108,8 @@ private: UICircleProgress *playbackProgress{nullptr};//播放进度条 UILabel *musicListTitle{nullptr}; //歌单列表名 int16_t volumeSet{0}; //声音值的大小设置 + PlayerListDelSongView *p_PlayerListDelSongView{nullptr}; + UIScrollView *DelSongView{nullptr}; UIList *list{nullptr}; JumpView *jumpView{nullptr}; PlayersPresenter *playersPresenter{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListDelSongView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListDelSongView.cpp new file mode 100644 index 000000000..03d6d6ae8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayerListDelSongView.cpp @@ -0,0 +1,169 @@ +#include "PlayerListDelSongView.h" +#include "PlayersPresenter.h" +namespace OHOS +{ + + + + static PlayerListDelSongView *g_pPlayerListDelSongView{nullptr}; + + PlayerListDelSongView::PlayerListDelSongView() + { + g_pPlayerListDelSongView = this; + } + + PlayerListDelSongView::~PlayerListDelSongView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pPlayerListDelSongView = nullptr; + } + + PlayerListDelSongView *PlayerListDelSongView::GetInstance() + { + + return g_pPlayerListDelSongView; + } + + /// @brief 设置歌曲名标签样式 + /// @param songName 歌曲名 + void PlayerListDelSongView::SetTheSongLabelStyle(const char * songName) + { + songNameLabel->SetText(songName); + songNameLabel->Invalidate(); + } + + UIScrollView * PlayerListDelSongView::InitDelSongView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0,466,466); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView1_->SetDirection(1); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(172, 160); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + label1_->SetText("是否删除"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (songNameLabel == nullptr) + { + songNameLabel = new UILabel(); + } + songNameLabel->SetPosition(83, 220,300,35); + songNameLabel->SetStyle(STYLE_TEXT_FONT, 30); + songNameLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + songNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + songNameLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + songNameLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + songNameLabel->SetRollSpeed(0); + songNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(songNameLabel); + songNameLabel->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (label2_ == nullptr) + { + label2_ = new UILabel(); + } + label2_->SetPosition(173, 52); + label2_->Resize(120, 35); + label2_->SetViewId("label1"); + label2_->SetStyle(STYLE_TEXT_FONT, 30); + label2_->SetStyle(STYLE_LINE_HEIGHT, 36); + label2_->SetText("删除歌曲"); + label2_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + label2_->SetRollSpeed(0); + label2_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label2_); + label2_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (button1_ == nullptr) + { + button1_ = new UIButton(); + } + button1_->SetPosition(256, 299); + button1_->Resize(100, 100); + button1_->SetViewId("Delbutton"); + button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + char *button1defaultImgSrc = "/user/res/SYSTEM_CheckOn.bin"; + button1_->SetImageSrc(button1defaultImgSrc, nullptr); + button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + scrollView1_->Add(button1_); + button1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (button2_ == nullptr) + { + button2_ = new UIButton(); + } + button2_->SetPosition(111, 299); + button2_->Resize(100, 100); + button2_->SetViewId("returnbutton"); + button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + char *button2defaultImgSrc = "/user/res/SYSTEM_CheckOff.bin"; + button2_->SetImageSrc(button2defaultImgSrc, nullptr); + button2_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + scrollView1_->Add(button2_); + button2_->SetVisible(true); + + UIView::OnClickListener *buttonClickListener = static_cast(new ButtonOnClickListener()); + button1_->SetOnClickListener(buttonClickListener); + button2_->SetOnClickListener(buttonClickListener); + viewInitStatus = true; + return scrollView1_; + } + + void PlayerListDelSongView::DeInitView() + { + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (songNameLabel != nullptr) + { + delete songNameLabel; + songNameLabel = nullptr; + } + if (button3_ != nullptr) + { + delete button3_; + button3_ = nullptr; + } + if (label2_ != nullptr) + { + delete label2_; + label2_ = nullptr; + } + if (button1_ != nullptr) + { + delete button1_; + button1_ = nullptr; + } + if (button2_ != nullptr) + { + delete button2_; + button2_ = nullptr; + } + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp index 7b8d797b8..526b2f2d1 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp @@ -75,26 +75,27 @@ void BtnOnClickListListener::SongNotClick(PlayersCaseListAdapter *P_PlayersCaseL /// @return bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event) { + PlayersView *playersView = PlayersView::GetInstance(); + PlayersCaseListAdapter *P_PlayersCaseListAdapter = PlayersCaseListAdapter::GetInstance(); + //BtnOnListData该函数的作用是从传入的视图中提取相关数据 + BtnOnListData(view); + if((&view == P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_button[index_]) && + P_PlayersCaseListAdapter->p_BtnOnClickListListener->playOrDeleteStatus[index_] == 0) + { + playersView->GetDelSongView()->SetTheSongLabelStyle(sliceId_); + playersView->SetPlayerDelSongViewStatus(true); + return false; + } + else if((&view == P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_label[index_])){ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtnOnClickListListener sliceId_: %s.", sliceId_); UNUSED(event); int ret; int32_t playerState; uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; - PlayersView *playersView = PlayersView::GetInstance(); if (playersView == nullptr) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playersView null!"); return false; } - //BtnOnListData该函数的作用是从传入的视图中提取相关数据 - BtnOnListData(view); - /* -------------------------------------------------------------------------- */ - PlayersCaseListAdapter *P_PlayersCaseListAdapter = PlayersCaseListAdapter::GetInstance(); - // if((&view == P_PlayersCaseListAdapter->p_BtnOnClickListListener->m_button[index_]) && (P_PlayersCaseListAdapter->p_BtnOnClickListListener->playOrDeleteStatus[index_] == 0)) - // { - // printf("delete index = %d song,%s\n",index_,__func__); - // return false; - // } - /* -------------------------------------------------------------------------- */ // 标记当前播放歌曲index_ PlayersModel::GetInstance()->SetCurrentIndex(index_); //当前正在播放的歌曲 // 本地播放文件路径和状态 @@ -105,12 +106,10 @@ bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uri: %s.", PlayersModel::GetInstance()->GetPlayerUri().c_str()); std::string strSongName = sliceId_; std::string pureName = strSongName.substr(0, strSongName.rfind(".")); //获取纯粹歌曲名 - const char *songName = pureName.c_str(); //playersView->TitleSetText(songName); - playersView->SetPlayerListGroupStatus(false); + //playersView->SetPlayerListGroupStatus(false);//这是点击歌曲后就会播放歌曲歌单隐藏 /* -------------------------------------------------------------------------- */ - //PlayersCaseListAdapter *P_PlayersCaseListAdapter = PlayersCaseListAdapter::GetInstance(); SongClick(P_PlayersCaseListAdapter,index_); for(int i= 0;iGetCount();i++) { @@ -146,12 +145,14 @@ bool BtnOnClickListListener::OnClick(UIView& view, const ClickEvent& event) } PlayersModel::GetInstance()->PlayerStat(); } + } return true; } void BtnOnClickListListener::BtnOnListData(UIView& view) { - index_ = view.GetViewIndex(); + //index_ = view.GetViewIndex(); + index_ = view.GetParent()->GetViewIndex(); //list中如果其他组件,想点击里面组件,得先获取父视图 List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); ListNode* node = playersCaseList.Begin(); for (uint16_t i = 0; i < index_; i++) { @@ -198,12 +199,12 @@ UIView *PlayersCaseListAdapter::GetView(UIView* inView, int16_t index) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listener == nullptr"); return nullptr; } - listitem->SetOnClickListener(listener); + //listitem->SetOnClickListener(listener); p_BtnOnClickListListener->SetButtonAndLabel(listitem->GetLabel(),listitem->GetButton(),index,listener); } else { - listitem->SetOnClickListener(listener); + //listitem->SetOnClickListener(listener); p_BtnOnClickListListener->SetButtonAndLabel(listitem->GetLabel(),listitem->GetButton(),index,listener); } return listitem; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp index 4bd5e659a..70159e4ca 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp @@ -664,6 +664,17 @@ bool ButtonOnClickListener::OnClick(UIView& view, const ClickEvent& event) { PlayersPresenter::GetInstance()->ShowPlayerListGroup(); } + else if(strcmp(view.GetViewId(),"Delbutton") == 0) + { + printf("Delbutton %s %d\n",__func__,__LINE__); + } + else if(strcmp(view.GetViewId(),"returnbutton") == 0) + { + PlayersView *playersView = PlayersView::GetInstance(); + playersView->SetPlayerDelSongViewStatus(false); + playersView->SetPlayerListGroupStatus(true); + RootView::GetInstance()->Invalidate(); + } return true; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp index 0e31a000e..dd0f38659 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp @@ -167,7 +167,8 @@ UIList *PlayersView::GetPlayerList(void) { return list; } - +/// @brief 根据传入的status参数来控制歌曲列表组的显示与隐藏。 +/// @param status void PlayersView::SetPlayerListGroupStatus(bool status) { if (listGroup == nullptr) { @@ -182,6 +183,24 @@ void PlayersView::SetPlayerListGroupStatus(bool status) return; } +/// @brief 根据传入的status参数来控制删除歌曲视图的显示与隐藏。 +/// @param status +void PlayersView::SetPlayerDelSongViewStatus(bool status) +{ + if (DelSongView == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView DelSongView is NULL"); + return; + } + UIView *vew = MainViewSample::GetInstance()->GetMainViewGroup(); + if (vew != nullptr) { + vew->SetVisible(!status); + } + DelSongView->SetVisible(status); + RootView::GetInstance()->Invalidate(); + return; + +} + void PlayersView::SetPlayerCtrVolume(float leftVolume, float rightVolume) { PlayersModel::GetInstance()->GetPlayerCtr()->SetVolume(leftVolume, rightVolume); @@ -272,6 +291,21 @@ void PlayersView::ShowUpListView() listGroup->SetVisible(false); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView end"); } + +/// @brief 创建删除歌曲视图 +/// @param songName +void PlayersView::ShowUpDelSongView() +{ + if(p_PlayerListDelSongView == nullptr) + { + p_PlayerListDelSongView = new PlayerListDelSongView(); + } + DelSongView = p_PlayerListDelSongView->InitDelSongView(); + RootView::GetInstance()->Add(DelSongView); + DelSongView->SetTouchable(true); + DelSongView->SetVisible(false); +} + //设置按钮的位置和监听 void PlayersView::SetUpButton(UIButton *btn, const Point& point, int16_t width, int16_t height, UIView::OnClickListener *listener) @@ -672,6 +706,7 @@ bool PlayersView::InitView(void) PlayersListGroup::GetInstance()->SetUpListCase(); PlayersModel::GetInstance()->PlayerInit(); ShowUpListView(); + ShowUpDelSongView(); SetTouchable(true); SetDraggable(true); return true;