Cleanup
This commit is contained in:
parent
616f5ace91
commit
94afbb1bcf
@ -5,13 +5,16 @@ import SwiftUI
|
|||||||
// Loads a default image from the flutter assets bundle,
|
// Loads a default image from the flutter assets bundle,
|
||||||
// or displays a base64 encoded image that has been saved from the flutter application
|
// or displays a base64 encoded image that has been saved from the flutter application
|
||||||
struct BgImage : View {
|
struct BgImage : View {
|
||||||
var entry: WonderousEntry
|
var entry: WonderousTimelineEntry
|
||||||
var body: some View {
|
var body: some View {
|
||||||
var uiImage:UIImage?;
|
var uiImage:UIImage?;
|
||||||
|
// If there is no saved imageData, use the default bg image
|
||||||
if(entry.imageData.isEmpty){
|
if(entry.imageData.isEmpty){
|
||||||
let defaultImage = flutterAssetBundle.appending(path: "/assets/images/widget/background-empty.jpg").path();
|
let defaultImage = flutterAssetBundle.appending(path: "/assets/images/widget/background-empty.jpg").path();
|
||||||
uiImage = UIImage(contentsOfFile: defaultImage);
|
uiImage = UIImage(contentsOfFile: defaultImage);
|
||||||
} else {
|
}
|
||||||
|
// Load a base64 encoded image that has been written by the flutter app
|
||||||
|
else {
|
||||||
uiImage = UIImage(data: Data(base64Encoded: entry.imageData)!)
|
uiImage = UIImage(data: Data(base64Encoded: entry.imageData)!)
|
||||||
}
|
}
|
||||||
if(uiImage != nil){
|
if(uiImage != nil){
|
||||||
@ -34,7 +37,6 @@ struct BgImage : View {
|
|||||||
struct GaugeProgressStyle: ProgressViewStyle {
|
struct GaugeProgressStyle: ProgressViewStyle {
|
||||||
func makeBody(configuration: Configuration) -> some View {
|
func makeBody(configuration: Configuration) -> some View {
|
||||||
let fractionCompleted = configuration.fractionCompleted ?? 0
|
let fractionCompleted = configuration.fractionCompleted ?? 0
|
||||||
|
|
||||||
return ZStack {
|
return ZStack {
|
||||||
Circle()
|
Circle()
|
||||||
.stroke(Color.body, style: StrokeStyle(lineWidth: 2))
|
.stroke(Color.body, style: StrokeStyle(lineWidth: 2))
|
||||||
|
@ -3,7 +3,7 @@ import SwiftUI
|
|||||||
import Intents
|
import Intents
|
||||||
|
|
||||||
/// Entry, is passed into the view and defines the data it needs
|
/// Entry, is passed into the view and defines the data it needs
|
||||||
struct WonderousEntry : TimelineEntry {
|
struct WonderousTimelineEntry : TimelineEntry {
|
||||||
let date: Date
|
let date: Date
|
||||||
let discoveredCount:Int;
|
let discoveredCount:Int;
|
||||||
var title:String = "";
|
var title:String = "";
|
||||||
@ -17,7 +17,7 @@ struct WonderousWidget: Widget {
|
|||||||
let kind: String = "WonderousWidget"
|
let kind: String = "WonderousWidget"
|
||||||
|
|
||||||
var body: some WidgetConfiguration {
|
var body: some WidgetConfiguration {
|
||||||
StaticConfiguration(kind: kind, provider: Provider()) { entry in
|
StaticConfiguration(kind: kind, provider: WonderousTimelineProvider()) { entry in
|
||||||
WonderousWidgetView(entry: entry)
|
WonderousWidgetView(entry: entry)
|
||||||
}
|
}
|
||||||
.configurationDisplayName("Wonderous Widget")
|
.configurationDisplayName("Wonderous Widget")
|
||||||
@ -27,15 +27,15 @@ struct WonderousWidget: Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Provider,returns various WonderousEntry configs based on current context
|
// Provider,returns various WonderousEntry configs based on current context
|
||||||
struct Provider: TimelineProvider {
|
struct WonderousTimelineProvider: TimelineProvider {
|
||||||
// Provide an entry for a placeholder version of the widget
|
// Provide an entry for a placeholder version of the widget
|
||||||
func placeholder(in context: Context) -> WonderousEntry {
|
func placeholder(in context: Context) -> WonderousTimelineEntry {
|
||||||
WonderousEntry(date: Date(), discoveredCount: 0)
|
WonderousTimelineEntry(date: Date(), discoveredCount: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide an entry for the current time and state of the widget
|
// Provide an entry for the current time and state of the widget
|
||||||
func getSnapshot(in context: Context, completion: @escaping (WonderousEntry) -> ()) {
|
func getSnapshot(in context: Context, completion: @escaping (WonderousTimelineEntry) -> ()) {
|
||||||
let entry:WonderousEntry
|
let entry:WonderousTimelineEntry
|
||||||
let userDefaults = UserDefaults(suiteName: "group.com.gskinner.flutter.wonders.widget")
|
let userDefaults = UserDefaults(suiteName: "group.com.gskinner.flutter.wonders.widget")
|
||||||
let discoveredCount = userDefaults?.integer(forKey: "discoveredCount") ?? 0
|
let discoveredCount = userDefaults?.integer(forKey: "discoveredCount") ?? 0
|
||||||
let title = userDefaults?.string(forKey: "lastDiscoveredTitle") ?? ""
|
let title = userDefaults?.string(forKey: "lastDiscoveredTitle") ?? ""
|
||||||
@ -44,7 +44,7 @@ struct Provider: TimelineProvider {
|
|||||||
// if(context.isPreview){
|
// if(context.isPreview){
|
||||||
// entry = WonderousEntry(date: Date(), discoveredCount: discoveredCount)
|
// entry = WonderousEntry(date: Date(), discoveredCount: discoveredCount)
|
||||||
// }
|
// }
|
||||||
entry = WonderousEntry(
|
entry = WonderousTimelineEntry(
|
||||||
date: Date(),
|
date: Date(),
|
||||||
discoveredCount:discoveredCount,
|
discoveredCount:discoveredCount,
|
||||||
title: title,
|
title: title,
|
||||||
@ -55,7 +55,7 @@ struct Provider: TimelineProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Provide an array of entries for the current time and, optionally, any future times
|
// Provide an array of entries for the current time and, optionally, any future times
|
||||||
func getTimeline(in context: Context, completion: @escaping (Timeline<WonderousEntry>) -> ()) {
|
func getTimeline(in context: Context, completion: @escaping (Timeline<WonderousTimelineEntry>) -> ()) {
|
||||||
getSnapshot(in: context) { (entry) in
|
getSnapshot(in: context) { (entry) in
|
||||||
let timeline = Timeline(entries: [entry], policy: .atEnd)
|
let timeline = Timeline(entries: [entry], policy: .atEnd)
|
||||||
completion(timeline)
|
completion(timeline)
|
||||||
|
@ -5,7 +5,7 @@ import Intents
|
|||||||
// Defines the view / layout of the widget
|
// Defines the view / layout of the widget
|
||||||
struct WonderousWidgetView : View {
|
struct WonderousWidgetView : View {
|
||||||
@Environment(\.widgetFamily) var family: WidgetFamily
|
@Environment(\.widgetFamily) var family: WidgetFamily
|
||||||
var entry: Provider.Entry
|
var entry: WonderousTimelineProvider.Entry
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let showTitle = family == .systemLarge
|
let showTitle = family == .systemLarge
|
||||||
let showIcon = family != .systemSmall
|
let showIcon = family != .systemSmall
|
||||||
@ -62,7 +62,7 @@ struct WonderousWidgetView : View {
|
|||||||
startPoint: .center,
|
startPoint: .center,
|
||||||
endPoint: .bottom)
|
endPoint: .bottom)
|
||||||
content.padding(16)
|
content.padding(16)
|
||||||
}.widgetURL(URL(string: "wonderous://collection"))
|
}.widgetURL(URL(string: "wonderous:///collection"))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user