Search in sources :

Example 51 with Header

use of retrofit2.http.Header in project autorest.java by Azure.

the class LROsImpl method putAsyncRetryFailedWithServiceResponseAsync.

/**
 * Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status.
 *
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the observable for the request
 */
public Observable<ServiceResponseWithHeaders<Product, LROsPutAsyncRetryFailedHeaders>> putAsyncRetryFailedWithServiceResponseAsync() {
    final Product product = null;
    Observable<Response<ResponseBody>> observable = service.putAsyncRetryFailed(product, this.client.acceptLanguage(), this.client.userAgent());
    return client.getAzureClient().getPutOrPatchResultWithHeadersAsync(observable, new TypeToken<Product>() {
    }.getType(), LROsPutAsyncRetryFailedHeaders.class);
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) TypeToken(com.google.common.reflect.TypeToken) Product(fixtures.lro.models.Product) SubProduct(fixtures.lro.models.SubProduct)

Example 52 with Header

use of retrofit2.http.Header in project autorest.java by Azure.

the class LROsImpl method putNoHeaderInRetryWithServiceResponseAsync.

/**
 * Long running put request, service returns a 202 to the initial request with location header. Subsequent calls to operation status do not contain location header.
 *
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the observable for the request
 */
public Observable<ServiceResponseWithHeaders<Product, LROsPutNoHeaderInRetryHeaders>> putNoHeaderInRetryWithServiceResponseAsync() {
    final Product product = null;
    Observable<Response<ResponseBody>> observable = service.putNoHeaderInRetry(product, this.client.acceptLanguage(), this.client.userAgent());
    return client.getAzureClient().getPutOrPatchResultWithHeadersAsync(observable, new TypeToken<Product>() {
    }.getType(), LROsPutNoHeaderInRetryHeaders.class);
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) TypeToken(com.google.common.reflect.TypeToken) Product(fixtures.lro.models.Product) SubProduct(fixtures.lro.models.SubProduct)

Example 53 with Header

use of retrofit2.http.Header in project Tusky by tuskyapp.

the class AccountActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    avatar = findViewById(R.id.account_avatar);
    header = findViewById(R.id.account_header);
    floatingBtn = findViewById(R.id.floating_btn);
    followBtn = findViewById(R.id.follow_btn);
    followsYouView = findViewById(R.id.account_follows_you);
    tabLayout = findViewById(R.id.tab_layout);
    accountLockedView = findViewById(R.id.account_locked);
    container = findViewById(R.id.activity_account);
    followersTextView = findViewById(R.id.followers_tv);
    followingTextView = findViewById(R.id.following_tv);
    statusesTextView = findViewById(R.id.statuses_btn);
    if (savedInstanceState != null) {
        accountId = savedInstanceState.getString("accountId");
        followState = (FollowState) savedInstanceState.getSerializable("followState");
        blocking = savedInstanceState.getBoolean("blocking");
        muting = savedInstanceState.getBoolean("muting");
    } else {
        Intent intent = getIntent();
        accountId = intent.getStringExtra("id");
        followState = FollowState.NOT_FOLLOWING;
        blocking = false;
        muting = false;
    }
    loadedAccount = null;
    // Setup the toolbar.
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }
    hideFab = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fabHide", false);
    // Add a listener to change the toolbar icon color when it enters/exits its collapsed state.
    AppBarLayout appBarLayout = findViewById(R.id.account_app_bar_layout);
    final CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @AttrRes
        int priorAttribute = R.attr.account_toolbar_icon_tint_uncollapsed;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            @AttrRes int attribute;
            if (collapsingToolbar.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) {
                toolbar.setTitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorPrimary));
                toolbar.setSubtitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorSecondary));
                attribute = R.attr.account_toolbar_icon_tint_collapsed;
            } else {
                toolbar.setTitleTextColor(Color.TRANSPARENT);
                toolbar.setSubtitleTextColor(Color.TRANSPARENT);
                attribute = R.attr.account_toolbar_icon_tint_uncollapsed;
            }
            if (attribute != priorAttribute) {
                priorAttribute = attribute;
                Context context = toolbar.getContext();
                ThemeUtils.setDrawableTint(context, toolbar.getNavigationIcon(), attribute);
                ThemeUtils.setDrawableTint(context, toolbar.getOverflowIcon(), attribute);
            }
            if (floatingBtn != null && hideFab && !isSelf && !blocking) {
                if (verticalOffset > oldOffset) {
                    floatingBtn.show();
                }
                if (verticalOffset < oldOffset) {
                    floatingBtn.hide();
                }
            }
            oldOffset = verticalOffset;
        }
    });
    // Initialise the default UI states.
    floatingBtn.hide();
    followBtn.setVisibility(View.GONE);
    followsYouView.setVisibility(View.GONE);
    // Obtain information to fill out the profile.
    obtainAccount();
    AccountEntity activeAccount = TuskyApplication.getInstance(this).getServiceLocator().get(AccountManager.class).getActiveAccount();
    if (accountId.equals(activeAccount.getAccountId())) {
        isSelf = true;
    } else {
        isSelf = false;
        obtainRelationships();
    }
    // Setup the tabs and timeline pager.
    AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), accountId);
    String[] pageTitles = { getString(R.string.title_statuses), getString(R.string.title_media) };
    adapter.setPageTitles(pageTitles);
    final ViewPager viewPager = findViewById(R.id.pager);
    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(0);
    tabLayout.setupWithViewPager(viewPager);
    View.OnClickListener accountListClickListener = v -> {
        AccountListActivity.Type type;
        switch(v.getId()) {
            case R.id.followers_tv:
                type = AccountListActivity.Type.FOLLOWERS;
                break;
            case R.id.following_tv:
                type = AccountListActivity.Type.FOLLOWING;
                break;
            default:
                throw new AssertionError();
        }
        Intent intent = AccountListActivity.newIntent(AccountActivity.this, type, accountId);
        startActivity(intent);
    };
    followersTextView.setOnClickListener(accountListClickListener);
    followingTextView.setOnClickListener(accountListClickListener);
    statusesTextView.setOnClickListener(v -> {
        // Make nice ripple effect on tab
        // noinspection ConstantConditions
        tabLayout.getTabAt(0).select();
        final View poorTabView = ((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0);
        poorTabView.setPressed(true);
        tabLayout.postDelayed(() -> poorTabView.setPressed(false), 300);
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Drawable(android.graphics.drawable.Drawable) Picasso(com.squareup.picasso.Picasso) Assert(com.keylesspalace.tusky.util.Assert) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) AttrRes(android.support.annotation.AttrRes) ViewCompat(android.support.v4.view.ViewCompat) Account(com.keylesspalace.tusky.entity.Account) PreferenceManager(android.preference.PreferenceManager) DispatchingAndroidInjector(dagger.android.DispatchingAndroidInjector) Log(android.util.Log) FloatingActionButton(android.support.design.widget.FloatingActionButton) AndroidInjector(dagger.android.AndroidInjector) Fragment(android.support.v4.app.Fragment) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) List(java.util.List) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) HasSupportFragmentInjector(dagger.android.support.HasSupportFragmentInjector) Call(retrofit2.Call) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Response(retrofit2.Response) NumberFormat(java.text.NumberFormat) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Menu(android.view.Menu) ActionBar(android.support.v7.app.ActionBar) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) DialogInterface(android.content.DialogInterface) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) TimelineReceiver(com.keylesspalace.tusky.receiver.TimelineReceiver) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) LinkListener(com.keylesspalace.tusky.interfaces.LinkListener) Color(android.graphics.Color) Callback(retrofit2.Callback) Toolbar(android.support.v7.widget.Toolbar) CircularImageView(com.pkmmte.view.CircularImageView) MastodonApi(com.keylesspalace.tusky.network.MastodonApi) AccountManager(com.keylesspalace.tusky.db.AccountManager) Collections(java.util.Collections) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) ViewPager(android.support.v4.view.ViewPager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CircularImageView(com.pkmmte.view.CircularImageView) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) AttrRes(android.support.annotation.AttrRes) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AccountManager(com.keylesspalace.tusky.db.AccountManager) AppBarLayout(android.support.design.widget.AppBarLayout) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 54 with Header

