diff --git a/components/AndroidWidget/InfoWidget.jsx b/components/AndroidWidget/InfoWidget.jsx index 7363143..f70c8cc 100644 --- a/components/AndroidWidget/InfoWidget.jsx +++ b/components/AndroidWidget/InfoWidget.jsx @@ -4,6 +4,25 @@ import { TextWidget, ListWidget, } from "react-native-android-widget"; +import dayjs from "dayjs"; +import { ToastAndroid } from "react-native"; + +export const getInfoString = async () => { + // Fetch data from the server + const time = dayjs().format("HH:mm"); + const text = await fetch( + "https://script.google.com/macros/s/AKfycbz80LcaEUrhnlEsLkJy0LG2IRO3DBVQhfNmN1d_0f_HvtsujNQpxM90SrV9yKWH_JG1Ww/exec" + ) + .then((response) => response.text()) + .then((data) => { + if (data !== "") { + return data.split("^"); + } + return null; + }); + ToastAndroid.show(`${text}`, ToastAndroid.SHORT); + return { time, text }; +}; export function InfoWidget({ time, text }) { return ( diff --git a/components/AndroidWidget/TraInfoEXWidget.jsx b/components/AndroidWidget/TraInfoEXWidget.jsx index d55cb43..3cfc161 100644 --- a/components/AndroidWidget/TraInfoEXWidget.jsx +++ b/components/AndroidWidget/TraInfoEXWidget.jsx @@ -4,7 +4,25 @@ import { TextWidget, ListWidget, } from "react-native-android-widget"; +import dayjs from "dayjs"; +import { ToastAndroid } from "react-native"; +export const getDelayData = async () => { + // Fetch data from the server + const time = dayjs().format("HH:mm"); + const delayString = await fetch( + "https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec" + ) + .then((response) => response.text()) + .then((data) => { + if (data !== "") { + return data.split("^"); + } + return null; + }); + ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT); + return { time, delayString }; +}; export function TraInfoEXWidget({ time, delayString }) { return ( { - // Fetch data from the server - const time = dayjs().format("HH:mm"); - const text = await fetch( - "https://script.google.com/macros/s/AKfycbz80LcaEUrhnlEsLkJy0LG2IRO3DBVQhfNmN1d_0f_HvtsujNQpxM90SrV9yKWH_JG1Ww/exec" - ) - .then((response) => response.text()) - .then((data) => { - if (data !== "") { - return data.split("^"); - } - return null; - }); - ToastAndroid.show(`${text}`, ToastAndroid.SHORT); - return { time, text }; -}; - -export const getDelayData = async () => { - // Fetch data from the server - const time = dayjs().format("HH:mm"); - const delayString = await fetch( - "https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec" - ) - .then((response) => response.text()) - .then((data) => { - if (data !== "") { - return data.split("^"); - } - return null; - }); - ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT); - return { time, delayString }; -}; export async function widgetTaskHandler(props) { const { widgetInfo, @@ -65,18 +31,12 @@ export async function widgetTaskHandler(props) { case "WIDGET_CLICK": case "WIDGET_RESIZED": switch (WidgetName) { - case "JR_shikoku_train_info": { - const { time, delayString } = await getDelayData(); - renderWidget( - - ); - break; - } case "Info_Widget": { const { time, text } = await getInfoString(); renderWidget(); break; } + case "JR_shikoku_train_info": default: { const { time, delayString } = await getDelayData(); renderWidget( diff --git a/components/Settings/WidgetSettings.js b/components/Settings/WidgetSettings.js index 38633b2..20077d3 100644 --- a/components/Settings/WidgetSettings.js +++ b/components/Settings/WidgetSettings.js @@ -4,13 +4,10 @@ import { SwitchArea } from "../atom/SwitchArea"; import { CheckBox } from "react-native-elements"; import { TripleSwitchArea } from "../atom/TripleSwitchArea"; import { getWidgetInfo, WidgetPreview } from "react-native-android-widget"; -import { TraInfoEXWidget } from "../AndroidWidget/TraInfoEXWidget"; +import { getDelayData } from "../AndroidWidget/TraInfoEXWidget"; +import { getInfoString } from "../AndroidWidget/InfoWidget"; import { AS } from "../../storageControl"; -import { - getDelayData, - nameToWidget, - getInfoString, -} from "../AndroidWidget/widget-task-handler"; +import { nameToWidget } from "../AndroidWidget/widget-task-handler"; import { ListItem } from "native-base"; export const WidgetSettings = ({ navigate }) => { @@ -116,9 +113,7 @@ export const WidgetSettings = ({ navigate }) => { }} > ( - - )} + renderWidget={() => } width={400} height={250} />