Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Sep 7, 2024
1 parent ca40756 commit 07b9970
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 26 deletions.
58 changes: 38 additions & 20 deletions src/activitys/MainApplication.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import CodeRoundedIcon from "@mui/icons-material/CodeRounded";
import React from "react";
import Typography from "@mui/material/Typography";
import MenuIcon from "@mui/icons-material/Menu";
import ModuleFragment from "./fragments/ModuleFragment";
import DeviceModule from "@Components/module/DeviceModule";
import ExploreModule from "@Components/module/ExploreModule";
import UpdateModule from "@Components/module/UpdateModule";
import { ModuleViewActivity } from "./ModuleViewActivity";
import CreateNewFolderIcon from "@mui/icons-material/CreateNewFolder";
import { useActivity } from "@Hooks/useActivity";
import { Toolbar } from "@Components/onsenui/Toolbar";
import { os } from "@Native/Os";
import { useModuleQueue } from "@Components/ModulesQueue";
import Fab from "@Components/onsenui/Fab";
import { Page } from "@Components/onsenui/Page";
import { useStrings } from "@Hooks/useStrings";
import { Tabbar, TabbarRenderTab } from "@Components/onsenui/Tabbar";
import { useRepos } from "@Hooks/useRepos";
import SearchIcon from "@mui/icons-material/Search";
import Fab from "@Components/onsenui/Fab";
import { Toolbar } from "@Components/onsenui/Toolbar";
import { useActivity } from "@Hooks/useActivity";
import { useLocalModules } from "@Hooks/useLocalModules";
import { Shell } from "@Native/Shell";
import { useRepos } from "@Hooks/useRepos";
import { useSettings } from "@Hooks/useSettings";
import { useOpenModuleSearch } from "@Hooks/useOpenModuleSearch";
import InstallTerminalV2Activity from "./InstallTerminalV2Activity";
import { Chooser } from "@Native/Chooser";
import { useConfirm } from "material-ui-confirm";
import { useStrings } from "@Hooks/useStrings";
import CodeRoundedIcon from "@mui/icons-material/CodeRounded";
import CreateNewFolderIcon from "@mui/icons-material/CreateNewFolder";
import MenuIcon from "@mui/icons-material/Menu";
import VolunteerActivismIcon from "@mui/icons-material/VolunteerActivism";
import { SuFile } from "@Native/SuFile";
import Typography from "@mui/material/Typography";
import { Chooser } from "@Native/Chooser";
import { Log } from "@Native/Log";
import { os } from "@Native/Os";
import { Shell } from "@Native/Shell";
import { SuFile } from "@Native/SuFile";
import { SuZip } from "@Native/SuZip";
import { useConfirm } from "material-ui-confirm";
import { Properties } from "properties-file";
import React from "react";
import ModuleFragment from "./fragments/ModuleFragment";
import InstallTerminalV2Activity from "./InstallTerminalV2Activity";
import { ModuleViewActivity } from "./ModuleViewActivity";
import LayersIcon from "@mui/icons-material/Layers";

const TAG = "MainApplication";

Expand Down Expand Up @@ -114,6 +114,8 @@ const MainApplication = () => {
}
}, [modules]);

const { toggleQueueView } = useModuleQueue();

