Closed
Description
Issue
When instantiating the NextcloudAPI
we currently have some quite verbose code:
new NextcloudAPI(this, ssoAccount, new GsonBuilder().create(), new NextcloudAPI.ApiConnectedListener() {
@Override
public void onConnected() {
Log.i(TAG, "SSO API connected for " + ssoAccount);
}
@Override
public void onError(Exception e) {
e.printStackTrace();
}
});
The onConnected
callback is usually quite useless, because according to the README.md the requests are queued anyway.
The onError
callback might be more interesting, to handle exceptions more gracefully, use own loggers, etc.
Proposal
- Add a default implementation in
NextcloudAPI.ApiConnectedListener#onConnected
which simply logs an info - Add a second constructor for
NextcloudAPI
without anNextcloudAPI.ApiConnectedListener
. This can internally call the original constructor and add some default default behavior likee.printStackTrace()
in theonError
callback.
This would allow 3rd party apps to reduce the boilerplate code to:
new NextcloudAPI(this, ssoAccount, new GsonBuilder().create(), Throwable::printStackTrace);
in the first case, and
new NextcloudAPI(this, ssoAccount, new GsonBuilder().create());
in the second, depending on the needs of the 3rd party app developer - while still providing all features of today and maintaining full backward compatibility.