Skip to content

Commit

Permalink
Full streak view
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Jan 18, 2025
1 parent 55f4b6d commit 30ae5b6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
8 changes: 4 additions & 4 deletions streak-bar/streak-bar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
CODE_SIGN_ENTITLEMENTS = "streak-bar/streak_bar.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = UV3HUS49VJ;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -380,7 +380,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.pavelmakhov.streak-bar";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -396,7 +396,7 @@
CODE_SIGN_ENTITLEMENTS = "streak-bar/streak_bar.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = UV3HUS49VJ;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -409,7 +409,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.pavelmakhov.streak-bar";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
3 changes: 1 addition & 2 deletions streak-bar/streak-bar/GitHub/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Defaults

public class Client {

@Default(.githubUsername) var githubUsername
@FromKeychain(.githubToken) var githubToken

func getContributions(from: Date, completion: @escaping (Result<[ContributionWeek], ClientError>) -> Void) {
Expand Down Expand Up @@ -49,7 +48,7 @@ public class Client {
var variables: [String: Any] = [:]

// Adding values to the dictionary
variables["userName"] = githubUsername
variables["userName"] = Defaults[.githubUsername]
variables["from"] = formatDateToCustomString(from)
variables["to"] = formatDateToCustomString(.now)

Expand Down
10 changes: 6 additions & 4 deletions streak-bar/streak-bar/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import Foundation
import Defaults

class ViewModel: ObservableObject {
@Default(.daysBefore) var daysBefore
@Default(.viewMode) var viewMode

private var client = Client()

@Published var contributions: [ContributionWeek] = []

init() {
print("ViewModel init")
}

func getContributions() {
let multiplier = viewMode == .week ? 7 : 1
let multiplier = Defaults[.viewMode] == .week ? 7 : 1

let fromDate = getDateNDaysBeforeToday(n: daysBefore * multiplier)
let fromDate = getDateNDaysBeforeToday(n: Defaults[.daysBefore] * multiplier)

client.getContributions(from: fromDate) { result in
switch result {
Expand Down
16 changes: 10 additions & 6 deletions streak-bar/streak-bar/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import LaunchAtLogin
struct ContentView: View {

var appDelegate: AppDelegate
@State private var favoriteColor = 0
@State private var selectedTab = 0

var body: some View {

VStack(spacing: 10) {
ZStack {
Picker("", selection: $favoriteColor) {
Text("Settings").tag(0)
Text("About").tag(1)
Picker("", selection: $selectedTab) {
Text("Streaks").tag(0)
Text("Settings").tag(1)
Text("About").tag(2)
}
.pickerStyle(.segmented)
.frame(width: 150)
Expand Down Expand Up @@ -49,9 +50,12 @@ struct ContentView: View {
}
}

if favoriteColor == 0 {
if selectedTab == 0 {
StatusItemView(viewModel: appDelegate.viewModel, isFullSize: true)
.padding()
} else if selectedTab == 1 {
SettingsView(appDelegate: appDelegate)
} else {
} else if selectedTab == 2 {
AboutView()
}
}
Expand Down
8 changes: 5 additions & 3 deletions streak-bar/streak-bar/Views/StatusItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ struct StatusItemView: View {
@Default(.borders) var borders
@Default(.transparency) var transparency
@Default(.viewMode) var viewMode


var isFullSize: Bool = false

var body: some View {

if viewModel.contributions.first?.contributionDays.isEmpty ?? false {
Expand All @@ -31,7 +33,7 @@ struct StatusItemView: View {
ForEach(week.contributionDays, id:\.date) { day in
Rectangle()
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
.frame(width: borders ? 2 : 3, height: borders ? 2 : 3)
.frame(width: (borders ? 2 : 3) * (isFullSize ? 3 : 1), height: (borders ? 2 : 3) * (isFullSize ? 3 : 1))
}
}
}
Expand All @@ -42,7 +44,7 @@ struct StatusItemView: View {
ForEach(week.contributionDays, id:\.date) { day in
RoundedRectangle(cornerRadius: 4)
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
.frame(width: 16, height: 16)
.frame(width: 16 * (isFullSize ? 3 : 1), height: 16 * (isFullSize ? 3 : 1))
}
}
}
Expand Down

0 comments on commit 30ae5b6

Please sign in to comment.