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)
|
2024-02-20 16:34:40 +01:00
|
|
|
.emptyWidgetBackground()
|
2023-01-31 14:37:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 13:51:58 +01:00
|
|
|
private func viewForSmallWidget(_ accounts: [MultiFollowersEntryAccountable]) -> some View {
|
2023-01-31 14:37:49 +01:00
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
ForEach(accounts, id: \.acct) { account in
|
|
|
|
HStack {
|
2023-03-01 14:58:12 +01:00
|
|
|
Image(uiImage: account.avatarImage)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 32, height: 32)
|
|
|
|
.cornerRadius(5)
|
2023-01-31 14:37:49 +01:00
|
|
|
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)
|
2024-02-20 16:34:40 +01:00
|
|
|
.emptyWidgetBackground()
|
2023-01-31 14:37:49 +01:00
|
|
|
}
|
2023-01-31 14:54:05 +01:00
|
|
|
|
2023-02-06 13:51:58 +01:00
|
|
|
private func viewForMediumWidget(_ accounts: [MultiFollowersEntryAccountable]) -> some View {
|
2023-01-31 14:54:05 +01:00
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
LazyVGrid(columns: [
|
|
|
|
GridItem(.flexible()),
|
|
|
|
GridItem(.flexible())
|
|
|
|
]) {
|
|
|
|
ForEach(accounts, id: \.acct) { account in
|
|
|
|
HStack {
|
2023-03-01 14:58:12 +01:00
|
|
|
Image(uiImage: account.avatarImage)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 32, height: 32)
|
|
|
|
.cornerRadius(5)
|
2023-01-31 14:54:05 +01:00
|
|
|
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)
|
2024-02-20 16:34:40 +01:00
|
|
|
.emptyWidgetBackground()
|
2023-01-31 14:54:05 +01:00
|
|
|
}
|
2023-01-31 14:37:49 +01:00
|
|
|
}
|