Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TakePhotoViewModel.java « takephoto « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a6375c9f8b31ec5a37e6506a8c5cc49b9f4a5c53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package it.niedermann.nextcloud.deck.ui.takephoto;

import static androidx.camera.core.CameraSelector.DEFAULT_BACK_CAMERA;
import static androidx.camera.core.CameraSelector.DEFAULT_FRONT_CAMERA;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.camera.core.CameraSelector;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import it.niedermann.android.reactivelivedata.ReactiveLiveData;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.ui.viewmodel.BaseViewModel;

public class TakePhotoViewModel extends BaseViewModel {

    @NonNull
    private CameraSelector cameraSelector = DEFAULT_BACK_CAMERA;
    @NonNull
    private final MutableLiveData<Integer> cameraSelectorToggleButtonImageResource = new MutableLiveData<>(R.drawable.ic_camera_front_24);
    @NonNull
    private final MutableLiveData<Boolean> torchEnabled = new MutableLiveData<>(false);

    public TakePhotoViewModel(@NonNull Application application) {
        super(application);
    }

    public LiveData<Long> getCurrentAccountId$() {
        return baseRepository.getCurrentAccountId$();
    }

    public LiveData<Long> getCurrentBoardId$(long accountId) {
        return baseRepository.getCurrentBoardId$(accountId);
    }

    public LiveData<Integer> getBoardColor$(long accountId, long boardId) {
        return baseRepository.getBoardColor$(accountId, boardId);
    }

    @NonNull
    public CameraSelector getCameraSelector() {
        return this.cameraSelector;
    }

    public LiveData<Integer> getCameraSelectorToggleButtonImageResource() {
        return this.cameraSelectorToggleButtonImageResource;
    }

    public void toggleCameraSelector() {
        if (this.cameraSelector == DEFAULT_BACK_CAMERA) {
            this.cameraSelector = DEFAULT_FRONT_CAMERA;
            this.cameraSelectorToggleButtonImageResource.postValue(R.drawable.ic_camera_rear_24);
        } else {
            this.cameraSelector = DEFAULT_BACK_CAMERA;
            this.cameraSelectorToggleButtonImageResource.postValue(R.drawable.ic_camera_front_24);
        }
    }

    public void toggleTorchEnabled() {
        //noinspection ConstantConditions
        this.torchEnabled.postValue(!this.torchEnabled.getValue());
    }

    public LiveData<Boolean> isTorchEnabled() {
        return this.torchEnabled;
    }

    public LiveData<Integer> getTorchToggleButtonImageResource() {
        return new ReactiveLiveData<>(isTorchEnabled())
                .map(enabled -> enabled
                        ? R.drawable.ic_flash_off_24
                        : R.drawable.ic_flash_on_24);
    }
}