128 lines
4.4 KiB
C++
128 lines
4.4 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
|
|
*
|
|
* Description: TjdUiAppListModel.cpp
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2025-02-11
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiAppListModel.h"
|
|
#include "TjdUiAppListPresenter.h"
|
|
#include "TjdUiAppListView.h"
|
|
#include "TjdUiRegisterManager.h"
|
|
#include "adapter.h"
|
|
#include "bundlems_slite_client.h"
|
|
#include "sql_setting.h"
|
|
|
|
namespace TJD {
|
|
|
|
TjdUiAppListModel &TjdUiAppListModel::GetInstance()
|
|
{
|
|
static TjdUiAppListModel instance;
|
|
return instance;
|
|
}
|
|
|
|
void TjdUiAppListModel::Init()
|
|
{
|
|
if (!initFlag) {
|
|
ResolvingJSAppItems();
|
|
initFlag = true;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppListModel::SetInitFlag(bool flag) { initFlag = flag; }
|
|
|
|
void TjdUiAppListModel::ResolvingJSAppItems(void)
|
|
{
|
|
#ifdef JS_ENABLE
|
|
if (bundleInfos != nullptr) {
|
|
for (uint8_t i = 0; i < bundleLen; i++) {
|
|
ClearBundleInfo(bundleInfos + i);
|
|
}
|
|
|
|
if (bundleInfos != nullptr) {
|
|
AdapterFree(bundleInfos);
|
|
bundleInfos = nullptr;
|
|
}
|
|
}
|
|
#endif
|
|
bundleLen = 0;
|
|
appLen = 0;
|
|
OHOS::List<TjdAppItem> &nativeAppLists = TjdNativeRegisterManager::GetInstance().GetNativeAppLists();
|
|
uint8_t registerNativeAppNum = nativeAppLists.Size();
|
|
if (registerNativeAppNum > APP_MAX_NUM) {
|
|
registerNativeAppNum = APP_MAX_NUM;
|
|
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Numbers of Native app is more than APP_MAX_NUM.\r");
|
|
}
|
|
uint8_t nativeAppNumTotal = registerNativeAppNum;
|
|
OHOS::ListNode<TjdAppItem> *appNode = nativeAppLists.Head();
|
|
for (int32_t index = 0; index < nativeAppNumTotal; index++) {
|
|
applist[index] = appNode->data_;
|
|
appNode = appNode->next_;
|
|
}
|
|
appLen = nativeAppNumTotal;
|
|
|
|
std::sort(applist, applist + nativeAppNumTotal,
|
|
[](const TjdAppItem &a, const TjdAppItem &b) { return a.appItem.id < b.appItem.id; });
|
|
|
|
#ifdef JS_ENABLE
|
|
int32_t len = 0;
|
|
uint8_t ret = OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &len);
|
|
if ((ret == 0) && (len > 0) && (bundleInfos != nullptr)) {
|
|
bundleLen = len;
|
|
if (len > APP_MAX_NUM - nativeAppNumTotal) {
|
|
len = APP_MAX_NUM - nativeAppNumTotal;
|
|
}
|
|
while (len--) {
|
|
// clang-format off
|
|
TjdAppItem item = {-1, -1,bundleInfos[len].versionName, {VIEW_EXTERN_APP, bundleInfos[len].smallIconPath, bundleInfos[len].smallIconPath,
|
|
bundleInfos[len].bigIconPath, bundleInfos[len].label, bundleInfos[len].bundleName}};
|
|
applist[appLen] = item;
|
|
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems bundleName is %s \r", bundleInfos[len].bundleName);
|
|
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems label is %s \r", bundleInfos[len].label);
|
|
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems smallIconPath is %s \r", bundleInfos[len].smallIconPath);
|
|
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems bigIconPath is %s \r", bundleInfos[len].bigIconPath);
|
|
appLen++;
|
|
bundleInfos[len].abilityInfo = nullptr;
|
|
// clang-format on
|
|
}
|
|
} else {
|
|
WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems GetBundleInfos ret = %d \r", ret);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
const TjdAppItem *TjdUiAppListModel::GetApplistItems() const
|
|
{
|
|
TjdUiAppListModel::GetInstance().Init();
|
|
return applist;
|
|
}
|
|
|
|
uint8_t TjdUiAppListModel::GetAppListNum() const { return appLen; }
|
|
|
|
void TjdUiAppListModel::SetStartIndex(uint16_t index) { startIndex = index; }
|
|
|
|
uint16_t TjdUiAppListModel::GetStartIndex(void) { return startIndex; }
|
|
|
|
void TjdUiAppListModel::SetHeadItemY(int y) { headItemY = y; }
|
|
|
|
int TjdUiAppListModel::GetHeadItemY(void) { return headItemY; }
|
|
|
|
void TjdUiAppListModel::ApplistUpdate(void)
|
|
{
|
|
ResolvingJSAppItems();
|
|
TjdUiAppListPresenter *presenter = TjdUiAppListPresenter::GetInstance();
|
|
if (presenter != nullptr) {
|
|
presenter->GetAppListView()->ClearAppItemToList();
|
|
presenter->RefreshAppItemToList();
|
|
presenter->GetAppListView()->RefreshAppList();
|
|
}
|
|
}
|
|
|
|
void TjdUiAppListModel::SetCurrentStyle(E_MenuStyle style) { sql_setting_set_menu_style(style); }
|
|
|
|
E_MenuStyle TjdUiAppListModel::GetCurrentStyle(void) { return sql_setting_get_menu_style(); }
|
|
|
|
} // namespace TJD
|