瀏覽代碼

refactor: 将业务层Activity改为Fragment架构

- MainActivity改为容器Activity,统一管理Fragment切换和底部导航栏
- 创建5个业务Fragment:VehicleFragment、CommunityFragment、ServiceFragment、ShopFragment、UserFragment
- 删除5个业务Activity和MainFragment
- 重命名并修改布局文件,移除底部导航栏
- 实现权限请求接口,支持Fragment权限请求
- 更新AndroidManifest.xml,移除业务Activity声明
- 修复LoginActivity和RegisterActivity的导航目标
wangmeng 2 周之前
父節點
當前提交
99ca44fa1b
共有 22 個文件被更改,包括 1070 次插入2009 次删除
  1. 0 29
      app/src/main/AndroidManifest.xml
  2. 124 11
      app/src/main/java/com/narutohuo/xindazhou/MainActivity.kt
  3. 0 63
      app/src/main/java/com/narutohuo/xindazhou/MainFragment.kt
  4. 2 2
      app/src/main/java/com/narutohuo/xindazhou/auth/ui/login/LoginActivity.kt
  5. 2 2
      app/src/main/java/com/narutohuo/xindazhou/auth/ui/register/RegisterActivity.kt
  6. 15 55
      app/src/main/java/com/narutohuo/xindazhou/community/ui/CommunityActivity.kt
  7. 0 74
      app/src/main/java/com/narutohuo/xindazhou/service/ui/ServiceActivity.kt
  8. 34 0
      app/src/main/java/com/narutohuo/xindazhou/service/ui/ServiceFragment.kt
  9. 17 57
      app/src/main/java/com/narutohuo/xindazhou/shop/ui/ShopActivity.kt
  10. 17 56
      app/src/main/java/com/narutohuo/xindazhou/user/ui/UserActivity.kt
  11. 184 209
      app/src/main/java/com/narutohuo/xindazhou/vehicle/ui/VehicleActivity.kt
  12. 20 4
      app/src/main/res/layout/activity_main.xml
  13. 0 744
      app/src/main/res/layout/activity_vehicle.xml
  14. 1 14
      app/src/main/res/layout/activity_community.xml
  15. 0 21
      app/src/main/res/layout/fragment_main.xml
  16. 1 14
      app/src/main/res/layout/activity_service.xml
  17. 1 14
      app/src/main/res/layout/activity_shop.xml
  18. 1 14
      app/src/main/res/layout/activity_user.xml
  19. 575 569
      app/src/main/res/layout/fragment_vehicle.xml
  20. 62 1
      base-core/src/main/java/com/mooxygen/user/wxapi/WXEntryActivity.kt
  21. 4 11
      capability-share/src/main/java/com/narutohuo/xindazhou/share/callback/ShareCallback.kt
  22. 10 45
      capability-share/src/main/java/com/narutohuo/xindazhou/share/ui/ShareProxyActivity.kt

+ 0 - 29
app/src/main/AndroidManifest.xml

@@ -86,35 +86,6 @@
             android:exported="false"
             android:theme="@style/Theme.XinDaZhou" />
         
-        <!-- 用户模块 Activity -->
-        <activity
-            android:name="com.narutohuo.xindazhou.user.ui.UserActivity"
-            android:exported="false"
-            android:theme="@style/Theme.XinDaZhou" />
-        
-        <!-- 车辆模块 Activity -->
-        <activity
-            android:name="com.narutohuo.xindazhou.vehicle.ui.VehicleActivity"
-            android:exported="false"
-            android:theme="@style/Theme.XinDaZhou" />
-        
-        <!-- 商城模块 Activity -->
-        <activity
-            android:name="com.narutohuo.xindazhou.shop.ui.ShopActivity"
-            android:exported="false"
-            android:theme="@style/Theme.XinDaZhou" />
-        
-        <!-- 社区模块 Activity -->
-        <activity
-            android:name="com.narutohuo.xindazhou.community.ui.CommunityActivity"
-            android:exported="false"
-            android:theme="@style/Theme.XinDaZhou" />
-        
-        <!-- 服务模块 Activity -->
-        <activity
-            android:name="com.narutohuo.xindazhou.service.ui.ServiceActivity"
-            android:exported="false"
-            android:theme="@style/Theme.XinDaZhou" />
         
         <!-- LogcatViewer Activity(日志查看器) -->
         <!-- singleTask 确保只有一个实例,多次启动会复用同一个 Activity -->

+ 124 - 11
app/src/main/java/com/narutohuo/xindazhou/MainActivity.kt

@@ -1,35 +1,62 @@
 package com.narutohuo.xindazhou
 
-import android.content.Intent
 import android.os.Bundle
+import androidx.activity.result.contract.ActivityResultContracts
 import androidx.core.view.WindowCompat
 import androidx.core.view.WindowInsetsControllerCompat
-import com.narutohuo.xindazhou.core.log.ILog
+import androidx.fragment.app.Fragment
 import com.narutohuo.xindazhou.common.ui.BaseActivity
 import com.narutohuo.xindazhou.common.version.VersionUpdateManager
 import com.narutohuo.xindazhou.databinding.ActivityMainBinding
+import com.narutohuo.xindazhou.R
+import com.narutohuo.xindazhou.community.ui.CommunityFragment
+import com.narutohuo.xindazhou.service.ui.ServiceFragment
+import com.narutohuo.xindazhou.shop.ui.ShopFragment
+import com.narutohuo.xindazhou.user.ui.UserFragment
+import com.narutohuo.xindazhou.vehicle.ui.PermissionRequestHandler
+import com.narutohuo.xindazhou.vehicle.ui.VehicleFragment
 
 /**
- * 主界面 Activity(架构A:每个页面一个Activity)
+ * 主界面 Activity(容器Activity,管理Fragment切换
  * 
  * 职责:
- * 1. 作为应用的启动 Activity,包含底部导航栏和 MainFragment
- * 2. 点击底部导航栏时跳转到对应的业务模块 Activity
+ * 1. 作为应用的启动 Activity,包含底部导航栏和Fragment容器
+ * 2. 点击底部导航栏时切换对应的业务Fragment
  * 3. 版本检查(启动时检查是否有新版本)
+ * 4. 统一管理Fragment切换和回退栈
  * 
  * 注意:
- * - MainActivity 显示 MainFragment 作为主页内
- * - 底部导航栏用于在不同业务模块之间切换
- * - 点击底部导航栏时,跳转到对应的 Activity(VehicleActivity, ShopActivity等)
+ * - MainActivity 作为容器Activity,统一管理底部导航栏
+ * - 所有业务模块都是Fragment,通过FragmentTransaction切换
+ * - 默认显示VehicleFragment
  */
-class MainActivity : BaseActivity<ActivityMainBinding>() {
+class MainActivity : BaseActivity<ActivityMainBinding>(), PermissionRequestHandler {
     
     private val TAG = "MainActivity"
     
+    // 权限请求回调
+    private var permissionCallback: ((Map<String, Boolean>) -> Unit)? = null
+    
+    // 权限请求器
+    private val permissionLauncher = registerForActivityResult(
+        ActivityResultContracts.RequestMultiplePermissions()
+    ) { permissions ->
+        permissionCallback?.invoke(permissions)
+        permissionCallback = null
+    }
+    
     override fun getViewBinding(): ActivityMainBinding {
         return ActivityMainBinding.inflate(layoutInflater)
     }
     
+    override fun requestPermissions(
+        permissions: Array<String>,
+        callback: (Map<String, Boolean>) -> Unit
+    ) {
+        permissionCallback = callback
+        permissionLauncher.launch(permissions)
+    }
+    
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         
@@ -38,6 +65,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
         
         // 版本检查(独立处理,不影响页面显示)
         VersionUpdateManager.checkUpdate(this)
+        
+        // 初始化Fragment(如果savedInstanceState为null,说明是首次创建)
+        if (savedInstanceState == null) {
+            // 默认显示VehicleFragment
+            switchFragment(VehicleFragment(), false)
+        }
     }
     
     /**
@@ -58,8 +91,88 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
     }
     
     override fun initView() {
-        // MainFragment 中已经处理了底部导航栏的点击事件
-        // 这里不需要额外处理
+        // 设置底部导航栏
+        setupBottomNavigation()
+    }
+    
+    /**
+     * 设置底部导航栏
+     */
+    private fun setupBottomNavigation() {
+        // 设置默认选中项(车辆)
+        binding.bottomNavView.selectedItemId = R.id.vehicleFragment
+        
+        binding.bottomNavView.setOnItemSelectedListener { item ->
+            when (item.itemId) {
+                R.id.vehicleFragment -> {
+                    switchFragment(VehicleFragment())
+                    true
+                }
+                R.id.communityFragment -> {
+                    switchFragment(CommunityFragment())
+                    true
+                }
+                R.id.serviceFragment -> {
+                    switchFragment(ServiceFragment())
+                    true
+                }
+                R.id.shopFragment -> {
+                    switchFragment(ShopFragment())
+                    true
+                }
+                R.id.userFragment -> {
+                    switchFragment(UserFragment())
+                    true
+                }
+                else -> false
+            }
+        }
+    }
+    
+    /**
+     * 切换Fragment
+     * @param fragment 要显示的Fragment
+     * @param addToBackStack 是否添加到回退栈(默认true)
+     */
+    private fun switchFragment(fragment: Fragment, addToBackStack: Boolean = true) {
+        val transaction = supportFragmentManager.beginTransaction()
+            .replace(R.id.fragmentContainer, fragment)
+        
+        if (addToBackStack) {
+            transaction.addToBackStack(null)
+        }
+        
+        transaction.commit()
+    }
+    
+    /**
+     * 处理返回键
+     * 如果Fragment回退栈中有Fragment,则返回上一个Fragment
+     * 否则退出应用
+     */
+    @Deprecated("Deprecated in Java")
+    override fun onBackPressed() {
+        if (supportFragmentManager.backStackEntryCount > 1) {
+            supportFragmentManager.popBackStack()
+            // 更新底部导航栏选中状态
+            updateBottomNavigationSelection()
+        } else {
+            super.onBackPressed()
+        }
+    }
+    
+    /**
+     * 更新底部导航栏选中状态(根据当前Fragment)
+     */
+    private fun updateBottomNavigationSelection() {
+        val currentFragment = supportFragmentManager.findFragmentById(R.id.fragmentContainer)
+        when (currentFragment) {
+            is VehicleFragment -> binding.bottomNavView.selectedItemId = R.id.vehicleFragment
+            is CommunityFragment -> binding.bottomNavView.selectedItemId = R.id.communityFragment
+            is ServiceFragment -> binding.bottomNavView.selectedItemId = R.id.serviceFragment
+            is ShopFragment -> binding.bottomNavView.selectedItemId = R.id.shopFragment
+            is UserFragment -> binding.bottomNavView.selectedItemId = R.id.userFragment
+        }
     }
 }
 

