Skip to content

Commit

Permalink
redesigned add button, activity indicator at scanner view, fetch requ…
Browse files Browse the repository at this point in the history
…est default animation added
  • Loading branch information
s4rv4d committed Aug 7, 2020
1 parent ae681a7 commit 95cf66b
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 113 deletions.
35 changes: 23 additions & 12 deletions docWind/Custom View/ScannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ struct ScannerView: UIViewControllerRepresentable {
// MARK: - @Binding vars
@Binding var uiImages:[UIImage]
@Binding var uiImagesWithWatermarks: [UIImage]

@State var ac = false

// MARK: - Properties
typealias UIViewControllerType = VNDocumentCameraViewController

func makeCoordinator() -> Coordinator {
return Coordinator(uiImages: $uiImages, uiImagesWithWatermarks: $uiImagesWithWatermarks)
return Coordinator(uiImages: $uiImages, uiImagesWithWatermarks: $uiImagesWithWatermarks, state: $ac)
}

func makeUIViewController(context: UIViewControllerRepresentableContext<ScannerView>) -> VNDocumentCameraViewController {
Expand All @@ -33,30 +33,37 @@ struct ScannerView: UIViewControllerRepresentable {

func updateUIViewController(_ uiViewController: VNDocumentCameraViewController, context: UIViewControllerRepresentableContext<ScannerView>) {

if ac {
let acIndicator = UIActivityIndicatorView(style: .large)
acIndicator.hidesWhenStopped = true
acIndicator.center = uiViewController.view.center
acIndicator.color = .cyan
uiViewController.view.addSubview(acIndicator)
uiViewController.view.bringSubviewToFront(acIndicator)
acIndicator.startAnimating()
}

}

// MARK: - Coordinator class
class Coordinator: NSObject, VNDocumentCameraViewControllerDelegate {

var uiImages: Binding<[UIImage]>
var uiImagesWithWatermarks: Binding<[UIImage]>
var state: Binding<Bool>

init(uiImages: Binding<[UIImage]>, uiImagesWithWatermarks: Binding<[UIImage]>) {
init(uiImages: Binding<[UIImage]>, uiImagesWithWatermarks: Binding<[UIImage]>, state: Binding<Bool>) {
self.uiImages = uiImages
self.uiImagesWithWatermarks = uiImagesWithWatermarks
self.state = state
}

public func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
print("Save TAPPED")
var imgs = [UIImage]()
var imgsWithWatermarks = [UIImage]()

// activity indicator
// let acIndicator = UIActivityIndicatorView(style: .large)
// acIndicator.hidesWhenStopped = true
// controller.view.addSubview(acIndicator)
// controller.view.bringSubviewToFront(acIndicator)
// acIndicator.startAnimating()


for pageIndex in 0 ..< scan.pageCount {
autoreleasepool {
Expand All @@ -65,6 +72,7 @@ struct ScannerView: UIViewControllerRepresentable {
imgs.append(image)
}
}
state.wrappedValue.toggle()

// appending images based on image counts
if self.uiImages.wrappedValue.count == 0 {
Expand All @@ -75,11 +83,14 @@ struct ScannerView: UIViewControllerRepresentable {
self.uiImagesWithWatermarks.wrappedValue += imgsWithWatermarks
}

// acIndicator.stopAnimating()
controller.dismiss(animated: true, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
controller.dismiss(animated: true, completion: nil)
}


}

func compressedImage(_ originalImage: UIImage) -> UIImage {
private func compressedImage(_ originalImage: UIImage) -> UIImage {
guard let imageData = originalImage.jpegData(compressionQuality: 1),
let reloadedImage = UIImage(data: imageData) else {
return originalImage
Expand Down
53 changes: 30 additions & 23 deletions docWind/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ContentView: View {
//MARK: - @State variables
@State private var tapped = false
@State private var isShown = false
// @State private var showingActionSheet = false
@State private var animationAmount: CGFloat = 1
@State var activeSheet: ActiveContentViewSheet = .intro
@State private var presentAlert = false
@State private var toggleSearchIcon = false
Expand All @@ -27,7 +27,7 @@ struct ContentView: View {

// MARK: - @Environment variables
@Environment(\.managedObjectContext) var context
@FetchRequest(entity: DirecModel.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \DirecModel.created, ascending: true)], predicate: NSPredicate(format: "name == %@", "DocWind")) var items: FetchedResults<DirecModel>
@FetchRequest(entity: DirecModel.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \DirecModel.created, ascending: true)], predicate: NSPredicate(format: "name == %@", "DocWind"), animation: .default) var items: FetchedResults<DirecModel>

// MARK: - ObservedObjects
@ObservedObject var searchBar: SearchBar = SearchBar()
Expand All @@ -41,32 +41,28 @@ struct ContentView: View {
if items.first != nil {
// display contents of file
if (items.first!.fileArray.count == 0) {
// NewStarterView()
// .padding()
NewStarterView()
} else {
List {
Section(header: Text("DocWind >").font(.caption), footer: Text("Tap on hold on a cell for more options").font(.caption)) {
Section(header: Text("DocWind >").font(.caption), footer: Text("Tap and hold on a cell for more options").font(.caption)) {
ForEach(self.items.first!.fileArray.filter { searchBar.text.isEmpty || $0.wrappedItemName.localizedStandardContains(searchBar.text)}, id: \.self) { item in
NormalListRowView(itemArray: item, masterFolder: "\(DWFMAppSettings.shared.fileURL())").environment(\.managedObjectContext, self.context)
NormalListRowView(itemArray: item, masterFolder: "\(DWFMAppSettings.shared.fileURL())")
.environment(\.managedObjectContext, self.context)
}.onDelete(perform: self.deleteRow(at:))
}
}
.listStyle(GroupedListStyle())
}
} else {
// NewStarterView()
// .padding()
NewStarterView()
}
}

// VStack {


ZStack(alignment: .bottom) {
Rectangle().onTapGesture {
print("saravad")
}
Rectangle()
.foregroundColor(.clear)
.frame(maxWidth: .infinity, maxHeight: .infinity)

Button(action: showOptions) {
Image(systemName: "plus")
.rotationEffect(.degrees(tapped ? 45 : 0))
Expand All @@ -79,13 +75,24 @@ struct ContentView: View {
.mask(Circle())
.animation(.spring(response: 0.2, dampingFraction: 0.4, blendDuration: 0))
.zIndex(10)
.overlay(
Circle()
.stroke(Color.blue, lineWidth: 1)
.scaleEffect(animationAmount)
.opacity(Double(2 - animationAmount))
.animation(
Animation.easeOut(duration: 1)
.repeatCount(10, autoreverses: false)
)
)
.onAppear {
self.animationAmount = 2
}
.padding()
// secondary buttons
SecondaryButtonView(tapped: $tapped, icon: "folder.fill", color: .blue, offsetX: 90, action: createDiectory).padding()
SecondaryButtonView(tapped: $tapped, icon: "camera.fill", color: .blue, offsetY: -90, delay: 0.2, action: scanDocumentTapped).padding()
SecondaryButtonView(tapped: $tapped, icon: "arrow.up.doc.fill", color: .blue, offsetX: -90, delay: 0.4, action: {
print("yooo")
}).padding()
SecondaryButtonView(tapped: $tapped, icon: "folder.fill", color: .green, offsetX: 90, action: createDiectory).padding()
SecondaryButtonView(tapped: $tapped, icon: "camera.fill", color: .pink, offsetY: -90, delay: 0.2, action: scanDocumentTapped).padding()
SecondaryButtonView(tapped: $tapped, icon: "arrow.up.doc.fill", color: .orange, offsetX: -90, delay: 0.4, action: importTapped).padding()
}
}

Expand Down Expand Up @@ -142,6 +149,7 @@ struct ContentView: View {
}

private func showOptions() {
self.animationAmount = 2
DispatchQueue.main.async {
withAnimation {
self.tapped.toggle()
Expand All @@ -156,10 +164,9 @@ struct ContentView: View {
}

private func importTapped() {
print("ere")
// self.activeSheet = .importDoc
// self.tapped.toggle()
// self.isShown.toggle()
self.activeSheet = .importDoc
self.tapped.toggle()
self.isShown.toggle()
}

private func scanDocumentTapped() {
Expand Down
6 changes: 3 additions & 3 deletions docWind/Views/Intro module/NewStarterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ struct NewStarterView: View {
.padding([.top, .leading, .trailing])
VStack {
Text("👆 on the ") +
Text("ADD").fontWeight(.bold).foregroundColor(.blue)
+ Text(" button on the top right to get started 😄")
Text("PLUS").fontWeight(.bold).foregroundColor(.blue)
+ Text(" button below to get started 😄")
}.padding()
}
}.settingsBackground()
// .background(Color.blue)
// .clipShape(RoundedRectangle(cornerRadius: 8))
// .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.blue))
Expand Down
112 changes: 62 additions & 50 deletions docWind/Views/Main module/Directory module/DetailedDirecView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct DetailedDirecView: View {

// MARK: - @State variables
@State var item: ItemModel
@State private var tapped = false
@State private var isShown = false
@State private var showingActionSheet = false
@State var activeSheet: ActiveContentViewSheet = .intro
@State private var presentAlert = false
@State private var toggleSearchIcon = false
Expand Down Expand Up @@ -43,45 +43,70 @@ struct DetailedDirecView: View {
self._items = FetchRequest(
entity: DirecModel.entity(),
sortDescriptors: [],
predicate: NSPredicate(format: "name == %@", "\(dirName)"))
// animation: .default)
predicate: NSPredicate(format: "name == %@", "\(dirName)"), animation: .default)
}

// MARK: - Properties
var body: some View {
VStack(alignment: .leading) {
//check if contents isnt empty
if items.first != nil {
// display contents of file
if (items.first?.fileArray.count == 0) {
Text("Looks empty here, scan a new document or create a new directory using the '+' button above.")
VStack {
VStack(alignment: .leading) {
//check if contents isnt empty
if items.first != nil {
// display contents of file
if (items.first?.fileArray.count == 0) {
Text("Looks empty here, scan a new document or create a new directory using the '+' button above.")
.font(.caption)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding([.leading, .trailing, .top])
} else {
List {
Section(header: Text("\(String(masterFolder.split(separator: "/").last!)) > \(item.wrappedItemName)").font(.caption), footer: Text("Tap and hold on cell for more options").font(.caption)) {
ForEach(items.first!.fileArray.filter {
searchBar.text.isEmpty ||
$0.wrappedItemName.localizedStandardContains(searchBar.text)
}, id: \.self){ item in
GenListRowView(itemArray: item, masterFolder: self.item.wrappedItemUrl).environment(\.managedObjectContext, self.context)
}.onDelete(perform: self.deleteRow(at:))
}
}
.listStyle(GroupedListStyle())
}
} else {
Text("Looks empty here, scan a new document using the '+' button above.")
.font(.caption)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding([.leading, .trailing, .top])
} else {
List {
Section(header: Text("\(String(masterFolder.split(separator: "/").last!)) > \(item.wrappedItemName)").font(.caption)) {
ForEach(items.first!.fileArray.filter {
searchBar.text.isEmpty ||
$0.wrappedItemName.localizedStandardContains(searchBar.text)
}, id: \.self){ item in
GenListRowView(itemArray: item, masterFolder: self.item.wrappedItemUrl).environment(\.managedObjectContext, self.context)
}.onDelete(perform: self.deleteRow(at:))
}
}
.listStyle(GroupedListStyle())
}
} else {
Text("Looks empty here, scan a new document using the '+' button above.")
.font(.caption)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding([.leading, .trailing, .top])

Spacer()

}

Spacer()
// button
ZStack(alignment: .bottom) {
Rectangle()
.foregroundColor(.clear)
.frame(maxWidth: .infinity, maxHeight: .infinity)

Button(action: showOptions) {
Image(systemName: "plus")
.rotationEffect(.degrees(tapped ? 45 : 0))
.foregroundColor(.white)
.font(.title)
.animation(.spring(response: 0.2, dampingFraction: 0.4, blendDuration: 0))
}
.padding(24)
.background(Color.blue)
.mask(Circle())
.animation(.spring(response: 0.2, dampingFraction: 0.4, blendDuration: 0))
.zIndex(10) .padding()
// secondary buttons
SecondaryButtonView(tapped: $tapped, icon: "folder.fill", color: .green, offsetX: 90, action: createDiectory).padding()
SecondaryButtonView(tapped: $tapped, icon: "camera.fill", color: .pink, offsetY: -90, delay: 0.2, action: createFile).padding()
SecondaryButtonView(tapped: $tapped, icon: "arrow.up.doc.fill", color: .orange, offsetX: -90, delay: 0.4, action: importTapped).padding()
}
}
// sheet code
.sheet(isPresented: $isShown) {
Expand All @@ -98,26 +123,8 @@ struct DetailedDirecView: View {

.navigationBarTitle(Text(item.wrappedItemName), displayMode: .inline)
.navigationViewStyle(StackNavigationViewStyle())
.navigationBarItems(trailing:
HStack{
Button(action: showOptions){
Image(systemName: "plus")
.font(.system(size: 25))
}
}
)
.add(self.searchBar)

// action sheet code
.actionSheet(isPresented: $showingActionSheet) {
ActionSheet(title: Text("Options"), message: Text("Choose an option"), buttons: [
.default(Text("Create a new document"), action: createFile),
.default(Text("Create a new directory"), action: createDiectory),
.default(Text("Import a document"), action: importTapped),
.cancel()
])
}

.alert(isPresented: $showAlert) {
Alert(title: Text(self.alertTitle), message: Text(self.alertMessage), dismissButton: .cancel(Text("Dismiss"), action: {
print("retry")
Expand All @@ -128,19 +135,23 @@ struct DetailedDirecView: View {

// MARK: - Functions
private func showOptions() {
self.showingActionSheet.toggle()
// self.showingActionSheet.toggle()
DispatchQueue.main.async {
withAnimation {
self.tapped.toggle()
}
}
}

private func createDiectory() {
//1. bring up sheet
self.activeSheet = .createdDirec
self.tapped.toggle()
self.isShown.toggle()
//2. enter detials
//3. reload list
}

private func createFile() {
self.activeSheet = .createPdf
self.tapped.toggle()
self.isShown.toggle()
}

Expand All @@ -152,6 +163,7 @@ struct DetailedDirecView: View {

private func importTapped() {
self.activeSheet = .importDoc
self.tapped.toggle()
self.isShown.toggle()
}

Expand Down
3 changes: 2 additions & 1 deletion docWind/Views/Main module/Pdf module/AddPdfFileGenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ struct AddPdfFileGenView: View {
.foregroundColor(.yellow)
Spacer()
}
}.disabled(!AppSettings.shared.bougthNonConsumable)
}
// .disabled(!AppSettings.shared.bougthNonConsumable)
.onTapGesture {
if !AppSettings.shared.bougthNonConsumable {
print("You need to buy")
Expand Down
Loading

0 comments on commit 95cf66b

Please sign in to comment.