carplay stuff

This commit is contained in:
Violet Caulfield
2025-04-14 18:51:19 -05:00
parent 8b2896e83d
commit 2d3756ebd2
5 changed files with 52 additions and 58 deletions

View File

@@ -1,11 +1,10 @@
import { ListTemplate } from 'react-native-carplay'
import uuid from 'react-native-uuid'
const CarPlayDiscover = () =>
new ListTemplate({
id: uuid.v4(),
tabTitle: 'Discover',
tabSystemImageName: 'globe',
})
const CarPlayDiscover = new ListTemplate({
id: uuid.v4(),
tabTitle: 'Discover',
tabSystemImageName: 'globe',
})
export default CarPlayDiscover

View File

@@ -7,45 +7,42 @@ import RecentTracksTemplate from './RecentTracks'
import RecentArtistsTemplate from './RecentArtists'
import uuid from 'react-native-uuid'
const CarPlayHome = () =>
new ListTemplate({
id: uuid.v4(),
title: 'Home',
tabTitle: 'Home',
tabSystemImageName: 'music.house.fill',
sections: [
{
header: `Hi ${Client.user?.name ?? 'there'}`,
items: [
{ id: QueryKeys.RecentlyPlayedArtists, text: 'Recent Artists' },
{ id: QueryKeys.RecentlyPlayed, text: 'Recently Played' },
{ id: QueryKeys.UserPlaylists, text: 'Your Playlists' },
],
},
],
onItemSelect: async ({ index }) => {
console.debug(`Home item selected`)
switch (index) {
case 0: {
const artists =
queryClient.getQueryData<BaseItemDto[]>([
QueryKeys.RecentlyPlayedArtists,
]) ?? []
CarPlay.pushTemplate(RecentArtistsTemplate(artists))
break
}
case 1: {
const items =
queryClient.getQueryData<BaseItemDto[]>([QueryKeys.RecentlyPlayed]) ?? []
CarPlay.pushTemplate(RecentTracksTemplate(items))
break
}
case 2: {
break
}
}
const CarPlayHome = new ListTemplate({
id: uuid.v4(),
title: 'Home',
tabTitle: 'Home',
tabSystemImageName: 'music.house.fill',
sections: [
{
header: `Hi ${Client.user?.name ?? 'there'}`,
items: [
{ id: QueryKeys.RecentlyPlayedArtists, text: 'Recent Artists' },
{ id: QueryKeys.RecentlyPlayed, text: 'Recently Played' },
{ id: QueryKeys.UserPlaylists, text: 'Your Playlists' },
],
},
})
],
onItemSelect: async ({ index }) => {
console.debug(`Home item selected`)
switch (index) {
case 0: {
const artists =
queryClient.getQueryData<BaseItemDto[]>([QueryKeys.RecentlyPlayedArtists]) ?? []
CarPlay.pushTemplate(RecentArtistsTemplate(artists))
break
}
case 1: {
const items =
queryClient.getQueryData<BaseItemDto[]>([QueryKeys.RecentlyPlayed]) ?? []
CarPlay.pushTemplate(RecentTracksTemplate(items))
break
}
case 2: {
break
}
}
},
})
export default CarPlayHome

View File

@@ -3,12 +3,11 @@ import CarPlayHome from './Home'
import CarPlayDiscover from './Discover'
import uuid from 'react-native-uuid'
const CarPlayNavigation = () =>
new TabBarTemplate({
id: uuid.v4(),
title: 'Tabs',
templates: [CarPlayHome(), CarPlayDiscover()],
onTemplateSelect(template, e) {},
})
const CarPlayNavigation = new TabBarTemplate({
id: uuid.v4(),
title: 'Tabs',
templates: [CarPlayHome, CarPlayDiscover],
onTemplateSelect(template, e) {},
})
export default CarPlayNavigation

View File

@@ -1,9 +1,8 @@
import { NowPlayingTemplate } from 'react-native-carplay'
import uuid from 'react-native-uuid'
const CarPlayNowPlaying = () =>
new NowPlayingTemplate({
id: uuid.v4(),
})
const CarPlayNowPlaying = new NowPlayingTemplate({
id: uuid.v4(),
})
export default CarPlayNowPlaying

View File

@@ -28,8 +28,8 @@ const JellifyContextInitializer = () => {
setCarPlayConnected(true)
if (loggedIn) {
CarPlay.setRootTemplate(CarPlayNavigation())
// CarPlay.pushTemplate(CarPlayNowPlaying())
CarPlay.setRootTemplate(CarPlayNavigation)
CarPlay.pushTemplate(CarPlayNowPlaying)
if (Platform.OS === 'ios') {
CarPlay.enableNowPlaying(true) // https://github.com/birkir/react-native-carplay/issues/185