This file contains hidden or 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
| @Test | |
| fun logInSuccess_test() { | |
| val email = "cool@cool.com" | |
| val password = "123456" | |
| Mockito.`when`(mAuth!!.signInWithEmailAndPassword(email, password)) | |
| .thenReturn(successTask) | |
| logInModel!!.logIn(email, password) | |
| assert(logInResult == SUCCESS) | |
| } |
This file contains hidden or 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
| @Before | |
| fun setUp() { | |
| MockitoAnnotations.initMocks(this) | |
| successTask = object : Task<AuthResult>() { | |
| override fun isComplete(): Boolean = true | |
| override fun isSuccessful(): Boolean = true | |
| // ... | |
| override fun addOnCompleteListener(executor: Executor, | |
| onCompleteListener: OnCompleteListener<AuthResult>): Task<AuthResult> { |
This file contains hidden or 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
| class LogInModelTest : LogInListener { | |
| private lateinit var successTask: Task<AuthResult> | |
| private lateinit var failureTask: Task<AuthResult> | |
| @Mock | |
| private lateinit val mAuth: FirebaseAuth | |
| private lateinit var logInModel: LogInModel | |
| private var logInResult = UNDEF | |
This file contains hidden or 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
| public interface LogInListener { | |
| void logInSuccess(String email, String password); | |
| void logInFailure(Exception exception, String email, String password); | |
| } |
This file contains hidden or 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
| fun logIn(email: String, password: String) { | |
| mAuth.signInWithEmailAndPassword(email, password) | |
| .addOnCompleteListener(this, OnCompleteListener { task -> | |
| if (task.isSuccessful) { | |
| observer.logInSuccess(email, password) | |
| } else { | |
| observer.logInFailure(task.exception, email, password) | |
| } | |
| }) | |
| } |
This file contains hidden or 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
| var body: some View { | |
| ImagePicker() | |
| } |
This file contains hidden or 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
| func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { | |
| self.imagePicker.dismiss(animated: true) | |
| guard let image = info[.editedImage] as? UIImage else { | |
| print("No image found.") | |
| return | |
| } | |
| // At this point we know we have an image. | |
| // Print out the scale and size as a test: |
This file contains hidden or 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
| self.imagePicker = UIImagePickerController() | |
| // Use the camera as the source | |
| imagePicker.source = .camera | |
| // Need to specify the delegate to get the result | |
| imagePicker.delegate = self | |
| // Present the imagePicker | |
| present(imagePicker, animated: true) |
This file contains hidden or 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
| func processClassifications(for request: VNRequest, error: Error?) { | |
| DispatchQueue.main.async { | |
| guard let results = request.results else { | |
| return | |
| } | |
| let classifications = results as! [VNClassificationObservation] | |
| if classifications.first!.confidence > 0.9 { | |
| print("> 0.9 confidence that request is a \(classifications.first!.identifier)") | |
| } |
This file contains hidden or 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
| let request = VNCoreMLRequest(model: model) { (request, error) in | |
| self.processClassifications(for: request, error: error) | |
| } |