Skip to content

Commit

Permalink
Holding offset buttons adjusts by fine increments
Browse files Browse the repository at this point in the history
  • Loading branch information
killergerbah committed Feb 24, 2024
1 parent 4300c9b commit 06b686c
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 17 deletions.
4 changes: 3 additions & 1 deletion common/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"stopRecording": "Stop Recording",
"importSettings": "Import Settings",
"exportSettings": "Export Settings",
"hideOverlay": "Hide Overlay"
"hideOverlay": "Hide Overlay",
"decreaseOffsetButton": "Decrease offset to so that next subtitle is at current position. Hold to decrease by 100ms.",
"increaseOffsetButton": "Increase offset to so that previous subtitle is at current position. Hold to increase by 100ms."
},
"postMineAction": {
"none": "None",
Expand Down
4 changes: 3 additions & 1 deletion common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"stopRecording": "Stop Recording",
"importSettings": "Import Settings",
"exportSettings": "Export Settings",
"hideOverlay": "Hide Overlay"
"hideOverlay": "Hide Overlay",
"decreaseOffsetButton": "Decrease offset to so that next subtitle is at current position. Hold to decrease by 100ms.",
"increaseOffsetButton": "Increase offset to so that previous subtitle is at current position. Hold to increase by 100ms."
},
"postMineAction": {
"none": "None",
Expand Down
4 changes: 3 additions & 1 deletion common/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"stopRecording": "Finalizar Grabación",
"importSettings": "Importar Ajustes",
"exportSettings": "Exportar Ajustes",
"hideOverlay": "Hide Overlay"
"hideOverlay": "Hide Overlay",
"decreaseOffsetButton": "Decrease offset to so that next subtitle is at current position. Hold to decrease by 100ms.",
"increaseOffsetButton": "Increase offset to so that previous subtitle is at current position. Hold to increase by 100ms."
},
"postMineAction": {
"none": "Ninguna",
Expand Down
4 changes: 3 additions & 1 deletion common/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"stopRecording": "録音停止",
"importSettings": "設定をインポートする",
"exportSettings": "設定をエクスポートする",
"hideOverlay": "オーバーレイを非表示"
"hideOverlay": "オーバーレイを非表示",
"decreaseOffsetButton": "次の字幕を現在のタイムスタンプに合わせる。長押しすると、字幕表示タイミングが100msずつ変わる。",
"increaseOffsetButton": "前の字幕を現在のタイムスタンプに合わせる。長押しすると、字幕表示タイミングが100msずつ変わる。"
},
"postMineAction": {
"none": "何もしない",
Expand Down
4 changes: 3 additions & 1 deletion common/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"stopRecording": "Stop Recording",
"importSettings": "Import Settings",
"exportSettings": "Export Settings",
"hideOverlay": "Hide Overlay"
"hideOverlay": "Hide Overlay",
"decreaseOffsetButton": "Decrease offset to so that next subtitle is at current position. Hold to decrease by 100ms.",
"increaseOffsetButton": "Increase offset to so that previous subtitle is at current position. Hold to increase by 100ms."
},
"postMineAction": {
"none": "None",
Expand Down
4 changes: 3 additions & 1 deletion common/locales/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"stopRecording": "Parar gravação",
"importSettings": "Importar configurações",
"exportSettings": "Exportar configurações",
"hideOverlay": "Hide Overlay"
"hideOverlay": "Hide Overlay",
"decreaseOffsetButton": "Decrease offset to so that next subtitle is at current position. Hold to decrease by 100ms.",
"increaseOffsetButton": "Increase offset to so that previous subtitle is at current position. Hold to increase by 100ms."
},
"postMineAction": {
"none": "Nada",
Expand Down
4 changes: 3 additions & 1 deletion common/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"stopRecording": "Stop Recording",
"importSettings": "Import Settings",
"exportSettings": "Export Settings",
"hideOverlay": "Hide Overlay"
"hideOverlay": "Hide Overlay",
"decreaseOffsetButton": "Decrease offset to so that next subtitle is at current position. Hold to decrease by 100ms.",
"increaseOffsetButton": "Increase offset to so that previous subtitle is at current position. Hold to increase by 100ms."
},
"postMineAction": {
"none": "None",
Expand Down
67 changes: 67 additions & 0 deletions extension/src/ui/components/HoldableIconButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { IconButton, IconButtonProps } from '@material-ui/core';
import React, { useEffect, useCallback, useState } from 'react';
import { isMobile } from 'react-device-detect';

interface Props extends IconButtonProps {
onHold?: (repetition: number) => void;
onClick: () => void;
children: React.ReactNode;
}

const HoldableIconButton = ({ onHold, onClick, children, ...rest }: Props) => {
const [startTime, setStartTime] = useState<number>();

const repetitions = useCallback(() => {
if (startTime === undefined) {
return undefined;
}

const holdTime = Date.now() - startTime;
return holdTime / 250;
}, [startTime]);

const handleMouseUp = (event: any) => {
const reps = repetitions();

if (reps !== undefined && reps < 1) {
onClick?.();
}

setStartTime(undefined);
};

const handleMouseDown = (event: any) => {
setStartTime(Date.now());
};

useEffect(() => {
if (startTime === undefined) {
return;
}

const interval = setInterval(() => {
const reps = repetitions();

if (reps !== undefined && reps > 0) {
onHold?.(reps);
}
}, 250);
return () => clearInterval(interval);
}, [startTime, onHold, repetitions]);
return (
<>
{isMobile && (
<IconButton onTouchStart={handleMouseDown} onTouchEnd={handleMouseUp} onClick={() => {}} {...rest}>
{children}
</IconButton>
)}
{!isMobile && (
<IconButton onMouseDown={handleMouseDown} onMouseUp={handleMouseUp} onClick={() => {}} {...rest}>
{children}
</IconButton>
)}
</>
);
};

export default HoldableIconButton;
57 changes: 47 additions & 10 deletions extension/src/ui/components/MobileVideoOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useTranslation } from 'react-i18next';
import { Tooltip } from '@material-ui/core';
import LogoIcon from '@project/common/components/LogoIcon';
import CloseIcon from '@material-ui/icons/Close';
import HoldableIconButton from './HoldableIconButton';

