Skip to content

#400 Make NextcloudAPI constructor less verbose #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ private static Void getVoidInstance() {
public @interface FollowRedirects { }

public interface ApiConnectedListener {
void onConnected();
void onError(Exception ex);
default void onConnected() {
Log.i(TAG, "Single Sign On API successfully connected.");
}
void onError(Exception e);
}

public NextcloudAPI(@NonNull Context context, @NonNull SingleSignOnAccount account, @NonNull Gson gson) {
this(gson, new AidlNetworkRequest(context, account, Throwable::printStackTrace));
}

public NextcloudAPI(@NonNull Context context, @NonNull SingleSignOnAccount account, @NonNull Gson gson, @NonNull ApiConnectedListener callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

Expand All @@ -15,7 +14,6 @@
import com.nextcloud.android.sso.exceptions.AccountImportCancelledException;
import com.nextcloud.android.sso.exceptions.AndroidGetAccountsPermissionNotGranted;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException;
import com.nextcloud.android.sso.model.SingleSignOnAccount;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -60,7 +58,7 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
runOnUiThread(() -> ((TextView) findViewById(R.id.result)).setText(R.string.loading));

/* Create local bridge API to the Nextcloud Files Android app */
final var nextcloudAPI = createNextcloudAPI(ssoAccount);
final var nextcloudAPI = new NextcloudAPI(this, ssoAccount, new GsonBuilder().create());

/* Create the Ocs API to talk to the server */
final var ocsAPI = new NextcloudRetrofitApiBuilder(nextcloudAPI, "/ocs/v2.php/cloud/").create(OcsAPI.class);
Expand Down Expand Up @@ -96,25 +94,4 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
Log.i(TAG, "Account import cancelled.");
}
}

private NextcloudAPI createNextcloudAPI(@NonNull SingleSignOnAccount ssoAccount) {
return new NextcloudAPI(this, ssoAccount, new GsonBuilder().create(), new NextcloudAPI.ApiConnectedListener() {
@Override
public void onConnected() {
/*
* We don't have to actually wait for this callback because requests are queued and executed
* automatically as soon as the connection has been established.
*
* @see https://github.com/nextcloud/Android-SingleSignOn#5-how-to-make-a-network-request
* @see https://github.com/nextcloud/Android-SingleSignOn/issues/400
*/
Log.i(TAG, "SSO API connected for " + ssoAccount);
}

@Override
public void onError(Exception e) {
e.printStackTrace();
}
});
}
}