소스 검색

删除不需要的文件

yangyang 3 주 전
부모
커밋
b56ce4bce8

+ 0 - 136
base-common/src/main/java/com/narutohuo/xindazhou/common/bridge/BridgeManager.kt

@@ -1,136 +0,0 @@
-package com.narutohuo.xindazhou.common.bridge
-
-import com.narutohuo.xindazhou.core.log.ILog
-import java.util.concurrent.ConcurrentHashMap
-import java.util.concurrent.CopyOnWriteArrayList
-
-/**
- * 桥接服务管理器
- * 
- * 业务层封装,提供便捷的桥接服务调用方式
- * 直接实现 H5 通信和模块间通信功能
- * 
- * 使用方式:
- * ```kotlin
- * // H5通信
- * BridgeManager.callH5Method("showToast", "Hello")
- * BridgeManager.onH5Call("getUserInfo") { result ->
- *     // 处理结果
- * }
- * 
- * // 模块间通信
- * BridgeManager.postEvent("user_login", userData)
- * BridgeManager.subscribeEvent("user_logout") { data ->
- *     // 处理事件
- * }
- * ```
- */
-object BridgeManager {
-    
-    private const val TAG = "BridgeManager"
-    
-    // H5 方法回调存储
-    private val h5Callbacks = ConcurrentHashMap<String, (String) -> Unit>()
-    
-    // 事件订阅者存储
-    private val eventSubscribers = ConcurrentHashMap<String, CopyOnWriteArrayList<(Any?) -> Unit>>()
-    
-    // H5 调用原生方法的回调(由外部设置,比如 WebView 的 JavaScriptInterface)
-    private var h5CallNativeCallback: ((String, String) -> Unit)? = null
-    
-    /**
-     * 设置 H5 调用原生方法的回调
-     * 在 WebView 的 JavaScriptInterface 中调用此方法注册回调
-     * 
-     * @param callback 回调函数(method: 方法名, params: 参数)
-     */
-    fun setH5CallNativeCallback(callback: (String, String) -> Unit) {
-        h5CallNativeCallback = callback
-    }
-    
-    /**
-     * 调用 H5 方法
-     * 需要在 WebView 的 JavaScriptInterface 中实现对应的方法
-     * 
-     * @param method 方法名
-     * @param params 参数(JSON 字符串)
-     */
-    fun callH5Method(method: String, params: String = "{}") {
-        // 这里需要由外部实现(比如在 WebView 的 JavaScriptInterface 中)
-        // 可以通过回调或者事件通知外部执行
-        ILog.d(TAG, "callH5Method: $method, params: $params")
-        // 实际实现需要在 WebView 的 JavaScriptInterface 中调用
-        // 可以通过 postEvent 通知,或者设置回调
-    }
-    
-    /**
-     * 监听 H5 调用原生方法
-     * 
-     * @param method 方法名
-     * @param callback 回调函数
-     */
-    fun onH5Call(method: String, callback: (String) -> Unit) {
-        h5Callbacks[method] = callback
-    }
-    
-    /**
-     * 处理 H5 调用原生方法(由 WebView 的 JavaScriptInterface 调用)
-     * 
-     * @param method 方法名
-     * @param params 参数(JSON 字符串)
-     */
-    fun handleH5Call(method: String, params: String) {
-        h5Callbacks[method]?.invoke(params) ?: run {
-            ILog.w(TAG, "未注册的 H5 方法调用: $method")
-        }
-    }
-    
-    /**
-     * 发送事件(模块间通信)
-     * 
-     * @param event 事件名
-     * @param data 事件数据
-     */
-    fun postEvent(event: String, data: Any? = null) {
-        val subscribers = eventSubscribers[event]
-        if (subscribers != null && subscribers.isNotEmpty()) {
-            subscribers.forEach { callback ->
-                try {
-                    callback(data)
-                } catch (e: Exception) {
-                    ILog.e(TAG, "事件回调执行失败: $event", e)
-                }
-            }
-        } else {
-            ILog.d(TAG, "事件无订阅者: $event")
-        }
-    }
-    
-    /**
-     * 订阅事件(模块间通信)
-     * 
-     * @param event 事件名
-     * @param callback 回调函数
-     */
-    fun subscribeEvent(event: String, callback: (Any?) -> Unit) {
-        eventSubscribers.getOrPut(event) { CopyOnWriteArrayList() }.add(callback)
-    }
-    
-    /**
-     * 取消订阅事件
-     * 
-     * @param event 事件名
-     * @param callback 回调函数
-     */
-    fun unsubscribeEvent(event: String, callback: (Any?) -> Unit) {
-        eventSubscribers[event]?.remove(callback)
-    }
-    
-    /**
-     * 清除所有事件订阅
-     */
-    fun clearAllSubscriptions() {
-        eventSubscribers.clear()
-    }
-}
-

