import React, { useRef, useState, useEffect } from "react";
import Carousel from "react-native-snap-carousel";
import {
Platform,
View,
ScrollView,
Linking,
Text,
TouchableOpacity,
ToastAndroid,
} from "react-native";
import Constants from "expo-constants";
import { ListItem } from "native-base";
import Icon from "react-native-vector-icons/Entypo";
import * as Location from "expo-location";
import StatusbarDetect from "./StatusbarDetect";
import { useNavigation } from "@react-navigation/native";
import AutoHeightImage from "react-native-auto-height-image";
import { widthPercentageToDP as wp } from "react-native-responsive-screen";
import {
FontAwesome,
Foundation,
Ionicons,
MaterialCommunityIcons,
} from "@expo/vector-icons";
import LottieView from "lottie-react-native";
import { StationDeteilView } from "./components/ActionSheetComponents/StationDeteilView";
import { parseAllTrainDiagram } from "./lib/parseAllTrainDiagram";
import trainList from "./assets/originData/trainList";
import LED_vision from "./components/発車時刻表/LED_vidion";
import Sign from "./components/駅名表/Sign";
import { UsefulBox } from "./components/atom/UsefulBox";
import { TicketBox } from "./components/atom/TicketBox";
import { TextBox } from "./components/atom/TextBox";
import { getStationList, lineList } from "./lib/getStationList";
import { JRSTraInfo } from "./components/ActionSheetComponents/JRSTraInfo";
import { EachTrainInfo } from "./components/ActionSheetComponents/EachTrainInfo";
import useInterval from "./lib/useInterval";
import { HeaderConfig } from "./lib/HeaderConfig";
export default function Menu(props) {
const {
navigation: { navigate },
favoriteStation,
setFavoriteStation,
busAndTrainData,
} = props;
const JRSTraInfoEXAcSR = useRef(null);
const StationBoardAcSR = useRef(null);
const navigation = useNavigation();
//位置情報
const [locationStatus, setLocationStatus] = useState(null);
useEffect(() => {
Location.requestForegroundPermissionsAsync().then((data) => {
setLocationStatus(data.status);
});
}, []);
//列車情報表示関連
const EachTrainInfoAsSR = useRef(null);
const [trainInfo, setTrainInfo] = useState({
trainNum: undefined,
limited: undefined,
});
const getCurrentPosition = () => {
if (locationStatus !== "granted") return () => {};
Location.getCurrentPositionAsync({}).then((location) =>
makeCurrentStation(location)
);
};
const makeCurrentStation = (location) => {
if (!originalStationList) return () => {};
const findStationEachLine = (selectLine) => {
const searchArea = 0.0015;
const _calcDistance = (from, to) => {
let lat = Math.abs(from.lat - to.lat);
let lng = Math.abs(from.lng - to.lng);
return Math.sqrt(lat * lat + lng * lng);
};
let NearStation = selectLine.filter(
(d) =>
_calcDistance(d, {
lat: location.coords.latitude,
lng: location.coords.longitude,
}) < searchArea
);
return NearStation;
};
let returnDataBase = lineList
.map((d) => findStationEachLine(originalStationList[d]))
.filter((d) => d.length > 0)
.reduce((pre, current) => {
pre.push(...current);
return pre;
}, []);
if (returnDataBase.length) {
let currentStation = currentStation == undefined ? [] : currentStation;
if (currentStation.toString() != returnDataBase.toString()) {
setCurrentStation(returnDataBase);
}
} else {
setCurrentStation(undefined);
}
};
useEffect(getCurrentPosition, [locationStatus]);
useInterval(getCurrentPosition, 5000);
const [currentStation, setCurrentStation] = useState(undefined); //第三要素
const [originalStationList, setOriginalStationList] = useState(); // 第一要素
useEffect(() => getStationList().then(setOriginalStationList), []);
const [count, setCount] = useState(0);
const [delayData, setDelayData] = useState(undefined);
const [getTime, setGetTime] = useState(new Date());
const [loadingDelayData, setLoadingDelayData] = useState(true);
const carouselRef = useRef();
const [selectedCurrentStation, setSelectedCurrentStation] = useState(0);
useEffect(() => {
fetch(
"https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec"
)
.then((response) => response.text())
.then((data) => setDelayData(data !== "" ? data.split("^") : null))
.then(() => setGetTime(new Date()))
.finally(() => setLoadingDelayData(false));
}, [loadingDelayData]);
const allStationData = [currentStation, ...favoriteStation].filter(
(d) => d != undefined
);
useEffect(() => {
if (allStationData.length == 0) {
setSelectedCurrentStation(0);
return;
}
if (allStationData[selectedCurrentStation] == undefined) {
const count = selectedCurrentStation - 1;
setSelectedCurrentStation(count);
}
}, [selectedCurrentStation, currentStation, favoriteStation]);
useEffect(() => {
if (!carouselRef.current) return;
if (carouselRef.current?._itemToSnapTo != selectedCurrentStation) {
carouselRef.current.snapToItem(0);
carouselRef.current.snapToItem(selectedCurrentStation);
}
}, [selectedCurrentStation]);
//全列車ダイヤリストを作成するuseEffect
const [trainDiagram, setTrainDiagram] = useState(null); // 全列車のダイヤを列番ベースで整理
useEffect(() => {
//全列車リストを生成する副作用[無条件初回実行]
fetch(
"https://train.jr-shikoku.co.jp/g?arg1=station&arg2=traintimeinfo&arg3=dia",
HeaderConfig
)
.then((response) => response.text())
.then((d) => {
if (d.indexOf("
404 Not Found") != -1) throw Error;
setTrainDiagram(parseAllTrainDiagram(d));
})
.catch((d) => {
console.log("fallback");
setTrainDiagram(trainList);
});
}, []);
const openStationACFromEachTrainInfo = (stationName) => {
// EachTrainInfoAsSR.current?.hide();
// const findStationEachLine = (selectLine) => {
// let NearStation = selectLine.filter((d) => d.Station_JP == stationName);
// return NearStation;
// };
// let returnDataBase = lineList
// .map((d) => findStationEachLine(originalStationList[d]))
// .filter((d) => d.length > 0)
// .reduce((pre, current) => {
// pre.push(...current);
// return pre;
// }, []);
// if (returnDataBase.length) {
// setStationBoardData(returnDataBase);
// sleep(30, function () {
// StationBoardAcSR.current?.show();
// });
// } else {
// setStationBoardData(undefined);
// StationBoardAcSR.current?.hide();
// }
};
return (
{originalStationList && allStationData.length != 0 && (
{
setSelectedCurrentStation(d);
}}
renderItem={({ item, index }) => {
return (
);
}}
/>
)}
{allStationData.length != 0 &&
originalStationList &&
allStationData[selectedCurrentStation] && (
)}
{
StationBoardAcSR.current?.setModalVisible();
navigate("menu");
}}
/>
);
}
const TitleBar = () => {
return (
Linking.openURL("https://www.jr-shikoku.co.jp")}
>
);
};
const TopMenuButton = () => {
const buttonList = [
{
backgroundColor: "#F89038",
icon: "train-car",
onPress: () =>
Linking.openURL("https://www.jr-shikoku.co.jp/01_trainbus/sp/"),
title: "駅・鉄道情報",
},
{
backgroundColor: "#EA4752",
icon: "google-spreadsheet",
onPress: () =>
Linking.openURL(
"https://www.jr-shikoku.co.jp/01_trainbus/jikoku/sp/#mainprice-box"
),
title: "運賃表",
},
{
backgroundColor: "#91C31F",
icon: "clipboard-list-outline",
onPress: () => Linking.openURL("https://www.jr-shikoku.co.jp/e5489/"),
title: "予約",
},
];
return (
{buttonList.map((d, index) => (
{d.title}
))}
);
};
const JRSTraInfoBox = (props) => {
const {
JRSTraInfoEXAcSR,
getTime,
setLoadingDelayData,
loadingDelayData,
delayData,
} = props;
const styles = {
touch: {
backgroundColor: "#0099CC",
borderRadius: 5,
margin: 10,
borderColor: "black",
borderWidth: 2,
overflow: "hidden",
},
scroll: {
backgroundColor: "#0099CC",
borderRadius: 5,
maxHeight: 300,
},
bottom: {
position: "absolute",
top: 250,
alignItems: "center",
width: "100%",
height: 50,
backgroundColor: "#007FCC88",
},
box: {
padding: 10,
backgroundColor: "white",
borderBottomLeftRadius: 5,
borderBottomRightRadius: 5,
},
};
return (
列車遅延速報EX
{getTime
? getTime.toLocaleTimeString("ja-JP").split(":")[0] +
":" +
getTime.toLocaleTimeString("ja-JP").split(":")[1]
: NaN}
{
setLoadingDelayData(true);
}}
/>
{loadingDelayData ? (
) : delayData ? (
delayData.map((d, index) => {
let data = d.split(" ");
return (
{data[0].replace("\n", "")}
{data[1]}
{data[3]}
);
})
) : (
現在、5分以上の遅れはありません。
)}
詳細を見る
);
};
const FixedContentTop = (props) => {
return (
<>
>
);
};
const FixedContentBottom = (props) => {
return (
<>
{props.children}
}
flex={1}
onPressButton={() =>
Linking.openURL("https://www.jr-eki.com/ticket/brand")
}
>
トクトク切符
}
flex={1}
onPressButton={() =>
Linking.openURL(
"https://www.jr-shikoku.co.jp/01_trainbus/event_train/sp/"
)
}
>
観光列車
}
flex={1}
onPressButton={() =>
Linking.openURL("https://www.jr-eki.com/tour/brand")
}
>
旅行ツアー
Linking.openURL("https://www.jr-eki.com/smart-eki/index.html")
}
>
スマートえきちゃん
JR四国のチケットレススマホアプリです。
Linking.openURL("https://www.jr-shikoku.co.jp/sp/index.html#menu-box")
}
>
臨時列車などのお知らせ
区間縮小・計画運休・イベント・季節臨時列車など
Linking.openURL("https://www.jr-shikoku.co.jp/03_news/press/")
}
>
ニュースリリース
公式プレス記事はこちら
Linking.openURL("https://www.jr-shikoku.co.jp/teiki/")
}
>
定期運賃計算
通常/学生/快て〜き等はこちら
Linking.openURL("https://www.jr-shikoku.co.jp/04_company/group/sp/")
}
>
JR四国のお店・サービス
JR四国グループの施設をご案内
Linking.openURL("https://www.jr-odekake.net/smt/")}
>
時刻・運賃計算
(マイ・ダイヤ)
マイ・ダイヤはJR西日本提供のサービスです。
Linking.openURL("tel:0570-00-4592")}
>
JR四国案内センター
0570-00-4592
(8:00~20:00 年中無休)
(通話料がかかります)
JR四国公式Twitter一族
{((data) =>
data.map((d) => (
Linking.openURL(d.url)}>
{d.name}
)))([
{
url: "https://twitter.com/JRshikoku_eigyo",
name: "JR四国営業部【公式】",
},
{
url: "https://twitter.com/JRshikoku_tokyo",
name: "JR四国 東京営業情報【公式】",
},
{
url: "https://twitter.com/JRshikoku_osaka",
name: "JR四国 大阪営業部【公式】",
},
{
url: "https://twitter.com/jr_shikoku_info",
name: "JR四国列車運行情報【公式】",
},
{
url: "https://twitter.com/Smile_Eki_Chan",
name: "すまいるえきちゃん♡JR四国【公式】",
},
{
url: "https://twitter.com/jrs_matsuyama",
name: "JR四国 松山駅 【公式】",
},
{
url: "https://twitter.com/jrshikoku_kochi",
name: "JR四国 高知駅【公式】",
},
{
url: "https://twitter.com/jr_tokust",
name: "JR四国 徳島駅【公式】",
},
{
url: "https://twitter.com/jrshikoku_uwjm",
name: "JR四国 宇和島駅【公式】",
},
{
url: "https://twitter.com/JRshikoku_wkoch",
name: "JR四国 ワープ高知支店【公式】",
},
{
url: "https://twitter.com/jrshikoku_nihaw",
name: "JR四国 ワープ新居浜営業所【公式】",
},
{
url: "https://twitter.com/Yoakemonogatari",
name: "志国土佐 時代の夜明けのものがたり【公式】",
},
])}
このアプリについて
このアプリはXprocess(HARUKIN)が製作しているJR四国の完全非公式アシストアプリケーションです。このアプリに関することでのJR四国公式へ問合せすることはお控えください。以下のTwitterよりお願いします。
Linking.openURL("https://twitter.com/Xprocess_main")
}
>
XprocessのTwitter
制作運営のTwitterです。
props.navigate("setting")}
>
アプリの設定
アプリの設定画面を表示します。
{/*
*/}
>
);
};