diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index e9f1bbe..acf27b8 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -33,6 +33,7 @@ import WindowSnackbar from './ui/components/WindowSnackbar'; import { usePhone } from './os/phone/hooks/usePhone'; import { useTranslation } from 'react-i18next'; import { useSnackbar } from './ui/hooks/useSnackbar'; +import set = Reflect.set; function Phone() { const { t, i18n } = useTranslation(); @@ -104,7 +105,9 @@ function Phone() { id="phone" className="PhoneScreen" style={{ - backgroundImage: `url(media/backgrounds/${settings.wallpaper.value})`, + backgroundImage: settings.customWallpaper + ? `url(${settings.customWallpaper})` + : `url(media/backgrounds/${settings.wallpaper.value})`, }} > {isPhoneReady ? ( diff --git a/phone/src/apps/settings/components/SettingItem.tsx b/phone/src/apps/settings/components/SettingItem.tsx index a6dff73..336f393 100644 --- a/phone/src/apps/settings/components/SettingItem.tsx +++ b/phone/src/apps/settings/components/SettingItem.tsx @@ -10,7 +10,10 @@ import { Tooltip, Typography, Switch, + TextField, } from '@material-ui/core'; +import CreateIcon from '@material-ui/icons/Create'; +import { PictureThumbnail } from '../../../ui/components/PictureThumbnail'; interface ISettingItem { options?: any; @@ -106,3 +109,15 @@ export const SettingItemIconAction = ({ ); + +export const SettingItemModal = ({ icon, label, secondary, onClick }) => ( + + {icon} + + + + + + + +); diff --git a/phone/src/apps/settings/components/SettingsApp.tsx b/phone/src/apps/settings/components/SettingsApp.tsx index 0b27fac..e740a5c 100644 --- a/phone/src/apps/settings/components/SettingsApp.tsx +++ b/phone/src/apps/settings/components/SettingsApp.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { AppWrapper } from '../../../ui/components'; import { AppTitle } from '../../../ui/components/AppTitle'; import { AppContent } from '../../../ui/components/AppContent'; @@ -12,6 +12,7 @@ import { SettingItemIconAction, SettingItemSlider, SettingSwitch, + SettingItemModal, } from './SettingItem'; import { useTranslation } from 'react-i18next'; import VisibilityOffIcon from '@material-ui/icons/VisibilityOff'; @@ -28,12 +29,13 @@ import { Book, DeleteForever, } from '@material-ui/icons'; - +import { makeStyles } from '@material-ui/core/styles'; import { ListSubheader } from '@material-ui/core'; -import { useResetSettings, useSettings } from '../hooks/useSettings'; +import { useCustomWallpaperModal, useResetSettings, useSettings } from '../hooks/useSettings'; import { setClipboard } from '../../../os/phone/hooks/useClipboard'; import { useSnackbar } from '../../../ui/hooks/useSnackbar'; import { IContextMenuOption } from '../../../ui/components/ContextMenu'; +import WallpaperModal from './WallpaperModal'; const SubHeaderComp = (props: { text: string }) => ( @@ -41,12 +43,26 @@ const SubHeaderComp = (props: { text: string }) => ( ); +const useStyles = makeStyles({ + backgroundModal: { + background: 'black', + opacity: '0.6', + position: 'absolute', + top: 0, + left: 0, + right: 0, + bottom: 0, + zIndex: 5, + }, +}); + export const SettingsApp = () => { const settingsApp = useApp('SETTINGS'); const [config] = useConfig(); const simcard = useSimcard(); const [settings, setSettings] = useSettings(); const { t } = useTranslation(); + const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal(); const { addAlert } = useSnackbar(); @@ -123,9 +139,12 @@ export const SettingsApp = () => { }; const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu(); + const classes = useStyles(); return ( + +
}> { onClick={openMenu} icon={} /> + {/* CUSTOM BACKGROUND */} + } + label={t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER')} + secondary={settings.customWallpaper} + onClick={() => setCustomWallpaperModal(true)} + /> { + return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url); + }; + + const handleCloseModal = () => { + setCustomWallpaperModal(false); + }; + + const handleSettingChange = (key: string | number, value: unknown) => { + setSettings({ ...settings, [key]: value }); + }; + + const handleNewWallpaper = () => { + handleSettingChange('customWallpaper', value); + }; + + const handleRemoveWallpaper = () => { + handleSettingChange('customWallpaper', ''); + }; + + return ( + + + {settings.customWallpaper && ( + + )} + setValue(e.currentTarget.value)} + inputProps={{ + className: classes.inputProps, + }} + placeholder="Image URL" + /> + + {settings.customWallpaper && ( + + {t('GENERIC_DELETE')} + + )} + + + ); +} diff --git a/phone/src/apps/settings/hooks/useSettings.ts b/phone/src/apps/settings/hooks/useSettings.ts index 38e5370..ab086db 100644 --- a/phone/src/apps/settings/hooks/useSettings.ts +++ b/phone/src/apps/settings/hooks/useSettings.ts @@ -23,6 +23,7 @@ const settingsSchema: Schema = { properties: { language: { $ref: '/SettingOption' }, wallpaper: { $ref: '/SettingOption' }, + customWallpaper: { $ref: '/SettingOption' }, frame: { $ref: '/SettingOption' }, theme: { $ref: '/SettingOption' }, zoom: { $ref: '/SettingOption' }, @@ -63,6 +64,7 @@ export function isSettingsSchemaValid(): boolean { export interface IPhoneSettings { language: SettingOption; wallpaper: SettingOption; + customWallpaper: string; frame: SettingOption; theme: SettingOption; zoom: SettingOption; @@ -110,6 +112,11 @@ export const settingsState = atom({ effects_UNSTABLE: [localStorageEffect(NPWD_STORAGE_KEY)], }); +const customWallpaperState = atom({ + key: 'customWallpaperState', + default: false, +}); + export const useSettings = () => { return useRecoilState(settingsState); }; @@ -117,3 +124,8 @@ export const useSettings = () => { export const useResetSettings = () => { return useResetRecoilState(settingsState); }; + +export const useCustomWallpaperModal = () => { + const [customWallpaperModal, setCustomWallpaperModal] = useRecoilState(customWallpaperState); + return { customWallpaperModal, setCustomWallpaperModal }; +}; diff --git a/phone/src/config/default.json b/phone/src/config/default.json index f338264..5516dd0 100644 --- a/phone/src/config/default.json +++ b/phone/src/config/default.json @@ -144,6 +144,7 @@ "label": "Project Error", "value": "projecterror.jpg" }, + "customWallpaper": "", "frame": { "label": "Default", "value": "default.png" diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 36d1d0d..f724357 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -180,6 +180,7 @@ "APPS_SETTINGS_PHONE_NUMBER": "Phone Number", "APPS_SETTINGS_OPTION_WALLPAPER": "Wallpaper", + "APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER": "Custom Wallpaper", "APPS_SETTINGS_OPTION_FRAME": "Frame", "APPS_SETTINGS_OPTION_THEME": "Theme", "APPS_SETTINGS_OPTION_ZOOM": "Zoom", @@ -190,6 +191,7 @@ "APPS_SETTINGS_OPTION_NOTIFICATION": "Notification", "APPS_SETTINGS_OPTION_NOTIFICATIONVOL": "Notification Volume", "APPS_SETTING_STREAMER_MODE_DESC": "Hide images before they are shown", + "APPS_SETTINGS_SET_CUSTOM_WALLPAPER": "Set new wallpaper", "APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing", "APPS_MARKETPLACE_CREATE_LISTING_FAILED": "Failed to create a new listing",