dunkmann00 / PrusaLinkiOS

iOS app to access PrusaLink from your Prusa printer on your local network.
https://apps.apple.com/us/app/prusalinkios/id6467438508
MIT License
19 stars 0 forks source link

Add support for multiple printers #3

Closed dunkmann00 closed 8 months ago

dunkmann00 commented 8 months ago

This commit adds support for multiple printers.

This required creating a data model for each printer and a mechanism for persisting the data. While UserDefaults worked well before, we now save the data to a json file on disk. This is more appropriate, given the potential amount of data stored, and turns out to be more convenient. This continues to leverage combine, which works well with the SwiftUI components of the app.

This also required adding/improving the UI to support multiple printers. One noteworthy thing here is the PrintersCollectionView SwiftUI View. I took a stab at wrapping a UICollectionView, and tried to do it in a slightly generalized way. It is not completely generalized, but I do think the groundwork is there and with some more work it could be made to act as a useful SwiftUI CollectionView wherever needed. I opted to do this because I wasted so much time trying to get the LazyVGrid to do what I wanted, it seemed like it would've been easier to implement the UICollectionView in SwiftUI. While I don't think that ended up being true, I am very happy with the CollectionView. The thing the LazyVGrid (or Regular grid for that matter) cannot really do that made me give up on it, is moving items. This is trivial with a UICollectionView, but hacky with a LazyVGrid. And not that it is necessary in this implementation, but the CollectionView will have better performance for large numbers of items...so if anyone adds 1,000 printers, this should still be buttery smooth with no memory issues.

Another noteworthy change is that this app is now a SwiftUI app. Before it was a UIKit app with some SwiftUI. Now, it is the other way around.

This closes #1