Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
il1ane committed Oct 18, 2021
1 parent 3646f3a commit c1e2ab5
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 115 deletions.
8 changes: 4 additions & 4 deletions PasswordGenerator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -544,7 +544,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -570,7 +570,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.4;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.ilianezedadra.passwordGenerator;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -594,7 +594,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.4;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.ilianezedadra.passwordGenerator;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct PasswordGeneratorView: View {
}
.font(characterCount > 25 ? .system(size: 15) : .body)
.animation(.easeOut(duration: 0.1))

Spacer()

Button(action: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ final class PasswordListViewModel: ObservableObject {
deletePassword(key: keyToDelete)

//delay before refreshing keys because of an animation glich in list
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3){
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.getAllKeys()
}
}
Expand Down
13 changes: 1 addition & 12 deletions PasswordGenerator/Views/AuthenticationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct AuthenticationView: View {
@ObservedObject var passwordViewModel: PasswordListViewModel
@ObservedObject var settingsViewModel: SettingsViewModel
@State private var animate = false

var body: some View {

ZStack {
Expand Down Expand Up @@ -84,18 +85,6 @@ struct AuthenticationView: View {
}
}

extension View {
func animateForever(using animation: Animation = Animation.easeInOut(duration: 1), autoreverses: Bool = false, _ action: @escaping () -> Void) -> some View {
let repeated = animation.repeatForever(autoreverses: autoreverses)

return onAppear {
withAnimation(repeated) {
action()
}
}
}
}

struct LoggingView_Previews: PreviewProvider {
static var previews: some View {
AuthenticationView(viewModel: SettingsViewModel(), biometricType: SettingsViewModel.BiometricType.touch, passwordViewModel: PasswordListViewModel(), settingsViewModel: SettingsViewModel())
Expand Down
3 changes: 0 additions & 3 deletions PasswordGenerator/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ struct MainView: View {

var body: some View {



TabViews(settingsViewModel: settingsViewModel, passwordListViewModel: passwordViewModel, passwordGeneratorViewModel: passwordGeneratorViewModel)
.overlay(!settingsViewModel.isUnlocked ? AuthenticationView(viewModel: settingsViewModel, biometricType: settingsViewModel.biometricType(), passwordViewModel: passwordViewModel, settingsViewModel: settingsViewModel) : nil)
.overlay(settingsViewModel.isHiddenInAppSwitcher ? PrivacyView() : nil)


}
}

Expand Down
158 changes: 64 additions & 94 deletions PasswordGenerator/Views/StrenghtMeterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import SwiftUI

struct StrenghtMeterView: View {

@State private var scale: CGFloat = 1
@State var offset = CGFloat()
@ObservedObject var viewModel = PasswordListViewModel()
let entropy: Double
let characterCount: Double
@State var offset = CGFloat()
let gradient = Gradient(stops: [
.init(color: .red, location: 0.07),
.init(color: .orange, location: 0.15),
Expand All @@ -24,107 +24,77 @@ struct StrenghtMeterView: View {
let ratio:CGFloat = 250
let lenght: Int
let animation:Double = 1.4
@ObservedObject var viewModel = PasswordListViewModel(
)

var body: some View {

VStack {

VStack(alignment: .center) {
Spacer()
.frame(height: 15)
HStack {
Spacer()
RoundedRectangle(cornerRadius: 10)
.fill(LinearGradient(gradient: gradient, startPoint: .leading, endPoint: .trailing))
.frame(width: 190 * UIScreen.main.bounds.width / ratio, height: 17)

.overlay(
VStack(alignment: .center) {
Rectangle()
.fill(LinearGradient(gradient: gradient, startPoint: .leading, endPoint: .trailing))
.frame(width: 190 * UIScreen.main.bounds.width / ratio, height: 80)

}

.mask (
VStack(alignment: .center) {
Image(systemName: "triangle.fill")
.rotationEffect(Angle(degrees: 180))
.font(.system(size: 10))
}
.offset(x: calculateOffset(entropy: entropy), y: -20)
.foregroundColor(.blue)
.shadow(radius: 1)
.animation(.easeIn(duration: 0.55))
.transition(.opacity)

))
Spacer()
}

// Button(action: { withAnimation {
// infoIsShowing.toggle()
// }
// viewModel.simpleHaptic()
// }, label: HStack {
//
// Text("Plus")
//
// infoIsShowing ?
//
// Image(systemName: "chevron.down.circle.fill")
// .transition(.opacity)
// .buttonStyle(PlainButtonStyle())
// .foregroundColor(.gray)
// .padding(3)
// .animation(.easeInOut(duration: 0.6))
//
// : Image(systemName: "chevron.right.circle.fill")
// .transition(.opacity)
// .buttonStyle(PlainButtonStyle())
// .foregroundColor(.gray)
// .padding(3)
// .animation(.easeInOut(duration: 0.6))
// })

}

VStack {
HStack {
Text("Nombre de combinaisons possibles")
Spacer()
Text(characterCount > 6 ? "\(combinaisons.scientificFormatted)" : "\(combinaisons.largeNumberFormat)").transition(.opacity)
}


Divider().padding()

HStack {
Text("Entropie")
Spacer()
Text("\(Int(entropy)) bits")
.transition(.opacity)
}


Divider()
.padding()
HStack {
Text("Nombre de caractères")
Spacer()
Text("\(lenght)")
.transition(.opacity)
Spacer().frame(height: 15)

HStack {

Spacer()

RoundedRectangle(cornerRadius: 10)
.fill(LinearGradient(gradient: gradient, startPoint: .leading, endPoint: .trailing))
.frame(width: 190 * UIScreen.main.bounds.width / ratio, height: 17)
.overlay(
VStack(alignment: .center) {
Rectangle()
.fill(LinearGradient(gradient: gradient, startPoint: .leading, endPoint: .trailing))
.frame(width: 190 * UIScreen.main.bounds.width / ratio, height: 80)
}


}
.padding()

.mask(
VStack(alignment: .center) {
Image(systemName: "triangle.fill")
.rotationEffect(Angle(degrees: 180))
.font(.system(size: 10))
}
.offset(x: calculateOffset(entropy: entropy), y: -20)
.foregroundColor(.blue)
.shadow(radius: 1)
.animation(.easeIn(duration: 0.55))
.transition(.opacity)))

Spacer()

}
}

VStack {
HStack {
Text("Nombre de combinaisons possibles")
Spacer()
Text(characterCount > 6 ? "\(combinaisons.scientificFormatted)" : "\(combinaisons.largeNumberFormat)").transition(.opacity)
}


Divider().padding()

HStack {
Text("Entropie")
Spacer()
Text("\(Int(entropy)) bits")
.transition(.opacity)
}

Divider().padding()

HStack {
Text("Nombre de caractères")
Spacer()
Text("\(lenght)")
.transition(.opacity)
}
}
.padding()

}
}

}
}



Expand All @@ -134,7 +104,7 @@ extension StrenghtMeterView {

switch(entropy) {
case 0...4:
return ((-190 * UIScreen.main.bounds.width / ratio) / 2) + 5 * UIScreen.main.bounds.width / ratio
return ((-190 * UIScreen.main.bounds.width / ratio) / 2) + 5 * UIScreen.main.bounds.width / ratio
case 187...189:
return ((-190 * UIScreen.main.bounds.width / ratio) / 2) + 186 * UIScreen.main.bounds.width / ratio
default:
Expand Down
10 changes: 10 additions & 0 deletions PasswordGenerator/Views/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import SwiftUI

extension View {

func animateForever(using animation: Animation = Animation.easeInOut(duration: 1), autoreverses: Bool = false, _ action: @escaping () -> Void) -> some View {
let repeated = animation.repeatForever(autoreverses: autoreverses)

return onAppear {
withAnimation(repeated) {
action()
}
}
}

func adaptativeImage(biometricType: SettingsViewModel.BiometricType) -> String {

switch biometricType {
Expand Down

0 comments on commit c1e2ab5

Please sign in to comment.