const useStyles = makeStyles({
button: {
Expand Down Expand Up @@ -124,6 +125,22 @@ const MobileVideoOverlay = () => {
handleOffset(model.currentTimestamp - model.nextSubtitleTimestamp);
}, [handleOffset, model]);

const handleIncrementOffset = useCallback(() => {
if (!model) {
return;
}

handleOffset(model.offset + 100);
}, [handleOffset, model]);

const handleDecrementOffset = useCallback(() => {
if (!model) {
return;
}

handleOffset(model.offset - 100);
}, [handleOffset, model]);

const handleDisableOverlay = useCallback(async () => {
await settings.set({ streamingEnableOverlay: false });
const command: MobileOverlayCommand<SettingsUpdatedMessage> = {
Expand Down Expand Up @@ -211,11 +228,21 @@ const MobileVideoOverlay = () => {
{!model.emptySubtitleTrack && (
<>
<Grid item>
<IconButton onClick={handleOffsetToPrevious} disabled={offsetToPreviousButtonDisabled}>
<NavigateBeforeIcon
className={offsetToPreviousButtonDisabled ? classes.inactiveButton : classes.button}
/>
</IconButton>
<Tooltip title={t('action.increaseOffsetButton')!}>
<span>
<HoldableIconButton
onClick={handleOffsetToPrevious}
onHold={handleIncrementOffset}
disabled={offsetToPreviousButtonDisabled}
>
<NavigateBeforeIcon
className={
offsetToPreviousButtonDisabled ? classes.inactiveButton : classes.button
}
/>
</HoldableIconButton>
</span>
</Tooltip>
</Grid>
<Grid item>
<SubtitleOffsetInput
Expand All @@ -225,11 +252,21 @@ const MobileVideoOverlay = () => {
/>
</Grid>
<Grid item>
<IconButton onClick={handleOffsetToNext} disabled={offsetToNextButtonDisabled}>
<NavigateNextIcon
className={offsetToNextButtonDisabled ? classes.inactiveButton : classes.button}
/>
</IconButton>
<Tooltip title={t('action.decreaseOffsetButton')!}>
<span>
<HoldableIconButton
onClick={handleOffsetToNext}
onHold={handleDecrementOffset}
disabled={offsetToNextButtonDisabled}
>
<NavigateNextIcon
className={
offsetToNextButtonDisabled ? classes.inactiveButton : classes.button
}
/>
</HoldableIconButton>
</span>
</Tooltip>
</Grid>
</>
)}
Expand Down

0 comments on commit 06b686c

Please sign in to comment.