Skip to content

Commit

Permalink
move toast to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimblebee committed Dec 11, 2023
1 parent 09408ce commit b2b439e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.jetpackcamera.feature.preview

import android.widget.Toast
import androidx.camera.core.CameraSelector
import com.google.jetpackcamera.feature.preview.ui.ToastMessage
import com.google.jetpackcamera.settings.model.CameraAppSettings

/**
Expand All @@ -33,28 +34,6 @@ data class PreviewUiState(
val toastMessageToShow: ToastMessage? = null
)

/**
* Helper class containing information used to create a toast.
*
* @param message the text to be displayed.
* @param isLongToast determines if the display time is [Toast.LENGTH_LONG] or [Toast.LENGTH_SHORT]
* @param testDesc the *unique* description for toast message. i.e. *captureFailedToast* vs *captureSuccessToast*.
* @property testTag the identifiable resource ID of a Toast on screen.
*/
class ToastMessage(
val message: String,
isLongToast: Boolean = false,
val testDesc: String = "Toast Message"
) {
val testTag: String = "Toast Message"
val toastLength: Int = when (isLongToast) {
true -> Toast.LENGTH_LONG
false -> Toast.LENGTH_SHORT
}
}



/**
* Defines the current state of Video Recording
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.camera.core.Preview.SurfaceProvider
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.jetpackcamera.domain.camera.CameraUseCase
import com.google.jetpackcamera.feature.preview.ui.ToastMessage
import com.google.jetpackcamera.settings.SettingsRepository
import com.google.jetpackcamera.settings.model.AspectRatio
import com.google.jetpackcamera.settings.model.CaptureMode
Expand Down Expand Up @@ -192,13 +193,15 @@ class PreviewViewModel @Inject constructor(
viewModelScope.launch {
try {
cameraUseCase.takePicture()
//todo: remove toast after postcapture screen implemented
_previewUiState.emit(
previewUiState.value.copy(
toastMessageToShow = ToastMessage(message = "Image Capture Success", testDesc = "ImageCaptureSuccessToast")
)
)
Log.d(TAG, "cameraUseCase.takePicture success")
} catch (exception: ImageCaptureException) {
//todo: remove toast after postcapture screen implemented
_previewUiState.emit(
previewUiState.value.copy(
toastMessageToShow = ToastMessage(message = "Image Capture Failure", testDesc = "ImageCaptureFailureToast")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.jetpackcamera.feature.preview.R
import com.google.jetpackcamera.feature.preview.ToastMessage
import com.google.jetpackcamera.feature.preview.VideoRecordingState
import com.google.jetpackcamera.settings.model.AspectRatio
import com.google.jetpackcamera.viewfinder.CameraPreview
Expand All @@ -68,10 +67,10 @@ private const val TAG = "PreviewScreen"


/**
* Displays a [Toast] with specifications set by a [ToastMessage]
* Displays a [Toast] with specifications set by a [ToastMessage].
*
* @param toastMessage the specifications for the [Toast]
* @param onToastShown called once the toast has been displayed
* @param toastMessage the specifications for the [Toast].
* @param onToastShown called once the Toast has been displayed.
*/
@Composable
fun ShowToast(modifier: Modifier = Modifier, toastMessage: ToastMessage, onToastShown : () -> Unit){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.jetpackcamera.feature.preview.ui

import android.widget.Toast

/**
* Helper class containing information used to create a [Toast].
*
* @param message the text to be displayed.
* @param isLongToast determines if the display time is [Toast.LENGTH_LONG] or [Toast.LENGTH_SHORT]
* @param testDesc the *unique* description for toast message. i.e. *captureFailedToast* vs *captureSuccessToast*.
* @property testTag the identifiable resource ID of a Toast on screen.
*/
class ToastMessage(
val message: String,
isLongToast: Boolean = false,
val testDesc: String = "Toast Message"
) {
val testTag: String = "Toast Message"
val toastLength: Int = when (isLongToast) {
true -> Toast.LENGTH_LONG
false -> Toast.LENGTH_SHORT
}
}

0 comments on commit b2b439e

Please sign in to comment.