-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from lrtlt/feat/car-play-navigation
Feat/car play navigation
- Loading branch information
Showing
31 changed files
with
735 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {ListTemplate} from 'react-native-carplay'; | ||
|
||
export const carPlayEmptyTemplate = new ListTemplate({ | ||
id: 'lrt-empty-template', | ||
backButtonHidden: true, | ||
emptyViewSubtitleVariants: ['Prašome palaukti...'], | ||
sections: [ | ||
{ | ||
items: [], | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {ListTemplate} from 'react-native-carplay'; | ||
|
||
export const carPlayLiveTemplate = new ListTemplate({ | ||
title: 'Tiesiogiai', | ||
id: 'lrt-list-template-live', | ||
trailingNavigationBarButtons: [ | ||
{ | ||
id: 'reload', | ||
type: 'text', | ||
title: 'Atnaujinti', | ||
}, | ||
], | ||
sections: [ | ||
{ | ||
items: [], | ||
}, | ||
], | ||
backButtonHidden: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {useEffect, useState} from 'react'; | ||
import useCarLiveChannels from './useCarLiveChannels'; | ||
import {CarPlay, ListTemplate} from 'react-native-carplay'; | ||
import {carPlayLiveTemplate} from './createPlayLiveTemplate'; | ||
import {useMediaPlayer} from '../../components/videoComponent/context/useMediaPlayer'; | ||
import {MediaType} from '../../components/videoComponent/context/PlayerContext'; | ||
import {carPlayNowPlayingTemplate} from '../nowPlaying/createNowPlayingTemplate'; | ||
|
||
const useCarLiveTemplate = (isConnected: boolean) => { | ||
const [template] = useState<ListTemplate>(carPlayLiveTemplate); | ||
const {channels, reload} = useCarLiveChannels(isConnected); | ||
|
||
const {setPlaylist} = useMediaPlayer(); | ||
|
||
useEffect(() => { | ||
console.log('updating live template'); | ||
template.updateSections([ | ||
{ | ||
items: channels.map((item) => ({ | ||
text: item.text, | ||
detailText: item.detailText, | ||
imgUrl: item.imgUrl as any, | ||
})), | ||
}, | ||
]); | ||
template.config.onItemSelect = async ({index}) => { | ||
const item = channels[index]; | ||
setPlaylist([ | ||
{ | ||
uri: item.streamUrl, | ||
mediaType: MediaType.VIDEO, | ||
isLiveStream: true, | ||
poster: item.imgUrl, | ||
title: item.text, | ||
}, | ||
]); | ||
CarPlay.pushTemplate(carPlayNowPlayingTemplate, true); | ||
}; | ||
return () => { | ||
template.config.onItemSelect = undefined; | ||
}; | ||
}, [channels]); | ||
|
||
useEffect(() => { | ||
if (template) { | ||
template.config.onBarButtonPressed = async ({id}) => { | ||
if (id === 'reload') { | ||
console.log('reloading live template'); | ||
reload(); | ||
} | ||
}; | ||
return () => { | ||
template.config.onBarButtonPressed = undefined; | ||
}; | ||
} | ||
}, [template, reload]); | ||
|
||
return template; | ||
}; | ||
|
||
export default useCarLiveTemplate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {ListTemplate} from 'react-native-carplay'; | ||
|
||
export const carPlayNewestTemplate = new ListTemplate({ | ||
title: 'Naujausi', | ||
id: 'lrt-list-template-newest', | ||
trailingNavigationBarButtons: [ | ||
{ | ||
id: 'reload', | ||
type: 'text', | ||
title: 'Atnaujinti', | ||
}, | ||
], | ||
sections: [ | ||
{ | ||
items: [], | ||
}, | ||
], | ||
backButtonHidden: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {useSelector} from 'react-redux'; | ||
import {selectHomeChannels} from '../../redux/selectors'; | ||
import {checkEqual} from '../../util/LodashEqualityCheck'; | ||
import {useEffect, useState} from 'react'; | ||
import {PlayListItem} from '../CarPlayContext'; | ||
import useCancellablePromise from '../../hooks/useCancellablePromise'; | ||
import {fetchCarNewestPlaylist} from '../../api'; | ||
|
||
const useCarPlayNewestPlaylist = (isConnected: boolean) => { | ||
const [channels, setChannels] = useState<PlayListItem[]>([]); | ||
const [lastLoadTime, setLastLoadTime] = useState<number>(0); | ||
const channelsData = useSelector(selectHomeChannels, checkEqual); | ||
|
||
const cancellablePromise = useCancellablePromise(); | ||
|
||
useEffect(() => { | ||
if (!isConnected) { | ||
return; | ||
} | ||
cancellablePromise( | ||
fetchCarNewestPlaylist().then((data) => { | ||
if (data?.length) { | ||
const channels: PlayListItem[] = data.map((item) => ({ | ||
id: item.title, | ||
text: item.title, | ||
detailText: item.content, | ||
imgUrl: item.cover, | ||
streamUrl: item.streamUrl, | ||
})); | ||
setChannels(channels); | ||
} | ||
}), | ||
); | ||
}, [channelsData, isConnected, lastLoadTime]); | ||
|
||
return { | ||
channels, | ||
reload: () => setLastLoadTime(Date.now()), | ||
}; | ||
}; | ||
|
||
export default useCarPlayNewestPlaylist; |
Oops, something went wrong.