Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Home - Activity Indicator #1282

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Shared/Coordinators/HomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class HomeCoordinator: NavigationCoordinatable {
var item = makeItem
@Route(.push)
var library = makeLibrary
@Route(.push)
var adminDashboard = makeAdminDashboard
#endif

#if os(tvOS)
Expand All @@ -46,6 +48,10 @@ final class HomeCoordinator: NavigationCoordinatable {
func makeLibrary(viewModel: PagingLibraryViewModel<BaseItemDto>) -> LibraryCoordinator<BaseItemDto> {
LibraryCoordinator(viewModel: viewModel)
}

func makeAdminDashboard() -> NavigationViewCoordinator<AdminDashboardCoordinator> {
NavigationViewCoordinator(AdminDashboardCoordinator())
}
#endif

@ViewBuilder
Expand Down
2 changes: 2 additions & 0 deletions Shared/Strings/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal enum L10n {
internal static let activeDevices = L10n.tr("Localizable", "activeDevices", fallback: "Active Devices")
/// Activity
internal static let activity = L10n.tr("Localizable", "activity", fallback: "Activity")
/// Activity Indicator
internal static let activityIndicator = L10n.tr("Localizable", "activityIndicator", fallback: "Activity Indicator")
/// Add
internal static let add = L10n.tr("Localizable", "add", fallback: "Add")
/// Add API key
Expand Down
8 changes: 8 additions & 0 deletions Shared/SwiftfinStore/StoredValue/StoredValues+User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ extension StoredValues.Keys {
)
}

static var activeSessionIndicator: Key<Bool> {
CurrentUserKey(
"activeSessionIndicator",
domain: "activeSessionIndicator",
default: false
)
}

static var customDeviceProfiles: Key<[CustomDeviceProfile]> {
CurrentUserKey(
"customDeviceProfiles",
Expand Down
12 changes: 12 additions & 0 deletions Swiftfin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
4E0253BD2CBF0C06007EB9CD /* DeviceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E12F9152CBE9615006C217E /* DeviceType.swift */; };
4E0A8FFB2CAF74D20014B047 /* TaskCompletionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E0A8FFA2CAF74CD0014B047 /* TaskCompletionStatus.swift */; };
4E0A8FFC2CAF74D20014B047 /* TaskCompletionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E0A8FFA2CAF74CD0014B047 /* TaskCompletionStatus.swift */; };
4E10F7F32CC49BDE0032C4B7 /* ActiveSessionsIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E10F7F22CC49BCF0032C4B7 /* ActiveSessionsIndicator.swift */; };
4E10C8112CC030CD0012CC9F /* DeviceDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E10C8102CC030C90012CC9F /* DeviceDetailsView.swift */; };
4E10C8172CC0455A0012CC9F /* CompatibilitiesSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E10C8162CC045530012CC9F /* CompatibilitiesSection.swift */; };
4E10C8192CC045700012CC9F /* CustomDeviceNameSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E10C8182CC045690012CC9F /* CustomDeviceNameSection.swift */; };
Expand Down Expand Up @@ -114,6 +115,10 @@
4EC6C16B2C92999800FC904B /* TranscodeSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EC6C16A2C92999800FC904B /* TranscodeSection.swift */; };
4ECDAA9E2C920A8E0030F2F5 /* TranscodeReason.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ECDAA9D2C920A8E0030F2F5 /* TranscodeReason.swift */; };
4ECDAA9F2C920A8E0030F2F5 /* TranscodeReason.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ECDAA9D2C920A8E0030F2F5 /* TranscodeReason.swift */; };
4EDBDCD12CBDD6590033D347 /* SessionInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EDBDCD02CBDD6510033D347 /* SessionInfo.swift */; };
4EDBDCD22CBDD6590033D347 /* SessionInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EDBDCD02CBDD6510033D347 /* SessionInfo.swift */; };
4EE11E1A2CC6A513004BF852 /* ActivityBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE11E192CC6A50D004BF852 /* ActivityBadge.swift */; };
4EE141692C8BABDF0045B661 /* ProgressSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE141682C8BABDF0045B661 /* ProgressSection.swift */; };
4EE141692C8BABDF0045B661 /* ActiveSessionProgressSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE141682C8BABDF0045B661 /* ActiveSessionProgressSection.swift */; };
4EED874A2CBF824B002354D2 /* DeviceRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EED87462CBF824B002354D2 /* DeviceRow.swift */; };
4EED874B2CBF824B002354D2 /* DevicesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EED87482CBF824B002354D2 /* DevicesView.swift */; };
Expand Down Expand Up @@ -1065,6 +1070,7 @@
/* Begin PBXFileReference section */
091B5A872683142E00D78B61 /* ServerDiscovery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerDiscovery.swift; sourceTree = "<group>"; };
4E0A8FFA2CAF74CD0014B047 /* TaskCompletionStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskCompletionStatus.swift; sourceTree = "<group>"; };
4E10F7F22CC49BCF0032C4B7 /* ActiveSessionsIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveSessionsIndicator.swift; sourceTree = "<group>"; };
4E10C8102CC030C90012CC9F /* DeviceDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceDetailsView.swift; sourceTree = "<group>"; };
4E10C8162CC045530012CC9F /* CompatibilitiesSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompatibilitiesSection.swift; sourceTree = "<group>"; };
4E10C8182CC045690012CC9F /* CustomDeviceNameSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomDeviceNameSection.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1145,6 +1151,8 @@
4EC6C16A2C92999800FC904B /* TranscodeSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TranscodeSection.swift; sourceTree = "<group>"; };
4ECDAA9D2C920A8E0030F2F5 /* TranscodeReason.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TranscodeReason.swift; sourceTree = "<group>"; };
4EDBDCD02CBDD6510033D347 /* SessionInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionInfo.swift; sourceTree = "<group>"; };
4EE11E192CC6A50D004BF852 /* ActivityBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityBadge.swift; sourceTree = "<group>"; };
4EE141682C8BABDF0045B661 /* ProgressSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressSection.swift; sourceTree = "<group>"; };
4EE141682C8BABDF0045B661 /* ActiveSessionProgressSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveSessionProgressSection.swift; sourceTree = "<group>"; };
4EED87462CBF824B002354D2 /* DeviceRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceRow.swift; sourceTree = "<group>"; };
4EED87482CBF824B002354D2 /* DevicesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevicesView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2688,6 +2696,8 @@
53F866422687A45400DCD1D7 /* Components */ = {
isa = PBXGroup;
children = (
4E10F7F22CC49BCF0032C4B7 /* ActiveSessionsIndicator.swift */,
4EE11E192CC6A50D004BF852 /* ActivityBadge.swift */,
E1D8429429346C6400D1041A /* BasicStepper.swift */,
E133328C2953AE4B00EE76AB /* CircularProgressView.swift */,
E1A3E4CE2BB7E02B005C59F8 /* DelayedProgressView.swift */,
Expand Down Expand Up @@ -4948,6 +4958,7 @@
E1CB75732C80E71800217C76 /* DirectPlayProfile.swift in Sources */,
E1B490472967E2E500D3EDCE /* CoreStore.swift in Sources */,
6220D0C026D61C5000B8E046 /* ItemCoordinator.swift in Sources */,
4EE11E1A2CC6A513004BF852 /* ActivityBadge.swift in Sources */,
4EC2B1A22CC96F6600D866BE /* ServerUsersViewModel.swift in Sources */,
E1B90C6A2BBE68D5007027C8 /* OffsetScrollView.swift in Sources */,
E18E01DB288747230022598C /* iPadOSEpisodeItemView.swift in Sources */,
Expand Down Expand Up @@ -5219,6 +5230,7 @@
E13332912953B91000EE76AB /* DownloadTaskCoordinator.swift in Sources */,
E43918662AD5C8310045A18C /* OnScenePhaseChangedModifier.swift in Sources */,
E1579EA72B97DC1500A31CA1 /* Eventful.swift in Sources */,
4E10F7F32CC49BDE0032C4B7 /* ActiveSessionsIndicator.swift in Sources */,
E1B33ED128EB860A0073B0FD /* LargePlaybackButtons.swift in Sources */,
E1549664296CA2EF00C4EF88 /* SwiftfinStore.swift in Sources */,
E102313F2BCF8A3C009D71FC /* DetailedChannelView.swift in Sources */,
Expand Down
103 changes: 103 additions & 0 deletions Swiftfin/Components/ActiveSessionsIndicator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import JellyfinAPI
import SwiftUI

struct ActiveSessionIndicator: View {
@ObservedObject
var viewModel = ActiveSessionsViewModel()

let action: () -> Void

// MARK: - View Model Update Timer

private let timer = Timer.publish(every: 60, on: .main, in: .common)
.autoconnect()

// MARK: - Session States

var activeSessions: [SessionInfo] {
viewModel.sessions.compactMap(\.value.value).filter {
$0.nowPlayingItem != nil
}
}

// MARK: - Initializer

init(action: @escaping () -> Void) {
self.action = action
self.viewModel.send(.getSessions)
}

// MARK: - Body

var body: some View {
Button(action: action) {
contentView
.onReceive(timer) { _ in
viewModel.send(.getSessions)
}
}
}

// MARK: - Content View

@ViewBuilder
var contentView: some View {
JPKribs marked this conversation as resolved.
Show resolved Hide resolved
switch viewModel.state {
case .content, .initial:
sessionsView
default:
errorView
}
}

// MARK: - Sessions View

var sessionsView: some View {
HStack(alignment: .bottom) {
imageView
.overlay {
if !activeSessions.isEmpty {
ActivityBadge(value: activeSessions.count)
}
}
}
}

// MARK: - Image View

var imageView: some View {
Image(systemName: "waveform.path.ecg")
.resizable()
.scaledToFit()
.padding(4)
.frame(width: 25, height: 25)
.foregroundColor(.primary)
.background(
Circle()
.fill(.secondary)
)
}

// MARK: - Error View

var errorView: some View {
Image(systemName: "exclamationmark.triangle")
.resizable()
.scaledToFit()
.padding(4)
.frame(width: 25, height: 25)
.foregroundColor(.black)
.background(
Circle()
.fill(.yellow)
)
}
}
83 changes: 83 additions & 0 deletions Swiftfin/Components/ActivityBadge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI

struct ActivityBadge: View {

let value: Int

private let size = 16.0
private let x = 20.0
private let y = 0.0

var body: some View {
ZStack {
Capsule()
.fill(.primary)
.frame(width: size * widthMultplier(), height: size, alignment: .topTrailing)
.overlay {
Capsule()
.stroke(Color.systemBackground, lineWidth: 1.5)
}
.position(x: x, y: y)

if hasTwoOrLessDigits() {
Text("\(value)")
.font(.caption)
.fontWeight(.semibold)
.foregroundStyle(.secondary)
.position(x: x, y: y)
} else {
Text("99+")
.font(.caption)
.fontWeight(.semibold)
.foregroundStyle(.secondary)
.frame(width: size * widthMultplier(), height: size, alignment: .center)
.position(x: x, y: y)
}
}
.opacity(value == 0 ? 0 : 1)
}

func hasTwoOrLessDigits() -> Bool {
value < 100
}

func widthMultplier() -> Double {
if value < 10 {
return 1.0
} else if value < 100 {
return 1.5
} else {
return 2.0
}
}
}

#Preview {
VStack {
Button {} label: {
Image(systemName: "waveform.path.ecg")
.resizable()
.backport
.fontWeight(.semibold)
.padding(4)
.frame(width: 25, height: 25)
.foregroundColor(.primary)
.background(
Circle()
.fill(.secondary)
)
.overlay {
ActivityBadge(value: 24)
.foregroundStyle(.blue, .blue.overlayColor)
}
}
}
}
10 changes: 10 additions & 0 deletions Swiftfin/Views/HomeView/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import SwiftUI
// - indicated by snapping to the top
struct HomeView: View {

@StoredValue(.User.activeSessionIndicator)
private var activeSessionIndicator

@Default(.Customization.nextUpPosterType)
private var nextUpPosterType
@Default(.Customization.Home.showRecentlyAdded)
Expand Down Expand Up @@ -87,6 +90,13 @@ struct HomeView: View {
ProgressView()
}

if activeSessionIndicator {
ActiveSessionIndicator {
router.route(to: \.adminDashboard)
}
.foregroundStyle(Color.accentColor, .secondary)
}

SettingsBarButton(
server: viewModel.userSession.server,
user: viewModel.userSession.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
//

import Defaults
import Factory
import SwiftUI

extension CustomizeViewsSettings {

struct HomeSection: View {

@Injected(\.currentUserSession)
private var userSession

@StoredValue(.User.activeSessionIndicator)
private var activeSessionIndicator

@Default(.Customization.Home.showRecentlyAdded)
private var showRecentlyAdded
@Default(.Customization.Home.maxNextUp)
Expand All @@ -23,6 +30,10 @@ extension CustomizeViewsSettings {
var body: some View {
Section(L10n.home) {

if userSession?.user.isAdministrator ?? false {
Toggle(L10n.activityIndicator, isOn: $activeSessionIndicator)
}

Toggle(L10n.showRecentlyAdded, isOn: $showRecentlyAdded)

Toggle(L10n.nextUpRewatch, isOn: $resumeNextUp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
//

import Defaults
import Factory
import SwiftUI

// TODO: will be entirely re-organized

struct CustomizeViewsSettings: View {

@Injected(\.currentUserSession)
private var userSesssion

@Default(.Customization.itemViewType)
private var itemViewType
@Default(.Customization.CinematicItemViewType.usePrimaryImage)
Expand Down
5 changes: 5 additions & 0 deletions Translations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,11 @@
/* Section Title for Column Configuration */
"columns" = "Columns";

// Activity Indicator - Setting
// Setting to enable/disable the HomeView Activity Indicator
// Appears in CustomizeSettingView
"activityIndicator" = "Activity Indicator";

// Date Created - Label
// Label for displaying the date an API key was created
// Appears in the API key details
Expand Down