Skip to content

Instantly share code, notes, and snippets.

View mayowa-egbewunmi's full-sized avatar

Egbewunmi Mayowa mayowa-egbewunmi

View GitHub Profile
class PermissionsHandler {
private val _state = MutableStateFlow(State())
val state: StateFlow<State> = _state
fun onEvent(event: Event) {
when (event) {
Event.PermissionDenied -> onPermissionDenied()
Event.PermissionDismissTapped -> onPermissionDismissTapped()
Event.PermissionNeverAskAgain -> onPermissionNeverShowAgain()
@Composable
internal fun RecordingScreen(viewModel: RecordingViewModel) {
...
val listener = remember(viewModel) {
object : VideoCaptureManager.Listener {
...
override fun recordingPaused() {
//Dispatch Recording Paused Event to the viewModel
}
class VideoCaptureManager private constructor(private val builder: Builder) :
LifecycleEventObserver {
...
@SuppressLint("MissingPermission")
fun startRecording(filePath: String) {
val outputOptions = FileOutputOptions.Builder(File(filePath)).build()
activeRecording = videoCapture.output
.prepareRecording(getContext(), outputOptions)
val LocalVideoCaptureManager =
compositionLocalOf<VideoCaptureManager> { error("No capture manager found!") }
@Composable
internal fun RecordingScreen(viewModel: RecordingViewModel) {
val state by viewModel.state.collectAsState()
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
val listener = remember {
object : VideoCaptureManager.Listener {
override fun onInitialised(cameraLensInfo: HashMap<Int, CameraInfo>) {
//TODO: Dispatch an Event to the viewModel to update State with CameraInfo
class VideoCaptureManager ... LifecycleEventObserver {
...
fun showPreview(previewState: PreviewState, cameraPreview: PreviewView = getCameraPreview()): View {
getLifeCycleOwner().lifecycleScope.launchWhenResumed {
val cameraProvider = cameraProviderFuture.await()
cameraProvider.unbindAll()
//Select a camera lens
val cameraSelector: CameraSelector = CameraSelector.Builder()
class VideoCaptureManager private constructor(private val builder: Builder) : LifecycleEventObserver {
init {
getLifecycle().addObserver(this)
}
...
class Builder(val context: Context) {
class LocationActivity : AppCompatActivity() {
private lateinit var locationViewModel: LocationViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_location)
locationViewModel = ViewModelProviders.of(this).get(LocationViewModel::class.java)
}
class LocationViewModel(application: Application) : AndroidViewModel(application) {
private val locationData = LocationLiveData(application)
fun getLocationData() = locationData
}
class LocationLiveData(context: Context) : LiveData<LocationModel>() {
private var fusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
override fun onInactive() {
super.onInactive()
fusedLocationClient.removeLocationUpdates(locationCallback)
}
@SuppressLint("MissingPermission")