Search in sources :

Example 56 with GET

use of retrofit2.http.GET in project Grupp by tmoronta1208.

the class BarzzNetworkCall method start.

public static void start(final String zipcode) {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BARZZ_URL).addConverterFactory(GsonConverterFactory.create()).build();
    final BarzzService barzzService = retrofit.create(BarzzService.class);
    for (int i = 0; i < BarPreferencesFragment.selectedPrefs.size(); i++) {
        Call<BarzzModel> call = barzzService.getBarzz(zipcode, BarPreferencesFragment.selectedPrefs.get(i));
        call.enqueue(new Callback<BarzzModel>() {

            @Override
            public void onResponse(Call<BarzzModel> call, Response<BarzzModel> response) {
                if (response != null) {
                    Log.d("SUCESSSS!", response.body().getSuccess().getResults().get(0).getName());
                }
            }

            @Override
            public void onFailure(Call<BarzzModel> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BarzzModel(com.example.c4q.capstone.network.barzz.barzzmodel.BarzzModel)

Example 57 with GET

use of retrofit2.http.GET in project Grupp by tmoronta1208.

the class FourSNetworkCall method start.

public static void start(final String zipcode) {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.FOUR_SQUARE_URL).addConverterFactory(GsonConverterFactory.create()).build();
    final FourSService fourSService = retrofit.create(FourSService.class);
    for (int i = 0; i < BarPreferencesFragment.selectedPrefs.size(); i++) {
        Call<FourSquareModel> call = fourSService.getVenues("11224", "10001", "beer", "20180328");
        call.enqueue(new Callback<FourSquareModel>() {

            @Override
            public void onResponse(Call<FourSquareModel> call, Response<FourSquareModel> response) {
                Log.d("SUCESSSS", response.body().getResponse().getVenues().get(0).getName());
            }

            @Override
            public void onFailure(Call<FourSquareModel> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) FourSquareModel(com.example.c4q.capstone.network.foursquare.foursquaremodel.FourSquareModel)

Example 58 with GET

use of retrofit2.http.GET in project ocreader by schaal.

the class APIv2 method sync.

@Override
public void sync(final SharedPreferences sharedPreferences, final Realm realm, SyncType syncType, Intent intent, APICallback<Void, Throwable> apiCallback) {
    // TODO: 02.10.16 sync user
    final BaseRetrofitCallback<SyncResponse> retrofitCallback = new BaseRetrofitCallback<SyncResponse>(apiCallback) {

        @Override
        protected void onResponseReal(Response<SyncResponse> response) {
            final SyncResponse syncResponse = response.body();
            if (syncResponse != null) {
                sharedPreferences.edit().putString(Preferences.SYS_APIv2_ETAG.getKey(), response.headers().get("Etag")).apply();
                Queries.deleteAndInsert(realm, Folder.class, syncResponse.getFolders());
                Queries.deleteAndInsert(realm, Feed.class, syncResponse.getFeeds());
                Queries.insert(realm, syncResponse.getItems());
            }
        }
    };
    if (intent.getBooleanExtra(SyncService.EXTRA_INITIAL_SYNC, false))
        sharedPreferences.edit().remove(Preferences.SYS_APIv2_ETAG.getKey()).apply();
    switch(syncType) {
        case FULL_SYNC:
        case SYNC_CHANGES_ONLY:
            final String etag = Preferences.SYS_APIv2_ETAG.getString(sharedPreferences);
            if (etag == null) {
                api.sync().enqueue(retrofitCallback);
            } else {
                final Items items = new Items();
                items.setItems(realm.where(Item.class).equalTo(Item.UNREAD_CHANGED, true).or().equalTo(Item.STARRED_CHANGED, true).findAll());
                api.sync(etag, items).enqueue(retrofitCallback);
            }
            break;
        case LOAD_MORE:
            // TODO: 06.09.16
            apiCallback.onFailure(new UnsupportedOperationException("not implemented in APIv2"));
            break;
    }
}
Also used : Response(retrofit2.Response) SyncResponse(email.schaal.ocreader.api.json.v2.SyncResponse) Item(email.schaal.ocreader.database.model.Item) SyncResponse(email.schaal.ocreader.api.json.v2.SyncResponse) Items(email.schaal.ocreader.api.json.Items)

Example 59 with GET

use of retrofit2.http.GET in project EssayJoke by qiyei2015.

the class RetrofitEngine method getMethodName.

/**
 * 找到method
 * @param task
 * @return
 */
private String getMethodName(HttpTask task) {
    String methodName = null;
    // 这个循环找到method
    for (Method method : task.getRequest().getApiClazz().getDeclaredMethods()) {
        String value = null;
        switch(task.getRequest().getMethod()) {
            case HTTP.GET:
                GET getAnnotation = method.getAnnotation(GET.class);
                if (getAnnotation != null) {
                    value = getAnnotation.value();
                }
                break;
            case HTTP.POST:
                POST postAnnotation = method.getAnnotation(POST.class);
                if (postAnnotation != null) {
                    value = postAnnotation.value();
                }
                break;
            case HTTP.DOWNLOAD:
                if (method.getAnnotation(Streaming.class) != null) {
                    GET downloadAnnotation = method.getAnnotation(GET.class);
                    if (downloadAnnotation != null) {
                        value = downloadAnnotation.value();
                    }
                }
                break;
            case HTTP.UPLOAD:
                if (method.getAnnotation(Multipart.class) != null) {
                    POST uploadAnnotation = method.getAnnotation(POST.class);
                    if (uploadAnnotation != null) {
                        value = uploadAnnotation.value();
                    }
                }
                break;
            default:
                break;
        }
        if (value != null && task.getRequest().getPathUrl().equals(value)) {
            methodName = method.getName();
            LogManager.v(HTTP.TAG, "method :" + methodName);
        }
    }
    return methodName;
}
Also used : Streaming(retrofit2.http.Streaming) Multipart(retrofit2.http.Multipart) POST(retrofit2.http.POST) GET(retrofit2.http.GET) Method(java.lang.reflect.Method)

Example 60 with GET

use of retrofit2.http.GET 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)

Aggregations

ResponseBody (okhttp3.ResponseBody)61 Test (org.junit.Test)54 Request (okhttp3.Request)52 Response (retrofit2.Response)27 Retrofit (retrofit2.Retrofit)23 Query (retrofit2.http.Query)15 List (java.util.List)14 IOException (java.io.IOException)12 OkHttpClient (okhttp3.OkHttpClient)12 HttpUrl (okhttp3.HttpUrl)10 Path (retrofit2.http.Path)10 ArrayList (java.util.ArrayList)9 BrainSentences (com.gladysinc.gladys.Models.BrainSentences)8 RetrofitAPI (com.gladysinc.gladys.Utils.RetrofitAPI)8 SelfSigningClientBuilder (com.gladysinc.gladys.Utils.SelfSigningClientBuilder)8 ServiceResponse (com.microsoft.rest.ServiceResponse)8 Call (retrofit2.Call)8 Url (retrofit2.http.Url)8 Uri (android.net.Uri)6 View (android.view.View)6