+ 0 - 63
app/src/main/java/com/narutohuo/xindazhou/MainFragment.kt

@@ -1,63 +0,0 @@
-package com.narutohuo.xindazhou
-
-import android.content.Intent
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import androidx.fragment.app.Fragment
-import com.narutohuo.xindazhou.community.ui.CommunityActivity
-import com.narutohuo.xindazhou.service.ui.ServiceActivity
-import com.narutohuo.xindazhou.shop.ui.ShopActivity
-import com.narutohuo.xindazhou.user.ui.UserActivity
-import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
-import com.google.android.material.bottomnavigation.BottomNavigationView
-
-/**
- * 主界面 Fragment
- * 
- * 包含底部导航栏,点击跳转到对应的 Activity
- */
-class MainFragment : Fragment() {
-
-    override fun onCreateView(
-        inflater: LayoutInflater,
-        container: ViewGroup?,
-        savedInstanceState: Bundle?
-    ): View? {
-        val view = inflater.inflate(R.layout.fragment_main, container, false)
-        
-        val bottomNavView = view.findViewById<BottomNavigationView>(R.id.bottomNavView)
-        bottomNavView.setOnItemSelectedListener { item ->
-            when (item.itemId) {
-                R.id.vehicleFragment -> {
-                    startActivity(Intent(requireContext(), VehicleActivity::class.java))
-                    true
-                }
-                R.id.communityFragment -> {
-                    startActivity(Intent(requireContext(), CommunityActivity::class.java))
-                    true
-                }
-                R.id.serviceFragment -> {
-                    startActivity(Intent(requireContext(), ServiceActivity::class.java))
-                    true
-                }
-                R.id.shopFragment -> {
-                    startActivity(Intent(requireContext(), ShopActivity::class.java))
-                    true
-                }
-                R.id.userFragment -> {
-                    startActivity(Intent(requireContext(), UserActivity::class.java))
-                    true
-                }
-                else -> false
-            }
-        }
-        
-        // 设置默认选中项
-        bottomNavView.selectedItemId = R.id.vehicleFragment
-        
-        return view
-    }
-}
-

+ 2 - 2
app/src/main/java/com/narutohuo/xindazhou/auth/ui/login/LoginActivity.kt

@@ -16,7 +16,7 @@ import com.narutohuo.xindazhou.socketio.SocketIOManager
 import com.narutohuo.xindazhou.auth.ui.viewmodel.LoginViewModel
 import com.narutohuo.xindazhou.auth.ui.viewmodel.LoginViewModelFactory
 import com.narutohuo.xindazhou.auth.ui.viewmodel.LoginState
-import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
+import com.narutohuo.xindazhou.MainActivity
 import kotlinx.coroutines.launch
 
 /**
@@ -121,7 +121,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
     // ==================== 导航方法 ====================
     
     private fun navigateToMain() {
-        startActivity(Intent(this, VehicleActivity::class.java))
+        startActivity(Intent(this, MainActivity::class.java))
         finish()
     }
     

+ 2 - 2
app/src/main/java/com/narutohuo/xindazhou/auth/ui/register/RegisterActivity.kt

@@ -15,7 +15,7 @@ import com.narutohuo.xindazhou.socketio.SocketIOManager
 import com.narutohuo.xindazhou.auth.ui.viewmodel.RegisterViewModel
 import com.narutohuo.xindazhou.auth.ui.viewmodel.RegisterViewModelFactory
 import com.narutohuo.xindazhou.auth.ui.viewmodel.RegisterState
-import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
+import com.narutohuo.xindazhou.MainActivity
 import kotlinx.coroutines.launch
 
 /**
@@ -121,7 +121,7 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
     // ==================== 导航方法 ====================
     
     private fun navigateToMain() {
-        startActivity(Intent(this, VehicleActivity::class.java))
+        startActivity(Intent(this, MainActivity::class.java))
         finish()
     }
     

+ 15 - 55
app/src/main/java/com/narutohuo/xindazhou/community/ui/CommunityActivity.kt

@@ -1,44 +1,40 @@
 package com.narutohuo.xindazhou.community.ui
 
-import android.content.Intent
 import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
 import android.widget.Button
 import android.widget.LinearLayout
 import android.widget.TextView
 import android.widget.Toast
-import com.narutohuo.xindazhou.R
-import com.narutohuo.xindazhou.common.ui.BaseActivity
-import com.narutohuo.xindazhou.databinding.ActivityCommunityBinding
+import com.narutohuo.xindazhou.common.ui.BaseFragment
+import com.narutohuo.xindazhou.databinding.FragmentCommunityBinding
 import com.narutohuo.xindazhou.qrcode.factory.QRCodeManagerFactory
-import com.narutohuo.xindazhou.service.ui.ServiceActivity
-import com.narutohuo.xindazhou.shop.ui.ShopActivity
-import com.narutohuo.xindazhou.user.ui.UserActivity
-import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
 
 /**
- * 社区 Activity
+ * 社区 Fragment
  * 
- * 架构A:每个页面一个Activity
  * 显示社区相关功能
  */
