EasternEdgeRobotics / Software_2017

The control software for 2017
MIT License
3 stars 0 forks source link

Calibration view refactor #302

Closed cal-pratt closed 7 years ago

cal-pratt commented 7 years ago

The initial commit of the calibration view code needed a large refactor. A lot of the problem was caused by not having an Observable directory. I found out the Java 7 introduced an API for this, so I went about creating an rxjava wrapper for the utility. I also ended up learning how to use the Observable#create method the safe way, which is by creating an OnSubscribe class to handle back-pressure. The outcome was the DirectoryUtil class which has a static method for turning a directory into an Observable. I have this observable emit the Path of a file when it is newly created or is destroyed (We have no need to modify a file in place, so I left that out, however, it wouldn't be to hard to create).

In this PR I change the way that the controllers learn about changes in the gallery model, ie) the files in a directory. I'm now using an ObservableList in the model that will hold the new GalleryImageView objects (a way to display a thumbnail and load a fullscreen image). Deleting an image file from the CameraCalibrationViewController code now creates a logical reaction in the rest of the controllers. The DirectoryUtil Observable detects the deleted file and notifies the GalleryViewController. This controller deletes the image from the list in the GalleryView ObservableList which notifies the CameraCalibrationViewController that the file is removed. This allows the CameraCalibrationViewController to safely unsubscribe from events related to that image even when the file is deleted by an external program, ie) if the user deletes the files using the file explorer.