Search in sources :

Example 1 with NextcloudAPI

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;
    }
}
Also used : NextcloudAPI(com.nextcloud.android.sso.api.NextcloudAPI) Context(android.content.Context) NotesAPI(it.niedermann.owncloud.notes.persistence.sync.NotesAPI) NonNull(androidx.annotation.NonNull) NextcloudRetrofitApiBuilder(retrofit2.NextcloudRetrofitApiBuilder) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WorkerThread(androidx.annotation.WorkerThread) JsonSerializer(com.google.gson.JsonSerializer) CapabilitiesDeserializer(it.niedermann.owncloud.notes.persistence.sync.CapabilitiesDeserializer) GsonBuilder(com.google.gson.GsonBuilder) Retrofit(retrofit2.Retrofit) Nullable(androidx.annotation.Nullable) Calendar(java.util.Calendar) OcsAPI(it.niedermann.owncloud.notes.persistence.sync.OcsAPI) Gson(com.google.gson.Gson) Map(java.util.Map) JsonDeserializer(com.google.gson.JsonDeserializer) NextcloudAPI(com.nextcloud.android.sso.api.NextcloudAPI) SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) JsonPrimitive(com.google.gson.JsonPrimitive) ApiVersion(it.niedermann.owncloud.notes.shared.model.ApiVersion) Log(android.util.Log) GsonBuilder(com.google.gson.GsonBuilder) JsonPrimitive(com.google.gson.JsonPrimitive) Calendar(java.util.Calendar) CapabilitiesDeserializer(it.niedermann.owncloud.notes.persistence.sync.CapabilitiesDeserializer) JsonDeserializer(com.google.gson.JsonDeserializer)

Aggregations

Context (android.content.Context)1 Log (android.util.Log)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 WorkerThread (androidx.annotation.WorkerThread)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonDeserializer (com.google.gson.JsonDeserializer)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 JsonSerializer (com.google.gson.JsonSerializer)1 NextcloudAPI (com.nextcloud.android.sso.api.NextcloudAPI)1 SingleSignOnAccount (com.nextcloud.android.sso.model.SingleSignOnAccount)1 CapabilitiesDeserializer (it.niedermann.owncloud.notes.persistence.sync.CapabilitiesDeserializer)1 NotesAPI (it.niedermann.owncloud.notes.persistence.sync.NotesAPI)1 OcsAPI (it.niedermann.owncloud.notes.persistence.sync.OcsAPI)1 ApiVersion (it.niedermann.owncloud.notes.shared.model.ApiVersion)1 Capabilities (it.niedermann.owncloud.notes.shared.model.Capabilities)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1