2023-01-31 14:37:49 +01:00
|
|
|
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import WidgetKit
|
|
|
|
import MastodonAsset
|
2023-02-06 12:13:29 +01:00
|
|
|
import MastodonLocalization
|
2023-01-31 14:37:49 +01:00
|
|
|
|
|
|
|
struct MultiFollowersCountWidgetView: View {
|
|
|
|
@Environment(\.widgetFamily) var family
|
|
|
|
|
|
|
|
var entry: MultiFollowersCountWidgetProvider.Entry
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
if let accounts = entry.accounts {
|
|
|
|
switch family {
|
|
|
|
case .systemSmall:
|
2023-01-31 14:54:05 +01:00
|
|
|
viewForSmallWidget(accounts)
|
|
|
|
case .systemMedium:
|
|
|
|
viewForMediumWidget(accounts)
|
2023-01-31 14:37:49 +01:00
|
|
|
default:
|
2023-02-06 12:13:29 +01:00
|
|
|
Text(L10n.Widget.Common.unsupportedWidgetFamily)
|
2023-01-31 14:37:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
2023-02-06 12:13:29 +01:00
|
|
|
Text(L10n.Widget.Common.userNotLoggedIn)
|
2023-01-31 14:37:49 +01:00
|
|
|
.multilineTextAlignment(.center)
|
|
|
|
.font(.caption)
|
|
|
|
.padding(.all, 20)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-31 14:54:05 +01:00
|
|
|
private func viewForSmallWidget(_ accounts: [FollowersEntryAccountable]) -> some View {
|
2023-01-31 14:37:49 +01:00
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
ForEach(accounts, id: \.acct) { account in
|
|
|
|
HStack {
|
|
|
|
if let avatarImage = account.avatarImage {
|
|
|
|
Image(uiImage: avatarImage)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 32, height: 32)
|
|
|
|
.cornerRadius(5)
|
|
|
|
}
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(account.followersCount.asAbbreviatedCountString())
|
|
|
|
.font(.title2)
|
|
|
|
.lineLimit(1)
|
|
|
|
.truncationMode(.tail)
|
|
|
|
|
|
|
|
Text("@\(account.acct)")
|
|
|
|
.font(.caption2)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.lineLimit(1)
|
|
|
|
.truncationMode(.tail)
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.leading, 20)
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.vertical, 16)
|
|
|
|
}
|
2023-01-31 14:54:05 +01:00
|
|
|
|
|
|
|
private func viewForMediumWidget(_ accounts: [FollowersEntryAccountable]) -> some View {
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
LazyVGrid(columns: [
|
|
|
|
GridItem(.flexible()),
|
|
|
|
GridItem(.flexible())
|
|
|
|
]) {
|
|
|
|
ForEach(accounts, id: \.acct) { account in
|
|
|
|
HStack {
|
|
|
|
if let avatarImage = account.avatarImage {
|
|
|
|
Image(uiImage: avatarImage)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 32, height: 32)
|
|
|
|
.cornerRadius(5)
|
|
|
|
}
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(account.followersCount.asAbbreviatedCountString())
|
|
|
|
.font(.title2)
|
|
|
|
.lineLimit(1)
|
|
|
|
.truncationMode(.tail)
|
|
|
|
|
|
|
|
Text("@\(account.acct)")
|
|
|
|
.font(.caption2)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.lineLimit(1)
|
|
|
|
.truncationMode(.tail)
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.leading, 20)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.vertical, 16)
|
|
|
|
}
|
2023-01-31 14:37:49 +01:00
|
|
|
}
|