Skip to content

Commit

Permalink
Only show banner if less than 10% space is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioEstevao committed Nov 15, 2024
1 parent 9ffa791 commit 6b2c7e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions podcasts/DownloadsManageBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class DownloadsManageModel: ObservableObject {
}
}
}

static var shouldShowBanner: Bool {
guard let percentage = FileManager.devicePercentageFreeSpace else {
return false
}
return percentage < 0.1
}
}

struct DownloadsManageBannerView: View {
Expand Down
4 changes: 3 additions & 1 deletion podcasts/DownloadsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ class DownloadsViewController: PCViewController {
}

func showManageDownloads() {
guard FeatureFlag.manageDownloadedEpisodes.enabled else {
guard FeatureFlag.manageDownloadedEpisodes.enabled,
DownloadsManageModel.shouldShowBanner
else {
downloadsTable.tableHeaderView = nil
return
}
Expand Down
28 changes: 28 additions & 0 deletions podcasts/FileManager+Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,32 @@ extension FileManager {
}
return Int64(fileSize)
}

static var deviceRemainingFreeSpaceInBytes: Int64? {
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String)
do {
let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityKey])
return Int64(values.volumeAvailableCapacity ?? 0)
} catch {
return nil
}
}

static var deviceTotalSpaceInBytes: Int64? {
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String)
do {
let values = try fileURL.resourceValues(forKeys: [.volumeTotalCapacityKey])
return Int64(values.volumeTotalCapacity ?? 0)
} catch {
return nil
}
}

static var devicePercentageFreeSpace: Double? {
guard let total = deviceTotalSpaceInBytes,
let free = deviceRemainingFreeSpaceInBytes else {
return nil
}
return Double(free) / Double(total)
}
}

0 comments on commit 6b2c7e6

Please sign in to comment.