import React, { useState, useEffect } from "react";
import {
StyleSheet,
View,
StatusBar,
TextInput,
Text,
Switch,
} from "react-native";
import themeColors from '../components/themeColors';
import MaterialIcon from "react-native-vector-icons/MaterialCommunityIcons";
import EntypoIcon from "react-native-vector-icons/Entypo";
import ImageHeader from "../components/ImageHeader";
import { connect } from 'react-redux';
import { TouchableOpacity } from "react-native-gesture-handler";
import request from '../utility/PromiseRequest';
import i18n from 'i18n-js';
// ---------------------------------------------------------------------------------------------
function SettingsTextInput(props) {
return (
{props.label}
);
}
function SettingsSwitch(props) {
const [isEnabled, setIsEnabled] = useState(false);
const toggleSwitch = () => setIsEnabled(previousState => !previousState);
return (
{props.label}
)
}
function SettingsButton(props) {
return (
{props.label}
{props.buttonText}
)
}
function SettingsText(props) {
return (
{props.label}
{props.text}
)
}
function SettingsSlider(props) {
/*
*/
return (
{props.label}
)
}
function SettingsCombo(props) {
}
function SettingsGroup(props) {
return (
{props.title}
{React.Children.map(props.children, (child, idx) =>
{child}
)}
);
};
const settingsGroupStyles = StyleSheet.create({
container: {
padding: 20,
paddingRight: 30,
},
title: {
color: "white",
fontSize: 20,
fontWeight: "600",
},
subsettings: {
padding: 10,
paddingLeft: 30,
},
row: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
borderTopColor: "rgba(255, 255,255, 0.6)",
paddingTop: 5,
paddingBottom: 5,
borderTopWidth: 0.5,
minHeight: 40,
},
firstRow: {
paddingTop: 0,
borderTopWidth: 0,
},
label: {
color: "white",
fontSize: 17,
},
textInput: {
color: "rgba(255,255,255,1)",
marginTop: 8,
textAlign: "right",
},
slider: {
minWidth: 100,
width: 150,
//minHeight: 50,
},
switch: {
//minHeight: 50,
//minWidth: 80,
},
buttonText: {
color: "rgba(255,255,255,1)",
width: "100%",
textAlign: "center",
},
text : {
color: "rgba(255,255,255,1)",
width: "100%",
textAlign: "right",
},
buttonTouchable: {
backgroundColor: themeColors["CARROT"],
width: 128,
padding: 10,
justifyContent: "center",
borderRadius: 4,
}
});
// ---------------------------------------------------------------------------------------------
async function queryDeviceFirmwareVersion(swimTrackerHost) {
const result = await request({ url: "http://" + swimTrackerHost + "/api/status", responseType: "json" });
return result["firmware"]["version"];
}
async function queryNewestFirmwareVersion() {
const QUERY_URL = "https://swimtracker-update.bauer.tech/VERSION";
const result = await request({ url: QUERY_URL, responseType: "text" });
console.log("newest firmware version, got", result);
return result;
}
function SettingsView(props) {
const [deviceFirmwareVersion, setDeviceFirmwareVersion] = useState("");
const [newestFirmwareVersion, setNewestFirmwareVersion] = useState("");
useEffect(() => {
Promise.all([queryDeviceFirmwareVersion(props.settings.swimTrackerHost), queryNewestFirmwareVersion()]).then(
(values) => {
setDeviceFirmwareVersion(values[0]);
setNewestFirmwareVersion(values[1]);
}
);
});
const doFirmwareUpdate = () => {
request({ url: "http://" + props.settings.swimTrackerHost + "/api/firmwareupdate", responseType: "text"});
};
return (
)
}
const mapStateToProps = (state) => {
return { settings: state.settings };
};
export default connect(mapStateToProps)(SettingsView);