Skip to content

Make NextcloudAPI constructor less verbose #400

Description

@stefan-niedermann

Issue

When instantiating the NextcloudAPI we currently have some quite verbose code:

newNextcloudAPI(this, ssoAccount, newGsonBuilder().create(), newNextcloudAPI.ApiConnectedListener() {
@OverridepublicvoidonConnected() {
Log.i(TAG, "SSO API connected for " + ssoAccount);
}
@OverridepublicvoidonError(Exceptione) {
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

  1. Add a default implementation in NextcloudAPI.ApiConnectedListener#onConnected which simply logs an info
  2. Add a second constructor for NextcloudAPI without an NextcloudAPI.ApiConnectedListener. This can internally call the original constructor and add some default default behavior like e.printStackTrace() in the onError callback.

This would allow 3rd party apps to reduce the boilerplate code to:

newNextcloudAPI(this, ssoAccount, newGsonBuilder().create(), Throwable::printStackTrace);

in the first case, and

newNextcloudAPI(this, ssoAccount, newGsonBuilder().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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions