Skip to content

Commit

Permalink
Implement Large widget UI
Browse files Browse the repository at this point in the history
  • Loading branch information
asiliuk committed Sep 26, 2020
1 parent f02e9b4 commit ba9d1f2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
5 changes: 3 additions & 2 deletions BsuirUI/PairView.swift
Expand Up @@ -28,7 +28,8 @@ public struct PairCell: View {

public var body: some View {
pair
.padding(.horizontal)
.padding(.leading)
.padding(.trailing, 4)
.padding(.vertical, 8)
.background(
RoundedRectangle(cornerRadius: 8)
Expand Down Expand Up @@ -144,7 +145,7 @@ public struct PairView: View {
private var subtitle: some View {
Group {
if isCompact {
combineTexts(auditoryText, noteText).lineLimit(2)
combineTexts(auditoryText, noteText).lineLimit(1)
} else {
VStack(alignment: .leading) {
auditoryText
Expand Down
70 changes: 62 additions & 8 deletions ScheduleWidget/ScheduleWidget.swift
Expand Up @@ -96,7 +96,7 @@ struct ScheduleWidgetEntrySmallView : View {
HStack {
Image("BsuirSymbol").resizable().scaledToFit().frame(width: 20, height: 20)
Text(entry.title).font(.subheadline).lineLimit(1)
Spacer()
Spacer(minLength: 0)
}

Text("Сегодня 24.09").font(.headline).foregroundColor(.blue)
Expand Down Expand Up @@ -131,8 +131,9 @@ struct ScheduleWidgetEntrySmallView : View {

struct ScheduleWidgetEntryMediumView : View {
var entry: Provider.Entry
var pair: Provider.Entry.Pair { entry.pairs.first! }
var pairs: ArraySlice<Provider.Entry.Pair> { entry.pairs.dropFirst() }
var pair: Provider.Entry.Pair { entry.pairs[0] }
var secondPair: Provider.Entry.Pair { entry.pairs[1] }
var pairs: ArraySlice<Provider.Entry.Pair> { entry.pairs.dropFirst(2) }

var body: some View {
VStack(alignment: .leading, spacing: 2) {
Expand All @@ -141,6 +142,7 @@ struct ScheduleWidgetEntryMediumView : View {
Spacer()
Image("BsuirSymbol").resizable().scaledToFit().frame(width: 20, height: 20)
Text(entry.title).font(.subheadline).lineLimit(1)

}

Spacer().frame(height: 4)
Expand All @@ -161,11 +163,11 @@ struct ScheduleWidgetEntryMediumView : View {
)

PairView(
from: pair.from,
to: pair.to,
subject: pair.title,
from: secondPair.from,
to: secondPair.to,
subject: secondPair.title,
subgroup: "1",
auditory: pair.subtitle,
auditory: secondPair.subtitle,
note: "asasasas as asas",
form: .lecture,
progress: PairProgress(constant: 0.5),
Expand All @@ -189,6 +191,53 @@ struct ScheduleWidgetEntryMediumView : View {
}
}

struct ScheduleWidgetEntryLargeView : View {
var entry: Provider.Entry

var body: some View {
VStack(alignment: .leading, spacing: 6) {
HStack {
Text("Сегодня, 24.09").font(.headline).foregroundColor(.blue)
Spacer()
Image("BsuirSymbol").resizable().scaledToFit().frame(width: 20, height: 20)
Text(entry.title).font(.subheadline).lineLimit(1)
}

VStack(alignment: .leading, spacing: 8) {
ForEach(entry.pairs.prefix(6), id: \.title) { pair in
PairView(
from: pair.from,
to: pair.to,
subject: pair.title,
subgroup: "1",
auditory: pair.subtitle,
note: "asasasas as asa as asassaa asas as s",
form: .lecture,
progress: PairProgress(constant: 0.5),
isCompact: true
)
.padding(.leading, 10)
.padding(.vertical, 4)
.background(ContainerRelativeShape().foregroundColor(Color(.secondarySystemBackground)))
}
//
// if !pairs.isEmpty {
// HStack {
// Text("12:00").font(.system(.footnote, design: .monospaced))
// Circle().frame(width: 8, height: 8)
// Text(listFormatter.string(from: pairs.map { $0.title }, visibleCount: 3) ?? "")
// .font(.footnote)
// }.foregroundColor(.secondary)
// }
}

Spacer(minLength: 0)
}
.padding()
.background(Color(.systemBackground))
}
}

struct ScheduleWidgetEntryView: View {
let entry: Provider.Entry
@Environment(\.widgetFamily) var size
Expand All @@ -199,6 +248,8 @@ struct ScheduleWidgetEntryView: View {
ScheduleWidgetEntrySmallView(entry: entry)
case .systemMedium:
ScheduleWidgetEntryMediumView(entry: entry)
case .systemLarge:
ScheduleWidgetEntryLargeView(entry: entry)
default:
EmptyView()
}
Expand Down Expand Up @@ -230,11 +281,14 @@ struct ScheduleWidget_Previews: PreviewProvider {

ScheduleWidgetEntryView(entry: entry)
.previewContext(WidgetPreviewContext(family: .systemMedium))

ScheduleWidgetEntryView(entry: entry)
.previewContext(WidgetPreviewContext(family: .systemLarge))
}

static let entry = ScheduleEntry(
date: Date(),
title: "010102",
title: "Иванов А.Н.",
pairs: [
.init(from: "10:00", to: "11:45", title: "Философ", subtitle: "101-2"),
.init(from: "10:00", to: "11:45", title: "Миапр", subtitle: "101-2"),
Expand Down

0 comments on commit ba9d1f2

Please sign in to comment.