use of com.nextcloud.android.sso.api.NextcloudAPI in project nextcloud-notes by stefan-niedermann.
the class ApiProvider method getNextcloudAPI.
private synchronized NextcloudAPI getNextcloudAPI(@NonNull Context context, @NonNull SingleSignOnAccount ssoAccount) {
if (API_CACHE.containsKey(ssoAccount.name)) {
return API_CACHE.get(ssoAccount.name);
} else {
Log.v(TAG, "NextcloudRequest account: " + ssoAccount.name);
final var nextcloudAPI = new NextcloudAPI(context.getApplicationContext(), ssoAccount, new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeHierarchyAdapter(Calendar.class, (JsonSerializer<Calendar>) (src, typeOfSrc, ctx) -> new JsonPrimitive(src.getTimeInMillis() / 1_000)).registerTypeHierarchyAdapter(Calendar.class, (JsonDeserializer<Calendar>) (src, typeOfSrc, ctx) -> {
final var calendar = Calendar.getInstance();
calendar.setTimeInMillis(src.getAsLong() * 1_000);
return calendar;
}).registerTypeAdapter(Capabilities.class, new CapabilitiesDeserializer()).create(), (e) -> {
invalidateAPICache(ssoAccount);
e.printStackTrace();
});
API_CACHE.put(ssoAccount.name, nextcloudAPI);
return nextcloudAPI;
}
}
Aggregations