Remove EventBus usage

This commit is contained in:
Ensar Sarajčić
2023-10-02 18:24:02 +02:00
parent 163e053e1d
commit ee9a539cf5
10 changed files with 143 additions and 221 deletions

View File

@ -7,8 +7,9 @@ import android.os.Handler
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.flashlight.extensions.config
import com.simplemobiletools.flashlight.models.Events
import org.greenrobot.eventbus.EventBus
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
internal class CameraFlash(
private val context: Context,
@ -17,6 +18,8 @@ internal class CameraFlash(
private val manager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
private val cameraId: String
private val scope = CoroutineScope(Dispatchers.Default)
private val torchCallback = object : CameraManager.TorchCallback() {
override fun onTorchModeChanged(cameraId: String, enabled: Boolean) {
cameraTorchListener?.onTorchEnabled(enabled)
@ -46,10 +49,9 @@ internal class CameraFlash(
}
} catch (e: Exception) {
context.showErrorToast(e)
val mainRunnable = Runnable {
EventBus.getDefault().post(Events.CameraUnavailable())
scope.launch {
MyCameraImpl.cameraError.emit(Unit)
}
Handler(context.mainLooper).post(mainRunnable)
}
}