This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
internal fun RecordingScreen(viewModel: RecordingViewModel) { | |
... | |
val listener = remember(viewModel) { | |
object : VideoCaptureManager.Listener { | |
... | |
override fun recordingPaused() { | |
//Dispatch Recording Paused Event to the viewModel | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val LocalVideoCaptureManager = | |
compositionLocalOf<VideoCaptureManager> { error("No capture manager found!") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VideoCaptureManager private constructor(private val builder: Builder) : LifecycleEventObserver { | |
init { | |
getLifecycle().addObserver(this) | |
} | |
... | |
class Builder(val context: Context) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocationViewModel(application: Application) : AndroidViewModel(application) { | |
private val locationData = LocationLiveData(application) | |
fun getLocationData() = locationData | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocationLiveData(context: Context) : LiveData<LocationModel>() { | |
private var fusedLocationClient = LocationServices.getFusedLocationProviderClient(context) | |
override fun onInactive() { | |
super.onInactive() | |
fusedLocationClient.removeLocationUpdates(locationCallback) | |
} | |
@SuppressLint("MissingPermission") |
NewerOlder