From d55a62b8ae3f073191e87c488195e734286c0464 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Thu, 28 Mar 2024 13:37:17 +0000 Subject: [PATCH] =?UTF-8?q?=E9=A0=98=E5=9F=9F=E3=82=92=E4=BB=AE=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AndroidWidget/widget-task-handler.jsx | 19 +- components/Settings/SettingTopPage.js | 28 +++ components/Settings/WidgetSettings.js | 168 ++++++++++++++++++ components/Settings/settings.js | 13 ++ 4 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 components/Settings/WidgetSettings.js diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.jsx index 0acfb19..42fc7ff 100644 --- a/components/AndroidWidget/widget-task-handler.jsx +++ b/components/AndroidWidget/widget-task-handler.jsx @@ -8,14 +8,9 @@ const nameToWidget = { JR_shikoku_train_info: TraInfoEXWidget, }; -export async function widgetTaskHandler(props) { - const widgetInfo = props.widgetInfo; - const Widget = nameToWidget[widgetInfo.widgetName]; +export const getDelayData = async () => { + // Fetch data from the server const time = dayjs().format("HH:mm"); - ToastAndroid.show( - `Widget Action: ${props.widgetAction} ${time}`, - ToastAndroid.SHORT - ); const delayString = await fetch( "https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec" ) @@ -27,6 +22,16 @@ export async function widgetTaskHandler(props) { return null; }); ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT); + return { time, delayString }; +}; +export async function widgetTaskHandler(props) { + const widgetInfo = props.widgetInfo; + const Widget = nameToWidget[widgetInfo.widgetName]; + ToastAndroid.show( + `Widget Action: ${JSON.stringify(props.widgetInfo.widgetId)}`, + ToastAndroid.SHORT + ); + const { time, delayString } = await getDelayData(); switch (props.widgetAction) { case "WIDGET_ADDED": case "WIDGET_UPDATE": diff --git a/components/Settings/SettingTopPage.js b/components/Settings/SettingTopPage.js index 490caf0..8eb06b8 100644 --- a/components/Settings/SettingTopPage.js +++ b/components/Settings/SettingTopPage.js @@ -167,6 +167,34 @@ export const SettingTopPage = ({ {">"} + navigate("WidgetSettings")} + > + + ウィジェット設定 + + + + {">"} + + diff --git a/components/Settings/WidgetSettings.js b/components/Settings/WidgetSettings.js new file mode 100644 index 0000000..31cefa6 --- /dev/null +++ b/components/Settings/WidgetSettings.js @@ -0,0 +1,168 @@ +import React, { useEffect, useState } from "react"; +import { View, Text, TouchableOpacity, ScrollView } from "react-native"; +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/widget-task-handler"; +import { ListItem } from "native-base"; + +export const WidgetSettings = ({ navigate }) => { + const widgetInfo = getWidgetInfo("JR_shikoku_train_info"); + const [widgetList, setWidgetList] = useState([]); + useEffect(() => { + widgetInfo.then((s) => { + if (s.length > 0) { + setWidgetList(s); + s.forEach((element) => { + console.log(element); + }); + } + }); + }, []); + + const [time, setTime] = useState(time); + const [delayString, setDelayString] = useState(delayString); + useEffect(() => { + getDelayData().then(({ time, delayString }) => { + setTime(time); + setDelayString(delayString); + }); + }, []); + return ( + + + + navigate("settingTopPage")} + style={{ + flexDirection: "column", + flex: 1, + }} + > + + + < 設定 + + + + + + + ウィジェット設定 + + + + + + + ( + + )} + width={400} + height={250} + /> + + + + + ID + + + 名前 + + + {widgetList.map((widget) => ( + + + {widget.widgetId} + + + {widget.widgetName} + + + ))} + + + ); +}; + +const SimpleSwitch = ({ bool, setBool, str }) => ( + + setBool(bool == "true" ? "false" : "true")} + containerStyle={{ + flex: 1, + backgroundColor: "#00000000", + borderColor: "white", + alignContent: "center", + }} + textStyle={{ fontSize: 20, fontWeight: "normal" }} + title={str} + /> + +); diff --git a/components/Settings/settings.js b/components/Settings/settings.js index fbeb3ba..03d4fb1 100644 --- a/components/Settings/settings.js +++ b/components/Settings/settings.js @@ -20,6 +20,7 @@ import { Switch } from "react-native-elements"; import AutoHeightImage from "react-native-auto-height-image"; import { SettingTopPage } from "./SettingTopPage"; import { LayoutSettings } from "./LayoutSettings"; +import { WidgetSettings } from "./WidgetSettings"; const Stack = createStackNavigator(); export default function Setting(props) { @@ -123,6 +124,18 @@ export default function Setting(props) { /> )} + + {(props) => } + ); }