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 1/3] =?UTF-8?q?=E9=A0=98=E5=9F=9F=E3=82=92=E4=BB=AE?= =?UTF-8?q?=E4=BD=9C=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) => } + ); } From f55420e3abf659941d5d8acd2cfbdcdeebf4808a Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Fri, 29 Mar 2024 15:44:40 +0000 Subject: [PATCH 2/3] =?UTF-8?q?iOS=E3=81=A7=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Settings/SettingTopPage.js | 57 ++++++++++++++------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/components/Settings/SettingTopPage.js b/components/Settings/SettingTopPage.js index 8eb06b8..ec16df8 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"; @@ -167,34 +168,36 @@ export const SettingTopPage = ({ {">"} - navigate("WidgetSettings")} - > - navigate("WidgetSettings")} > - ウィジェット設定 - - - - {">"} - - + + ウィジェット設定 + + + + {">"} + + + ) : null} From db4ac86875db03fc06b37ff4bf44045370d102e6 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 2 Apr 2024 03:39:39 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E3=82=A6=E3=82=A3=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=81=AB=E5=BF=9C=E3=81=98=E3=81=A6=E8=87=AA?= =?UTF-8?q?=E5=8B=95=E5=A4=89=E5=8C=96=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AndroidWidget/widget-task-handler.jsx | 2 +- components/Settings/WidgetSettings.js | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.jsx index 42fc7ff..5b7ae14 100644 --- a/components/AndroidWidget/widget-task-handler.jsx +++ b/components/AndroidWidget/widget-task-handler.jsx @@ -3,7 +3,7 @@ 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, }; diff --git a/components/Settings/WidgetSettings.js b/components/Settings/WidgetSettings.js index 31cefa6..982906f 100644 --- a/components/Settings/WidgetSettings.js +++ b/components/Settings/WidgetSettings.js @@ -5,21 +5,28 @@ 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 { + getDelayData, + nameToWidget, +} 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 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);