Skip to content

Commit

Permalink
Add info bubble for start button and show bubbles only a limited numb…
Browse files Browse the repository at this point in the history
…er of times.
  • Loading branch information
Staacks committed May 29, 2019
1 parent ab0fea2 commit 8564560
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 34 deletions.
4 changes: 4 additions & 0 deletions phyphox-iOS/phyphox.xcodeproj/project.pbxproj
Expand Up @@ -196,6 +196,7 @@
C0984B2E2278870300D0EBCD /* GLMapShaderProgram.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0984B2D2278870300D0EBCD /* GLMapShaderProgram.swift */; };
C09962AD22391AF00015AE17 /* FixedTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09962AC22391AF00015AE17 /* FixedTableView.swift */; };
C0AD8542229E7E7A00421738 /* MenuTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0AD8541229E7E7A00421738 /* MenuTableViewController.swift */; };
C0AD8552229EA1CF00421738 /* HintBubbleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0AD8551229EA1CF00421738 /* HintBubbleViewController.swift */; };
C0AE8A982294558000A3EC48 /* ConfigConversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0AE8A972294558000A3EC48 /* ConfigConversion.swift */; };
C0C529002254C01E001E5EFD /* ReduceAnalysis.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0C528FF2254C01E001E5EFD /* ReduceAnalysis.swift */; };
C0C529102254F2F3001E5EFD /* MapAnalysis.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0C5290F2254F2F3001E5EFD /* MapAnalysis.swift */; };
Expand Down Expand Up @@ -603,6 +604,7 @@
C0984B2D2278870300D0EBCD /* GLMapShaderProgram.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLMapShaderProgram.swift; sourceTree = "<group>"; };
C09962AC22391AF00015AE17 /* FixedTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FixedTableView.swift; sourceTree = "<group>"; };
C0AD8541229E7E7A00421738 /* MenuTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuTableViewController.swift; sourceTree = "<group>"; };
C0AD8551229EA1CF00421738 /* HintBubbleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HintBubbleViewController.swift; sourceTree = "<group>"; };
C0AE8A972294558000A3EC48 /* ConfigConversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigConversion.swift; sourceTree = "<group>"; };
C0B840C3229DE5BC006C958A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/InfoPlist.strings; sourceTree = "<group>"; };
C0B840D2229DE5BC006C958A /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1005,6 +1007,7 @@
isa = PBXGroup;
children = (
4B53E8481CFC65EE004E6164 /* ExperimentPageViewController.swift */,
C0AD8551229EA1CF00421738 /* HintBubbleViewController.swift */,
6B00F0291C4072B700971941 /* ExperimentViewController.swift */,
6B9E3D91205296DF008073D5 /* ExperimentViewModuleTableViewCell.swift */,
6BFE376620447B0600301CA3 /* WebServer */,
Expand Down Expand Up @@ -1610,6 +1613,7 @@
6BEA9457207FF8CE0077274A /* GraphViewElementHandler.swift in Sources */,
C079BC6A2260D2B40018D6A5 /* localizationHelper.swift in Sources */,
6B00F0AC1C4680CC00971941 /* IntegrationAnalysis.swift in Sources */,
C0AD8552229EA1CF00421738 /* HintBubbleViewController.swift in Sources */,
6B00F0971C44176900971941 /* ExperimentAnalysisDataIO.swift in Sources */,
C07B53032294264200BA085A /* BluetoothScanResultsTableViewController.swift in Sources */,
6BEA9451207FE3D90077274A /* SeparatorViewElementHandler.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion phyphox-iOS/phyphox/Info.plist
Expand Up @@ -47,7 +47,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>7282</string>
<string>7308</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
Expand Down
Expand Up @@ -17,7 +17,7 @@ protocol StopExperimentDelegate {
func stopExperiment()
}

final class ExperimentPageViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate, ExperimentWebServerDelegate, UIPopoverPresentationControllerDelegate, UIGestureRecognizerDelegate, ExportDelegate, StopExperimentDelegate, BluetoothScanDialogDismissedDelegate {
final class ExperimentPageViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIPopoverPresentationControllerDelegate, ExperimentWebServerDelegate, ExportDelegate, StopExperimentDelegate, BluetoothScanDialogDismissedDelegate {

var segControl: UISegmentedControl? = nil
var tabBar: UIScrollView? = nil
Expand Down Expand Up @@ -272,6 +272,8 @@ final class ExperimentPageViewController: UIViewController, UIPageViewController

updateSelectedViewCollection()

var hintShown = false

//Ask to save the experiment locally if it has been loaded from a remote source
if !experiment.local {
let al = UIAlertController(title: localize("save_locally"), message: localize("save_locally_message"), preferredStyle: .alert)
Expand All @@ -289,35 +291,31 @@ final class ExperimentPageViewController: UIViewController, UIPageViewController
self.navigationController!.present(al, animated: true, completion: nil)

//Show a hint for the experiment info
}
else if (experiment.localizedCategory != localize("categoryRawSensor")) {
// TODO: Only show this hint until the experiment has been started a limited number of times
let label = UILabel()
label.text = localize("experimentinfo_hint")
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body)
label.textColor = kDarkBackgroundColor
let maxSize = CGSize(width: self.view.frame.width*2/3, height: self.view.frame.height*2/3)
label.frame.size = label.sizeThatFits(maxSize)
label.frame = label.frame.offsetBy(dx: 10, dy: 10)
let paddedFrame = label.frame.insetBy(dx: -10, dy: -10)
let popoverHint = UIViewController()
popoverHint.view.addSubview(label)
popoverHint.preferredContentSize = paddedFrame.size
popoverHint.modalPresentationStyle = UIModalPresentationStyle.popover
let pc = popoverHint.popoverPresentationController
pc?.permittedArrowDirections = .any
pc?.barButtonItem = actionItem
pc?.sourceView = self.view
pc?.delegate = self
self.present(popoverHint, animated: true, completion: nil)
} else {
if !hintShown {
let defaults = UserDefaults.standard
let key = "experiment_start_hint_dismiss_count"
if (defaults.integer(forKey: key) < 3) {
let bubble = HintBubbleViewController(text: localize("start_hint"), onDismiss: {() -> Void in
}, button: playItem, source: self.view, delegate: self)

self.present(bubble, animated: true, completion: nil)
hintShown = true
}
}

let tapHandler = UITapGestureRecognizer.init(target: self, action: #selector(closeHint))
tapHandler.delegate = self
tapHandler.numberOfTapsRequired = 1
popoverHint.view.isUserInteractionEnabled = true
popoverHint.view.addGestureRecognizer(tapHandler)
if !hintShown && (experiment.localizedCategory != localize("categoryRawSensor")) {
let defaults = UserDefaults.standard
let key = "experiment_info_hint_dismiss_count"
if (defaults.integer(forKey: key) < 3) {
let bubble = HintBubbleViewController(text: localize("experimentinfo_hint"), onDismiss: {() -> Void in
defaults.set(defaults.integer(forKey: key) + 1, forKey: key)
}, button: actionItem, source: self.view, delegate: self)

self.present(bubble, animated: true, completion: nil)
hintShown = true
}
}
}

}
Expand All @@ -338,10 +336,6 @@ final class ExperimentPageViewController: UIViewController, UIPageViewController
return .none
}

@objc func closeHint(_ sender: UITapGestureRecognizer? = nil) {
self.dismiss(animated: true, completion: nil)
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

Expand Down Expand Up @@ -879,6 +873,11 @@ final class ExperimentPageViewController: UIViewController, UIPageViewController
}

func startExperiment() {
let defaults = UserDefaults.standard
let key = "experiment_start_hint_dismiss_count"
defaults.set(defaults.integer(forKey: key) + 1, forKey: key)
print(defaults.integer(forKey: key))

if !experiment.running {
UIApplication.shared.isIdleTimerDisabled = true

Expand Down
@@ -0,0 +1,61 @@
//
// HintBubbleViewController.swift
// phyphox
//
// Created by Sebastian Staacks on 29.05.19.
// Copyright © 2019 RWTH Aachen. All rights reserved.
//

import Foundation

class HintBubbleViewController: UIViewController, UIPopoverPresentationControllerDelegate, UIGestureRecognizerDelegate {
let callback: () -> Void

init(text: String, onDismiss: @escaping () -> Void, button: UIBarButtonItem, source: UIView, delegate: UIPopoverPresentationControllerDelegate) {
self.callback = onDismiss

super.init(nibName: nil, bundle: nil)

let label = UILabel()
label.text = text
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body)
label.textColor = kDarkBackgroundColor
let maxSize = CGSize(width: 250, height: 250)
label.frame.size = label.sizeThatFits(maxSize)
label.frame = label.frame.offsetBy(dx: 10, dy: 10)
let paddedFrame = label.frame.insetBy(dx: -10, dy: -10)

self.view.addSubview(label)
self.preferredContentSize = paddedFrame.size
self.modalPresentationStyle = .popover
guard let pc = self.popoverPresentationController else {
print("Bubble error: Could not get popoverPresentationController")
return
}

pc.permittedArrowDirections = .any
pc.barButtonItem = button
pc.sourceView = source
pc.delegate = delegate

let tapHandler = UITapGestureRecognizer.init(target: self, action: #selector(closeHint))
tapHandler.delegate = self
tapHandler.numberOfTapsRequired = 1
self.view.isUserInteractionEnabled = true
self.view.addGestureRecognizer(tapHandler)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc func closeHint(_ sender: UITapGestureRecognizer? = nil) {
self.dismiss(animated: true, completion: nil)
}

override func viewDidDisappear(_ animated: Bool) {
callback()
}
}

0 comments on commit 8564560

Please sign in to comment.