diff --git a/screens/EventScreen.js b/screens/EventScreen.js index 8171304..eeb367a 100644 --- a/screens/EventScreen.js +++ b/screens/EventScreen.js @@ -1,115 +1,319 @@ - -import React, {useEffect, useState, useCallback, useContext, useRef} from 'react'; -import {View, Text, FlatList, TouchableOpacity, SafeAreaView} from 'react-native'; -import { createStackNavigator } from '@react-navigation/stack'; +import React, { + useEffect, + useState, + useCallback, + useContext, + useRef, +} from 'react'; +import { + View, + Text, + FlatList, + TouchableOpacity, + SafeAreaView, + ActivityIndicator, + StyleSheet, +} from 'react-native'; +import { + Menu, + MenuOption, + MenuOptions, + MenuTrigger, +} from 'react-native-popup-menu'; +import Icon from 'react-native-vector-icons/MaterialIcons'; +import Micon from 'react-native-vector-icons/MaterialCommunityIcons'; +import {createStackNavigator} from '@react-navigation/stack'; import dayJs from 'dayjs'; +import {VLCPlayer} from 'react-native-vlc-media-player'; import {getEvents} from '../lib/api'; - import {getAddressByCredentials} from '../lib/util'; - import PlayerError from '../components/PlayerError'; - -import { VLCPlayer } from 'react-native-vlc-media-player'; - import SessionContext from '../session-context'; - -import {Menu, MenuOption, MenuOptions, MenuTrigger} from "react-native-popup-menu"; -import Icon from "react-native-vector-icons/MaterialIcons"; - import ToggleNavigationButton from '../components/ToggleNavigationButton'; const Stack = createStackNavigator(); - const dateFormat = 'M-D-YY h:m:s A'; function Player({uri}) { - const [error, setError] = useState(false); - const [stopped, setStopped] = useState(false); + const [error, setError] = useState(false); + const [stopped, setStopped] = useState(false); + const [loading, setLoading] = useState(true); + const player = useRef(null); - const player = useRef(null); + if (error) { + return setError(false)} />; + } + const onError = () => { + setError(true); + setLoading(false); + }; + const onStopped = () => { + setStopped(true); + setLoading(false); + }; + if (stopped) { + return ( + setStopped(false)} + style={{ + backgroundColor: '#333333', + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }}> + + + ); + } - if (error) { - return setError(false)} />; - } - - if (stopped) { - return setStopped(false)} style={{backgroundColor: '#333333', flex: 1, alignItems: 'center', justifyContent: 'center'}}>; - } - - return setError(true)} style={{flex: 1}} onStopped={() => setStopped(true)} />; + return ( + + {loading && ( + + )} + onError()} + style={{flex: 1}} + onProgress={() => setLoading(false)} + onStopped={() => onStopped()} + /> + + ); } function EventButton({id, title, published, updated, active, current}) { - return ( - {title} - {updated ? Updated: {dayJs(updated).format(dateFormat)} : - (published ? Published: {published} : null)} - ); + return ( + + + {title} + + {updated ? ( + + + Updated: {dayJs(updated).format(dateFormat)} + + + ) : published ? ( + + + Published: {published} + + + ) : null} + + ); } - function EventList({navigation}) { + const {state} = useContext(SessionContext); + const [lastUpdate, setLastUpdate] = useState(); + const [eventList, setEventList] = useState([]); + const [refreshing, setRefreshing] = useState(false); + + const onRefresh = useCallback(() => { + setRefreshing(true); + getEvents(getAddressByCredentials(state.activeAccount)).then( + ([list, update]) => { + setEventList(list); + setLastUpdate(dayJs(update).format(dateFormat)); + setRefreshing(false); + }, + ); + }, [state.activeAccount]); - const {state} = useContext(SessionContext); - const [lastUpdate, setLastUpdate] = useState(); - const [eventList, setEventList] = useState([]); - const [refreshing, setRefreshing] = useState(false); - const onRefresh = useCallback(() => { - setRefreshing(true); - getEvents(getAddressByCredentials(state.activeAccount)).then(([list, update]) => { - setEventList(list); - setLastUpdate(dayJs(update).format(dateFormat)); - setRefreshing(false); - }); - }, [state.activeAccount]); - - useEffect(() => { - onRefresh(); - }, []); - return ( - {lastUpdate && ( - Last Update:{lastUpdate} - )} - id} - refreshing={refreshing} - onRefresh={onRefresh} - renderItem={({item}) => ( - navigation.navigate('EventVideoPlayer', {eventId: item.content})}> - )}/> - ); + useEffect(() => { + onRefresh(); + }, []); + + return ( + + {lastUpdate && ( + + Last Update: + {lastUpdate} + + )} + + id} + refreshing={refreshing} + onRefresh={onRefresh} + renderItem={({item, index}) => ( + + navigation.navigate('EventVideoPlayer', { + eventId: item.content, + eventList, + index, + }) + }> + + + )} + /> + + + ); } -function EventVideoPlayer({route: {params: {eventId}}, navigation}) { +/* + * EventVideoPlayer function components styles + * */ + +const eventVideoPlayerStyles = StyleSheet.create({ + commonNextPreviousButton: { + borderColor: '#777777', + borderStyle: 'solid', + borderWidth: 1, + backgroundColor: '#333333', + position: 'absolute', + bottom: 0, + padding: 5, + marginBottom: 10, + }, + previousButton: { + left: 0, + marginLeft: 30, + }, + nextButton: { + right: 0, + marginRight: 30, + }, +}); + +function EventVideoPlayer({ + route: { + params: {eventList, index}, + }, + navigation, +}) { + const [eventId, setEventId] = useState(eventList[index].content); + const [lockIndex, setLockIndex] = useState(index); + const {state} = useContext(SessionContext); + + if (!eventId) { + return navigation.navigate('EventList')} />; + } + + /* + * Handle previous event from event list + * */ + + const previousEvent = () => { + if (lockIndex > 0) { + const tempIndex = lockIndex - 1; + setLockIndex(tempIndex); + setEventId(eventList[tempIndex]?.content); + } + }; - const {state} = useContext(SessionContext); + /* + * Handle next event from event list + * */ - if (!eventId) { - return navigation.navigate('EventList')} />; + const nextEvent = () => { + if (lockIndex <= eventList.length - 1) { + const tempIndex = lockIndex + 1; + setLockIndex(tempIndex); + setEventId(eventList[tempIndex]?.content); } + }; - return ( - - - - - - navigation.navigate('EventList')} /> - - - ); + return ( + + + + + + + navigation.navigate('EventList')} + /> + + + + ); } export default function EventScreen() { - return ( - }} component={EventList} /> - - ); + return ( + + ( + + + + ), + }} + component={EventList} + /> + + + ); }