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

[WIP] [iOS] Home - Activity Indicator #1282

Draft
wants to merge 17 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(.modal)
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 @@ -32,6 +32,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")
/// Actor
internal static let actor = L10n.tr("Localizable", "actor", fallback: "Actor")
/// Add
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 @@ -16,6 +16,7 @@
4E026A8B2CE804E7005471B5 /* ResetUserPasswordView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E026A8A2CE804E7005471B5 /* ResetUserPasswordView.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 @@ -200,6 +201,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 */; };
4EE07CBB2D08B19700B0B636 /* ErrorMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE07CBA2D08B19100B0B636 /* ErrorMessage.swift */; };
4EE07CBC2D08B19700B0B636 /* ErrorMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE07CBA2D08B19100B0B636 /* ErrorMessage.swift */; };
4EE141692C8BABDF0045B661 /* ActiveSessionProgressSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE141682C8BABDF0045B661 /* ActiveSessionProgressSection.swift */; };
Expand Down Expand Up @@ -1170,6 +1175,7 @@
4E0195E32CE04678007844F4 /* ItemSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemSection.swift; sourceTree = "<group>"; };
4E026A8A2CE804E7005471B5 /* ResetUserPasswordView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResetUserPasswordView.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 @@ -1312,6 +1318,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>"; };
4EE07CBA2D08B19100B0B636 /* ErrorMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorMessage.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>"; };
Expand Down Expand Up @@ -3103,6 +3111,8 @@
53F866422687A45400DCD1D7 /* Components */ = {
isa = PBXGroup;
children = (
4E10F7F22CC49BCF0032C4B7 /* ActiveSessionsIndicator.swift */,
4EE11E192CC6A50D004BF852 /* ActivityBadge.swift */,
E1D8429429346C6400D1041A /* BasicStepper.swift */,
E133328C2953AE4B00EE76AB /* CircularProgressView.swift */,
4E661A242CEFE64200025C99 /* CountryPicker.swift */,
Expand Down Expand Up @@ -5405,6 +5415,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 @@ -5719,6 +5730,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
108 changes: 108 additions & 0 deletions Swiftfin/Components/ActiveSessionsIndicator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// 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.isNotEmpty {
ActivityBadge(value: activeSessions.count)
.foregroundStyle(.primary)
}
}
}
}

// 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(
activeSessions.isNotEmpty
? Color.accentColor.opacity(0.5)
: Color.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)
)
}
}
67 changes: 67 additions & 0 deletions Swiftfin/Components/ActivityBadge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// 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

// MARK: - Body

var body: some View {
ZStack {
Capsule()
.fill(Color.accentColor)
.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(.primary)
.position(x: x, y: y)
} else {
Text("99+")
.font(.caption)
.fontWeight(.semibold)
.foregroundStyle(.primary)
.frame(width: size * widthMultplier(), height: size, alignment: .center)
.position(x: x, y: y)
}
}
.opacity(value == 0 ? 0 : 1)
}

// MARK: - Check Number of Digits

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

// MARK: - Get Badge Width

func widthMultplier() -> Double {
if value < 10 {
return 1.0
} else if value < 100 {
return 1.5
} else {
return 2.0
}
}
}
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(.primary, .secondary, Color.accentColor)
}

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 @@ -888,6 +888,11 @@
// Title for the column configuration section.
"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
"dateCreated" = "Date Created";
Expand Down