2023-10-23 17:43:16 -06:00
|
|
|
import WidgetKit
|
|
|
|
import SwiftUI
|
|
|
|
import Intents
|
|
|
|
|
2024-01-25 15:01:16 -07:00
|
|
|
/// Defines the view / layout of the widget
|
2023-10-23 17:43:16 -06:00
|
|
|
struct WonderousWidgetView : View {
|
|
|
|
@Environment(\.widgetFamily) var family: WidgetFamily
|
2023-11-02 09:58:07 -06:00
|
|
|
var entry: WonderousTimelineProvider.Entry
|
2023-10-23 17:43:16 -06:00
|
|
|
var body: some View {
|
|
|
|
let showTitle = family == .systemLarge
|
|
|
|
let showIcon = family != .systemSmall
|
|
|
|
let showTitleAndDesc = family != .systemSmall
|
2024-01-25 15:01:16 -07:00
|
|
|
let progressPct = Double(entry.discoveredCount) / 24.0
|
|
|
|
let iconImage = FlutterImages.icon;
|
2023-10-25 16:33:57 -06:00
|
|
|
let title = entry.title.isEmpty ? "Wonderous" : entry.title;
|
|
|
|
let subTitle = entry.subTitle.isEmpty ? "Search for hidden artifacts" : entry.subTitle;
|
2024-01-25 15:01:16 -07:00
|
|
|
|
2023-10-23 17:43:16 -06:00
|
|
|
let content = VStack{
|
2024-01-25 15:01:16 -07:00
|
|
|
// Top row with optional Title and Icon
|
2023-10-23 17:43:16 -06:00
|
|
|
HStack {
|
|
|
|
if(showTitle) {
|
|
|
|
Text("Collection")
|
|
|
|
.font(.system(size: 15))
|
2023-10-23 21:40:55 -06:00
|
|
|
.foregroundColor(.offWhite)
|
2023-10-23 17:43:16 -06:00
|
|
|
}
|
|
|
|
Spacer();
|
|
|
|
if(showIcon) {
|
|
|
|
Image(uiImage: UIImage(contentsOfFile: iconImage)!)
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(height: 24)
|
|
|
|
}
|
|
|
|
}
|
2024-01-25 15:01:16 -07:00
|
|
|
|
2023-10-23 17:43:16 -06:00
|
|
|
Spacer();
|
2024-01-25 15:01:16 -07:00
|
|
|
|
|
|
|
// Bottom hz row with title, desc and progress gauge
|
2023-10-23 17:43:16 -06:00
|
|
|
HStack {
|
|
|
|
if(showTitleAndDesc) {
|
|
|
|
VStack(alignment: .leading){
|
|
|
|
Text(title)
|
|
|
|
.font(.system(size: 22))
|
|
|
|
.foregroundColor(.white);
|
|
|
|
Text(subTitle)
|
|
|
|
.font(.system(size: 15))
|
2023-10-23 21:40:55 -06:00
|
|
|
.foregroundColor(.mediumGrey);
|
2023-10-23 17:43:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Spacer();
|
|
|
|
ZStack{
|
2024-01-25 15:01:16 -07:00
|
|
|
ProgressView(value: progressPct)
|
2023-10-23 17:43:16 -06:00
|
|
|
.progressViewStyle(GaugeProgressStyle())
|
|
|
|
.frame(width: 48, height: 48)
|
2024-01-25 15:01:16 -07:00
|
|
|
|
|
|
|
Text("\(Int((progressPct * 100).rounded()))%").font(.system(size: 13)).foregroundColor(.white)
|
2023-10-23 17:43:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-25 15:01:16 -07:00
|
|
|
// Stack content on top of the background image and a gradient
|
2023-10-23 21:40:55 -06:00
|
|
|
return ZStack{
|
|
|
|
BgImage(entry: entry).opacity(0.8)
|
2023-10-23 17:43:16 -06:00
|
|
|
LinearGradient(
|
|
|
|
gradient: Gradient(colors: [.black.opacity(0), .black]),
|
|
|
|
startPoint: .center,
|
|
|
|
endPoint: .bottom)
|
|
|
|
content.padding(16)
|
2023-11-07 11:12:05 -07:00
|
|
|
}
|
2024-01-25 15:01:16 -07:00
|
|
|
// Ios requires that widgets have a background color
|
2023-11-07 11:12:05 -07:00
|
|
|
.widgetBackground(Color.darkGrey)
|
2024-01-25 15:01:16 -07:00
|
|
|
// Deeplink into collections view when tapped
|
2023-11-07 17:38:09 -07:00
|
|
|
.widgetURL(URL(string: "wonderous:///home/collection"))
|
2023-10-23 17:43:16 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2023-10-23 18:06:39 -06:00
|
|
|
|