mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
feat(phone/settings): custom background
This commit is contained in:
1 parent
ee7e3a3ae1
commit
4d46566811
7 files changed
+149
-4
No files matched your search
+4
-1
@@ -33,6 +33,7 @@ import WindowSnackbar from './ui/components/WindowSnackbar';
|
|||||||
import { usePhone } from './os/phone/hooks/usePhone';
|
import { usePhone } from './os/phone/hooks/usePhone';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useSnackbar } from './ui/hooks/useSnackbar';
|
import { useSnackbar } from './ui/hooks/useSnackbar';
|
||||||
|
import set = Reflect.set;
|
||||||
|
|
||||||
function Phone() {
|
function Phone() {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
@@ -104,7 +105,9 @@ function Phone() {
|
|||||||
id="phone"
|
id="phone"
|
||||||
className="PhoneScreen"
|
className="PhoneScreen"
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: `url(media/backgrounds/${settings.wallpaper.value})`,
|
backgroundImage: settings.customWallpaper
|
||||||
|
? `url(${settings.customWallpaper})`
|
||||||
|
: `url(media/backgrounds/${settings.wallpaper.value})`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isPhoneReady ? (
|
{isPhoneReady ? (
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
Typography,
|
Typography,
|
||||||
Switch,
|
Switch,
|
||||||
|
TextField,
|
||||||
} from '@material-ui/core';
|
} from '@material-ui/core';
|
||||||
|
import CreateIcon from '@material-ui/icons/Create';
|
||||||
|
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
|
||||||
|
|
||||||
interface ISettingItem {
|
interface ISettingItem {
|
||||||
options?: any;
|
options?: any;
|
||||||
@@ -106,3 +109,15 @@ export const SettingItemIconAction = ({
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const SettingItemModal = ({ icon, label, secondary, onClick }) => (
|
||||||
|
<ListItem divider>
|
||||||
|
<ListItemIcon>{icon}</ListItemIcon>
|
||||||
|
<ListItemText primary={label} secondary={secondary} />
|
||||||
|
<ListItemSecondaryAction>
|
||||||
|
<IconButton onClick={onClick}>
|
||||||
|
<CreateIcon />
|
||||||
|
</IconButton>
|
||||||
|
</ListItemSecondaryAction>
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { AppWrapper } from '../../../ui/components';
|
import { AppWrapper } from '../../../ui/components';
|
||||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||||
import { AppContent } from '../../../ui/components/AppContent';
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
SettingItemIconAction,
|
SettingItemIconAction,
|
||||||
SettingItemSlider,
|
SettingItemSlider,
|
||||||
SettingSwitch,
|
SettingSwitch,
|
||||||
|
SettingItemModal,
|
||||||
} from './SettingItem';
|
} from './SettingItem';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import VisibilityOffIcon from '@material-ui/icons/VisibilityOff';
|
import VisibilityOffIcon from '@material-ui/icons/VisibilityOff';
|
||||||
@@ -28,12 +29,13 @@ import {
|
|||||||
Book,
|
Book,
|
||||||
DeleteForever,
|
DeleteForever,
|
||||||
} from '@material-ui/icons';
|
} from '@material-ui/icons';
|
||||||
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { ListSubheader } from '@material-ui/core';
|
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 { setClipboard } from '../../../os/phone/hooks/useClipboard';
|
||||||
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||||
import { IContextMenuOption } from '../../../ui/components/ContextMenu';
|
import { IContextMenuOption } from '../../../ui/components/ContextMenu';
|
||||||
|
import WallpaperModal from './WallpaperModal';
|
||||||
|
|
||||||
const SubHeaderComp = (props: { text: string }) => (
|
const SubHeaderComp = (props: { text: string }) => (
|
||||||
<ListSubheader color="primary" component="div" disableSticky>
|
<ListSubheader color="primary" component="div" disableSticky>
|
||||||
@@ -41,12 +43,26 @@ const SubHeaderComp = (props: { text: string }) => (
|
|||||||
</ListSubheader>
|
</ListSubheader>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
backgroundModal: {
|
||||||
|
background: 'black',
|
||||||
|
opacity: '0.6',
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
zIndex: 5,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export const SettingsApp = () => {
|
export const SettingsApp = () => {
|
||||||
const settingsApp = useApp('SETTINGS');
|
const settingsApp = useApp('SETTINGS');
|
||||||
const [config] = useConfig();
|
const [config] = useConfig();
|
||||||
const simcard = useSimcard();
|
const simcard = useSimcard();
|
||||||
const [settings, setSettings] = useSettings();
|
const [settings, setSettings] = useSettings();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal();
|
||||||
|
|
||||||
const { addAlert } = useSnackbar();
|
const { addAlert } = useSnackbar();
|
||||||
|
|
||||||
@@ -123,9 +139,12 @@ export const SettingsApp = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu();
|
const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu();
|
||||||
|
const classes = useStyles();
|
||||||
return (
|
return (
|
||||||
<AppWrapper>
|
<AppWrapper>
|
||||||
<AppTitle app={settingsApp} />
|
<AppTitle app={settingsApp} />
|
||||||
|
<WallpaperModal />
|
||||||
|
<div className={customWallpaperModal ? classes.backgroundModal : undefined} />
|
||||||
<AppContent backdrop={isMenuOpen} onClickBackdrop={closeMenu}>
|
<AppContent backdrop={isMenuOpen} onClickBackdrop={closeMenu}>
|
||||||
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.PHONE')} />}>
|
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.PHONE')} />}>
|
||||||
<SettingItemIconAction
|
<SettingItemIconAction
|
||||||
@@ -194,6 +213,13 @@ export const SettingsApp = () => {
|
|||||||
onClick={openMenu}
|
onClick={openMenu}
|
||||||
icon={<Wallpaper />}
|
icon={<Wallpaper />}
|
||||||
/>
|
/>
|
||||||
|
{/* CUSTOM BACKGROUND */}
|
||||||
|
<SettingItemModal
|
||||||
|
icon={<Wallpaper />}
|
||||||
|
label={t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER')}
|
||||||
|
secondary={settings.customWallpaper}
|
||||||
|
onClick={() => setCustomWallpaperModal(true)}
|
||||||
|
/>
|
||||||
<SettingItem
|
<SettingItem
|
||||||
label={t('APPS_SETTINGS_OPTION_FRAME')}
|
label={t('APPS_SETTINGS_OPTION_FRAME')}
|
||||||
value={settings.frame.label}
|
value={settings.frame.label}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import Modal from '../../../ui/components/Modal';
|
||||||
|
import { useCustomWallpaperModal, useSettings } from '../hooks/useSettings';
|
||||||
|
import { Box, Button, TextField } from '@material-ui/core';
|
||||||
|
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
|
import { StatusButton } from '../../../ui/components/StatusButton';
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
input: {
|
||||||
|
marginTop: 10,
|
||||||
|
marginBottom: 10,
|
||||||
|
},
|
||||||
|
inputProps: {
|
||||||
|
fontSize: 18,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function WallpaperModal() {
|
||||||
|
const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal();
|
||||||
|
const [settings, setSettings] = useSettings();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [value, setValue] = useState(settings.customWallpaper ? settings.customWallpaper : '');
|
||||||
|
const classes = useStyles();
|
||||||
|
|
||||||
|
const isImage = (url) => {
|
||||||
|
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 (
|
||||||
|
<Modal visible={customWallpaperModal} handleClose={handleCloseModal}>
|
||||||
|
<Box
|
||||||
|
display="flex"
|
||||||
|
justifyContent="center"
|
||||||
|
alignItems="center"
|
||||||
|
textAlign="center"
|
||||||
|
flexDirection="column"
|
||||||
|
>
|
||||||
|
{settings.customWallpaper && (
|
||||||
|
<PictureThumbnail src={settings.customWallpaper} alt="chipisbest" />
|
||||||
|
)}
|
||||||
|
<TextField
|
||||||
|
value={value}
|
||||||
|
variant="outlined"
|
||||||
|
className={classes.input}
|
||||||
|
onChange={(e) => setValue(e.currentTarget.value)}
|
||||||
|
inputProps={{
|
||||||
|
className: classes.inputProps,
|
||||||
|
}}
|
||||||
|
placeholder="Image URL"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
variant="contained"
|
||||||
|
disabled={!isImage(value)}
|
||||||
|
onClick={handleNewWallpaper}
|
||||||
|
style={{ marginBottom: 10 }}
|
||||||
|
>
|
||||||
|
{t('APPS_SETTINGS_SET_CUSTOM_WALLPAPER')}
|
||||||
|
</Button>
|
||||||
|
{settings.customWallpaper && (
|
||||||
|
<StatusButton color="error" variant="contained" onClick={handleRemoveWallpaper}>
|
||||||
|
{t('GENERIC_DELETE')}
|
||||||
|
</StatusButton>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ const settingsSchema: Schema = {
|
|||||||
properties: {
|
properties: {
|
||||||
language: { $ref: '/SettingOption' },
|
language: { $ref: '/SettingOption' },
|
||||||
wallpaper: { $ref: '/SettingOption' },
|
wallpaper: { $ref: '/SettingOption' },
|
||||||
|
customWallpaper: { $ref: '/SettingOption' },
|
||||||
frame: { $ref: '/SettingOption' },
|
frame: { $ref: '/SettingOption' },
|
||||||
theme: { $ref: '/SettingOption' },
|
theme: { $ref: '/SettingOption' },
|
||||||
zoom: { $ref: '/SettingOption' },
|
zoom: { $ref: '/SettingOption' },
|
||||||
@@ -63,6 +64,7 @@ export function isSettingsSchemaValid(): boolean {
|
|||||||
export interface IPhoneSettings {
|
export interface IPhoneSettings {
|
||||||
language: SettingOption;
|
language: SettingOption;
|
||||||
wallpaper: SettingOption;
|
wallpaper: SettingOption;
|
||||||
|
customWallpaper: string;
|
||||||
frame: SettingOption;
|
frame: SettingOption;
|
||||||
theme: SettingOption;
|
theme: SettingOption;
|
||||||
zoom: SettingOption;
|
zoom: SettingOption;
|
||||||
@@ -110,6 +112,11 @@ export const settingsState = atom({
|
|||||||
effects_UNSTABLE: [localStorageEffect(NPWD_STORAGE_KEY)],
|
effects_UNSTABLE: [localStorageEffect(NPWD_STORAGE_KEY)],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const customWallpaperState = atom({
|
||||||
|
key: 'customWallpaperState',
|
||||||
|
default: false,
|
||||||
|
});
|
||||||
|
|
||||||
export const useSettings = () => {
|
export const useSettings = () => {
|
||||||
return useRecoilState(settingsState);
|
return useRecoilState(settingsState);
|
||||||
};
|
};
|
||||||
@@ -117,3 +124,8 @@ export const useSettings = () => {
|
|||||||
export const useResetSettings = () => {
|
export const useResetSettings = () => {
|
||||||
return useResetRecoilState(settingsState);
|
return useResetRecoilState(settingsState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useCustomWallpaperModal = () => {
|
||||||
|
const [customWallpaperModal, setCustomWallpaperModal] = useRecoilState(customWallpaperState);
|
||||||
|
return { customWallpaperModal, setCustomWallpaperModal };
|
||||||
|
};
|
||||||
@@ -144,6 +144,7 @@
|
|||||||
"label": "Project Error",
|
"label": "Project Error",
|
||||||
"value": "projecterror.jpg"
|
"value": "projecterror.jpg"
|
||||||
},
|
},
|
||||||
|
"customWallpaper": "",
|
||||||
"frame": {
|
"frame": {
|
||||||
"label": "Default",
|
"label": "Default",
|
||||||
"value": "default.png"
|
"value": "default.png"
|
||||||
|
|||||||
@@ -180,6 +180,7 @@
|
|||||||
|
|
||||||
"APPS_SETTINGS_PHONE_NUMBER": "Phone Number",
|
"APPS_SETTINGS_PHONE_NUMBER": "Phone Number",
|
||||||
"APPS_SETTINGS_OPTION_WALLPAPER": "Wallpaper",
|
"APPS_SETTINGS_OPTION_WALLPAPER": "Wallpaper",
|
||||||
|
"APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER": "Custom Wallpaper",
|
||||||
"APPS_SETTINGS_OPTION_FRAME": "Frame",
|
"APPS_SETTINGS_OPTION_FRAME": "Frame",
|
||||||
"APPS_SETTINGS_OPTION_THEME": "Theme",
|
"APPS_SETTINGS_OPTION_THEME": "Theme",
|
||||||
"APPS_SETTINGS_OPTION_ZOOM": "Zoom",
|
"APPS_SETTINGS_OPTION_ZOOM": "Zoom",
|
||||||
@@ -190,6 +191,7 @@
|
|||||||
"APPS_SETTINGS_OPTION_NOTIFICATION": "Notification",
|
"APPS_SETTINGS_OPTION_NOTIFICATION": "Notification",
|
||||||
"APPS_SETTINGS_OPTION_NOTIFICATIONVOL": "Notification Volume",
|
"APPS_SETTINGS_OPTION_NOTIFICATIONVOL": "Notification Volume",
|
||||||
"APPS_SETTING_STREAMER_MODE_DESC": "Hide images before they are shown",
|
"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_SUCCESS": "Successfully created a new listing",
|
||||||
"APPS_MARKETPLACE_CREATE_LISTING_FAILED": "Failed to create a new listing",
|
"APPS_MARKETPLACE_CREATE_LISTING_FAILED": "Failed to create a new listing",
|
||||||
|
|||||||
Reference in new issue
Block a user