/* * Nextcloud Talk application * * @author Andy Scherzinger * @author Stefan Niedermann * Copyright (C) 2021 Andy Scherzinger * Copyright (C) 2021 Stefan Niedermann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.nextcloud.talk.models; import com.nextcloud.talk.R; import androidx.annotation.NonNull; import androidx.camera.core.CameraSelector; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.Transformations; import androidx.lifecycle.ViewModel; import static androidx.camera.core.CameraSelector.DEFAULT_BACK_CAMERA; import static androidx.camera.core.CameraSelector.DEFAULT_FRONT_CAMERA; public class TakePictureViewModel extends ViewModel { @NonNull private CameraSelector cameraSelector = DEFAULT_BACK_CAMERA; @NonNull private final MutableLiveData torchEnabled = new MutableLiveData<>(Boolean.FALSE); @NonNull private final MutableLiveData lowResolutionEnabled = new MutableLiveData<>(Boolean.FALSE); @NonNull private final MutableLiveData cropEnabled = new MutableLiveData<>(Boolean.FALSE); @NonNull public CameraSelector getCameraSelector() { return this.cameraSelector; } public void toggleCameraSelector() { if (this.cameraSelector == DEFAULT_BACK_CAMERA) { this.cameraSelector = DEFAULT_FRONT_CAMERA; if (this.torchEnabled.getValue()) { toggleTorchEnabled(); } } else { this.cameraSelector = DEFAULT_BACK_CAMERA; } } public void toggleTorchEnabled() { //noinspection ConstantConditions this.torchEnabled.postValue(!this.torchEnabled.getValue()); } public void toggleLowResolutionEnabled() { //noinspection ConstantConditions this.lowResolutionEnabled.postValue(!this.lowResolutionEnabled.getValue()); } public void toggleCropEnabled() { //noinspection ConstantConditions this.cropEnabled.postValue(!this.cropEnabled.getValue()); } public LiveData isTorchEnabled() { return this.torchEnabled; } public LiveData isLowResolutionEnabled() { return this.lowResolutionEnabled; } public LiveData isCropEnabled() { return this.cropEnabled; } public LiveData getTorchToggleButtonImageResource() { return Transformations.map(isTorchEnabled(), enabled -> enabled ? R.drawable.ic_baseline_flash_off_24 : R.drawable.ic_baseline_flash_on_24); } public LiveData getLowResolutionToggleButtonImageResource() { return Transformations.map(isLowResolutionEnabled(), enabled -> enabled ? R.drawable.ic_high_quality : R.drawable.ic_low_quality); } public LiveData getCropToggleButtonImageResource() { return Transformations.map(isCropEnabled(), enabled -> enabled ? R.drawable.ic_crop_4_3 : R.drawable.ic_crop_16_9); } }