mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 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 { 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 ? (
|
||||
|
||||
@@ -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 = ({
|
||||
</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 { 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 }) => (
|
||||
<ListSubheader color="primary" component="div" disableSticky>
|
||||
@@ -41,12 +43,26 @@ const SubHeaderComp = (props: { text: string }) => (
|
||||
</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 = () => {
|
||||
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 (
|
||||
<AppWrapper>
|
||||
<AppTitle app={settingsApp} />
|
||||
<WallpaperModal />
|
||||
<div className={customWallpaperModal ? classes.backgroundModal : undefined} />
|
||||
<AppContent backdrop={isMenuOpen} onClickBackdrop={closeMenu}>
|
||||
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.PHONE')} />}>
|
||||
<SettingItemIconAction
|
||||
@@ -194,6 +213,13 @@ export const SettingsApp = () => {
|
||||
onClick={openMenu}
|
||||
icon={<Wallpaper />}
|
||||
/>
|
||||
{/* CUSTOM BACKGROUND */}
|
||||
<SettingItemModal
|
||||
icon={<Wallpaper />}
|
||||
label={t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER')}
|
||||
secondary={settings.customWallpaper}
|
||||
onClick={() => setCustomWallpaperModal(true)}
|
||||
/>
|
||||
<SettingItem
|
||||
label={t('APPS_SETTINGS_OPTION_FRAME')}
|
||||
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: {
|
||||
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 };
|
||||
};
|
||||
@@ -144,6 +144,7 @@
|
||||
"label": "Project Error",
|
||||
"value": "projecterror.jpg"
|
||||
},
|
||||
"customWallpaper": "",
|
||||
"frame": {
|
||||
"label": "Default",
|
||||
"value": "default.png"
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user