Search in sources :

Example 66 with GET

use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.

the class RejectedSentencesFragment method setLabel.

public void setLabel(final Long id, final String label) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<BrainSentences> call = service.setLabel(id, label, pref_token);
        call.enqueue(new Callback<BrainSentences>() {

            @Override
            public void onResponse(Call<BrainSentences> call, Response<BrainSentences> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setLabel(response.body().getLabel());
                    brainSentences.setService(response.body().getService());
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<BrainSentences> call, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 67 with GET

use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.

the class RejectedSentencesFragment method setStatus.

public void setStatus(final Long id) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        final RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<Void> call = service.setStatus(id, "approved", pref_token);
        call.enqueue(new Callback<Void>() {

            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setStatue("approved");
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 68 with GET

use of retrofit2.http.GET in project open-event-orga-app by fossasia.

the class ErrorUtils method getErrorDetails.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
public static String getErrorDetails(ResponseBody responseBody) {
    try {
        JSONObject jsonObject = new JSONObject(responseBody.string());
        JSONObject jsonArray = new JSONObject(jsonObject.getJSONArray(ERRORS).get(0).toString());
        JSONObject errorSource = new JSONObject(jsonArray.get(SOURCE).toString());
        try {
            String pointedField = getPointedField(errorSource.getString(POINTER));
            if (pointedField == null)
                return jsonArray.get(DETAIL).toString();
            else
                return jsonArray.get(DETAIL).toString().replace(".", "") + ": " + pointedField;
        } catch (Exception e) {
            return jsonArray.get(DETAIL).toString();
        }
    } catch (Exception e) {
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) HttpException(retrofit2.HttpException)

Example 69 with GET

use of retrofit2.http.GET in project dhis2-android-sdk by dhis2.

the class MetadataCallShould method return_last_response_items_returned.

@Test
public void return_last_response_items_returned() throws Exception {
    Response response = metadataCall.call();
    Payload<DataElement> payload = (Payload<DataElement>) response.body();
    assertTrue(!payload.items().isEmpty());
    assertThat(payload.items().get(0)).isEqualTo(dataElement);
}
Also used : Response(retrofit2.Response) DataElement(org.hisp.dhis.android.core.dataelement.DataElement) Test(org.junit.Test)

Example 70 with GET

use of retrofit2.http.GET in project talk-android by nextcloud.

the class CallsListController method fetchData.

private void fetchData(boolean fromBottomSheet) {
    dispose(null);
    callItems = new ArrayList<>();
    roomsQueryDisposable = ncApi.getRooms(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlForGetRooms(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(roomsOverall -> {
        if (roomsOverall != null) {
            for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) {
                callItems.add(new CallItem(roomsOverall.getOcs().getData().get(i), userEntity));
            }
            adapter.updateDataSet(callItems, true);
            Collections.sort(callItems, (callItem, t1) -> Long.compare(t1.getModel().getLastPing(), callItem.getModel().getLastPing()));
            if (searchItem != null) {
                searchItem.setVisible(callItems.size() > 0);
            }
        }
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(false);
        }
    }, throwable -> {
        if (searchItem != null) {
            searchItem.setVisible(false);
        }
        if (throwable instanceof HttpException) {
            HttpException exception = (HttpException) throwable;
            switch(exception.code()) {
                case 401:
                    if (getParentController() != null && getParentController().getRouter() != null) {
                        getParentController().getRouter().pushController((RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(), true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler())));
                    }
                    break;
                default:
                    break;
            }
        }
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(false);
        }
        dispose(roomsQueryDisposable);
    }, () -> {
        dispose(roomsQueryDisposable);
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(false);
        }
        if (fromBottomSheet) {
            new Handler().postDelayed(() -> {
                bottomSheet.setCancelable(true);
                if (bottomSheet.isShowing()) {
                    bottomSheet.cancel();
                }
            }, 2500);
        }
    });
}
Also used : AutoInjector(autodagger.AutoInjector) Bundle(android.os.Bundle) UserUtils(com.nextcloud.talk.utils.database.user.UserUtils) EntryMenuController(com.nextcloud.talk.controllers.bottomsheet.EntryMenuController) SearchView(android.support.v7.widget.SearchView) CallMenuController(com.nextcloud.talk.controllers.bottomsheet.CallMenuController) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) BindView(butterknife.BindView) ApiUtils(com.nextcloud.talk.utils.ApiUtils) BottomSheet(com.kennyc.bottomsheet.BottomSheet) Handler(android.os.Handler) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) Participant(com.nextcloud.talk.models.json.participants.Participant) MenuItemCompat(android.support.v4.view.MenuItemCompat) HttpException(retrofit2.HttpException) InputType(android.text.InputType) FlexibleAdapter(eu.davidea.flexibleadapter.FlexibleAdapter) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) NoOpControllerChangeHandler(com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler) BundleKeys(com.nextcloud.talk.utils.bundle.BundleKeys) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) Parcels(org.parceler.Parcels) FastScroller(eu.davidea.fastscroller.FastScroller) CallItem(com.nextcloud.talk.adapters.items.CallItem) Nullable(android.support.annotation.Nullable) SearchManager(android.app.SearchManager) EditorInfo(android.view.inputmethod.EditorInfo) Context(android.content.Context) MoreMenuClickEvent(com.nextcloud.talk.events.MoreMenuClickEvent) UserEntity(com.nextcloud.talk.models.database.UserEntity) SmoothScrollLinearLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) BottomSheetLockEvent(com.nextcloud.talk.events.BottomSheetLockEvent) Inject(javax.inject.Inject) BaseController(com.nextcloud.talk.controllers.base.BaseController) MenuInflater(android.view.MenuInflater) EventBus(org.greenrobot.eventbus.EventBus) Menu(android.view.Menu) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) NcApi(com.nextcloud.talk.api.NcApi) BottomNavigationView(android.support.design.widget.BottomNavigationView) R(com.nextcloud.talk.R) Room(com.nextcloud.talk.models.json.rooms.Room) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) RecyclerView(android.support.v7.widget.RecyclerView) Subscribe(org.greenrobot.eventbus.Subscribe) KeyboardUtils(com.nextcloud.talk.utils.KeyboardUtils) CallActivity(com.nextcloud.talk.activities.CallActivity) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) NextcloudTalkApplication(com.nextcloud.talk.application.NextcloudTalkApplication) RouterTransaction(com.bluelinelabs.conductor.RouterTransaction) Handler(android.os.Handler) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) NoOpControllerChangeHandler(com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) CallItem(com.nextcloud.talk.adapters.items.CallItem) HttpException(retrofit2.HttpException) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler)

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