fix: 状态栏固定在顶部,不随ViewPager2滑动
- 状态栏从两个子页面移到fragment_home.xml顶层 - ViewPager2在状态栏下方滑动 - HomeFragment只维护一个固定statusBar引用 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,8 +39,10 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
@Inject lateinit var eventBus: EventBus
|
||||
@Inject lateinit var taskApi: TaskApi
|
||||
|
||||
// ===== 固定状态栏(不随 ViewPager 滑动) =====
|
||||
private lateinit var statusBar: StatusBarView
|
||||
|
||||
// ===== 主页 View 引用 =====
|
||||
private lateinit var mainStatusBar: StatusBarView
|
||||
private lateinit var tvClock: TextView
|
||||
private lateinit var tvDate: TextView
|
||||
private lateinit var tvPoolNum: TextView
|
||||
@@ -48,7 +50,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
private lateinit var tvCompleteNum: TextView
|
||||
|
||||
// ===== 设置页 View 引用 =====
|
||||
private lateinit var configStatusBar: StatusBarView
|
||||
private lateinit var tvAvatarLetter: TextView
|
||||
private lateinit var tvUserName: TextView
|
||||
private lateinit var tvUserPhone: TextView
|
||||
@@ -64,6 +65,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// 绑定固定状态栏(不随 ViewPager 滑动)
|
||||
statusBar = binding.statusBar
|
||||
|
||||
// 创建两个页面 View
|
||||
val inflater = LayoutInflater.from(requireContext())
|
||||
val configPage = inflater.inflate(R.layout.page_config, null)
|
||||
@@ -96,7 +100,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
|
||||
/** 绑定主页 View 引用 */
|
||||
private fun bindMainViews(page: View) {
|
||||
mainStatusBar = page.findViewById(R.id.statusBar)
|
||||
tvClock = page.findViewById(R.id.tvClock)
|
||||
tvDate = page.findViewById(R.id.tvDate)
|
||||
tvPoolNum = page.findViewById(R.id.tvPoolNum)
|
||||
@@ -161,7 +164,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
/** 绑定设置页 View 引用并直接填充数据 */
|
||||
private fun bindConfigViews(page: View) {
|
||||
configPageView = page
|
||||
configStatusBar = page.findViewById(R.id.statusBar)
|
||||
tvAvatarLetter = page.findViewById(R.id.tvAvatarLetter)
|
||||
tvUserName = page.findViewById(R.id.tvUserName)
|
||||
tvUserPhone = page.findViewById(R.id.tvUserPhone)
|
||||
@@ -225,15 +227,13 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
eventBus.events.collect { event ->
|
||||
when (event) {
|
||||
// 电量变化:更新两个状态栏
|
||||
// 电量变化:更新固定状态栏
|
||||
is AppEvent.BatteryChanged -> {
|
||||
mainStatusBar.updateBattery(event.level, event.isCharging)
|
||||
configStatusBar.updateBattery(event.level, event.isCharging)
|
||||
statusBar.updateBattery(event.level, event.isCharging)
|
||||
}
|
||||
// 蓝牙状态变化
|
||||
is AppEvent.BluetoothStateChanged -> {
|
||||
mainStatusBar.updateBluetooth(event.isOn)
|
||||
configStatusBar.updateBluetooth(event.isOn)
|
||||
statusBar.updateBluetooth(event.isOn)
|
||||
}
|
||||
// MQTT 消息
|
||||
is AppEvent.MqttMessageReceived -> {
|
||||
|
||||
Reference in New Issue
Block a user