Channels performance improvements

Add settings:
Show channel avatars in channels lists
Show channel avatars in videos lists

Fix #508
This commit is contained in:
Arkadiusz Fal
2023-07-22 19:02:59 +02:00
parent 37a96a01db
commit 3c9e04d243
14 changed files with 81 additions and 71 deletions

View File

@@ -50,6 +50,8 @@ struct RecentNavigationLink<DestinationContent: View>: View {
var recents = RecentsModel.shared
@ObservedObject private var navigation = NavigationModel.shared
@Default(.showChannelAvatarInChannelsLists) private var showChannelAvatarInChannelsLists
var recent: RecentItem
var systemImage: String?
let destination: DestinationContent
@@ -71,9 +73,10 @@ struct RecentNavigationLink<DestinationContent: View>: View {
HStack {
if recent.type == .channel,
let channel = recent.channel,
channel.thumbnailURLOrCached != nil
showChannelAvatarInChannelsLists
{
ChannelAvatarView(channel: channel, subscribedBadge: false)
.id("channel-avatar-\(channel.id)")
.frame(width: Constants.sidebarChannelThumbnailSize, height: Constants.sidebarChannelThumbnailSize)
Text(channel.name)

View File

@@ -8,6 +8,11 @@ struct AppSidebarSubscriptions: View {
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
@Default(.keepChannelsWithUnwatchedFeedOnTop) private var keepChannelsWithUnwatchedFeedOnTop
@Default(.showChannelAvatarInChannelsLists) private var showChannelAvatarInChannelsLists
@State private var channelLinkActive = false
@State private var channelForLink: Channel?
var body: some View {
Section(header: Text("Subscriptions")) {
@@ -16,9 +21,10 @@ struct AppSidebarSubscriptions: View {
LazyView(ChannelVideosView(channel: channel))
} label: {
HStack {
if channel.thumbnailURLOrCached != nil {
if showChannelAvatarInChannelsLists {
ChannelAvatarView(channel: channel, subscribedBadge: false)
.frame(width: Constants.sidebarChannelThumbnailSize, height: Constants.sidebarChannelThumbnailSize)
Text(channel.name)
} else {
Label(channel.name, systemImage: RecentsModel.symbolSystemImage(channel.name))
@@ -26,13 +32,10 @@ struct AppSidebarSubscriptions: View {
Spacer()
}
.lineLimit(1)
.badge(showUnwatchedFeedBadges ? feedCount.unwatchedByChannelText(channel) : nil)
}
.contextMenu {
if subscriptions.isSubscribing(channel.id) {
toggleWatchedButton(channel)
}
Button("Unsubscribe") {
navigation.presentUnsubscribeAlert(channel, subscriptions: subscriptions)
}
@@ -41,31 +44,6 @@ struct AppSidebarSubscriptions: View {
}
}
}
@ViewBuilder func toggleWatchedButton(_ channel: Channel) -> some View {
if feed.canMarkChannelAsWatched(channel.id) {
markChannelAsWatchedButton(channel)
} else {
markChannelAsUnwatchedButton(channel)
}
}
func markChannelAsWatchedButton(_ channel: Channel) -> some View {
Button {
feed.markChannelAsWatched(channel.id)
} label: {
Label("Mark channel feed as watched", systemImage: "checkmark.circle.fill")
}
.disabled(!feed.canMarkAllFeedAsWatched)
}
func markChannelAsUnwatchedButton(_ channel: Channel) -> some View {
Button {
feed.markChannelAsUnwatched(channel.id)
} label: {
Label("Mark channel feed as unwatched", systemImage: "checkmark.circle")
}
}
}
struct AppSidebarSubscriptions_Previews: PreviewProvider {