diff --git a/src/components/settings/SettingBoolean.tsx b/src/components/settings/SettingBoolean.tsx
index e6fc5c3..674a40c 100644
--- a/src/components/settings/SettingBoolean.tsx
+++ b/src/components/settings/SettingBoolean.tsx
@@ -4,8 +4,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-import React, {useCallback} from 'react';
-
import SettingItem from './SettingItem';
import {Switch} from 'react-native';
@@ -14,7 +12,6 @@ type Props = {
subtitle: string;
initialValue: boolean;
onValueChange: (value: boolean) => void;
- onValueSet: (value: boolean) => void;
};
const SettingBoolean = ({
@@ -22,20 +19,12 @@ const SettingBoolean = ({
subtitle,
initialValue,
onValueChange,
- onValueSet,
}: Props) => {
- const _onValueChange = useCallback(
- (value: boolean) => {
- onValueChange(value);
- onValueSet(value);
- },
- [onValueChange, onValueSet],
- );
return (
}
+ right={}
/>
);
};
diff --git a/src/components/settings/SettingRange.tsx b/src/components/settings/SettingRange.tsx
index 494bd35..7cb6816 100644
--- a/src/components/settings/SettingRange.tsx
+++ b/src/components/settings/SettingRange.tsx
@@ -14,7 +14,7 @@ import debounce from 'lodash/debounce';
type Props = {
title: string;
onValueChange: (value: number) => void;
- onValueSet: (value: number) => void;
+ // onValueSet: (value: number) => void;
subtitle?: string;
caption?: string;
initialValue?: number;
@@ -47,7 +47,7 @@ const SettingRange = (props: Props) => {
{
const [showSettings, setShowSettings] = useState<{
@@ -35,11 +30,9 @@ const BinaryClockScreen: React.FC = () => {
[showSettings],
);
const {height, width} = useWindowDimensions();
- const [brightness, setBrightness] = useBrightness();
- const brightnessString = `${Math.round(brightness * 100)}%`;
- const [roundness, setRoundness] = useRoundness();
- const roundnessString = `${Math.round(roundness * 100)}%`;
- const [showHints, setShowHints] = useShowHints();
+ const [settings, updateSetting] = useSettings('BinaryClockScreen');
+ const brightnessString = `${Math.round(settings.brightness * 100)}%`;
+ const roundnessString = `${Math.round(settings.roundness * 100)}%`;
return (
{
{showSettings.value && (
@@ -62,25 +55,21 @@ const BinaryClockScreen: React.FC = () => {
contentContainerStyle={styles.settingsContentContainer}>
updateSetting({brightness: value})}
caption={brightnessString}
/>
updateSetting({roundness: value})}
caption={roundnessString}
/>
{}}
- onValueSet={BinaryClockSettings.setShowHints}
- initialValue={showHints}
+ onValueChange={value => updateSetting({showHints: value})}
+ initialValue={settings.showHints}
/>
)}
diff --git a/src/utils/BinaryClockSettings.ts b/src/utils/BinaryClockSettings.ts
deleted file mode 100644
index a850ecc..0000000
--- a/src/utils/BinaryClockSettings.ts
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) 2022 Joseph Hale
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-import {Dispatch, SetStateAction, useEffect, useState} from 'react';
-
-import DefaultPreference from 'react-native-default-preference';
-
-const BRIGHTNESS_KEY = 'brightness';
-const ROUNDNESS_KEY = 'roundness';
-const SHOW_HINTS_KEY = 'showHints';
-
-class BinaryClockSettings {
- public static async getSettings() {
- return {
- brightness: await this.getBrightness(),
- roundness: await this.getRoundness(),
- showHints: await this.getShowHints(),
- };
- }
-
- public static async setSettings(preferences: {
- brightness: number;
- roundness: number;
- showHints: boolean;
- }) {
- await this.setBrightness(preferences.brightness);
- await this.setShowHints(preferences.showHints);
- await this.setRoundness(preferences.roundness);
- }
-
- public static async getBrightness() {
- let temp = await DefaultPreference.get(BRIGHTNESS_KEY);
- if (temp === undefined || temp === null) {
- temp = '1';
- }
- return Number(temp);
- }
-
- public static async setBrightness(brightness: number) {
- await DefaultPreference.set(BRIGHTNESS_KEY, brightness.toString());
- }
-
- public static async getRoundness() {
- let temp = await DefaultPreference.get(ROUNDNESS_KEY);
- if (temp === undefined || temp === null) {
- temp = '1';
- }
- return Number(temp);
- }
-
- public static async setRoundness(roundness: number) {
- await DefaultPreference.set(ROUNDNESS_KEY, roundness.toString());
- }
-
- public static async getShowHints() {
- let temp = await DefaultPreference.get(SHOW_HINTS_KEY);
- if (temp === undefined || temp === null) {
- temp = 'false';
- }
- return temp === 'true';
- }
-
- public static async setShowHints(showHints: boolean) {
- await DefaultPreference.set(SHOW_HINTS_KEY, showHints.toString());
- }
-}
-
-function useBrightness(): [number, Dispatch>] {
- const [brightness, setBrightness] = useState(1);
- useEffect(() => {
- BinaryClockSettings.getBrightness()
- .then(value => {
- setTimeout(() => {
- console.debug('Brightness Setting: ' + value);
- setBrightness(value);
- }, 0);
- })
- .catch(err => {
- console.error(err);
- setBrightness(1);
- });
- }, []);
- return [brightness, setBrightness];
-}
-
-function useRoundness(): [number, Dispatch>] {
- const [roundness, setRoundness] = useState(1);
- useEffect(() => {
- BinaryClockSettings.getRoundness()
- .then(value => {
- setTimeout(() => {
- console.debug('Roundness Setting: ' + value);
- setRoundness(value);
- }, 0);
- })
- .catch(err => {
- console.error(err);
- setRoundness(1);
- });
- }, []);
- return [roundness, setRoundness];
-}
-
-function useShowHints(): [boolean, Dispatch>] {
- const [showHints, setShowHints] = useState(false);
- useEffect(() => {
- BinaryClockSettings.getShowHints()
- .then(value => {
- console.debug('Show Hints Setting: ' + value);
- setShowHints(value);
- })
- .catch(err => {
- console.error(err);
- setShowHints(false);
- });
- }, []);
- return [showHints, setShowHints];
-}
-
-export {useBrightness, useRoundness, useShowHints, BinaryClockSettings};