Skip to content

Commit

Permalink
MultipleEventCutter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjiagoogle committed Oct 12, 2023
1 parent bc790b6 commit 2412f6c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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

/**
* A helper class that prevents multiple clicks.
*/
internal class MultipleEventsCutter {
private val now: Long
get() = System.currentTimeMillis()

private var lastEventTimeMs: Long = 0

fun processEvent(event: () -> Unit) {
if (now - lastEventTimeMs >= 300L) {
event.invoke()
}
lastEventTimeMs = now
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,12 @@ fun PreviewScreen(
)
}
}
val multipleEventsCutter = remember { MultipleEventsCutter() }
/*todo: close quick settings on start record/image capture*/
CaptureButton(
onClick = { viewModel.captureImage() },
onClick = {
multipleEventsCutter.processEvent { viewModel.captureImage() }
},
onLongPress = { viewModel.startVideoRecording() },
onRelease = { viewModel.stopVideoRecording() },
videoRecordingState = previewUiState.videoRecordingState
Expand Down

0 comments on commit 2412f6c

Please sign in to comment.