00c2634c创建于 2025年9月23日历史提交
/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { resourceManager } from '@kit.LocalizationKit';
import Logger from '../common/util/Logger';
import { VideoItem } from '../viewmodel/VideoItem';
import { HomeConstants } from '../common/constants/HomeConstants';
import { CommonConstants } from '../common/constants/CommonConstants';
import { HomeTabContentListItem } from './HomeTabContentListItem';
import { GlobalContext } from '../common/util/GlobalContext';
import { HomeTabModel } from '../common/model/HomeTabModel';

@Component
export struct HomeTabContentList {
  currIndex: number = 0;
  @Consume homeTabModel: HomeTabModel;
  @State item: VideoItem = new VideoItem('video1', {} as resourceManager.RawFileDescriptor, 'video1.mp4');

  async aboutToAppear() {
    if (this.currIndex === CommonConstants.TYPE_INTERNET) {
      let videoInternetList = GlobalContext.getContext().getObject('videoInternetList') as VideoItem[];
      this.homeTabModel.videoList = videoInternetList;
    }
  }

  build() {
    Column() {
      List({
        space: HomeConstants.LIST_SPACE,
        initialIndex: HomeConstants.LIST_INITIAL_INDEX
      }) {
        ForEach(this.homeTabModel.videoList, (item: VideoItem, index?: number) => {
          ListItem() {
            HomeTabContentListItem({ item: item });
          }.onClick(() => {
            GlobalContext.getContext().setObject('globalVideoList', this.homeTabModel.videoList);
            this.getUIContext().getRouter().pushUrl({
              url: CommonConstants.PAGE,
              params: {
                src: item.src,
                iSrc: item.iSrc,
                index: index,
                type: this.currIndex
              }
            }).catch((err: Error) => {
              Logger.error('[IndexTabLocalList] router error: ' + JSON.stringify(err))
            });
          })
        }, (item: VideoItem) => JSON.stringify(item))
      }
      .backgroundColor(Color.White)
      .borderRadius($r('app.float.list_border_radius'))
    }
    .width(HomeConstants.COLUMN_WIDTH)
    .height(CommonConstants.NINETY_PERCENT)
  }
}