diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.jsx index 0acfb19..5b7ae14 100644 --- a/components/AndroidWidget/widget-task-handler.jsx +++ b/components/AndroidWidget/widget-task-handler.jsx @@ -3,19 +3,14 @@ import { TraInfoEXWidget } from "./TraInfoEXWidget"; import dayjs from "dayjs"; import { ToastAndroid } from "react-native"; -const nameToWidget = { +export const nameToWidget = { // Hello will be the **name** with which we will reference our widget. 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 857d866..5db3529 100644 --- a/components/Settings/SettingTopPage.js +++ b/components/Settings/SettingTopPage.js @@ -6,6 +6,7 @@ import { ScrollView, Linking, Image, + Platform, } from "react-native"; import * as Updates from "expo-updates"; import { SwitchArea } from "../atom/SwitchArea"; @@ -170,6 +171,36 @@ export const SettingTopPage = ({ {">"} + {Platform.OS === "android" ? ( + navigate("WidgetSettings")} + > + + ウィジェット設定 + + + + {">"} + + + ) : null} diff --git a/components/Settings/WidgetSettings.js b/components/Settings/WidgetSettings.js new file mode 100644 index 0000000..982906f --- /dev/null +++ b/components/Settings/WidgetSettings.js @@ -0,0 +1,175 @@ +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, + nameToWidget, +} from "../AndroidWidget/widget-task-handler"; +import { ListItem } from "native-base"; + +export const WidgetSettings = ({ navigate }) => { + const [widgetList, setWidgetList] = useState([]); + useEffect(() => { + const d = []; + Object.keys(nameToWidget).forEach((element) => { + const widgetInfo = getWidgetInfo(element); + widgetInfo.then((s) => { + if (s.length > 0) { + s.forEach((elem) => { + console.log(elem); + d.push(elem); + }); + } + }); + }); + setWidgetList(d); + }, []); + + 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 21938ae..5d3be45 100644 --- a/components/Settings/settings.js +++ b/components/Settings/settings.js @@ -21,6 +21,7 @@ import AutoHeightImage from "react-native-auto-height-image"; import { SettingTopPage } from "./SettingTopPage"; import { LayoutSettings } from "./LayoutSettings"; import { FavoriteSettings } from "./FavoriteSettings"; +import { WidgetSettings } from "./WidgetSettings"; const Stack = createStackNavigator(); export default function Setting(props) { @@ -124,6 +125,18 @@ export default function Setting(props) { /> )} + + {(props) => } +