import { AlbumListItem, Artist, PlaylistListItem, Song } from '@app/models/music'
import { currentTrackAtom } from '@app/state/trackplayer'
import colors from '@app/styles/colors'
import font from '@app/styles/font'
import { useAtomValue } from 'jotai/utils'
import React, { useState } from 'react'
import { GestureResponderEvent, StyleSheet, Text, View } from 'react-native'
import IconFA from 'react-native-vector-icons/FontAwesome'
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
import IconMat from 'react-native-vector-icons/MaterialIcons'
import CoverArt from './CoverArt'
import PressableOpacity from './PressableOpacity'
const TitleTextSong = React.memo<{
id: string
title?: string
}>(({ id, title }) => {
const currentTrack = useAtomValue(currentTrackAtom)
const playing = currentTrack?.id === id
return (
{playing ? : <>>}
{title}
)
})
const TitleText = React.memo<{
title?: string
}>(({ title }) => {
return (
{title}
)
})
const ListItem: React.FC<{
item: Song | AlbumListItem | Artist | PlaylistListItem
onPress?: (event: GestureResponderEvent) => void
showArt?: boolean
showStar?: boolean
listStyle?: 'big' | 'small'
subtitle?: string
}> = ({ item, onPress, showArt, showStar, subtitle, listStyle }) => {
const [starred, setStarred] = useState(false)
showStar = showStar === undefined ? true : showStar
listStyle = listStyle || 'small'
const artSource = item.itemType === 'artist' ? { artistId: item.id } : { coverArt: item.coverArt }
const sizeStyle = listStyle === 'big' ? bigStyles : smallStyles
return (
{showArt ? : <>>}
{item.itemType === 'song' ? (
) : (
)}
{subtitle ? (
{starred ? (
) : (
<>>
)}
{subtitle}
) : (
<>>
)}
{showStar ? (
setStarred(!starred)} style={styles.controlItem}>
{starred ? (
) : (
)}
) : (
<>>
)}
)
}
const styles = StyleSheet.create({
container: {
marginBottom: 14,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
item: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start',
},
art: {
marginRight: 10,
},
text: {
flex: 1,
},
textLine: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
},
title: {
fontSize: 16,
fontFamily: font.semiBold,
color: colors.text.primary,
},
playingIcon: {
marginRight: 5,
marginLeft: 1,
},
downloadedIcon: {
marginRight: 2,
marginLeft: -3,
},
subtitle: {
fontSize: 14,
fontFamily: font.regular,
color: colors.text.secondary,
},
controls: {
flexDirection: 'row',
alignItems: 'center',
},
controlItem: {
marginLeft: 16,
},
})
const smallStyles = StyleSheet.create({
container: {
minHeight: 50,
},
art: {
height: 50,
width: 50,
},
})
const bigStyles = StyleSheet.create({
container: {
minHeight: 70,
},
art: {
height: 70,
width: 70,
},
})
export default React.memo(ListItem)