const renderTabs = (): TabbarRenderTab[] => {
return [
{
Expand All @@ -123,6 +125,22 @@ const MainApplication = () => {
modules={modules}
searchBy={["id", "name", "author", "__mmrl_repo_source"]}
renderItem={(module, key) => <ExploreModule key={key} module={module} />}
renderFixed={() => {
return (
<Fab
sx={{
"& .fab__icon": {
verticalAlign: "middle",
color: "black",
},
}}
onClick={toggleQueueView}
position="bottom right"
>
<LayersIcon />
</Fab>
);
}}
/>
),
tab: <Tabbar.Tab label={strings("explore")} />,
Expand Down
21 changes: 20 additions & 1 deletion src/activitys/ModuleViewActivity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import { AboutTab } from "./tabs/AboutTabs";
import { OverviewTab } from "./tabs/OverviewTab";
import { VersionsTab } from "./tabs/VersionsTab";
import { useDocumentTitle } from "usehooks-ts";
import LayersIcon from "@mui/icons-material/Layers";
import { useModuleQueue } from "@Components/ModulesQueue";
import Button from "@mui/material/Button";

function a11yProps(index: number) {
return {
Expand Down Expand Up @@ -71,6 +74,8 @@ const ModuleViewActivity = () => {

const search = React.useMemo(() => new URLSearchParams(window.location.search), [window.location.search]);

const { addModule: addModuleToQueue } = useModuleQueue();

useDocumentTitle(`${name} — MMRL`, { preserveTitleOnUnmount: false });

React.useEffect(() => {
Expand Down Expand Up @@ -334,12 +339,26 @@ const ModuleViewActivity = () => {
)}
</Stack>

<Stack direction="column" justifyContent="center" alignItems="stretch" spacing={1}>
<Stack direction="row" justifyContent="center" alignItems="stretch" spacing={1}>
<Button
size="small"
onClick={() => {
addModuleToQueue({
name: name,
url: latestVersion.zipUrl,
size: size,
});
}}
variant="contained"
>
<LayersIcon />
</Button>
<DropdownButton
sx={{
width: "100%",
"& .MuiButtonGroup-root": {
width: "100%",
height: "100%",
},
"& .MuiButton-root:first-child": {
width: "100%",
Expand Down
128 changes: 128 additions & 0 deletions src/components/ModulesQueue.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { Box, Button, Drawer, IconButton, List, ListItem, ListItemText, Stack, Typography } from "@mui/material";
import { view } from "@Native/View";
import React from "react";
import CloseIcon from "@mui/icons-material/Close";
import { useStrings } from "@Hooks/useStrings";
import { os } from "@Native/Os";
import { useFormatBytes } from "@Hooks/useFormatBytes";

interface ModulesQueueContext {
addModule: (queue: Queue) => void;
removeModule: (index: any) => void;
toggleQueueView: () => void;
isQueueOpen: boolean;
}
const ModulesQueueContext = React.createContext<ModulesQueueContext>({
addModule(queue) {},
removeModule(index) {},
toggleQueueView() {},
isQueueOpen: false,
});

interface Queue {
name: string;
url: string;
size?: number;
}

interface ModulesQueueProps extends React.PropsWithChildren {}

const QueueItem = ({ module, onClick }: any) => {
const [moduleFileSize, moduleFileSizeByteText] = useFormatBytes(module.size);
const { strings } = useStrings();

return (
<ListItem disablePadding>
<ListItemText primary={module.name} secondary={`${moduleFileSize} ${moduleFileSizeByteText}`} />
<Button variant="outlined" color="secondary" onClick={onClick}>
{strings("remove")}
</Button>
</ListItem>
);
};

export const ModulesQueue = (props: ModulesQueueProps) => {
const [queue, setQueue] = React.useState<Queue[]>([]);
const [open, setOpen] = React.useState(false);
const { strings } = useStrings();

const addModule = (queue: Queue) => {
setQueue((qu) => {
if (qu.some((g) => g.url === queue.url)) {
os.toast(strings("alr_add_queue") as string, Toast.LENGTH_SHORT);
return qu;
}

os.toast(strings("add_t_queue") as string, Toast.LENGTH_SHORT);
return [...qu, queue];
});
};

const removeModule = (index) => {
setQueue(queue.filter((_, i) => i !== index));
};

const toggleDrawer = () => {
setOpen(!open);
};

const value = React.useMemo(
() => ({
addModule,
removeModule,
toggleQueueView: toggleDrawer,
isQueueOpen: open,
}),
[addModule, removeModule, toggleDrawer, open]
);

return (
<ModulesQueueContext.Provider value={value}>
{props.children}

<Drawer anchor="bottom" open={open} onClose={toggleDrawer}>
<Box
role="presentation"
sx={{ p: 2, pb: `calc(16px + ${view.getWindowBottomInsets()}px)` }}
height="100%"
display="flex"
flexDirection="column"
justifyContent="space-between"
>
<Stack
direction="row"
spacing={2}
sx={{
justifyContent: "space-between",
alignItems: "center",
}}
>
<Box>
<Typography variant="h6">{strings("install_queue")}</Typography>
<Typography color="text.secondary" variant="caption" gutterBottom>
{strings("install_queue_notice")}
</Typography>
</Box>
<IconButton onClick={toggleDrawer} sx={{ height: "100%", alignSelf: "center" }}>
<CloseIcon />
</IconButton>
</Stack>

<Box sx={{ mt: 2 }}>
<List>
{queue.length !== 0 ? (
queue.map((module, index) => <QueueItem key={`wueue-${index}`} module={module} onClick={() => removeModule(index)} />)
) : (
<>
<Typography variant="h6">{strings("install_queue_empty")}</Typography>
</>
)}
</List>
</Box>
</Box>
</Drawer>
</ModulesQueueContext.Provider>
);
};

export const useModuleQueue = () => React.useContext(ModulesQueueContext);
15 changes: 15 additions & 0 deletions src/hooks/useTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ const THIS_IS_THE_THEME_OBJECT_OF_THIS_F_APP = createTheme({
},
},
},
MuiDrawer: {
styleOverrides: {
root: {
"& .MuiDrawer-paper": {
backgroundImage: "none",
borderTop: `1px solid #333638`,
},
"& .MuiModal-backdrop": {
backgroundColor: "rgba(0, 0, 0, 0.5)",
WebkitTapHighlightColor: "transparent",
backdropFilter: "blur(4px)",
},
},
},
},
MuiDialog: {
styleOverrides: {
root: {
Expand Down
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Toolbar } from "@Components/onsenui/Toolbar";
import { Pre } from "@Components/dapi/Pre";
import { Code } from "@Components/dapi/Code";
import { Anchor } from "@Components/dapi/Anchor";
import { ModulesQueue } from "@Components/ModulesQueue";

ons.platform.select("android");

Expand Down Expand Up @@ -103,7 +104,9 @@ ons.ready(() => {
<Preventer prevent="contextmenu">
<RepoProvider>
<ConfirmProvider>
<MainActivity />
<ModulesQueue>
<MainActivity />
</ModulesQueue>
</ConfirmProvider>
</RepoProvider>
</Preventer>
Expand Down
7 changes: 6 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,10 @@ export const en = {
feature: "Feature",
verified: "Verified",
last_updated: "Last updated: {date}",
telegram_channel: "Telegram channel"
telegram_channel: "Telegram channel",
install_queue: "Install queue",
install_queue_notice: "The queue will be deleted when you close the app",
install_queue_empty: "Your queue is empty. Add some modules!",
alr_add_queue: "This module has been already added to your queue",
add_t_queue: "Module has been added to your queue",
};
8 changes: 5 additions & 3 deletions src/styles/light_theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4491,12 +4491,14 @@ export const LightTheme = () => {
left: "0",
right: "0",
bottom: "0",
margin: "0",
backgroundColor: theme.palette.primary.main,
borderRadius: 0,
// margin: "0",
backgroundColor: theme.palette.background.paper,
borderRadius: theme.shape.borderRadius,
border: `1px solid ${theme.palette.divider}`,
boxShadow:
"rgb(255, 255, 255) 0px 0px 0px 0px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px, rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px",
padding: "16px 24px",
margin: `16px 16px calc(16px + ${view.getWindowBottomInsets()}px) 16px`,
},
".toast--material__message": {
fontFamily: '"Roboto", "Noto", sans-serif',
Expand Down

0 comments on commit 07b9970

Please sign in to comment.