Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyu-Xie committed Jun 6, 2024
1 parent b72873f commit dde1039
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
8 changes: 4 additions & 4 deletions VolumeVibe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.2.0;
CURRENT_PROJECT_VERSION = 1.3.0;
DEVELOPMENT_ASSET_PATHS = "\"VolumeVibe/Preview Content\"";
DEVELOPMENT_TEAM = ZR59599HJV;
ENABLE_PREVIEWS = YES;
Expand All @@ -476,7 +476,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.AcanXie.Hydrangea-VolumeVibe";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand All @@ -495,7 +495,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.2.0;
CURRENT_PROJECT_VERSION = 1.3.0;
DEVELOPMENT_ASSET_PATHS = "\"VolumeVibe/Preview Content\"";
DEVELOPMENT_TEAM = ZR59599HJV;
ENABLE_PREVIEWS = YES;
Expand All @@ -511,7 +511,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.AcanXie.Hydrangea-VolumeVibe";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down
Binary file not shown.
18 changes: 16 additions & 2 deletions VolumeVibe/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
struct Home: View {

@StateObject private var viewModel = VolumeViewModel()
@State private var showAlert_1 = false

var body: some View {
VStack {
Expand All @@ -22,7 +23,7 @@ struct Home: View {
Text("Version \((Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)!)").foregroundStyle(.secondary)
Text("iOS" + " " + UIDevice.current.systemVersion).foregroundStyle(.secondary)
Spacer().frame(maxHeight: 30)
Text("Press and Set Volume as 0.001").foregroundStyle(.secondary)
Text("Press and Set Volume as 0.1.").foregroundStyle(.secondary)

Spacer().frame(maxHeight: 20)

Expand All @@ -47,7 +48,20 @@ struct Home: View {
}
}
Spacer().frame(maxHeight: 20)
Text("Current Volume: \(formattedValue(value: Double(viewModel.currentVolume)))").foregroundStyle(.secondary).font(.subheadline)
HStack(alignment: .center, content: {
Text("Current Volume: About \(formattedValue(value: 100*Double(viewModel.currentVolume)))").foregroundStyle(.secondary).font(.subheadline)
Image(systemName: "questionmark.circle").resizable().frame(width: 12, height: 12).foregroundStyle(.secondary).onTapGesture {
showAlert_1 = true
}.alert(isPresented: $showAlert_1) {
Alert(
title: Text("Attention"),
message: Text("Due to Apple's API limitations, it is not possible to display precise volume numbers in this context."),
dismissButton: .default(Text("Got It"))
)
}

}).padding(0)

Spacer().frame(maxHeight: 20)
Text("Note: this app may not work on iOS versions earlier than 15.0.").foregroundStyle(.secondary).font(.subheadline)

Expand Down
2 changes: 1 addition & 1 deletion VolumeVibe/More.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct More: View {
HStack {
Label("Accurate", systemImage: "ruler")
Spacer()
Text("\(formattedValue(value: Double(viewModel.currentVolume)))").foregroundStyle(.secondary)
Text("\(formattedValue(value: 100*Double(viewModel.currentVolume)))").foregroundStyle(.secondary)
}
}
NavigationLink(destination: Simulation().navigationBarTitle("Simulation", displayMode: .inline)) {
Expand Down
9 changes: 6 additions & 3 deletions VolumeVibe/More/Accurate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ struct Accurate: View {
.foregroundColor(.secondary)

VStack(alignment: .leading, content: {
Text("On Apple devices, the volume value typically ranges from 0 to 1, where 0 represents muted or no sound, and 1 indicates the maximum volume.").foregroundStyle(.secondary).multilineTextAlignment(.leading)
Text("On Apple devices, the volume value typically ranges from 0 to 1. However, in this app the range is 0.0 to 100.0, which is believed to be more intuitive.").foregroundStyle(.secondary).multilineTextAlignment(.leading)
Spacer().frame(maxHeight: 20)
Text("This range allows for precise control over the audio output level. It's important to note that values outside this range might not have any effect on the actual volume level.").foregroundStyle(.secondary).multilineTextAlignment(.leading)
Spacer().frame(maxHeight: 20)
Text("Additionally, some devices might have slightly different behavior or additional features related to volume control.")
.foregroundColor(.secondary).multilineTextAlignment(.leading)
})

TextField("Set Volume 0 - 1", text: $volumeInput)
TextField("Set Volume 0.0 - 100.0", text: $volumeInput)
.padding(12)
.background(Color(UIColor.systemBackground))
.cornerRadius(10)
Expand All @@ -43,7 +43,10 @@ struct Accurate: View {


Button(action: {
setSysVolum(Float(volumeInput.replacingOccurrences(of: ",", with: "."))!)
if let volume = Float(volumeInput.replacingOccurrences(of: ",", with: ".")) {
let sysVolume = volume * 0.01
setSysVolum(sysVolume)
}
}) {
Text("Set Volume")
.foregroundColor(.white)
Expand Down
18 changes: 18 additions & 0 deletions VolumeVibe/More/Simulation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import SwiftUI
import AVFoundation

struct Simulation: View {
@StateObject private var viewModel = VolumeViewModel()
@State private var isPlaying = false
@State private var showAlert_1 = false
private var audioPlayer: AVAudioPlayer?

init() {
Expand All @@ -18,6 +20,7 @@ struct Simulation: View {
}

var body: some View {
Spacer()
VStack {
Button(action: {
if self.isPlaying {
Expand All @@ -34,5 +37,20 @@ struct Simulation: View {
.foregroundColor(.blue)
}
}
Spacer()
HStack(alignment: .center, content: {
Text("Current Volume: About \(formattedValue(value: 100*Double(viewModel.currentVolume)))").foregroundStyle(.secondary).font(.subheadline)
Image(systemName: "questionmark.circle").resizable().frame(width: 12, height: 12).foregroundStyle(.secondary).onTapGesture {
showAlert_1 = true
}.alert(isPresented: $showAlert_1) {
Alert(
title: Text("Attention"),
message: Text("Due to Apple's API limitations, it is not possible to display precise volume numbers in this context."),
dismissButton: .default(Text("Got It"))
)
}

})
Spacer().frame(maxHeight: 20)
}
}
6 changes: 3 additions & 3 deletions VolumeVibe/VolumeVibeFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class VolumeViewModel: ObservableObject {

func formattedValue(value: Double) -> String {
let formatter = NumberFormatter()
formatter.minimumFractionDigits = 4
formatter.maximumFractionDigits = 4
return formatter.string(from: NSNumber(value: value)) ?? ""
formatter.minimumFractionDigits = 1
formatter.maximumFractionDigits = 1
return formatter.string(from: NSNumber(value: value))?.replacingOccurrences(of: ",", with: ".") ?? ""
}

struct CustomTextFieldStyle: TextFieldStyle {
Expand Down

0 comments on commit dde1039

Please sign in to comment.