6_3-互动学堂场景-状态栏
1 Feature Overview
The status bar mainly includes features such as displaying the lesson number, current class status, lesson name display, and network latency. The class status includes not started, delayed, overtime, and ended. The status bar UI is encapsulated in PLVHCStatusBarLayout.
2 Usage Demo
To use the status bar module, simply add the PLVHCStatusBarLayout layout to the Activity layout and include the relevant layouts in the layout file.
<!-- 状态栏布局 -->
<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" />
Call the init method to initialize the status bar layout.
// 初始化状态栏布局
plvhcStatusBarLy.init(liveRoomDataManager);
You can call the methods defined in the interface to modify the status bar.
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 Implementation Details
PLVHCStatusBarLayout is the status bar layout for the interactive classroom scenario, implementing the IPLVHCStatusBarLayout interface.
3.1 Initializing the View Method
PLVHCStatusBarLayout inherits from FrameLayout and uses the initView method in the constructor to initialize the view.
//构造器
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 Initializing the Data Method
The init method of PLVHCStatusBarLayout is a public API, called once during initialization. It requires the external IPLVLiveRoomDataManager to be passed in for initialization.
@Override
public void init(IPLVLiveRoomDataManager liveRoomDataManager) {
this.liveRoomDataManager = liveRoomDataManager;
initLessonIdText(liveRoomDataManager);
observeLessonDataBean(liveRoomDataManager);
}
private void initLessonIdText(IPLVLiveRoomDataManager liveRoomDataManager) {
//初始化课节号信息
}
private void observeLessonDataBean(IPLVLiveRoomDataManager liveRoomDataManager) {
//监听数据变化
}
The above is the initialization method. The methods in the interface are then implemented in the public API.
3.3 Updating the Status Bar UI
The current class status is determined using the processUpdateLessonTimeStatus() method. Based on this result, the updateLessonTimeStatus method is called to update the class status UI. Network updates are implemented through processUpdateNetworkDelay(). The adjustLessonNameTvWidth() is used to adapt the width of the course name.
