Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safety plan view controller swift conversion #18

Conversation

shayneptorres
Copy link
Contributor

@shayneptorres shayneptorres commented Mar 17, 2020

Closes #15

Refactor Plan ViewControllers from objc into Swift.

  • Refactor SafetyPlanViewController into swift, add BaseViewController components, Add SafetyPlanItem for data management.
  • Refactor EditWarningSignsViewController, create TextField and Button Cells, Update UserDefaults save method
  • Add reusable EditSafetyPlanItemViewController for rest of Plan view controllers, update edit vc and user default gateway for personal contacts
  • Finish migrating Plan ViewControllers from objc into swift

Closes #19
Implement RealmDB for the data persistence layer

  • Updated our use of UserDefaults gateway for personal contacts and SafetyPlanItems to use RealmDB
  • Implemented a Gateway protocol template for future gateways, each pertaining to the data we want to query from the DB
  • Added AppSettings class to manage our use of UserDefaults for storing app settings

Refactor CrisisViewController, sync with original repo master branch
…ViewController components, Add SafetyPlanItem for data management.
…eld and Button Cells, Update UserDefaults save method
…Plan view controllers, update edit vc and user default gateway for personal contacts
Updating Local master with original master
@shayneptorres
Copy link
Contributor Author

@eddielement While refactoring into Swift, I had updated some of the views to be more consistent with iOS app UI. Namely, I made the entire rows tappable on instead of just a button on the SafetyPlanViewController. I also updated the look and functionality of the text fields used to update and edit all of the plan items (Warning Signs, Coping Strategies, etc). They now look and behave more consistently with what is expected from other iOS applications.

Feel free to comment and let me know what you like and dont like. I will update anything changes you deem not wanted.

@eddielement
Copy link
Contributor

Wow! This all looks amazing!!! I love the changes you made to make it more consistent with iOS app UI - it feels much smoother and more natural. Only two things I found -

Minor bug: Upon updating from an old version when I had two contacts entered, the app thought I had all 10 contacts filled when I actually only had two. (It showed 8 empty bullet points). This was easily fixed just by entering the edit contacts page and closing it again.

Crisis page & iPads: The third tab was typically hidden for users on iPads (since they don't have calling or texting functionality). There are lots of potential solutions here - we could make it visible, but we should probably hide the Call and Text buttons. (Or maybe just the Text button, the Call button actually does work if they also have an iPhone).

@shayneptorres
Copy link
Contributor Author

shayneptorres commented Mar 18, 2020

@eddielement
Good catch on that migration bug, I will update that so it wont happen when moving from an older version to the newer one.

Regarding Crisis Page and iPads, I like the option of keeping it visible but hiding the call/text options if those actions are not available. I think it would be a helpful page to have available for all users.

Not sure if there is a way to detect if the action is available, but I can look into it

@eddielement
Copy link
Contributor

@shayneptorres Sounds good! When those changes are in, happy to merge it in then push out an update (unless you want to wait for the Realm change is in before shipping this to real users, either way works for me).

@shayneptorres
Copy link
Contributor Author

@eddielement Since I can actually include the Realm changes in with my next push. Since I will be dealing with how we show these saved items, it might just make sense to include it all with this PR.

@shayneptorres
Copy link
Contributor Author

Finished adding the changes to migrate the data persistence layer from User defaults to RealmDB. There are a couple things to note.

1.) Getting Saved data from RealmDB

  • I added 4 classes to represent all our saved data, RLMPersonalContact, PersonalContact, RLMSafetyPlanItem, and SafetyPlanItem. The classes with RLM in their name are the actual Realm classes that model how those objects are saved in the DB. I created domain level counterparts to them (PersonalContact and SafetyPlanItem) so that we can manipulate them without dealing with Realms unsafe thread issues. Always use the domain level classes when displaying data in the app to avoid crashes, the RLM classes are for modeling and manipulating the data only. Retrieving the data for these classes can be done by creating an instance of the PersonalContactGateway and SafetyPlanItemGateway respectively. These instances will have access to getAll() methods which can be used with or without a filter to query the needed data. If you are confused, please checkout the fetchSafetyPlanItems() method on the EditSafetyPlanItemViewController for an example how to do this.

2.) Saving data to Realm DB

  • Much like getting data from RealmDB, you must use the appropriate gateway object and call the save() method with a given domain object. The logic behind the save method handles converting it into the RLM for the data manipulation. If you are confused, checkout the onSave method in the class EditSafetyPlanItemViewController for an example how to use this

3.) Moving from UserDefaults to RealmDB.

  • I added a migration method which can be found in the AppDelegate.swift file. It handles transferring data from the previous UserDefaults way to Realm. If you have issues with the conversion, please let me know. I tested it and it should be working.

4.) Realm Migrations

  • I added a RealmMigrationHelper class to handle any future changes to the structure of the RealmDB. If you choose to update an the structure of an RLM object, you must add a migration (example in the RealmMigrationHelper.swift class) in order for the app to know that an update is needed and you wont get a crash.

If you have any more questions, please do reach out. Im sure there is something important I am forgetting

@eddielement
Copy link
Contributor

@shayneptorres Wow awesome job, I'm super impressed! Overall, this codebase is SO much better than the old one!!!

I went through the code and tested the app thoroughly, and the only thing I could find that causes an error is Plan -> Contacts -> Save causes the app to crash with the error "Property ‘safetyPlanItemTypeId’ not found in object of type RLMPersonalContact".

I'm excited to get this out there! :)

@shayneptorres
Copy link
Contributor Author

Nice catch, it looks like I messed up with my refactor. Pushed up another commit that should fix that problem. I also found one spot on the CrisisViewController where I hadn't migrated from UserDefaults to Realm. This should do the trick

@eddielement eddielement merged commit 5263383 into suicidesafetyplan:master Apr 20, 2020
@eddielement
Copy link
Contributor

@shayneptorres Just submitted the update to Apple, thanks for your work on this! :) I put a little shoutout for you in the update notes.

@eddielement
Copy link
Contributor

@shayneptorres By the way, the update was accepted and we just got a new positive review.

"Way better than paper!
I have recommended this several times to others & many different mental health professionals. I have received very positive feedback from them. The just plain love it!

I had & have outstanding mental health care by the VA. However, a safety plan on a sheet of paper, upon leaving the hospital or in the course of outpatient treatment, is not practical. It’ll get lost, destroyed in the laundry, the dog will eat it, it might be shredded accidentally, or just plain wear out. Most people carry around their cell phone. This app is easy to use, wise to have, has a great layout, & was thoughtfully designed.

I recommend you review your plan every 3 months & write down what changes you think your plan needs then review with your psychotherapist before updating it. If you don’t have the energy to devote to updating it (yes, depression can do that), talk it out every 3 months with your psychotherapist (you are worth it, darn it!). I would give this app 10 stars if that were possible."

@shayneptorres
Copy link
Contributor Author

That is so cool! Good job @eddielement ! It is awesome to work on a project like this that will provide a real service to people. Thank you for allowing me to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement RealmDB for the data persistence layer Plan View Controllers Objective-C -> Swift Conversion
2 participants