2020-03-14 11:35:35 +01:00
|
|
|
import React, { useState } from "react";
|
2020-03-28 13:48:49 +01:00
|
|
|
import Color from "color";
|
2020-03-17 14:55:03 +01:00
|
|
|
import PropTypes from "prop-types";
|
2020-03-14 11:35:35 +01:00
|
|
|
import {
|
|
|
|
Appbar,
|
|
|
|
Text,
|
|
|
|
Card,
|
2020-03-17 14:55:03 +01:00
|
|
|
Dialog,
|
|
|
|
Portal,
|
|
|
|
Button,
|
|
|
|
Provider,
|
|
|
|
RadioButton,
|
2020-03-28 13:48:49 +01:00
|
|
|
TouchableRipple,
|
|
|
|
overlay,
|
2020-03-14 11:35:35 +01:00
|
|
|
} from "react-native-paper";
|
|
|
|
|
2020-03-28 13:48:49 +01:00
|
|
|
import { View, StatusBar, StyleSheet, Text as RNText } from "react-native";
|
2020-03-20 11:15:54 +01:00
|
|
|
import { NavigationContainer } from "@react-navigation/native";
|
2020-03-28 13:48:49 +01:00
|
|
|
import { TabView, SceneMap, TabBar } from "react-native-tab-view";
|
|
|
|
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
|
2020-03-17 14:55:03 +01:00
|
|
|
|
2020-03-16 16:01:05 +01:00
|
|
|
import SubjectsContainer from "./containers/SubjectsContainer";
|
2020-03-20 11:15:54 +01:00
|
|
|
import TimetableContainer from "./containers/TimetableContainer";
|
2020-03-17 14:55:03 +01:00
|
|
|
import themes from "./themes";
|
2020-03-16 16:01:05 +01:00
|
|
|
|
2020-03-14 11:35:35 +01:00
|
|
|
|
|
|
|
function Dummy() {
|
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<Card.Title title="Card Title" />
|
|
|
|
<Card.Content>
|
|
|
|
<Text>Dummy</Text>
|
|
|
|
</Card.Content>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
2020-03-07 09:23:17 +01:00
|
|
|
|
2020-03-17 14:55:03 +01:00
|
|
|
function ThemePicker({ onPress, selectionIdx }) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{themes.map((t, idx) => (
|
|
|
|
<TouchableRipple
|
|
|
|
onPress={() => onPress(t, idx)}
|
|
|
|
key={idx}
|
|
|
|
>
|
|
|
|
<View style={styles.radio}>
|
|
|
|
<RadioButton
|
|
|
|
status={selectionIdx === idx ? "checked": "unchecked"}
|
2020-03-20 11:15:54 +01:00
|
|
|
onPress={() => onPress(t, idx)}
|
2020-03-17 14:55:03 +01:00
|
|
|
/>
|
|
|
|
<Text>{t.name}</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableRipple>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThemePicker.propTypes = {
|
|
|
|
onPress: PropTypes.func,
|
|
|
|
selectionIdx: PropTypes.number,
|
|
|
|
};
|
|
|
|
|
|
|
|
const App = ({ theme, setTheme }) => {
|
2020-03-28 13:48:49 +01:00
|
|
|
|
|
|
|
function renderLabel({ route, focused, color }) {
|
|
|
|
return <RNText style={{color: focused ? color : backgroundColor}}>{route.title}</RNText>;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLabel.propTypes = {
|
|
|
|
route: PropTypes.object,
|
|
|
|
focused: PropTypes.bool,
|
|
|
|
color: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
function renderIcon({ route, color }) {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Icon name={route.icon} color={color} size={20}/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderIcon.propTypes = renderLabel.propTypes;
|
|
|
|
|
2020-03-14 11:35:35 +01:00
|
|
|
const [ pane, setPane ] = useState({
|
|
|
|
index: 0,
|
|
|
|
routes: [
|
2020-03-16 16:01:05 +01:00
|
|
|
{ key: "add", title: "Add Classes", icon: "pencil-plus" },
|
2020-03-14 11:35:35 +01:00
|
|
|
{ key: "statistics", title: "Statistics", icon: "file-chart" },
|
2020-03-20 11:15:54 +01:00
|
|
|
{ key: "timetable", title: "Timetable", icon: "timetable" },
|
2020-03-16 16:01:05 +01:00
|
|
|
{ key: "subjects", title: "Subjects", icon: "book-open" },
|
2020-03-14 11:35:35 +01:00
|
|
|
],
|
|
|
|
});
|
2020-03-17 14:55:03 +01:00
|
|
|
const [ showDialog, setShowDialog ] = useState(false);
|
|
|
|
const [ newTheme, setNewTheme ] = useState(themes.findIndex(
|
|
|
|
i => JSON.stringify(i.theme) === JSON.stringify(theme)
|
|
|
|
));
|
2020-03-28 13:48:49 +01:00
|
|
|
const renderScene = SceneMap({
|
2020-03-16 16:01:05 +01:00
|
|
|
add: Dummy,
|
2020-03-14 11:35:35 +01:00
|
|
|
statistics: Dummy,
|
2020-03-20 11:15:54 +01:00
|
|
|
timetable: TimetableContainer,
|
2020-03-16 16:01:05 +01:00
|
|
|
subjects: SubjectsContainer,
|
2020-03-14 11:35:35 +01:00
|
|
|
});
|
2020-03-17 14:55:03 +01:00
|
|
|
|
2020-03-28 13:48:49 +01:00
|
|
|
const backgroundColor = theme.dark && theme.mode === "adaptive" ?
|
|
|
|
overlay(4, theme.colors.surface):
|
|
|
|
theme.colors.primary;
|
|
|
|
|
|
|
|
const activeColor = Color(backgroundColor).isLight() ? "#000" : "#FFF";
|
|
|
|
const inactiveColor = Color(backgroundColor).isLight() ? "#222" : "#AAA";
|
2020-03-17 14:55:03 +01:00
|
|
|
function dialogSelection(theme, idx) {
|
|
|
|
setNewTheme(idx);
|
|
|
|
setTheme(theme.theme);
|
|
|
|
}
|
2020-03-12 18:14:38 +01:00
|
|
|
return (
|
2020-03-20 11:15:54 +01:00
|
|
|
<NavigationContainer theme={theme}>
|
2020-03-17 14:55:03 +01:00
|
|
|
<StatusBar
|
2020-03-28 13:48:49 +01:00
|
|
|
backgroundColor={backgroundColor}
|
2020-03-14 11:35:35 +01:00
|
|
|
/>
|
2020-03-17 14:55:03 +01:00
|
|
|
<Provider theme={theme}>
|
|
|
|
<Appbar.Header>
|
|
|
|
<Appbar.Content
|
|
|
|
title="Sonzai"
|
|
|
|
/>
|
|
|
|
<Appbar.Action
|
|
|
|
icon="brush"
|
|
|
|
onPress={() => setShowDialog(true)}
|
|
|
|
/>
|
|
|
|
</Appbar.Header>
|
2020-03-28 13:48:49 +01:00
|
|
|
<TabView
|
2020-03-17 14:55:03 +01:00
|
|
|
navigationState={pane}
|
|
|
|
onIndexChange={(index) => setPane({
|
|
|
|
index,
|
|
|
|
routes: pane.routes
|
|
|
|
})}
|
|
|
|
renderScene={renderScene}
|
|
|
|
shifting={true}
|
2020-03-28 13:48:49 +01:00
|
|
|
tabBarPosition="bottom"
|
|
|
|
renderTabBar={props => (
|
|
|
|
<TabBar
|
|
|
|
{...props}
|
|
|
|
style={{
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
}}
|
|
|
|
activeColor={activeColor}
|
|
|
|
inactiveColor={inactiveColor}
|
|
|
|
renderLabel={renderLabel}
|
|
|
|
renderIcon={renderIcon}
|
|
|
|
renderIndicator={() => null}
|
|
|
|
/>)
|
|
|
|
}
|
|
|
|
sceneContainerStyle={{
|
|
|
|
backgroundColor: theme.colors.background
|
|
|
|
}}
|
2020-03-17 14:55:03 +01:00
|
|
|
/>
|
|
|
|
<Portal>
|
|
|
|
<Dialog
|
|
|
|
visible={showDialog}
|
|
|
|
onDismiss={() => setShowDialog(false)}>
|
|
|
|
<Dialog.Title>Theme</Dialog.Title>
|
|
|
|
<Dialog.Content>
|
|
|
|
<ThemePicker
|
|
|
|
onPress={dialogSelection}
|
|
|
|
selectionIdx={newTheme}
|
|
|
|
/>
|
|
|
|
</Dialog.Content>
|
|
|
|
<Dialog.Actions>
|
|
|
|
<Button onPress={() => setShowDialog(false)}>Close</Button>
|
|
|
|
</Dialog.Actions>
|
|
|
|
</Dialog>
|
|
|
|
</Portal>
|
|
|
|
</Provider>
|
2020-03-20 11:15:54 +01:00
|
|
|
</NavigationContainer>
|
2020-03-12 18:14:38 +01:00
|
|
|
);
|
2020-03-07 09:23:17 +01:00
|
|
|
};
|
|
|
|
|
2020-03-17 14:55:03 +01:00
|
|
|
App.propTypes = {
|
|
|
|
theme: PropTypes.object,
|
|
|
|
setTheme: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
radio: {
|
|
|
|
flexDirection: "row",
|
|
|
|
alignItems: "center",
|
|
|
|
margin: 5
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-07 09:23:17 +01:00
|
|
|
export default App;
|