From f85c79ab2c511e0c63c89b50b49ce95f74f889bb Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 21 May 2024 10:06:08 +0000 Subject: [PATCH 1/7] =?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=AE=E3=82=B3=E3=82=A2=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AndroidWidget/InfoWidget.jsx | 95 +++++++++++++++ .../AndroidWidget/widget-task-handler.jsx | 37 +++++- components/Settings/WidgetSettings.js | 111 ++++++++++++------ 3 files changed, 201 insertions(+), 42 deletions(-) create mode 100644 components/AndroidWidget/InfoWidget.jsx diff --git a/components/AndroidWidget/InfoWidget.jsx b/components/AndroidWidget/InfoWidget.jsx new file mode 100644 index 0000000..8badfd2 --- /dev/null +++ b/components/AndroidWidget/InfoWidget.jsx @@ -0,0 +1,95 @@ +import React from "react"; +import { + FlexWidget, + TextWidget, + ListWidget, +} from "react-native-android-widget"; + +export function InfoWidget({ time, delayString }) { + return ( + + + + + + + + {delayString ? ( + + + + ) : ( + + )} + + + ); +} + +const FlexText = ({ flex, text }) => ( + + + +); diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.jsx index 5b7ae14..5f81036 100644 --- a/components/AndroidWidget/widget-task-handler.jsx +++ b/components/AndroidWidget/widget-task-handler.jsx @@ -2,10 +2,30 @@ import React from "react"; import { TraInfoEXWidget } from "./TraInfoEXWidget"; import dayjs from "dayjs"; import { ToastAndroid } from "react-native"; +import { InfoWidget } from "./InfoWidget"; +import { AS } from "../../storageControl"; export const nameToWidget = { // Hello will be the **name** with which we will reference our widget. JR_shikoku_train_info: TraInfoEXWidget, + Info_Widget: InfoWidget, +}; + +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 const getDelayData = async () => { @@ -25,20 +45,29 @@ export const getDelayData = async () => { return { time, delayString }; }; export async function widgetTaskHandler(props) { - const widgetInfo = props.widgetInfo; - const Widget = nameToWidget[widgetInfo.widgetName]; + const WidgetName = await AS.getItem( + `widgetType/${props.widgetInfo.widgetId}` + ).catch((e) => "JR_shikoku_train_info"); ToastAndroid.show( `Widget Action: ${JSON.stringify(props.widgetInfo.widgetId)}`, ToastAndroid.SHORT ); - const { time, delayString } = await getDelayData(); + ToastAndroid.show(`Widget Name: ${WidgetName}`, ToastAndroid.SHORT); switch (props.widgetAction) { case "WIDGET_ADDED": case "WIDGET_UPDATE": case "WIDGET_CLICK": case "WIDGET_RESIZED": // Not needed for now - props.renderWidget(); + if (WidgetName === "JR_shikoku_train_info") { + const Widget = nameToWidget[WidgetName]; + const { time, delayString } = await getDelayData(); + props.renderWidget(); + } else if (WidgetName === "Info_Widget") { + const Widget = nameToWidget[WidgetName]; + const { time, text } = await getInfoString(); + props.renderWidget(); + } break; diff --git a/components/Settings/WidgetSettings.js b/components/Settings/WidgetSettings.js index 5b08b0c..38633b2 100644 --- a/components/Settings/WidgetSettings.js +++ b/components/Settings/WidgetSettings.js @@ -5,13 +5,16 @@ 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 { AS } from "../../storageControl"; import { getDelayData, nameToWidget, + getInfoString, } from "../AndroidWidget/widget-task-handler"; import { ListItem } from "native-base"; export const WidgetSettings = ({ navigate }) => { + const { JR_shikoku_train_info, Info_Widget } = nameToWidget; const [widgetList, setWidgetList] = useState([]); useEffect(() => { const d = []; @@ -28,14 +31,18 @@ export const WidgetSettings = ({ navigate }) => { }); setWidgetList(d); }, []); - const [time, setTime] = useState(time); const [delayString, setDelayString] = useState(delayString); + const [trainInfo, setTrainInfo] = useState(); useEffect(() => { getDelayData().then(({ time, delayString }) => { setTime(time); setDelayString(delayString); }); + getInfoString().then(({ time, text }) => { + setTime(time); + setTrainInfo(text); + }); }, []); return ( @@ -90,18 +97,31 @@ export const WidgetSettings = ({ navigate }) => { margin: 10, }} > - {Object.keys(nameToWidget).map((Name) => { - const Data = nameToWidget[Name]; - return ( - ( - - )} - width={400} - height={250} - /> - ); - })} + ( + + )} + width={400} + height={250} + /> + + + ( + + )} + width={400} + height={250} + /> @@ -129,33 +149,48 @@ export const WidgetSettings = ({ navigate }) => { 名前 - {widgetList.map((widget) => ( - - { + return ( + { + //widget.widgetNameで定義されてないもう一つのウィジェットを選択する + if (widget.widgetName === "Info_Widget") { + AS.setItem( + `widgetType/${widget.widgetId}`, + "JR_shikoku_train_info" + ); + } else { + AS.setItem(`widgetType/${widget.widgetId}`, "Info_Widget"); + } }} > - {widget.widgetId} - - - {widget.widgetName} - - - ))} + + {widget.widgetId} + + + {widget.widgetName} + + + ); + })} Date: Tue, 21 May 2024 10:16:31 +0000 Subject: [PATCH 2/7] =?UTF-8?q?AS=E3=81=AEremove=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=80=81=E3=82=A6=E3=82=A3=E3=82=B8=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=83=88=E3=82=92=E5=8B=95=E7=9A=84=E3=81=A7=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E9=9D=99=E7=9A=84=E3=81=AB=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AndroidWidget/widget-task-handler.jsx | 12 +++++------- storageControl.js | 1 + 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.jsx index 5f81036..d6b811d 100644 --- a/components/AndroidWidget/widget-task-handler.jsx +++ b/components/AndroidWidget/widget-task-handler.jsx @@ -6,7 +6,6 @@ import { InfoWidget } from "./InfoWidget"; import { AS } from "../../storageControl"; export const nameToWidget = { - // Hello will be the **name** with which we will reference our widget. JR_shikoku_train_info: TraInfoEXWidget, Info_Widget: InfoWidget, }; @@ -58,21 +57,20 @@ export async function widgetTaskHandler(props) { case "WIDGET_UPDATE": case "WIDGET_CLICK": case "WIDGET_RESIZED": - // Not needed for now if (WidgetName === "JR_shikoku_train_info") { - const Widget = nameToWidget[WidgetName]; const { time, delayString } = await getDelayData(); - props.renderWidget(); + props.renderWidget( + + ); } else if (WidgetName === "Info_Widget") { - const Widget = nameToWidget[WidgetName]; const { time, text } = await getInfoString(); - props.renderWidget(); + props.renderWidget(); } break; case "WIDGET_DELETED": - // Not needed for now + AS.removeItem(`widgetType/${props.widgetInfo.widgetId}`); break; default: break; diff --git a/storageControl.js b/storageControl.js index 4f43140..939a943 100644 --- a/storageControl.js +++ b/storageControl.js @@ -11,4 +11,5 @@ export const AS = { // if set to null, then it will never expire. expires: null, }), + removeItem: (key) => storage.remove({ key }), }; From 170bc36afa0fb9a6e9eecd6ec74fec337067dc2e Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 21 May 2024 10:19:09 +0000 Subject: [PATCH 3/7] =?UTF-8?q?props=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AndroidWidget/widget-task-handler.jsx | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.jsx index d6b811d..7878f6f 100644 --- a/components/AndroidWidget/widget-task-handler.jsx +++ b/components/AndroidWidget/widget-task-handler.jsx @@ -44,33 +44,38 @@ export const getDelayData = async () => { return { time, delayString }; }; export async function widgetTaskHandler(props) { + const { + widgetInfo, + widgetAction, + renderWidget, + clickAction, + clickActionData, + } = props; const WidgetName = await AS.getItem( - `widgetType/${props.widgetInfo.widgetId}` + `widgetType/${widgetInfo.widgetId}` ).catch((e) => "JR_shikoku_train_info"); ToastAndroid.show( - `Widget Action: ${JSON.stringify(props.widgetInfo.widgetId)}`, + `Widget Action: ${JSON.stringify(widgetInfo.widgetId)}`, ToastAndroid.SHORT ); ToastAndroid.show(`Widget Name: ${WidgetName}`, ToastAndroid.SHORT); - switch (props.widgetAction) { + switch (widgetAction) { case "WIDGET_ADDED": case "WIDGET_UPDATE": case "WIDGET_CLICK": case "WIDGET_RESIZED": if (WidgetName === "JR_shikoku_train_info") { const { time, delayString } = await getDelayData(); - props.renderWidget( - - ); + renderWidget(); } else if (WidgetName === "Info_Widget") { const { time, text } = await getInfoString(); - props.renderWidget(); + renderWidget(); } break; case "WIDGET_DELETED": - AS.removeItem(`widgetType/${props.widgetInfo.widgetId}`); + AS.removeItem(`widgetType/${widgetInfo.widgetId}`); break; default: break; From 9447678f85ede9671ff67c17a3767dac9033ccfe Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 21 May 2024 10:23:51 +0000 Subject: [PATCH 4/7] =?UTF-8?q?switch=E3=81=AB=E5=88=86=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AndroidWidget/widget-task-handler.jsx | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.jsx index 7878f6f..eab1997 100644 --- a/components/AndroidWidget/widget-task-handler.jsx +++ b/components/AndroidWidget/widget-task-handler.jsx @@ -64,12 +64,26 @@ export async function widgetTaskHandler(props) { case "WIDGET_UPDATE": case "WIDGET_CLICK": case "WIDGET_RESIZED": - if (WidgetName === "JR_shikoku_train_info") { - const { time, delayString } = await getDelayData(); - renderWidget(); - } else if (WidgetName === "Info_Widget") { - const { time, text } = await getInfoString(); - renderWidget(); + switch (WidgetName) { + case "JR_shikoku_train_info": { + const { time, delayString } = await getDelayData(); + renderWidget( + + ); + break; + } + case "Info_Widget": { + const { time, text } = await getInfoString(); + renderWidget(); + break; + } + default: { + const { time, delayString } = await getDelayData(); + renderWidget( + + ); + break; + } } break; From 9df3d0c62ad4a32b9aec825c9c86147fa5def8dc Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 21 May 2024 10:25:10 +0000 Subject: [PATCH 5/7] =?UTF-8?q?=E5=90=8D=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AndroidWidget/InfoWidget.jsx | 6 +++--- components/AndroidWidget/widget-task-handler.jsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/AndroidWidget/InfoWidget.jsx b/components/AndroidWidget/InfoWidget.jsx index 8badfd2..7363143 100644 --- a/components/AndroidWidget/InfoWidget.jsx +++ b/components/AndroidWidget/InfoWidget.jsx @@ -5,7 +5,7 @@ import { ListWidget, } from "react-native-android-widget"; -export function InfoWidget({ time, delayString }) { +export function InfoWidget({ time, text }) { return ( - {delayString ? ( + {text ? ( - + ) : ( ); + renderWidget(); break; } default: { From 1fafe1649c1cacd270760cf16fbcaf732638feb5 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 21 May 2024 10:33:41 +0000 Subject: [PATCH 6/7] =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AndroidWidget/InfoWidget.jsx | 19 ++++++++ components/AndroidWidget/TraInfoEXWidget.jsx | 18 ++++++++ .../AndroidWidget/widget-task-handler.jsx | 46 ++----------------- components/Settings/WidgetSettings.js | 13 ++---- 4 files changed, 44 insertions(+), 52 deletions(-) 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} /> From 29593b497c6f19b2807c79a8aefce44e66855eb9 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Tue, 21 May 2024 14:07:06 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Settings/WidgetSettings.js | 122 ++++++++++++++------------ 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/components/Settings/WidgetSettings.js b/components/Settings/WidgetSettings.js index 20077d3..c4fb501 100644 --- a/components/Settings/WidgetSettings.js +++ b/components/Settings/WidgetSettings.js @@ -12,25 +12,21 @@ import { ListItem } from "native-base"; export const WidgetSettings = ({ navigate }) => { const { JR_shikoku_train_info, Info_Widget } = nameToWidget; + const [time, setTime] = useState(); + const [delayString, setDelayString] = useState(); + const [trainInfo, setTrainInfo] = useState(); const [widgetList, setWidgetList] = useState([]); - useEffect(() => { + const reload = async () => { 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); - }); - } - }); + const data = await getWidgetInfo("JR_shikoku_train_info"); + data.forEach((elem) => { + d.push(elem.widgetId); }); setWidgetList(d); - }, []); - const [time, setTime] = useState(time); - const [delayString, setDelayString] = useState(delayString); - const [trainInfo, setTrainInfo] = useState(); + }; + + useEffect(reload, []); + useEffect(() => { getDelayData().then(({ time, delayString }) => { setTime(time); @@ -144,48 +140,9 @@ export const WidgetSettings = ({ navigate }) => { 名前 - {widgetList.map((widget) => { - return ( - { - //widget.widgetNameで定義されてないもう一つのウィジェットを選択する - if (widget.widgetName === "Info_Widget") { - AS.setItem( - `widgetType/${widget.widgetId}`, - "JR_shikoku_train_info" - ); - } else { - AS.setItem(`widgetType/${widget.widgetId}`, "Info_Widget"); - } - }} - > - - {widget.widgetId} - - - {widget.widgetName} - - - ); - })} + {widgetList.map((id) => ( + + ))} ( /> ); +const WidgetList = ({ id }) => { + const [widgetConfig, setWidgetConfig] = useState(""); + const reload = () => { + AS.getItem(`widgetType/${id}`) + .then((widgetType) => { + setWidgetConfig(widgetType); + }) + .catch((e) => { + setWidgetConfig("JR_shikoku_train_info"); + }); + }; + useEffect(reload, [id]); + return ( + { + //widget.widgetNameで定義されてないもう一つのウィジェットを選択する + if (widgetConfig === "Info_Widget") { + AS.setItem(`widgetType/${id}`, "JR_shikoku_train_info"); + } else { + AS.setItem(`widgetType/${id}`, "Info_Widget"); + } + reload(); + }} + > + + {id} + + + {widgetConfig} + + + ); +};