kaloyan-raev / hello-storj

Demo app for integrating the libstorj native library in Android
GNU General Public License v3.0
5 stars 3 forks source link

Use callback instead of boolean #25

Closed dri94 closed 6 years ago

kaloyan-raev commented 6 years ago

The use of callbacks in the methods of the Storj class is derived from the design of the libstorj native library. The libstorj library executes all communication to the Bridge asynchronously and delivers the result through a callback.

Note that the Bridge is stateless and has no user session. So there is no real notion for login and logout. The equivalent of the login is to write the user, password and mnemonic to a local authentication file. The equivalent of the logout is to simply delete this file and clear the user, password and mnemonic from memory. All this happens on the local device. There is no communication with the bridge server. Thus, these operations are executed synchronously. The result is delivered as a return value of the method, not through a callback.

Also note that the way you propose implementing the callback in this PR does not give you any real advantage. Your code still calls the callback synchronously.

If you want to avoid blocking the UI while deleting the keys you should an AsyncTask like here: https://github.com/kaloyan-raev/hello-storj/blob/9411494a3fda350c40c9c6b28304e106c0d001af/app/src/main/java/name/raev/kaloyan/hellostorj/KeysFragment.java#L122-L144