# 6\_3-互动学堂场景-状态栏

* [1 功能概述](#1-功能概述)
* [2 使用演示](#2-使用演示)
* [3 实现介绍](#3-实现介绍)
  * [3.1 初始化view方法](#31-初始化view方法)
  * [3.2 初始化数据方法](#32-初始化数据方法)
  * [3.3 状态栏UI的更新](#33-状态栏ui的更新)

### 1 功能概述

状态栏主要包括课节号展示、当前上课状态、课节名称展示、网络延迟等功能。其中，上课状态包括未上课、上课延误、拖堂和已结束。状态栏界面封装在`PLVHCStatusBarLayout` 中。

### 2 使用演示

使用状态栏模块只需要在Activity布局中添加`PLVHCStatusBarLayout` 这个布局，同时在布局文件中添加相关的布局。

```xml
<!-- 状态栏布局 -->
<com.easefun.polyv.livehiclass.modules.statusbar.PLVHCStatusBarLayout
    android:id="@+id/plvhc_status_bar_ly"
    android:layout_width="match_parent"
    android:layout_height="24dp"
    android:background="#191A22"
    app:layout_constraintTop_toTopOf="parent" />
```

调用init方法去初始化状态栏布局

```java
// 初始化状态栏布局
plvhcStatusBarLy.init(liveRoomDataManager);
```

可以调用接口中定义的方法去实现对状态栏的修改。

```java
public interface IPLVHCStatusBarLayout {

    /**
     * 初始化
     *
     * @param liveRoomDataManager
     */
    void init(IPLVLiveRoomDataManager liveRoomDataManager);

    /**
     * 更新为已上课状态
     */
    void onLessonStart();

    /**
     * 更新为已下课状态
     */
    void onLessonEnd();

    /**
     * 更新网络质量
     *
     * @param networkQuality
     */
    void acceptNetworkQuality(int networkQuality);

    /**
     * 上行流量网络状态
     *
     * @param networkStatusVO
     */
    void acceptUpstreamNetworkStatus(PLVNetworkStatusVO networkStatusVO);

    /**
     * 远端连麦用户网络状态
     *
     * @param networkStatusVO
     */
    void acceptRemoteNetworkStatus(PLVNetworkStatusVO networkStatusVO);

    /**
     * 销毁方法
     */
    void destroy();

}
```

### 3 实现介绍

`PLVHCStatusBarLayout` 是互动学堂场景下的状态栏布局，实现了 `IPLVHCStatusBarLayout` 接口。

#### 3.1 初始化view方法

`PLVHCStatusBarLayout` 继承于 `FrameLayout` ，在构造器中使用 `initView` 方法对view进行初始化处理。

```java
//构造器
public PLVHCStatusBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initView();
}
//初始化方法
private void initView() {
    rootView = LayoutInflater.from(getContext()).inflate(R.layout.plvhc_live_room_status_layout, this);
    findView();
    initStatusUpdateTimer();
}
```

#### 3.2 初始化数据方法

`PLVHCStatusBarLayout` 的 `init` 方法是对外的API，在初始化的时候调用一次，需要外部传入 `IPLVLiveRoomDataManager` 后进行初始化。

```java
@Override
public void init(IPLVLiveRoomDataManager liveRoomDataManager) {
    this.liveRoomDataManager = liveRoomDataManager;
    initLessonIdText(liveRoomDataManager);
    observeLessonDataBean(liveRoomDataManager);
}

private void initLessonIdText(IPLVLiveRoomDataManager liveRoomDataManager) {
    //初始化课节号信息
}

private void observeLessonDataBean(IPLVLiveRoomDataManager liveRoomDataManager) {
    //监听数据变化
}
```

上面是初始化的方法。然后是在对外api中实现了接口中的方法。

#### 3.3 状态栏UI的更新

通过`processUpdateLessonTimeStatus()`方法对当前的上课状态进行判断。结合这个判断结果，调用`updateLessonTimeStatus`方法对上课状态的UI进行更新。 网络更新则是通过`processUpdateNetworkDelay()` 来实现的。使用`adjustLessonNameTvWidth()`来适配课程名的宽度。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://polyv.gitbook.io/document/docs/live/android/63-hu-dong-xue-tang-chang-jing-zhuang-tai-lan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