-class CommunityActivity : BaseActivity<ActivityCommunityBinding>() {
+class CommunityFragment : BaseFragment<FragmentCommunityBinding>() {
     
     private val qrCodeManager = QRCodeManagerFactory.getInstance()
     
-    override fun getViewBinding(): ActivityCommunityBinding {
-        return ActivityCommunityBinding.inflate(layoutInflater)
+    override fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentCommunityBinding {
+        return FragmentCommunityBinding.inflate(inflater, container, false)
     }
     
     override fun initView() {
         // 创建布局
-        val layout = LinearLayout(this).apply {
+        val layout = LinearLayout(requireContext()).apply {
             orientation = LinearLayout.VERTICAL
             gravity = android.view.Gravity.CENTER
             setPadding(32, 32, 32, 32)
         }
 
         // 标题
-        val textView = TextView(this).apply {
+        val textView = TextView(requireContext()).apply {
             text = "社区页面"
             textSize = 18f
             gravity = android.view.Gravity.CENTER
@@ -52,7 +48,7 @@ class CommunityActivity : BaseActivity<ActivityCommunityBinding>() {
         layout.addView(textView)
 
         // 扫码按钮
-        val scanButton = Button(this).apply {
+        val scanButton = Button(requireContext()).apply {
             text = "扫码"
             layoutParams = LinearLayout.LayoutParams(
                 LinearLayout.LayoutParams.WRAP_CONTENT,
@@ -67,20 +63,17 @@ class CommunityActivity : BaseActivity<ActivityCommunityBinding>() {
         // 将内容添加到布局中
         binding.contentContainer.removeAllViews()
         binding.contentContainer.addView(layout)
-        
-        // 设置底部导航栏
-        setupBottomNavigation()
     }
     
     /**
      * 开始扫码
      */
     private fun startScanQRCode() {
-        qrCodeManager.scanQRCode(this) { response ->
+        qrCodeManager.scanQRCode(requireActivity()) { response ->
             if (response.success) {
                 val qrCodeContent = response.data
                 Toast.makeText(
-                    this,
+                    requireContext(),
                     "扫码成功:$qrCodeContent",
                     Toast.LENGTH_SHORT
                 ).show()
@@ -89,7 +82,7 @@ class CommunityActivity : BaseActivity<ActivityCommunityBinding>() {
                 val error = response.errorMessage
                 if (error != null) {
                     Toast.makeText(
-                        this,
+                        requireContext(),
                         "扫码失败:$error",
                         Toast.LENGTH_SHORT
                     ).show()
@@ -97,38 +90,5 @@ class CommunityActivity : BaseActivity<ActivityCommunityBinding>() {
             }
         }
     }
-    
-    private fun setupBottomNavigation() {
-        binding.bottomNavView.selectedItemId = R.id.communityFragment
-        binding.bottomNavView.setOnItemSelectedListener { item ->
-            when (item.itemId) {
-                R.id.vehicleFragment -> {
-                    startActivity(Intent(this, VehicleActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.communityFragment -> {
-                    // 当前已在社区模块,不需要跳转
-                    true
-                }
-                R.id.serviceFragment -> {
-                    startActivity(Intent(this, ServiceActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.shopFragment -> {
-                    startActivity(Intent(this, ShopActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.userFragment -> {
-                    startActivity(Intent(this, UserActivity::class.java))
-                    finish()
-                    true
-                }
-                else -> false
-            }
-        }
-    }
 }
 

+ 0 - 74
app/src/main/java/com/narutohuo/xindazhou/service/ui/ServiceActivity.kt

@@ -1,74 +0,0 @@
-package com.narutohuo.xindazhou.service.ui
-
-import android.content.Intent
-import android.os.Bundle
-import android.widget.TextView
-import com.narutohuo.xindazhou.R
-import com.narutohuo.xindazhou.common.ui.BaseActivity
-import com.narutohuo.xindazhou.databinding.ActivityServiceBinding
-import com.narutohuo.xindazhou.community.ui.CommunityActivity
-import com.narutohuo.xindazhou.shop.ui.ShopActivity
-import com.narutohuo.xindazhou.user.ui.UserActivity
-import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
-
-/**
- * 服务 Activity
- * 
- * 架构A:每个页面一个Activity
- * 显示服务相关功能
- */
-class ServiceActivity : BaseActivity<ActivityServiceBinding>() {
-    
-    override fun getViewBinding(): ActivityServiceBinding {
-        return ActivityServiceBinding.inflate(layoutInflater)
-    }
-    
-    override fun initView() {
-        // 设置内容
-        val textView = TextView(this)
-        textView.text = "服务页面\n(待实现)"
-        textView.textSize = 18f
-        textView.gravity = android.view.Gravity.CENTER
-        
-        // 将内容添加到布局中
-        binding.contentContainer.removeAllViews()
-        binding.contentContainer.addView(textView)
-        
-        // 设置底部导航栏
-        setupBottomNavigation()
-    }
-    
-    private fun setupBottomNavigation() {
-        binding.bottomNavView.selectedItemId = R.id.serviceFragment
-        binding.bottomNavView.setOnItemSelectedListener { item ->
-            when (item.itemId) {
-                R.id.vehicleFragment -> {
-                    startActivity(Intent(this, VehicleActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.communityFragment -> {
-                    startActivity(Intent(this, CommunityActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.serviceFragment -> {
-                    // 当前已在服务模块,不需要跳转
-                    true
-                }
-                R.id.shopFragment -> {
-                    startActivity(Intent(this, ShopActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.userFragment -> {
-                    startActivity(Intent(this, UserActivity::class.java))
-                    finish()
-                    true
-                }
-                else -> false
-            }
-        }
-    }
-}
-

+ 34 - 0
app/src/main/java/com/narutohuo/xindazhou/service/ui/ServiceFragment.kt

@@ -0,0 +1,34 @@
+package com.narutohuo.xindazhou.service.ui
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import com.narutohuo.xindazhou.common.ui.BaseFragment
+import com.narutohuo.xindazhou.databinding.FragmentServiceBinding
+
+/**
+ * 服务 Fragment
+ * 
+ * 显示服务相关功能
+ */
+class ServiceFragment : BaseFragment<FragmentServiceBinding>() {
+    
+    override fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentServiceBinding {
+        return FragmentServiceBinding.inflate(inflater, container, false)
+    }
+    
+    override fun initView() {
+        // 设置内容
+        val textView = TextView(requireContext())
+        textView.text = "服务页面\n(待实现)"
+        textView.textSize = 18f
+        textView.gravity = android.view.Gravity.CENTER
+        
+        // 将内容添加到布局中
+        binding.contentContainer.removeAllViews()
+        binding.contentContainer.addView(textView)
+    }
+}
+

+ 17 - 57
app/src/main/java/com/narutohuo/xindazhou/shop/ui/ShopActivity.kt

@@ -1,46 +1,42 @@
 package com.narutohuo.xindazhou.shop.ui
 
-import android.content.Intent
 import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
 import android.widget.Button
 import android.widget.LinearLayout
 import android.widget.TextView
 import android.widget.Toast
-import com.narutohuo.xindazhou.R
-import com.narutohuo.xindazhou.common.ui.BaseActivity
+import com.narutohuo.xindazhou.common.ui.BaseFragment
 import com.narutohuo.xindazhou.core.log.ILog
-import com.narutohuo.xindazhou.databinding.ActivityShopBinding
-import com.narutohuo.xindazhou.community.ui.CommunityActivity
-import com.narutohuo.xindazhou.service.ui.ServiceActivity
+import com.narutohuo.xindazhou.databinding.FragmentShopBinding
 import com.narutohuo.xindazhou.share.ShareKit
 import com.narutohuo.xindazhou.share.model.ShareContent
-import com.narutohuo.xindazhou.user.ui.UserActivity
-import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
 
 /**
- * 商城 Activity
+ * 商城 Fragment
  * 
- * 架构A:每个页面一个Activity
  * 显示商城相关功能
  */
-class ShopActivity : BaseActivity<ActivityShopBinding>() {
+class ShopFragment : BaseFragment<FragmentShopBinding>() {
     
-    private val tag = "ShopActivity"
+    private val tag = "ShopFragment"
     
-    override fun getViewBinding(): ActivityShopBinding {
-        return ActivityShopBinding.inflate(layoutInflater)
+    override fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentShopBinding {
+        return FragmentShopBinding.inflate(inflater, container, false)
     }
     
     override fun initView() {
         // 创建布局
-        val layout = LinearLayout(this).apply {
+        val layout = LinearLayout(requireContext()).apply {
             orientation = LinearLayout.VERTICAL
             gravity = android.view.Gravity.CENTER
             setPadding(32, 32, 32, 32)
         }
 
         // 标题
-        val textView = TextView(this).apply {
+        val textView = TextView(requireContext()).apply {
             text = "商城页面"
             textSize = 18f
             gravity = android.view.Gravity.CENTER
@@ -54,7 +50,7 @@ class ShopActivity : BaseActivity<ActivityShopBinding>() {
         layout.addView(textView)
 
         // 分享按钮
-        val shareButton = Button(this).apply {
+        val shareButton = Button(requireContext()).apply {
             text = "分享"
             layoutParams = LinearLayout.LayoutParams(
                 LinearLayout.LayoutParams.WRAP_CONTENT,
@@ -69,9 +65,6 @@ class ShopActivity : BaseActivity<ActivityShopBinding>() {
         // 将内容添加到布局中
         binding.contentContainer.removeAllViews()
         binding.contentContainer.addView(layout)
-        
-        // 设置底部导航栏
-        setupBottomNavigation()
     }
     
     /**
@@ -90,53 +83,20 @@ class ShopActivity : BaseActivity<ActivityShopBinding>() {
                 .build()
             
             // 调用分享(不指定平台,会显示分享弹窗)
-            shareService.share(this, shareContent) { response ->
+            shareService.share(requireActivity(), shareContent) { response ->
                 if (response.success) {
                     val platformName = response.data?.name ?: "未知平台"
-                    Toast.makeText(this, "分享成功:$platformName", Toast.LENGTH_SHORT).show()
+                    Toast.makeText(requireContext(), "分享成功:$platformName", Toast.LENGTH_SHORT).show()
                     ILog.d(tag, "分享成功:$platformName")
                 } else {
                     val errorMsg = response.errorMessage ?: "分享失败"
-                    Toast.makeText(this, errorMsg, Toast.LENGTH_SHORT).show()
+                    Toast.makeText(requireContext(), errorMsg, Toast.LENGTH_SHORT).show()
                     ILog.e(tag, "分享失败:$errorMsg")
                 }
             }
         } catch (e: Exception) {
             ILog.e(tag, "分享功能异常", e)
-            Toast.makeText(this, "分享功能异常:${e.message}", Toast.LENGTH_SHORT).show()
-        }
-    }
-    
-    private fun setupBottomNavigation() {
-        binding.bottomNavView.selectedItemId = R.id.shopFragment
-        binding.bottomNavView.setOnItemSelectedListener { item ->
-            when (item.itemId) {
-                R.id.vehicleFragment -> {
-                    startActivity(Intent(this, VehicleActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.communityFragment -> {
-                    startActivity(Intent(this, CommunityActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.serviceFragment -> {
-                    startActivity(Intent(this, ServiceActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.shopFragment -> {
-                    // 当前已在商城模块,不需要跳转
-                    true
-                }
-                R.id.userFragment -> {
-                    startActivity(Intent(this, UserActivity::class.java))
-                    finish()
-                    true
-                }
-                else -> false
-            }
+            Toast.makeText(requireContext(), "分享功能异常:${e.message}", Toast.LENGTH_SHORT).show()
         }
     }
 }

+ 17 - 56
app/src/main/java/com/narutohuo/xindazhou/user/ui/UserActivity.kt

@@ -1,32 +1,27 @@
 package com.narutohuo.xindazhou.user.ui
 
-import android.content.Intent
 import android.os.Bundle
+import android.view.LayoutInflater
 import android.view.View
+import android.view.ViewGroup
 import android.widget.TextView
 import android.widget.Toast
-import androidx.lifecycle.lifecycleScope
 import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.lifecycleScope
 import com.google.android.material.button.MaterialButton
-import com.narutohuo.xindazhou.R
-import com.narutohuo.xindazhou.common.ui.BaseActivity
-import com.narutohuo.xindazhou.databinding.ActivityUserBinding
+import com.narutohuo.xindazhou.common.ui.BaseFragment
+import com.narutohuo.xindazhou.databinding.FragmentUserBinding
 import com.narutohuo.xindazhou.databinding.FragmentUserSocketTestBinding
-import com.narutohuo.xindazhou.community.ui.CommunityActivity
-import com.narutohuo.xindazhou.service.ui.ServiceActivity
-import com.narutohuo.xindazhou.shop.ui.ShopActivity
 import com.narutohuo.xindazhou.user.ui.viewmodel.UserViewModel
 import com.narutohuo.xindazhou.user.ui.viewmodel.UserViewModelFactory
-import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
 import kotlinx.coroutines.launch
 
 /**
- * 用户 Activity
+ * 用户 Fragment
  * 
- * 架构A:每个页面一个Activity
  * 包含 SocketIO 测试功能
  */
-class UserActivity : BaseActivity<ActivityUserBinding>() {
+class UserFragment : BaseFragment<FragmentUserBinding>() {
     
     private lateinit var viewModel: UserViewModel
     private lateinit var contentBinding: FragmentUserSocketTestBinding
@@ -36,17 +31,17 @@ class UserActivity : BaseActivity<ActivityUserBinding>() {
     private lateinit var btnFindVehicle: MaterialButton
     private lateinit var tvLog: TextView
     
-    override fun getViewBinding(): ActivityUserBinding {
-        return ActivityUserBinding.inflate(layoutInflater)
+    override fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentUserBinding {
+        return FragmentUserBinding.inflate(inflater, container, false)
     }
     
-    override fun onCreate(savedInstanceState: Bundle?) {
-        super.onCreate(savedInstanceState)
+    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+        super.onViewCreated(view, savedInstanceState)
         
         // 初始化 ViewModel
-        viewModel = androidx.lifecycle.ViewModelProvider(
-            this,
-            UserViewModelFactory(application)
+        viewModel = ViewModelProvider(
+            requireActivity(),
+            UserViewModelFactory(requireActivity().application)
         )[UserViewModel::class.java]
         
         // 初始化内容布局
@@ -60,8 +55,7 @@ class UserActivity : BaseActivity<ActivityUserBinding>() {
     }
     
     override fun initView() {
-        // 设置底部导航栏
-        setupBottomNavigation()
+        // UI初始化在onViewCreated中完成
     }
     
     private fun initViews() {
@@ -111,7 +105,7 @@ class UserActivity : BaseActivity<ActivityUserBinding>() {
         lifecycleScope.launch {
             viewModel.alarmMessage.collect { alarm ->
                 alarm?.let {
-                    Toast.makeText(this@UserActivity, "收到车辆报警!", Toast.LENGTH_LONG).show()
+                    Toast.makeText(requireContext(), "收到车辆报警!", Toast.LENGTH_LONG).show()
                 }
             }
         }
@@ -124,44 +118,11 @@ class UserActivity : BaseActivity<ActivityUserBinding>() {
         lifecycleScope.launch {
             viewModel.errorMessage.collect { error ->
                 error?.let {
-                    Toast.makeText(this@UserActivity, error, Toast.LENGTH_SHORT).show()
+                    Toast.makeText(requireContext(), error, Toast.LENGTH_SHORT).show()
                     viewModel.clearErrorMessage()
                 }
             }
         }
     }
-    
-    private fun setupBottomNavigation() {
-        binding.bottomNavView.selectedItemId = R.id.userFragment
-        binding.bottomNavView.setOnItemSelectedListener { item ->
-            when (item.itemId) {
-                R.id.vehicleFragment -> {
-                    startActivity(Intent(this, VehicleActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.communityFragment -> {
-                    startActivity(Intent(this, CommunityActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.serviceFragment -> {
-                    startActivity(Intent(this, ServiceActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.shopFragment -> {
-                    startActivity(Intent(this, ShopActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.userFragment -> {
-                    // 当前已在用户模块,不需要跳转
-                    true
-                }
-                else -> false
-            }
-        }
-    }
 }
 

+ 184 - 209
app/src/main/java/com/narutohuo/xindazhou/vehicle/ui/VehicleActivity.kt

@@ -1,19 +1,19 @@
 package com.narutohuo.xindazhou.vehicle.ui
 
 import android.Manifest
-import android.content.Intent
 import android.content.pm.PackageManager
 import android.os.Build
 import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
 import android.widget.Button
 import android.widget.EditText
 import android.widget.RadioButton
 import android.widget.Switch
 import android.widget.TextView
 import android.widget.Toast
-import androidx.activity.result.contract.ActivityResultContracts
 import androidx.core.content.ContextCompat
-import com.google.android.material.bottomnavigation.BottomNavigationView
 import com.narutohuo.xindazhou.R
 import com.narutohuo.xindazhou.ble.api.IBLE
 import com.narutohuo.xindazhou.ble.config.BLEConstants
@@ -21,22 +21,16 @@ import com.narutohuo.xindazhou.ble.BLEKit
 import com.narutohuo.xindazhou.ble.model.BLECommand
 import com.narutohuo.xindazhou.ble.model.SystemControlInstruction
 import com.narutohuo.xindazhou.ble.util.toHexString
-import com.narutohuo.xindazhou.common.ui.BaseActivity
+import com.narutohuo.xindazhou.common.ui.BaseFragment
 import com.narutohuo.xindazhou.core.log.ILog
-import com.narutohuo.xindazhou.databinding.ActivityVehicleBinding
-import com.narutohuo.xindazhou.community.ui.CommunityActivity
-import com.narutohuo.xindazhou.service.ui.ServiceActivity
-import com.narutohuo.xindazhou.shop.ui.ShopActivity
-import com.narutohuo.xindazhou.user.ui.UserActivity
+import com.narutohuo.xindazhou.databinding.FragmentVehicleBinding
 import kotlin.OptIn
 import kotlin.ExperimentalStdlibApi
 import java.nio.ByteBuffer
 import java.nio.ByteOrder
 
 /**
- * 车辆控制 Activity
- * 
- * 架构A:每个页面一个Activity
+ * 车辆控制 Fragment
  * 
  * 主要功能:
  * 1. 蓝牙连接管理
@@ -45,7 +39,7 @@ import java.nio.ByteOrder
  * 4. 系统控制(各种开关、时间设置、氛围灯等)
  * 5. 系统设置(钥匙学码、灵敏度、报警设置等)
  */
-class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
+class VehicleFragment : BaseFragment<FragmentVehicleBinding>() {
     
     // 蓝牙服务
     private lateinit var bleService: IBLE
@@ -112,53 +106,39 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
     private lateinit var switchAlarmReport: Switch
     private lateinit var btnSetTiltAlarmThreshold: Button
 
-    // 权限请求器
-    private val permissionLauncher = registerForActivityResult(
-        ActivityResultContracts.RequestMultiplePermissions()
-    ) { permissions ->
-        val allGranted = permissions.all { it.value }
-        if (allGranted) {
-            ILog.d("VehicleActivity", "✅ 所有权限已授予,开始连接设备")
-            performConnectToDevice()
-        } else {
-            val deniedPermissions = permissions.filter { !it.value }.keys.joinToString(", ")
-            ILog.e("VehicleActivity", "❌ 权限被拒绝: $deniedPermissions")
-            Toast.makeText(
-                this,
-                "需要蓝牙权限才能连接设备,请在设置中授予权限",
-                Toast.LENGTH_LONG
-            ).show()
-            btnConnectBluetooth.isEnabled = true
-            tvBluetoothStatus.text = "权限被拒绝"
-        }
+    override fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentVehicleBinding {
+        return FragmentVehicleBinding.inflate(inflater, container, false)
     }
 
-    override fun getViewBinding(): ActivityVehicleBinding {
-        return ActivityVehicleBinding.inflate(layoutInflater)
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View? {
+        // 初始化蓝牙服务
+        bleService = BLEKit.create(requireContext())
+        
+        return super.onCreateView(inflater, container, savedInstanceState)
     }
 
-    override fun onCreate(savedInstanceState: Bundle?) {
-        super.onCreate(savedInstanceState)
-        
-        // 初始化蓝牙服务
-        bleService = BLEKit.create(this)
+    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+        super.onViewCreated(view, savedInstanceState)
         
         initViews()
         setupClickListeners()
-        setupBottomNavigation()
         updateConnectionStatus()
     }
 
-    override fun onDestroy() {
-        super.onDestroy()
+    override fun onDestroyView() {
+        super.onDestroyView()
         // 断开连接
-        if (bleService.isConnected()) {
+        if (::bleService.isInitialized && bleService.isConnected()) {
             bleService.disconnect()
         }
     }
 
     override fun initView() {
-        // UI初始化在onCreate中完成
+        // UI初始化在onViewCreated中完成
     }
 
     private fun initViews() {
@@ -221,46 +201,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
     }
 
     /**
-     * 设置底部导航栏
-     */
-    private fun setupBottomNavigation() {
-        binding.bottomNavView.selectedItemId = R.id.vehicleFragment
-        binding.bottomNavView.setOnItemSelectedListener { item ->
-            when (item.itemId) {
-                R.id.vehicleFragment -> {
-                    // 当前已在车辆模块,不需要跳转
-                    true
-                }
-                R.id.communityFragment -> {
-                    startActivity(Intent(this, CommunityActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.serviceFragment -> {
-                    startActivity(Intent(this, ServiceActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.shopFragment -> {
-                    startActivity(Intent(this, ShopActivity::class.java))
-                    finish()
-                    true
-                }
-                R.id.userFragment -> {
-                    startActivity(Intent(this, UserActivity::class.java))
-                    finish()
-                    true
-                }
-                else -> false
-            }
-        }
-    }
-
-    /**
      * 更新连接状态显示
      */
     private fun updateConnectionStatus() {
-        if (bleService.isConnected()) {
+        if (::bleService.isInitialized && bleService.isConnected()) {
             tvBluetoothStatus.text = "蓝牙已连接"
             btnConnectBluetooth.text = "断开"
         } else {
@@ -272,13 +216,13 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
     private fun setupClickListeners() {
         // 蓝牙连接/断开
         btnConnectBluetooth.setOnClickListener {
-            Toast.makeText(this, "按钮被点击了", Toast.LENGTH_SHORT).show()
-            ILog.e("VehicleActivity", "🔴🔴🔴 按钮被点击了")
+            Toast.makeText(requireContext(), "按钮被点击了", Toast.LENGTH_SHORT).show()
+            ILog.e("VehicleFragment", "🔴🔴🔴 按钮被点击了")
             if (bleService.isConnected()) {
                 // 断开连接
                 bleService.disconnect()
                 updateConnectionStatus()
-                Toast.makeText(this, "已断开连接", Toast.LENGTH_SHORT).show()
+                Toast.makeText(requireContext(), "已断开连接", Toast.LENGTH_SHORT).show()
             } else {
                 // 一键扫描并连接
                 connectToDevice()
@@ -287,22 +231,22 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
 
         // 查询车辆信息
         btnQueryVehicleInfo.setOnClickListener {
-            ILog.d("VehicleActivity", "🟢 点击查询车辆信息按钮")
+            ILog.d("VehicleFragment", "🟢 点击查询车辆信息按钮")
             if (!checkConnection()) return@setOnClickListener
             
             bleService.queryVehicleInfo { response ->
-                ILog.d("VehicleActivity", "📥 查询车辆信息响应: success=${response.success}, error=${response.errorMessage}")
-                runOnUiThread {
+                ILog.d("VehicleFragment", "📥 查询车辆信息响应: success=${response.success}, error=${response.errorMessage}")
+                requireActivity().runOnUiThread {
                     if (response.success) {
                         val data = response.data
                         if (data != null) {
                             parseVehicleInfo(data)
-                            Toast.makeText(this@VehicleActivity, "查询成功", Toast.LENGTH_SHORT).show()
+                            Toast.makeText(requireContext(), "查询成功", Toast.LENGTH_SHORT).show()
                         } else {
-                            Toast.makeText(this@VehicleActivity, "查询失败: 数据为空", Toast.LENGTH_SHORT).show()
+                            Toast.makeText(requireContext(), "查询失败: 数据为空", Toast.LENGTH_SHORT).show()
                         }
                     } else {
-                        Toast.makeText(this@VehicleActivity, "查询失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "查询失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -312,19 +256,19 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
         // 设撤防
         btnDefense.setOnClickListener {
             val enabled = !isDefenseOn
-            ILog.d("VehicleActivity", "🟢 点击设撤防按钮: enabled=$enabled")
+            ILog.d("VehicleFragment", "🟢 点击设撤防按钮: enabled=$enabled")
             if (!checkConnection()) return@setOnClickListener
             
             isDefenseOn = enabled
             
             bleService.setDefense(enabled = enabled) { response ->
-                ILog.d("VehicleActivity", "📥 设撤防响应: success=${response.success}, error=${response.errorMessage}")
-                runOnUiThread {
+                ILog.d("VehicleFragment", "📥 设撤防响应: success=${response.success}, error=${response.errorMessage}")
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, if (enabled) "设防成功" else "撤防成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), if (enabled) "设防成功" else "撤防成功", Toast.LENGTH_SHORT).show()
                     } else {
                         isDefenseOn = !enabled // 恢复状态
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -332,20 +276,20 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
 
         // 上下电
         btnPower.setOnClickListener {
-            ILog.d("VehicleActivity", "🟢 点击上下电按钮: 当前状态 isPowerOn=$isPowerOn")
+            ILog.d("VehicleFragment", "🟢 点击上下电按钮: 当前状态 isPowerOn=$isPowerOn")
             if (!checkConnection()) return@setOnClickListener
             
             if (isPowerOn) {
                 // 下电
                 isPowerOn = false
                 bleService.powerOff { response ->
-                    ILog.d("VehicleActivity", "📥 下电响应: success=${response.success}, error=${response.errorMessage}")
-                    runOnUiThread {
+                    ILog.d("VehicleFragment", "📥 下电响应: success=${response.success}, error=${response.errorMessage}")
+                    requireActivity().runOnUiThread {
                         if (response.success) {
-                            Toast.makeText(this@VehicleActivity, "下电成功", Toast.LENGTH_SHORT).show()
+                            Toast.makeText(requireContext(), "下电成功", Toast.LENGTH_SHORT).show()
                         } else {
                             isPowerOn = true // 恢复状态
-                            Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                            Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                         }
                     }
                 }
@@ -353,13 +297,13 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
                 // 上电
                 isPowerOn = true
                 bleService.powerOn { response ->
-                    ILog.d("VehicleActivity", "📥 上电响应: success=${response.success}, error=${response.errorMessage}")
-                    runOnUiThread {
+                    ILog.d("VehicleFragment", "📥 上电响应: success=${response.success}, error=${response.errorMessage}")
+                    requireActivity().runOnUiThread {
                         if (response.success) {
-                            Toast.makeText(this@VehicleActivity, "上电成功", Toast.LENGTH_SHORT).show()
+                            Toast.makeText(requireContext(), "上电成功", Toast.LENGTH_SHORT).show()
                         } else {
                             isPowerOn = false // 恢复状态
-                            Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                            Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                         }
                     }
                 }
@@ -368,16 +312,16 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
 
         // 寻车
         btnFindCar.setOnClickListener {
-            ILog.d("VehicleActivity", "🟢 点击寻车按钮")
+            ILog.d("VehicleFragment", "🟢 点击寻车按钮")
             if (!checkConnection()) return@setOnClickListener
             
             bleService.findCar { response ->
-                ILog.d("VehicleActivity", "📥 寻车响应: success=${response.success}, error=${response.errorMessage}")
-                runOnUiThread {
+                ILog.d("VehicleFragment", "📥 寻车响应: success=${response.success}, error=${response.errorMessage}")
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "寻车成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "寻车成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "寻车失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "寻车失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -385,16 +329,16 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
 
         // 座桶锁
         btnSeatLock.setOnClickListener {
-            ILog.d("VehicleActivity", "🟢 点击座桶锁按钮")
+            ILog.d("VehicleFragment", "🟢 点击座桶锁按钮")
             if (!checkConnection()) return@setOnClickListener
             
             bleService.unlockSeat { response ->
-                ILog.d("VehicleActivity", "📥 座桶锁响应: success=${response.success}, error=${response.errorMessage}")
-                runOnUiThread {
+                ILog.d("VehicleFragment", "📥 座桶锁响应: success=${response.success}, error=${response.errorMessage}")
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "座桶锁已打开", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "座桶锁已打开", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -402,16 +346,16 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
 
         // 龙头锁
         btnHandlebarLock.setOnClickListener {
-            ILog.d("VehicleActivity", "🟢 点击车把锁按钮")
+            ILog.d("VehicleFragment", "🟢 点击车把锁按钮")
             if (!checkConnection()) return@setOnClickListener
             
             bleService.unlockHandlebar { response ->
-                ILog.d("VehicleActivity", "📥 车把锁响应: success=${response.success}, error=${response.errorMessage}")
-                runOnUiThread {
+                ILog.d("VehicleFragment", "📥 车把锁响应: success=${response.success}, error=${response.errorMessage}")
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "龙头锁已打开", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "龙头锁已打开", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -419,16 +363,16 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
 
         // 尾箱锁
         btnTrunkLock.setOnClickListener {
-            ILog.d("VehicleActivity", "🟢 点击尾箱锁按钮")
+            ILog.d("VehicleFragment", "🟢 点击尾箱锁按钮")
             if (!checkConnection()) return@setOnClickListener
             
             bleService.unlockTrunk { response ->
-                ILog.d("VehicleActivity", "📥 尾箱锁响应: success=${response.success}, error=${response.errorMessage}")
-                runOnUiThread {
+                ILog.d("VehicleFragment", "📥 尾箱锁响应: success=${response.success}, error=${response.errorMessage}")
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "尾箱锁已打开", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "尾箱锁已打开", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -443,10 +387,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             }
             
             bleService.setSensorUnlock(enabled = isChecked) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchInductionUnlock.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -461,10 +405,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.STOLEN_LOCK, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchTheftLock.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -479,10 +423,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.SEAT_SENSOR, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchSeatSensor.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -497,10 +441,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.SOUND_EFFECT, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchVehicleSound.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -515,10 +459,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.AUTO_HEADLIGHT, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchAutoHeadlight.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -532,10 +476,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             }
             
             bleService.setAmbientLight(enabled = isChecked) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchAtmosphereLight.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -550,10 +494,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.VOICE_BROADCAST, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchVoiceBroadcast.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -568,10 +512,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.WALK_ME_HOME, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchFollowMeHome.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -586,10 +530,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.ABS, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchABS.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -604,10 +548,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val action = if (isChecked) 0x01.toByte() else 0x00.toByte()
             bleService.sendSystemControlCommand(SystemControlInstruction.TCS, byteArrayOf(action)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchTCS.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -620,16 +564,16 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val time = etAutoPowerOffTime.text.toString().toIntOrNull() ?: 300
             if (time < 0 || time > 60000) {
-                Toast.makeText(this, "时间范围:0-60000秒", Toast.LENGTH_SHORT).show()
+                Toast.makeText(requireContext(), "时间范围:0-60000秒", Toast.LENGTH_SHORT).show()
                 return@setOnClickListener
             }
             
             bleService.setAutoPowerOffTime(timeSeconds = time) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -641,17 +585,17 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val time = etAutoDefenseTime.text.toString().toIntOrNull() ?: 5
             if (time < 0 || time > 60000) {
-                Toast.makeText(this, "时间范围:0-60000秒", Toast.LENGTH_SHORT).show()
+                Toast.makeText(requireContext(), "时间范围:0-60000秒", Toast.LENGTH_SHORT).show()
                 return@setOnClickListener
             }
             
             val data = ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putShort(time.toShort()).array()
             bleService.sendSystemControlCommand(SystemControlInstruction.AUTO_DEFENSE_TIME, data) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -663,17 +607,17 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val time = etEnterPTime.text.toString().toIntOrNull() ?: 300
             if (time < 0 || time > 60000) {
-                Toast.makeText(this, "时间范围:0-60000秒", Toast.LENGTH_SHORT).show()
+                Toast.makeText(requireContext(), "时间范围:0-60000秒", Toast.LENGTH_SHORT).show()
                 return@setOnClickListener
             }
             
             val data = ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putShort(time.toShort()).array()
             bleService.sendSystemControlCommand(SystemControlInstruction.ENTER_P_TIME, data) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -686,16 +630,16 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val volume = etBluetoothSpeakerVolume.text.toString().toIntOrNull() ?: 50
             if (volume < 0 || volume > 100) {
-                Toast.makeText(this, "音量范围:0-100%", Toast.LENGTH_SHORT).show()
+                Toast.makeText(requireContext(), "音量范围:0-100%", Toast.LENGTH_SHORT).show()
                 return@setOnClickListener
             }
             
             bleService.setSpeakerVolume(volume = volume) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -707,16 +651,16 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             
             val threshold = etLowBatteryThreshold.text.toString().toIntOrNull() ?: 20
             if (threshold < 0 || threshold > 100) {
-                Toast.makeText(this, "阈值范围:0-100%", Toast.LENGTH_SHORT).show()
+                Toast.makeText(requireContext(), "阈值范围:0-100%", Toast.LENGTH_SHORT).show()
                 return@setOnClickListener
             }
             
             bleService.sendSystemControlCommand(SystemControlInstruction.LOW_BATTERY_ALARM, byteArrayOf(threshold.toByte())) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -731,11 +675,11 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             val b = etAtmosphereLightB.text.toString().toIntOrNull()?.coerceIn(0, 255) ?: 255
             
             bleService.setAmbientLightColor(r = r, g = g, b = b) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -746,11 +690,11 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             if (!checkConnection()) return@setOnClickListener
             
             bleService.sendSystemControlCommand(SystemControlInstruction.RSSI_COLLECTION, byteArrayOf(0x01)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "RSSI采集成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "RSSI采集成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "采集失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "采集失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -761,11 +705,11 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             if (!checkConnection()) return@setOnClickListener
             
             bleService.sendSystemControlCommand(SystemControlInstruction.RESET_MILEAGE, byteArrayOf(0x01)) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "里程清零成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "里程清零成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -783,11 +727,11 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             )
             
             bleService.sendCommand(command) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "钥匙学码成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "钥匙学码成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -813,11 +757,11 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             )
             
             bleService.sendCommand(command) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -838,10 +782,10 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             )
             
             bleService.sendCommand(command) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (!response.success) {
                         switchAlarmReport.isChecked = !isChecked
-                        Toast.makeText(this@VehicleActivity, "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "操作失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -865,11 +809,11 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
             )
             
             bleService.sendCommand(command) { response ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     if (response.success) {
-                        Toast.makeText(this@VehicleActivity, "设置成功", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置成功", Toast.LENGTH_SHORT).show()
                     } else {
-                        Toast.makeText(this@VehicleActivity, "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
+                        Toast.makeText(requireContext(), "设置失败: ${response.errorMessage}", Toast.LENGTH_SHORT).show()
                     }
                 }
             }
@@ -881,7 +825,7 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
      */
     private fun checkConnection(): Boolean {
         if (!bleService.isConnected()) {
-            Toast.makeText(this, "请先连接蓝牙设备", Toast.LENGTH_SHORT).show()
+            Toast.makeText(requireContext(), "请先连接蓝牙设备", Toast.LENGTH_SHORT).show()
             return false
         }
         return true
@@ -891,7 +835,7 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
      * 连接到设备(一键完成扫描+连接+握手)
      */
     private fun connectToDevice() {
-        ILog.d("VehicleActivity", "========== 开始连接设备 ==========")
+        ILog.d("VehicleFragment", "========== 开始连接设备 ==========")
         
         // 检查并请求权限
         val requiredPermissions = mutableListOf<String>()
@@ -906,18 +850,37 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
         }
         
         val missingPermissions = requiredPermissions.filter { permission ->
-            ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED
+            ContextCompat.checkSelfPermission(requireContext(), permission) != PackageManager.PERMISSION_GRANTED
         }
         
         if (missingPermissions.isNotEmpty()) {
-            ILog.w("VehicleActivity", "缺少权限: ${missingPermissions.joinToString(", ")}")
+            ILog.w("VehicleFragment", "缺少权限: ${missingPermissions.joinToString(", ")}")
             btnConnectBluetooth.isEnabled = false
             tvBluetoothStatus.text = "请求权限..."
-            permissionLauncher.launch(missingPermissions.toTypedArray())
+            // 通过MainActivity请求权限
+            (requireActivity() as? PermissionRequestHandler)?.requestPermissions(
+                missingPermissions.toTypedArray()
+            ) { permissions ->
+                val allGranted = permissions.all { it.value }
+                if (allGranted) {
+                    ILog.d("VehicleFragment", "✅ 所有权限已授予,开始连接设备")
+                    performConnectToDevice()
+                } else {
+                    val deniedPermissions = permissions.filter { !it.value }.keys.joinToString(", ")
+                    ILog.e("VehicleFragment", "❌ 权限被拒绝: $deniedPermissions")
+                    Toast.makeText(
+                        requireContext(),
+                        "需要蓝牙权限才能连接设备,请在设置中授予权限",
+                        Toast.LENGTH_LONG
+                    ).show()
+                    btnConnectBluetooth.isEnabled = true
+                    tvBluetoothStatus.text = "权限被拒绝"
+                }
+            }
             return
         }
         
-        ILog.d("VehicleActivity", "✅ 所有权限已授予")
+        ILog.d("VehicleFragment", "✅ 所有权限已授予")
         performConnectToDevice()
     }
     
@@ -931,33 +894,33 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
         val userId = ByteArray(16) { it.toByte() }
         val userType = BLEConstants.USER_TYPE_OWNER
         
-        ILog.d("VehicleActivity", "开始扫描并连接设备...")
+        ILog.d("VehicleFragment", "开始扫描并连接设备...")
         
         bleService.initializeAndConnect(
             userId = userId,
             userType = userType,
             onConnected = {
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     btnConnectBluetooth.isEnabled = true
                     updateConnectionStatus()
-                    Toast.makeText(this@VehicleActivity, "连接成功", Toast.LENGTH_SHORT).show()
+                    Toast.makeText(requireContext(), "连接成功", Toast.LENGTH_SHORT).show()
                     btnQueryVehicleInfo.performClick()
                 }
             },
             onDisconnected = {
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     updateConnectionStatus()
-                    Toast.makeText(this@VehicleActivity, "连接已断开", Toast.LENGTH_SHORT).show()
+                    Toast.makeText(requireContext(), "连接已断开", Toast.LENGTH_SHORT).show()
                 }
             },
             onDataReceived = { data ->
                 handleReceivedData(data)
             },
             onError = { error ->
-                runOnUiThread {
+                requireActivity().runOnUiThread {
                     btnConnectBluetooth.isEnabled = true
                     updateConnectionStatus()
-                    Toast.makeText(this@VehicleActivity, "连接失败: $error", Toast.LENGTH_SHORT).show()
+                    Toast.makeText(requireContext(), "连接失败: $error", Toast.LENGTH_SHORT).show()
                 }
             }
         )
@@ -969,47 +932,47 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
     @OptIn(ExperimentalStdlibApi::class)
     private fun handleReceivedData(data: ByteArray) {
         val hexString = data.toHexString()
-        ILog.d("VehicleActivity", "🔔🔔🔔 Android收到设备响应 (${data.size} bytes): $hexString")
+        ILog.d("VehicleFragment", "🔔🔔🔔 Android收到设备响应 (${data.size} bytes): $hexString")
         
         if (data.size == 1) {
             val byte = data[0]
-            ILog.d("VehicleActivity", "⚠️ 收到单字节响应: 0x${String.format("%02x", byte)}")
+            ILog.d("VehicleFragment", "⚠️ 收到单字节响应: 0x${String.format("%02x", byte)}")
             
             if (byte == 0x33.toByte()) {
-                ILog.e("VehicleActivity", "❌ 设备返回认证失败 (0x33 = '3')")
+                ILog.e("VehicleFragment", "❌ 设备返回认证失败 (0x33 = '3')")
             }
             return
         }
         
         try {
             val jsonString = String(data, Charsets.UTF_8)
-            ILog.d("VehicleActivity", "📥 数据内容(JSON): $jsonString")
+            ILog.d("VehicleFragment", "📥 数据内容(JSON): $jsonString")
             val jsonObject = org.json.JSONObject(jsonString)
             
-            runOnUiThread {
+            requireActivity().runOnUiThread {
                 val ty = jsonObject.optInt("TY", 0)
                 val `in` = jsonObject.optInt("IN", 0)
                 
                 when {
                     ty == 3 && `in` == 3 -> {
-                        ILog.d("VehicleActivity", "收到握手请求")
+                        ILog.d("VehicleFragment", "收到握手请求")
                     }
                     ty == 3 && `in` == 4 -> {
                         val pairing = jsonObject.optJSONObject("C")?.optJSONObject("D")?.optInt("Pairing", 0) ?: 0
-                        ILog.d("VehicleActivity", "📥 收到配对请求,Pairing=$pairing")
+                        ILog.d("VehicleFragment", "📥 收到配对请求,Pairing=$pairing")
                         when (pairing) {
-                            1 -> ILog.d("VehicleActivity", "✅ 设备需要配对 (Pairing=1)")
-                            2 -> ILog.d("VehicleActivity", "✅ 设备不需要配对 (Pairing=2)")
-                            3 -> ILog.e("VehicleActivity", "❌ 认证失败 (Pairing=3)")
+                            1 -> ILog.d("VehicleFragment", "✅ 设备需要配对 (Pairing=1)")
+                            2 -> ILog.d("VehicleFragment", "✅ 设备不需要配对 (Pairing=2)")
+                            3 -> ILog.e("VehicleFragment", "❌ 认证失败 (Pairing=3)")
                         }
                     }
                     else -> {
-                        ILog.d("VehicleActivity", "收到业务消息: $jsonString")
+                        ILog.d("VehicleFragment", "收到业务消息: $jsonString")
                     }
                 }
             }
         } catch (e: Exception) {
-            ILog.e("VehicleActivity", "解析接收数据失败", e)
+            ILog.e("VehicleFragment", "解析接收数据失败", e)
         }
     }
 
@@ -1046,3 +1009,15 @@ class VehicleActivity : BaseActivity<ActivityVehicleBinding>() {
         switchTCS.isChecked = data.size > 39 && data[39] == 0x01.toByte()
     }
 }
+
+/**
+ * 权限请求接口
+ * 由MainActivity实现,供Fragment使用
+ */
+interface PermissionRequestHandler {
+    fun requestPermissions(
+        permissions: Array<String>,
+        callback: (Map<String, Boolean>) -> Unit
+    )
+}
+

+ 20 - 4
app/src/main/res/layout/activity_main.xml

@@ -6,11 +6,27 @@
     android:layout_height="match_parent"
     tools:context=".MainActivity">
 
-    <!-- MainFragment 容器(主页内容,包含底部导航栏) -->
+    <!-- Fragment 容器(用于显示业务Fragment) -->
     <androidx.fragment.app.FragmentContainerView
         android:id="@+id/fragmentContainer"
-        android:name="com.narutohuo.xindazhou.MainFragment"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent" />
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        app:layout_constraintBottom_toTopOf="@+id/bottomNavView"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <!-- 底部导航栏 -->
+    <com.google.android.material.bottomnavigation.BottomNavigationView
+        android:id="@+id/bottomNavView"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:background="?android:attr/windowBackground"
+        app:itemIconTint="@android:color/black"
+        app:itemTextColor="@android:color/black"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:menu="@menu/bottom_navigation_menu" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 0 - 744
app/src/main/res/layout/activity_vehicle.xml

@@ -1,744 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <!-- 车辆控制内容(使用 fragment_vehicle.xml 的内容) -->
-    <androidx.core.widget.NestedScrollView
-        android:id="@+id/scrollView"
-        android:layout_width="0dp"
-        android:layout_height="0dp"
-        android:fillViewport="true"
-        app:layout_constraintBottom_toTopOf="@+id/bottomNavView"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent">
-
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="vertical"
-            android:padding="16dp">
-
-            <!-- 蓝牙连接状态 -->
-            <androidx.cardview.widget.CardView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginBottom="16dp"
-                app:cardCornerRadius="8dp"
-                app:cardElevation="4dp">
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="horizontal"
-                    android:padding="16dp"
-                    android:gravity="center_vertical">
-
-                    <TextView
-                        android:id="@+id/tvBluetoothStatus"
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1"
-                        android:text="蓝牙未连接"
-                        android:textSize="16sp"
-                        android:textStyle="bold" />
-
-                    <Button
-                        android:id="@+id/btnConnectBluetooth"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:text="连接" />
-                </LinearLayout>
-            </androidx.cardview.widget.CardView>
-
-            <!-- 实时状态信息 -->
-            <androidx.cardview.widget.CardView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginBottom="16dp"
-                app:cardCornerRadius="8dp"
-                app:cardElevation="4dp">
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="vertical"
-                    android:padding="16dp">
-
-                    <TextView
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:text="实时状态"
-                        android:textSize="18sp"
-                        android:textStyle="bold"
-                        android:layout_marginBottom="12dp" />
-
-                    <GridLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:columnCount="2"
-                        android:rowCount="4">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="设防状态:"
-                            android:layout_marginEnd="8dp" />
-                        <TextView
-                            android:id="@+id/tvDefenseStatus"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="未知" />
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="上电状态:"
-                            android:layout_marginEnd="8dp" />
-                        <TextView
-                            android:id="@+id/tvPowerStatus"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="未知" />
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="门锁状态:"
-                            android:layout_marginEnd="8dp" />
-                        <TextView
-                            android:id="@+id/tvDoorLockStatus"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="未知" />
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="电池电量:"
-                            android:layout_marginEnd="8dp" />
-                        <TextView
-                            android:id="@+id/tvBatteryLevel"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_columnWeight="1"
-                            android:text="未知" />
-                    </GridLayout>
-
-                    <Button
-                        android:id="@+id/btnQueryVehicleInfo"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:layout_marginTop="12dp"
-                        android:text="查询车辆信息" />
-                </LinearLayout>
-            </androidx.cardview.widget.CardView>
-
-            <!-- 快捷控制 -->
-            <androidx.cardview.widget.CardView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginBottom="16dp"
-                app:cardCornerRadius="8dp"
-                app:cardElevation="4dp">
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="vertical"
-                    android:padding="16dp">
-
-                    <TextView
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:text="快捷控制"
-                        android:textSize="18sp"
-                        android:textStyle="bold"
-                        android:layout_marginBottom="12dp" />
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp">
-
-                        <Button
-                            android:id="@+id/btnDefense"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:layout_marginEnd="8dp"
-                            android:text="设防" />
-
-                        <Button
-                            android:id="@+id/btnPower"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:layout_marginEnd="8dp"
-                            android:text="上电" />
-
-                        <Button
-                            android:id="@+id/btnFindCar"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="寻车" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal">
-
-                        <Button
-                            android:id="@+id/btnSeatLock"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:layout_marginEnd="8dp"
-                            android:text="座桶锁" />
-
-                        <Button
-                            android:id="@+id/btnHandlebarLock"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:layout_marginEnd="8dp"
-                            android:text="龙头锁" />
-
-                        <Button
-                            android:id="@+id/btnTrunkLock"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="尾箱锁" />
-                    </LinearLayout>
-                </LinearLayout>
-            </androidx.cardview.widget.CardView>
-
-            <!-- 系统控制 -->
-            <androidx.cardview.widget.CardView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginBottom="16dp"
-                app:cardCornerRadius="8dp"
-                app:cardElevation="4dp">
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="vertical"
-                    android:padding="16dp">
-
-                    <TextView
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:text="系统控制"
-                        android:textSize="18sp"
-                        android:textStyle="bold"
-                        android:layout_marginBottom="12dp" />
-
-                    <!-- 开关类控制 -->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp">
-
-                        <Switch
-                            android:id="@+id/switchInductionUnlock"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="感应解锁" />
-
-                        <Switch
-                            android:id="@+id/switchTheftLock"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="被盗锁定" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp">
-
-                        <Switch
-                            android:id="@+id/switchSeatSensor"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="座椅感应" />
-
-                        <Switch
-                            android:id="@+id/switchVehicleSound"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="车辆音效" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp">
-
-                        <Switch
-                            android:id="@+id/switchAutoHeadlight"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="自动大灯" />
-
-                        <Switch
-                            android:id="@+id/switchAtmosphereLight"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="氛围灯" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp">
-
-                        <Switch
-                            android:id="@+id/switchVoiceBroadcast"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="语音播报" />
-
-                        <Switch
-                            android:id="@+id/switchFollowMeHome"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="伴我回家" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp">
-
-                        <Switch
-                            android:id="@+id/switchABS"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="ABS" />
-
-                        <Switch
-                            android:id="@+id/switchTCS"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="TCS" />
-                    </LinearLayout>
-
-                    <!-- 时间设置 -->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="自动下电时间(秒):" />
-
-                        <EditText
-                            android:id="@+id/etAutoPowerOffTime"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="300" />
-
-                        <Button
-                            android:id="@+id/btnSetAutoPowerOffTime"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="自动设防时间(秒):" />
-
-                        <EditText
-                            android:id="@+id/etAutoDefenseTime"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="5" />
-
-                        <Button
-                            android:id="@+id/btnSetAutoDefenseTime"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="进入P档时间(秒):" />
-
-                        <EditText
-                            android:id="@+id/etEnterPTime"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="300" />
-
-                        <Button
-                            android:id="@+id/btnSetEnterPTime"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-
-                    <!-- 其他设置 -->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="蓝牙音箱音量(%):" />
-
-                        <EditText
-                            android:id="@+id/etBluetoothSpeakerVolume"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="50" />
-
-                        <Button
-                            android:id="@+id/btnSetBluetoothSpeakerVolume"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="低电量报警阈值(%):" />
-
-                        <EditText
-                            android:id="@+id/etLowBatteryThreshold"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="20" />
-
-                        <Button
-                            android:id="@+id/btnSetLowBatteryThreshold"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-
-                    <!-- 氛围灯颜色设置 -->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="氛围灯颜色:" />
-
-                        <EditText
-                            android:id="@+id/etAtmosphereLightR"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="R(0-255)"
-                            android:layout_marginEnd="4dp" />
-
-                        <EditText
-                            android:id="@+id/etAtmosphereLightG"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="G(0-255)"
-                            android:layout_marginEnd="4dp" />
-
-                        <EditText
-                            android:id="@+id/etAtmosphereLightB"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:inputType="number"
-                            android:hint="B(0-255)" />
-
-                        <Button
-                            android:id="@+id/btnSetAtmosphereLightColor"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-
-                    <!-- 感应解锁RSSI信号强度采集 -->
-                    <Button
-                        android:id="@+id/btnCollectRSSI"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:layout_marginBottom="8dp"
-                        android:text="感应解锁RSSI信号强度采集" />
-
-                    <!-- 小计里程清零 -->
-                    <Button
-                        android:id="@+id/btnResetTripMileage"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:text="小计里程清零" />
-                </LinearLayout>
-            </androidx.cardview.widget.CardView>
-
-            <!-- 系统设置 -->
-            <androidx.cardview.widget.CardView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                app:cardCornerRadius="8dp"
-                app:cardElevation="4dp">
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="vertical"
-                    android:padding="16dp">
-
-                    <TextView
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:text="系统设置"
-                        android:textSize="18sp"
-                        android:textStyle="bold"
-                        android:layout_marginBottom="12dp" />
-
-                    <!-- 钥匙学码 -->
-                    <Button
-                        android:id="@+id/btnKeyLearning"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:layout_marginBottom="8dp"
-                        android:text="钥匙学码" />
-
-                    <!-- 震动灵敏度 -->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="震动灵敏度:" />
-
-                        <RadioGroup
-                            android:id="@+id/rgVibrationSensitivity"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="2"
-                            android:orientation="horizontal">
-
-                            <RadioButton
-                                android:id="@+id/rbSensitivity1"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="1" />
-
-                            <RadioButton
-                                android:id="@+id/rbSensitivity2"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="2" />
-
-                            <RadioButton
-                                android:id="@+id/rbSensitivity3"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="3" />
-
-                            <RadioButton
-                                android:id="@+id/rbSensitivity4"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="4" />
-
-                            <RadioButton
-                                android:id="@+id/rbSensitivity5"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="5" />
-                        </RadioGroup>
-
-                        <Button
-                            android:id="@+id/btnSetVibrationSensitivity"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-
-                    <!-- 报警开关 -->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:layout_marginBottom="8dp"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="报警是否上报:" />
-
-                        <Switch
-                            android:id="@+id/switchAlarmReport"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1" />
-                    </LinearLayout>
-
-                    <!-- 倾倒报警阈值 -->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:orientation="horizontal"
-                        android:gravity="center_vertical">
-
-                        <TextView
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="1"
-                            android:text="倾倒报警阈值:" />
-
-                        <RadioGroup
-                            android:id="@+id/rgTiltAlarmThreshold"
-                            android:layout_width="0dp"
-                            android:layout_height="wrap_content"
-                            android:layout_weight="2"
-                            android:orientation="horizontal">
-
-                            <RadioButton
-                                android:id="@+id/rbTilt50"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="50°" />
-
-                            <RadioButton
-                                android:id="@+id/rbTilt60"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="60°" />
-
-                            <RadioButton
-                                android:id="@+id/rbTilt70"
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="70°" />
-                        </RadioGroup>
-
-                        <Button
-                            android:id="@+id/btnSetTiltAlarmThreshold"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="设置" />
-                    </LinearLayout>
-                </LinearLayout>
-            </androidx.cardview.widget.CardView>
-
-        </LinearLayout>
-    </androidx.core.widget.NestedScrollView>
-
-    <!-- 底部导航栏 -->
-    <com.google.android.material.bottomnavigation.BottomNavigationView
-        android:id="@+id/bottomNavView"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/windowBackground"
-        app:itemIconTint="@android:color/black"
-        app:itemTextColor="@android:color/black"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
-        app:menu="@menu/bottom_navigation_menu" />
-
-</androidx.constraintlayout.widget.ConstraintLayout>
-

+ 1 - 14
app/src/main/res/layout/activity_community.xml

@@ -9,23 +9,10 @@
         android:id="@+id/contentContainer"
         android:layout_width="0dp"
         android:layout_height="0dp"
-        app:layout_constraintBottom_toTopOf="@+id/bottomNavView"
+        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
 
-    <!-- 底部导航栏 -->
-    <com.google.android.material.bottomnavigation.BottomNavigationView
-        android:id="@+id/bottomNavView"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/windowBackground"
-        app:itemIconTint="@android:color/black"
-        app:itemTextColor="@android:color/black"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
-        app:menu="@menu/bottom_navigation_menu" />
-
 </androidx.constraintlayout.widget.ConstraintLayout>
 

+ 0 - 21
app/src/main/res/layout/fragment_main.xml

@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <!-- 底部导航栏 -->
-    <com.google.android.material.bottomnavigation.BottomNavigationView
-        android:id="@+id/bottomNavView"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/windowBackground"
-        app:itemIconTint="@android:color/black"
-        app:itemTextColor="@android:color/black"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
-        app:menu="@menu/bottom_navigation_menu" />
-
-</androidx.constraintlayout.widget.ConstraintLayout>
-

+ 1 - 14
app/src/main/res/layout/activity_service.xml

@@ -9,23 +9,10 @@
         android:id="@+id/contentContainer"
         android:layout_width="0dp"
         android:layout_height="0dp"
-        app:layout_constraintBottom_toTopOf="@+id/bottomNavView"
+        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
 
-    <!-- 底部导航栏 -->
-    <com.google.android.material.bottomnavigation.BottomNavigationView
-        android:id="@+id/bottomNavView"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/windowBackground"
-        app:itemIconTint="@android:color/black"
-        app:itemTextColor="@android:color/black"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
-        app:menu="@menu/bottom_navigation_menu" />
-
 </androidx.constraintlayout.widget.ConstraintLayout>
 

+ 1 - 14
app/src/main/res/layout/activity_shop.xml

@@ -10,23 +10,10 @@
         android:id="@+id/contentContainer"
         android:layout_width="0dp"
         android:layout_height="0dp"
-        app:layout_constraintBottom_toTopOf="@+id/bottomNavView"
+        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
 
-    <!-- 底部导航栏 -->
-    <com.google.android.material.bottomnavigation.BottomNavigationView
-        android:id="@+id/bottomNavView"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/windowBackground"
-        app:itemIconTint="@android:color/black"
-        app:itemTextColor="@android:color/black"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
-        app:menu="@menu/bottom_navigation_menu" />
-
 </androidx.constraintlayout.widget.ConstraintLayout>
 

+ 1 - 14
app/src/main/res/layout/activity_user.xml

@@ -10,23 +10,10 @@
         layout="@layout/fragment_user_socket_test"
         android:layout_width="0dp"
         android:layout_height="0dp"
-        app:layout_constraintBottom_toTopOf="@+id/bottomNavView"
+        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
 
-    <!-- 底部导航栏 -->
-    <com.google.android.material.bottomnavigation.BottomNavigationView
-        android:id="@+id/bottomNavView"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/windowBackground"
-        app:itemIconTint="@android:color/black"
-        app:itemTextColor="@android:color/black"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
-        app:menu="@menu/bottom_navigation_menu" />
-
 </androidx.constraintlayout.widget.ConstraintLayout>
 

文件差異過大導致無法顯示
+ 575 - 569
app/src/main/res/layout/fragment_vehicle.xml


+ 62 - 1
base-core/src/main/java/com/mooxygen/user/wxapi/WXEntryActivity.kt

@@ -2,6 +2,7 @@ package com.mooxygen.user.wxapi
 
 import android.content.Intent
 import android.os.Bundle
+import android.util.Log
 import com.alibaba.android.arouter.facade.annotation.Autowired
 import com.alibaba.android.arouter.launcher.ARouter
 import com.narutohuo.xindazhou.core.log.ILog
@@ -39,28 +40,81 @@ class WXEntryActivity : WXCallbackActivity() {
         super.onCreate(savedInstanceState)
         // ARouter 依赖注入(用于解耦 base-core 与 capability-share)
         ARouter.getInstance().inject(this)
+        
+        // 使用 android.util.Log 确保 release 版本也能看到日志
+        Log.e(tag, "========== onCreate START ==========")
+        Log.e(tag, "onCreate: intent=$intent")
+        Log.e(tag, "onCreate: intent.data=${intent?.data}")
+        Log.e(tag, "onCreate: intent.extras=${intent?.extras}")
+        
+        // 检查微信错误码
+        val errcode = intent?.getIntExtra("_wxapi_baseresp_errcode", 0)
+        val errstr = intent?.getStringExtra("_wxapi_baseresp_errstr")
+        Log.e(tag, "onCreate: 微信错误码 errcode=$errcode, errstr=$errstr")
+        
         ILog.d(tag, "onCreate: 微信回调 Activity 已启动")
 
+        // 关键:微信回调是通过 onCreate 的 Intent 传递的
+        // 友盟 SDK 需要在启动分享的 Activity(ShareProxyActivity)中调用 onActivityResult
+        // 但是 WXEntryActivity 不是由 ShareProxyActivity 启动的,所以需要手动传递回调
+        // 方案:通过 Intent 启动 ShareProxyActivity,并传递回调数据
+        // 使用 FLAG_ACTIVITY_SINGLE_TOP 确保如果 ShareProxyActivity 已在栈中,会调用 onNewIntent
+        try {
+            // 尝试通过 Intent 启动 ShareProxyActivity,传递回调数据
+            val shareProxyIntent = Intent().apply {
+                setClassName(this@WXEntryActivity, "com.narutohuo.xindazhou.share.ui.ShareProxyActivity")
+                flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP
+                // 将微信回调数据传递给 ShareProxyActivity
+                putExtras(intent.extras ?: Bundle())
+            }
+            
+            // 检查 ShareProxyActivity 是否存在
+            if (shareProxyIntent.resolveActivity(packageManager) != null) {
+                startActivity(shareProxyIntent)
+                Log.e(tag, "onCreate: 已启动 ShareProxyActivity 传递回调")
+                ILog.d(tag, "onCreate: 已启动 ShareProxyActivity 传递回调")
+            } else {
+                // 如果 ShareProxyActivity 不存在,直接调用 UMShareAPI.onActivityResult()
+                // 友盟 SDK 可能会通过其他机制找到启动分享的 Activity
+                UMShareAPI.get(this).onActivityResult(0, 0, intent)
+                Log.e(tag, "onCreate: ShareProxyActivity 不存在,直接调用 UMShareAPI.onActivityResult()")
+                ILog.d(tag, "onCreate: ShareProxyActivity 不存在,直接调用 UMShareAPI.onActivityResult()")
+            }
+        } catch (e: Exception) {
+            Log.e(tag, "onCreate: 处理回调失败", e)
+            ILog.e(tag, "onCreate: 处理回调失败", e)
+        }
+
         // 将微信回调 Intent 转发给 share 模块处理(用于你提到的“之前有 ARouter 的那套”)
         try {
             shareCallback?.onWeChatCallback(intent)
+            Log.e(tag, "onCreate: 已通过 ARouter 转发 onWeChatCallback")
             ILog.d(tag, "onCreate: 已通过 ARouter 转发 onWeChatCallback")
         } catch (e: Exception) {
+            Log.e(tag, "onCreate: 转发 onWeChatCallback 失败", e)
             ILog.e(tag, "onCreate: 转发 onWeChatCallback 失败", e)
         }
+        
+        Log.e(tag, "========== onCreate END ==========")
     }
     
     override fun onNewIntent(intent: Intent?) {
         super.onNewIntent(intent)
-        ILog.d(tag, "onNewIntent: 收到新的 Intent")
+        Log.e(tag, "onNewIntent: 收到新的 Intent")
+        Log.e(tag, "onNewIntent: intent=$intent")
+        Log.e(tag, "onNewIntent: intent.data=${intent?.data}")
+        Log.e(tag, "onNewIntent: intent.extras=${intent?.extras}")
         setIntent(intent) // 更新 Intent,确保后续能获取到最新数据
+        ILog.d(tag, "onNewIntent: 收到新的 Intent")
 
         // 新 Intent 也需要转发一次(避免微信用 singleTask/singleTop 复用 Activity)
         intent?.let {
             try {
                 shareCallback?.onWeChatCallback(it)
+                Log.e(tag, "onNewIntent: 已通过 ARouter 转发 onWeChatCallback")
                 ILog.d(tag, "onNewIntent: 已通过 ARouter 转发 onWeChatCallback")
             } catch (e: Exception) {
+                Log.e(tag, "onNewIntent: 转发 onWeChatCallback 失败", e)
                 ILog.e(tag, "onNewIntent: 转发 onWeChatCallback 失败", e)
             }
         }
@@ -68,6 +122,9 @@ class WXEntryActivity : WXCallbackActivity() {
     
     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
         super.onActivityResult(requestCode, resultCode, data)
+        Log.e(tag, "onActivityResult: requestCode=$requestCode, resultCode=$resultCode")
+        Log.e(tag, "onActivityResult: data=$data")
+        Log.e(tag, "onActivityResult: data.extras=${data?.extras}")
         ILog.d(tag, "onActivityResult: requestCode=$requestCode, resultCode=$resultCode")
         
         // 友盟的 WXCallbackActivity 应该已经处理了回调
@@ -75,14 +132,18 @@ class WXEntryActivity : WXCallbackActivity() {
         // 这样可以确保回调被正确传递到 ShareProxyActivity
         try {
             UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data)
+            Log.e(tag, "onActivityResult: 已调用 UMShareAPI.onActivityResult()")
             ILog.d(tag, "onActivityResult: 已调用 UMShareAPI.onActivityResult()")
         } catch (e: Exception) {
+            Log.e(tag, "onActivityResult: 处理回调失败", e)
             ILog.e(tag, "onActivityResult: 处理回调失败", e)
         }
     }
     
     override fun onDestroy() {
+        Log.e(tag, "========== onDestroy START ==========")
         super.onDestroy()
+        Log.e(tag, "========== onDestroy END ==========")
         ILog.d(tag, "onDestroy: 微信回调 Activity 已销毁")
     }
 }

+ 4 - 11
capability-share/src/main/java/com/narutohuo/xindazhou/share/callback/ShareCallback.kt

@@ -41,18 +41,11 @@ class ShareCallback : IProvider, IShareCallback {
         ILog.d(TAG, "onWeChatCallback: 收到微信回调")
         
         try {
-            // 获取 ShareService 实例
-            val shareService = ShareKit.getInstance()
+            // 注意:UMShareAPI.onActivityResult() 已经在 WXEntryActivity.onCreate() 中调用了
+            // 这里只需要记录日志,不需要再次调用
+            // 友盟 SDK 会通过内部机制找到启动分享的 Activity(ShareProxyActivity)并传递回调
             
-            // 友盟 SDK 会自动处理微信回调
-            // 这里只需要确保 ShareProxyActivity 能够接收到回调
-            // ShareProxyActivity 会调用 shareService.onActivityResult()
-            
-            // 注意:友盟的 WXCallbackActivity 已经处理了回调
-            // 我们只需要确保 ShareProxyActivity 能够接收到 onActivityResult
-            // 实际的回调处理在 ShareProxyActivity 中完成
-            
-            ILog.d(TAG, "微信回调已转发给 ShareService")
+            ILog.d(TAG, "微信回调已记录(UMShareAPI.onActivityResult() 已在 WXEntryActivity 中调用)")
         } catch (e: Exception) {
             ILog.e(TAG, "处理微信回调失败", e)
         }

+ 10 - 45
capability-share/src/main/java/com/narutohuo/xindazhou/share/ui/ShareProxyActivity.kt

@@ -101,10 +101,6 @@ class ShareProxyActivity : FragmentActivity() {
             ILog.d("ShareProxyActivity", "share callback: success=${response.success}, platform=${response.data}, error=${response.errorMessage}")
             isShareCompleted = true
             
-            // 取消超时任务
-            timeoutHandler?.removeCallbacks(timeoutRunnable ?: return@shareManual)
-            timeoutRunnable = null
-            
             // 调用回调
             callbacks[callbackId]?.invoke(response)
             clearCallback(callbackId)
@@ -121,10 +117,17 @@ class ShareProxyActivity : FragmentActivity() {
         // 处理微信/QQ/微博返回的情况(某些平台可能通过 onNewIntent 传递回调)
         ILog.d("ShareProxyActivity", "onNewIntent: 收到新的 Intent")
         setIntent(intent) // 更新 Intent,确保后续能获取到最新数据
-        // 友盟 SDK 可能会通过 onNewIntent 传递回调,需要在这里处理
+        
+        // 检查是否是微信回调(包含 _wxapi_baseresp_errcode 等字段)
         intent?.let {
-            val shareService = ShareKit.getInstance()
-            shareService.onActivityResult(this, 0, 0, it) // requestCode, resultCode 不重要,友盟内部会处理
+            val errcode = it.getIntExtra("_wxapi_baseresp_errcode", Int.MIN_VALUE)
+            if (errcode != Int.MIN_VALUE) {
+                // 这是微信回调,需要处理
+                ILog.d("ShareProxyActivity", "onNewIntent: 收到微信回调,errcode=$errcode")
+                val shareService = ShareKit.getInstance()
+                // 调用友盟 SDK 的 onActivityResult,传入回调数据
+                shareService.onActivityResult(this, 0, 0, it) // requestCode, resultCode 不重要,友盟内部会处理
+            }
         }
     }
     
@@ -138,9 +141,6 @@ class ShareProxyActivity : FragmentActivity() {
         shareService.onActivityResult(this, requestCode, resultCode, data)
     }
     
-    private var timeoutHandler: android.os.Handler? = null
-    private var timeoutRunnable: Runnable? = null
-    
     override fun onResume() {
         super.onResume()
         
@@ -150,50 +150,15 @@ class ShareProxyActivity : FragmentActivity() {
             finish()
             return
         }
-        
-        // 增加超时保护:如果 3 秒后还没有回调,强制关闭
-        // 注意:每次 onResume 都会重新计时,避免重复设置
-        if (!isFinishing && !isDestroyed) {
-            // 取消之前的超时任务
-            timeoutHandler?.removeCallbacks(timeoutRunnable ?: return)
-            
-            timeoutHandler = android.os.Handler(android.os.Looper.getMainLooper())
-            timeoutRunnable = Runnable {
-                if (!isShareCompleted && !isFinishing && !isDestroyed) {
-                    ILog.w("ShareProxyActivity", "onResume: 超时未收到回调,强制关闭并调用失败回调")
-                    // 调用失败回调
-                    if (::callbackId.isInitialized) {
-                        callbacks[callbackId]?.invoke(
-                            ShareResponse(
-                                success = false,
-                                errorMessage = "分享超时,请重试",
-                                timestamp = System.currentTimeMillis()
-                            )
-                        )
-                        clearCallback(callbackId)
-                    }
-                    finish()
-                }
-            }
-            timeoutHandler?.postDelayed(timeoutRunnable!!, 3000) // 3 秒超时(缩短超时时间)
-        }
     }
     
     override fun onPause() {
         super.onPause()
-        // 取消超时任务,避免在后台时触发
-        timeoutHandler?.removeCallbacks(timeoutRunnable ?: return)
-        timeoutRunnable = null
     }
     
     override fun onDestroy() {
         super.onDestroy()
         
-        // 取消超时任务
-        timeoutHandler?.removeCallbacks(timeoutRunnable ?: return)
-        timeoutHandler = null
-        timeoutRunnable = null
-        
         // 如果还没有调用回调,说明可能出现了异常,调用失败回调
         if (!isShareCompleted && ::callbackId.isInitialized) {
             ILog.w("ShareProxyActivity", "onDestroy: Activity 被销毁但未收到回调,调用失败回调")