use of retrofit2.http.Header in project Varis-Android by dkhmelenko.

the class AuthPresenter method isTwoFactorAuthRequired.

private boolean isTwoFactorAuthRequired(HttpException exception) {
    Response response = exception.response();
    boolean twoFactorAuthRequired = false;
    for (String header : response.headers().names()) {
        if (GithubApiService.TWO_FACTOR_HEADER.equals(header)) {
            twoFactorAuthRequired = true;
            break;
        }
    }
    return response.code() == HttpURLConnection.HTTP_UNAUTHORIZED && twoFactorAuthRequired;
}
Also used : Response(retrofit2.Response)

Example 55 with Header

use of retrofit2.http.Header in project kcanotify by antest1.

the class KcaUtils method getInfoDownloader.

public static KcaDownloader getInfoDownloader(Context context) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).readTimeout(1, TimeUnit.MINUTES);
    builder.addInterceptor(chain -> {
        Request original = chain.request();
        Request request = original.newBuilder().header("User-Agent", "Kcanotify/".concat(BuildConfig.VERSION_NAME).replace("r", ".")).method(original.method(), original.body()).build();
        return chain.proceed(request);
    });
    OkHttpClient okHttpClient = builder.build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl(KcaUtils.getUpdateServer(context)).client(okHttpClient).addConverterFactory(ScalarsConverterFactory.create()).build();
    return retrofit.create(KcaDownloader.class);
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request)

Aggregations

Response (retrofit2.Response)39 ServiceResponse (com.microsoft.rest.ServiceResponse)30 TypeToken (com.google.common.reflect.TypeToken)29 Product (fixtures.lro.models.Product)29 Request (okhttp3.Request)23 Retrofit (retrofit2.Retrofit)21 OkHttpClient (okhttp3.OkHttpClient)19 IOException (java.io.IOException)15 Test (org.junit.Test)14 SubProduct (fixtures.lro.models.SubProduct)12 Interceptor (okhttp3.Interceptor)12 Response (okhttp3.Response)10 ResponseBody (okhttp3.ResponseBody)9 Header (retrofit2.http.Header)6 ArrayList (java.util.ArrayList)4 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)4 GsonBuilder (com.google.gson.GsonBuilder)3 HttpException (retrofit2.HttpException)3 Context (android.content.Context)2 Nullable (android.support.annotation.Nullable)2