Search in sources :

Example 1 with StringWithEmojiTypeAdapter

use of com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter in project Tusky by Vavassor.

the class BaseActivity method createMastodonAPI.

protected void createMastodonAPI() {
    mastodonApiDispatcher = new Dispatcher();
    Gson gson = new GsonBuilder().registerTypeAdapter(Spanned.class, new SpannedTypeAdapter()).registerTypeAdapter(StringWithEmoji.class, new StringWithEmojiTypeAdapter()).create();
    OkHttpClient okHttpClient = OkHttpUtils.getCompatibleClientBuilder().addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request originalRequest = chain.request();
            Request.Builder builder = originalRequest.newBuilder();
            String accessToken = getAccessToken();
            if (accessToken != null) {
                builder.header("Authorization", String.format("Bearer %s", accessToken));
            }
            Request newRequest = builder.build();
            return chain.proceed(newRequest);
        }
    }).dispatcher(mastodonApiDispatcher).build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseUrl()).client(okHttpClient).addConverterFactory(GsonConverterFactory.create(gson)).build();
    mastodonAPI = retrofit.create(MastodonAPI.class);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) SpannedTypeAdapter(com.keylesspalace.tusky.json.SpannedTypeAdapter) Request(okhttp3.Request) Gson(com.google.gson.Gson) IOException(java.io.IOException) Dispatcher(okhttp3.Dispatcher) Response(okhttp3.Response) Retrofit(retrofit2.Retrofit) StringWithEmojiTypeAdapter(com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter) MastodonAPI(com.keylesspalace.tusky.network.MastodonAPI) Interceptor(okhttp3.Interceptor) StringWithEmoji(com.keylesspalace.tusky.json.StringWithEmoji)

Example 2 with StringWithEmojiTypeAdapter

use of com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter in project Tusky by Vavassor.

the class PushNotificationClient method onMessageReceived.

private void onMessageReceived(final Context context, String message) {
    Log.v(TAG, "Notification received: " + message);
    Gson gson = new GsonBuilder().registerTypeAdapter(Spanned.class, new SpannedTypeAdapter()).registerTypeAdapter(StringWithEmoji.class, new StringWithEmojiTypeAdapter()).create();
    Notification notification = gson.fromJson(message, Notification.class);
    NotificationMaker.make(context, NOTIFY_ID, notification);
}
Also used : StringWithEmojiTypeAdapter(com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) SpannedTypeAdapter(com.keylesspalace.tusky.json.SpannedTypeAdapter) Gson(com.google.gson.Gson) StringWithEmoji(com.keylesspalace.tusky.json.StringWithEmoji) Notification(com.keylesspalace.tusky.entity.Notification)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 SpannedTypeAdapter (com.keylesspalace.tusky.json.SpannedTypeAdapter)2 StringWithEmoji (com.keylesspalace.tusky.json.StringWithEmoji)2 StringWithEmojiTypeAdapter (com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter)2 Notification (com.keylesspalace.tusky.entity.Notification)1 MastodonAPI (com.keylesspalace.tusky.network.MastodonAPI)1 IOException (java.io.IOException)1 Dispatcher (okhttp3.Dispatcher)1 Interceptor (okhttp3.Interceptor)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 Retrofit (retrofit2.Retrofit)1