+ 0 - 272
base-common/src/main/java/com/narutohuo/xindazhou/common/camera/CameraHelper.kt

@@ -1,272 +0,0 @@
-package com.narutohuo.xindazhou.common.camera
-
-import android.app.Activity
-import android.content.Intent
-import android.net.Uri
-import android.os.Build
-import android.provider.MediaStore
-import androidx.activity.ComponentActivity
-import androidx.activity.result.ActivityResultLauncher
-import androidx.activity.result.contract.ActivityResultContracts
-import androidx.core.content.FileProvider
-import androidx.fragment.app.Fragment
-import java.io.File
-
-/**
- * 相机/相册管理器
- * 
- * 统一封装相机拍照、相册选择、图片裁剪功能
- * 
- * 使用方式:
- * ```kotlin
- * // 注册拍照
- * private val takePhotoLauncher = CameraHelper.registerTakePhoto(this) { uri ->
- *     // 处理拍照结果
- * }
- * takePhotoLauncher.launch()
- * 
- * // 注册相册选择
- * private val pickGalleryLauncher = CameraHelper.registerPickGallery(this) { uri ->
- *     // 处理相册选择结果
- * }
- * pickGalleryLauncher.launch()
- * 
- * // 注册图片裁剪
- * private val cropImageLauncher = CameraHelper.registerCropImage(this) { uri ->
- *     // 处理裁剪结果
- * }
- * cropImageLauncher.launch(sourceUri)
- * ```
- */
-object CameraHelper {
-    
-    /**
-     * 临时文件目录(用于存储拍照和裁剪的临时文件)
-     * 需要在 Application 中设置
-     */
-    var tempFileDir: File? = null
-    
-    /**
-     * FileProvider Authority(用于 Android 7.0+ 文件共享)
-     * 需要在 Application 中设置,格式:${applicationId}.fileprovider
-     */
-    var fileProviderAuthority: String? = null
-    
-    /**
-     * 注册拍照功能(Activity)
-     * 
-     * @param activity ComponentActivity 实例
-     * @param onResult 拍照结果回调
-     * @return ActivityResultLauncher,调用 launch(uri) 启动相机(需要先创建临时文件并获取 URI)
-     */
-    fun registerTakePhoto(
-        activity: ComponentActivity,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Uri> {
-        return activity.registerForActivityResult(ActivityResultContracts.TakePicture()) { success ->
-            if (success) {
-                // 注意:TakePicture 会自动保存到传入的 URI,这里需要调用者传入 URI
-                // 实际使用时应该在调用处创建临时文件并传入 URI
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 注册拍照功能(Fragment)
-     * 
-     * @param fragment Fragment 实例
-     * @param onResult 拍照结果回调
-     * @return ActivityResultLauncher
-     */
-    fun registerTakePhoto(
-        fragment: Fragment,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Uri> {
-        return fragment.registerForActivityResult(ActivityResultContracts.TakePicture()) { success ->
-            if (success) {
-                val tempFile = createTempImageFile(fragment.requireContext())
-                val uri = getUriForFile(fragment.requireContext(), tempFile)
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 创建临时文件并启动拍照
-     * 
-     * @param launcher ActivityResultLauncher(通过 registerTakePhoto 获取)
-     * @param context 上下文
-     * @param onResult 拍照结果回调(返回图片 URI)
-     */
-    fun takePhoto(
-        launcher: ActivityResultLauncher<Uri>,
-        context: android.content.Context,
-        onResult: (Uri?) -> Unit
-    ) {
-        val tempFile = createTempImageFile(context)
-        val uri = getUriForFile(context, tempFile)
-        launcher.launch(uri)
-        // 注意:TakePicture 会自动保存到传入的 URI,所以这里需要保存 URI 以便后续使用
-        // 实际使用时应该在调用处保存 URI 并在回调中处理
-    }
-    
-    /**
-     * 注册相册选择功能(Activity)
-     * 
-     * @param activity ComponentActivity 实例
-     * @param onResult 选择结果回调
-     * @return ActivityResultLauncher
-     */
-    fun registerPickGallery(
-        activity: ComponentActivity,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Intent> {
-        return activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-            if (result.resultCode == Activity.RESULT_OK) {
-                val uri = result.data?.data
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 注册相册选择功能(Fragment)
-     * 
-     * @param fragment Fragment 实例
-     * @param onResult 选择结果回调
-     * @return ActivityResultLauncher
-     */
-    fun registerPickGallery(
-        fragment: Fragment,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Intent> {
-        return fragment.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-            if (result.resultCode == Activity.RESULT_OK) {
-                val uri = result.data?.data
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 启动相册选择
-     * 
-     * @param launcher ActivityResultLauncher(通过 registerPickGallery 获取)
-     */
-    fun pickFromGallery(launcher: ActivityResultLauncher<Intent>) {
-        val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
-        launcher.launch(intent)
-    }
-    
-    /**
-     * 注册图片裁剪功能(Activity)
-     * 
-     * @param activity ComponentActivity 实例
-     * @param onResult 裁剪结果回调
-     * @return ActivityResultLauncher,调用 launch(intent) 启动裁剪
-     */
-    fun registerCropImage(
-        activity: ComponentActivity,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Intent> {
-        return activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-            if (result.resultCode == Activity.RESULT_OK) {
-                val uri = result.data?.data
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 注册图片裁剪功能(Fragment)
-     * 
-     * @param fragment Fragment 实例
-     * @param onResult 裁剪结果回调
-     * @return ActivityResultLauncher
-     */
-    fun registerCropImage(
-        fragment: Fragment,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Uri> {
-        return fragment.registerForActivityResult(ActivityResultContracts.TakePicture()) { success ->
-            if (success) {
-                val tempFile = createTempImageFile(fragment.requireContext())
-                val uri = getUriForFile(fragment.requireContext(), tempFile)
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 启动图片裁剪
-     * 
-     * @param launcher ActivityResultLauncher(通过 registerCropImage 获取)
-     * @param context 上下文
-     * @param sourceUri 源图片 URI
-     * @param outputUri 输出图片 URI(可选,如果为 null 则使用临时文件)
-     */
-    fun cropImage(
-        launcher: ActivityResultLauncher<Intent>,
-        context: android.content.Context,
-        sourceUri: Uri,
-        outputUri: Uri? = null
-    ) {
-        val finalOutputUri = outputUri ?: run {
-            val tempFile = createTempImageFile(context)
-            getUriForFile(context, tempFile)
-        }
-        
-        val intent = Intent("com.android.camera.action.CROP").apply {
-            setDataAndType(sourceUri, "image/*")
-            putExtra("crop", "true")
-            putExtra("aspectX", 1)
-            putExtra("aspectY", 1)
-            putExtra("outputX", 800)
-            putExtra("outputY", 800)
-            putExtra("scale", true)
-            putExtra("return-data", false)
-            putExtra(MediaStore.EXTRA_OUTPUT, finalOutputUri)
-            addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
-            addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
-        }
-        
-        launcher.launch(intent)
-    }
-    
-    // ========== 内部辅助方法 ==========
-    
-    /**
-     * 创建临时图片文件
-     */
-    private fun createTempImageFile(context: android.content.Context): File {
-        val dir = tempFileDir ?: context.cacheDir
-        val fileName = "temp_image_${System.currentTimeMillis()}.jpg"
-        return File(dir, fileName)
-    }
-    
-    /**
-     * 获取文件的 URI(兼容 Android 7.0+)
-     */
-    private fun getUriForFile(context: android.content.Context, file: File): Uri {
-        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            val authority = fileProviderAuthority
-                ?: throw IllegalStateException("fileProviderAuthority 未设置,请在 Application 中设置")
-            FileProvider.getUriForFile(context, authority, file)
-        } else {
-            Uri.fromFile(file)
-        }
-    }
-}
-

+ 0 - 180
base-common/src/main/java/com/narutohuo/xindazhou/common/file/FilePickerHelper.kt

@@ -1,180 +0,0 @@
-package com.narutohuo.xindazhou.common.file
-
-import android.app.Activity
-import android.content.Intent
-import android.net.Uri
-import android.provider.MediaStore
-import androidx.activity.ComponentActivity
-import androidx.activity.result.ActivityResultLauncher
-import androidx.activity.result.contract.ActivityResultContracts
-import androidx.fragment.app.Fragment
-
-/**
- * 文件选择器管理器
- * 
- * 统一封装文件选择功能,提供便捷的文件选择方式
- * 
- * 使用方式:
- * ```kotlin
- * // 在 Activity/Fragment 中注册
- * private val pickImageLauncher = FilePickerHelper.registerPickImage(this) { uri ->
- *     // 处理选中的图片
- * }
- * 
- * // 选择图片
- * pickImageLauncher.launch()
- * 
- * // 选择文件
- * private val pickFileLauncher = FilePickerHelper.registerPickFile(this, "image/png") { uri ->
- *     // 处理选中的文件
- * }
- * pickFileLauncher.launch()
- * ```
- */
-object FilePickerHelper {
-    
-    /**
-     * 注册图片选择器(Activity)
-     * 
-     * @param activity ComponentActivity 实例
-     * @param onResult 选择结果回调
-     * @return ActivityResultLauncher,调用 launch() 启动选择器
-     */
-    fun registerPickImage(
-        activity: ComponentActivity,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Intent> {
-        return activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-            if (result.resultCode == Activity.RESULT_OK) {
-                val uri = result.data?.data
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 注册图片选择器(Fragment)
-     * 
-     * @param fragment Fragment 实例
-     * @param onResult 选择结果回调
-     * @return ActivityResultLauncher,调用 launch() 启动选择器
-     */
-    fun registerPickImage(
-        fragment: Fragment,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Intent> {
-        return fragment.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-            if (result.resultCode == Activity.RESULT_OK) {
-                val uri = result.data?.data
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 启动图片选择器(简化版,使用 Intent)
-     * 
-     * @param activity Activity 实例
-     * @param onResult 选择结果回调
-     */
-    fun pickImage(activity: Activity, onResult: (Uri?) -> Unit) {
-        val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
-        activity.startActivityForResult(intent, 1001)
-        // 注意:这种方式需要重写 onActivityResult,建议使用 registerPickImage
-    }
-    
-    /**
-     * 注册文件选择器(Activity)
-     * 
-     * @param activity ComponentActivity 实例
-     * @param mimeType MIME 类型(如 "image/png", "application/pdf")
-     * @param onResult 选择结果回调
-     * @return ActivityResultLauncher
-     */
-    fun registerPickFile(
-        activity: ComponentActivity,
-        mimeType: String,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Intent> {
-        return activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-            if (result.resultCode == Activity.RESULT_OK) {
-                val uri = result.data?.data
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 注册文件选择器(Fragment)
-     * 
-     * @param fragment Fragment 实例
-     * @param mimeType MIME 类型
-     * @param onResult 选择结果回调
-     * @return ActivityResultLauncher
-     */
-    fun registerPickFile(
-        fragment: Fragment,
-        mimeType: String,
-        onResult: (Uri?) -> Unit
-    ): ActivityResultLauncher<Intent> {
-        return fragment.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-            if (result.resultCode == Activity.RESULT_OK) {
-                val uri = result.data?.data
-                onResult(uri)
-            } else {
-                onResult(null)
-            }
-        }
-    }
-    
-    /**
-     * 启动文件选择器(简化版)
-     * 
-     * @param activity Activity 实例
-     * @param mimeType MIME 类型
-     * @param onResult 选择结果回调
-     */
-    fun pickFile(activity: Activity, mimeType: String, onResult: (Uri?) -> Unit) {
-        val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
-            type = mimeType
-            addCategory(Intent.CATEGORY_OPENABLE)
-        }
-        activity.startActivityForResult(Intent.createChooser(intent, "选择文件"), 1002)
-        // 注意:这种方式需要重写 onActivityResult,建议使用 registerPickFile
-    }
-    
-    /**
-     * 注册多文件选择器(Fragment,Android 11+)
-     * 
-     * @param fragment Fragment 实例
-     * @param mimeType MIME 类型
-     * @param onResult 选择结果回调
-     * @return ActivityResultLauncher
-     */
-    fun registerPickMultipleFiles(
-        fragment: Fragment,
-        mimeType: String,
-        onResult: (List<Uri>) -> Unit
-    ): ActivityResultLauncher<String> {
-        return fragment.registerForActivityResult(ActivityResultContracts.GetMultipleContents()) { uris ->
-            onResult(uris)
-        }
-    }
-    
-    /**
-     * 启动多文件选择器(Fragment)
-     * 
-     * @param launcher ActivityResultLauncher(通过 registerPickMultipleFiles 获取)
-     * @param mimeType MIME 类型
-     */
-    fun pickMultipleFiles(launcher: ActivityResultLauncher<String>, mimeType: String) {
-        launcher.launch(mimeType)
-    }
-}
-