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