theappbusiness / android-proxy-toggle

Small application to help android developers to quickly enable and disable proxy settings
MIT License
425 stars 59 forks source link

Add ProxyManager ViewModel #5

Closed fmontesino closed 4 years ago

fmontesino commented 4 years ago

Why?

The design is not ready yet, so at this point I just wanted to create the ViewModel logic. We want to enable or disable the proxy according to the user's interaction. We want some kind of validation when the user inputs the proxy data (valid IP + port numeric & in range).

What?

Created a ProxyValidator class that uses the AndroidX pattern validation for checking if the IP and port are valid. Added a ViewModel that exposes validation events (for now, at least) and the proxy state, mapping the liveData from the DeviceSettingsManager.

Bonus

Refactored the Proxy class to use two Strings: it makes everything more readable, and now that we have validation makes more sense. Added SingleLiveEvent for one-time only events.