-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Music Authorization/Subcription prompts (#49)
- Loading branch information
Showing
28 changed files
with
441 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
mupl/Common/Components/MusicAuthorizationPrompt/MusicAuthorizationPrompt.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// MusicAuthorizationPrompt.swift | ||
// mupl | ||
// | ||
// Created by Tamerlan Satualdypov on 28.02.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct MusicAuthorizationPrompt: View { | ||
@EnvironmentObject private var musicManager: MusicManager | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 16.0) { | ||
Image("Common/Logo") | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: 40.0, height: 40.0) | ||
.clipShape(.rect(cornerRadius: 12.0)) | ||
|
||
VStack(spacing: 16.0) { | ||
VStack(alignment: .leading, spacing: 8.0) { | ||
Text("Apple Music access required") | ||
.font(.system(size: 16.0, weight: .bold)) | ||
.foregroundStyle(Color.primaryText) | ||
|
||
Text("Granting permission allows us to enhance your experience by accessing your music library. We prioritize your privacy and will only utilize this access for its intended purpose.") | ||
.font(.system(size: 14.0)) | ||
.multilineTextAlignment(.leading) | ||
.foregroundStyle(Color.secondaryText) | ||
} | ||
|
||
Button { | ||
if self.musicManager.authorization.status == .notDetermined { | ||
self.requestAccess() | ||
} | ||
|
||
if self.musicManager.authorization.status == .denied { | ||
self.openSettings() | ||
} | ||
} label: { | ||
Text("Allow access") | ||
.frame(maxWidth: .infinity) | ||
} | ||
.buttonStyle(.app(.primary)) | ||
} | ||
} | ||
.padding(.all, 24.0) | ||
.frame(maxWidth: 512.0) | ||
.background(.ultraThinMaterial) | ||
.clipShape(.rect(cornerRadius: 16.0)) | ||
.border(style: .quinaryFill, cornerRadius: 16.0) | ||
} | ||
|
||
private func requestAccess() { | ||
Task { | ||
await self.musicManager.authorization.requestIfNeeded() | ||
} | ||
} | ||
|
||
private func openSettings() { | ||
guard let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Media") else { return } | ||
NSWorkspace.shared.open(url) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
mupl/Common/Components/MusicSubscriptionPrompt/MusicSubscriptionPrompt.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// MusicSubscriptionPrompt.swift | ||
// mupl | ||
// | ||
// Created by Tamerlan Satualdypov on 09.03.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct MusicSubscriptionPrompt: View { | ||
@State private var isShowingOffer: Bool = false | ||
|
||
@EnvironmentObject private var musicManager: MusicManager | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 16.0) { | ||
HStack { | ||
Image("Common/AppleMusic") | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: 40.0, height: 40.0) | ||
|
||
Spacer() | ||
|
||
Image(systemName: "xmark.circle.fill") | ||
.font(.system(size: 16.0)) | ||
.foregroundStyle(.white) | ||
.tappable { | ||
self.musicManager.subscription.isOffering = false | ||
} | ||
} | ||
|
||
VStack(alignment: .leading, spacing: 8.0) { | ||
Text("Join Apple Music") | ||
.font(.system(size: 16.0, weight: .bold)) | ||
.foregroundStyle(Color.primaryText) | ||
|
||
Text("Listen to over 100 million songs, ad-free with zero commercials. Plus get unlimited downloads to your library, and listen anywhere without Wi-Fi or using data. There’s no commitment, you can cancel anytime.") | ||
.font(.system(size: 14.0)) | ||
.multilineTextAlignment(.leading) | ||
.foregroundStyle(Color.secondaryText) | ||
} | ||
|
||
Button { | ||
self.isShowingOffer = true | ||
} label: { | ||
Text("Join") | ||
.frame(maxWidth: .infinity) | ||
} | ||
.buttonStyle(.app(.primary)) | ||
} | ||
.padding(.all, 24.0) | ||
.frame(maxWidth: 512.0) | ||
.background(.ultraThinMaterial) | ||
.clipShape(.rect(cornerRadius: 16.0)) | ||
.border(style: .quinaryFill, cornerRadius: 16.0) | ||
.musicSubscriptionOffer(isPresented: self.$isShowingOffer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.