Skip to content

Make NextcloudAPI constructor less verbose #400

Closed
@stefan-niedermann

Description

@stefan-niedermann

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

  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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions