retrofit2

How to handle pagination with Retrofit 2 and RxJava

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 17:19:29
问题 I know how to handle Retrofit responses but I have a problem with handling pagination from a REST API with rx java. Background The rest api that I'm using gives me the following response with the link to the next page in the headers: HTTP 200 OK Allow: GET, HEAD, OPTIONS Content-Type: application/json Link: <http://some-endpoint.com/pictures?page=2>; rel="next" Vary: Accept X-Total-Count: 80 [ { "id": 3, "url": "", "picture": { "id": 6, "url": "", "name": "Chrysler" }, "location": { "type":

How to handle JSONP response through Retrofit and GsonConverter?

南楼画角 提交于 2020-01-03 13:59:34
问题 I need to parse a response from the Flickr API. http://api.flickr.com/services/feeds/photos_public.gne?tagmode=any&format=json which returns a response in jsonFlickrFeed jQuery call back function (which is not a valid JSON response). I know we can remove JSON callback method for Flickr API using nojsoncallback=1 query. But is there any better approach to handle JSONP response if it is mandatory to use JSON with Padding (JSONP)? Instead of getting the response as a String, then trimming of the

MockWebserver and Retrofit 2.0

此生再无相见时 提交于 2020-01-03 13:43:13
问题 Trying to unit test a Retrofit 2.0 response using MockWebServer . I have the webserver setup, but the problem occurs when i am trying to pass a mock json file as a response. To illustrate, my folder structure is: src->test->java->package_name->class_name.java src->test->resources->list_success.json My unit test: @Before public void setUp() throws Exception{ MockitoAnnotations.initMocks(this); server = new MockWebServer(); serviceHelper = new ServiceHelper(); } @Test public void

deserialization of a JSON API response with moshi

末鹿安然 提交于 2020-01-03 04:14:05
问题 I got a null object attributes after deserialization of a json response. Developing under android, I'm using retrofit2 , moshi as converter (https://github.com/kamikat/moshi-jsonapi ) . When debugging ,I saw a json response fully retrieved (not null attributes),but deserialization fails. Should I use GSON instead? Here's my retrofit builder I use to make my json call: (no issue) public static JsonServerInterface getSimpleClient(){ Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_AUTH

how do I implement progress bar outside of the recycle view activity?

限于喜欢 提交于 2020-01-03 03:44:08
问题 I want to display something like this-->My Home activity..inside Whats Android,Start learning ,Get ahead there are recycleviews like this-->enter image description here..... how do I implement this kind of progressbar based upon users reading?? need help..thanks My Home activity: public class MainActivity extends AppCompatActivity { private RecyclerView recyclerview ; private String[] names ; private TypedArray profile_pics ; private TypedArray card_images; ImageView imageView; private List

Retrofit 2 simple upload file to server

吃可爱长大的小学妹 提交于 2020-01-02 17:56:30
问题 i'm newbie in retrofit and in this code i want to upload file as an image or other format to server, i read Retrofit document about that, but i can't do that, i can create provider and i can use that to POST or GET from server, but my problem is for that is upload file. Thanks to advance My SignalProvider class: public class SignalProvider { private SignalRetrofitServiceProviders signalRetrofitServiceProviders; public SignalProvider(){ OkHttpClient httpClient = new OkHttpClient(); Retrofit

Failure response retrofit 2

非 Y 不嫁゛ 提交于 2020-01-02 14:32:38
问题 I Implemented sample retrofit 2 response via GET type, where I click button to get the response, but I have Failure response public interface GithubServise { @GET("/users/waadalkatheri/repos") Call<ResponseBody> getGithub(); } public void loadData (View view){ String LINK = "https://api.github.com"; Retrofit retrofit = new Retrofit.Builder ().baseUrl (LINK).build (); GithubServise githubServise= retrofit.create (GithubServise.class); githubServise.getGithub ().enqueue (new Callback

How to combine Retrofit 2 with Realm and RxJava

血红的双手。 提交于 2020-01-02 10:04:11
问题 I want to save retrofit responses to realm on the background thread then pass it to the UI Thread, but its a bit tricky since Realm is very touchy with threads. so the code would look like something like this, please submit your edits to all better solutions :) restApi.userRealmList() .doOnNext(userRealmModels -> { if (userRealmModels != null){ mRealm = Realm.getInstance(mContext); mRealm.asObservable() .map(realm -> mRealm.copyToRealmOrUpdate(userEntity)) .subscribe(new Subscriber<Object>()

HTTP FAILED: java.net.SocketException: Socket closed; doesn't fire up exception handling methods

假装没事ソ 提交于 2020-01-02 04:12:50
问题 I have an RxJava chain request that should release some locks onError(), or onComplete(), so, basically, what my problem is: when I set read, connect and write timeouts to my OkHttpClient, I don't get the desired behavior. I'm using Retrofit2 and OkHttp3.6.0 Here's my simplified client: OkHttpClient.Builder builder = new OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) OkHttpClient okHttpClient = builder.build(

Retrofit2 proguard remove param

徘徊边缘 提交于 2020-01-02 02:44:14
问题 I use retrofit 2 & using proguard in my project. My proguard: -dontwarn retrofit2.** -keep class retrofit2.** { *; } -keepattributes Signature -keepattributes Exceptions -keepclassmembers class fqcn.of.javascript.interface.for.webview { public *; } # Begin twitter 4j. -dontwarn twitter4j.** -keep class twitter4j.conf.PropertyConfigurationFactory -keep class twitter4j.** { *; } # End twitter 4j. # Start androidsocialnetworks -keep class com.androidsocialnetworks.lib.** { *; } # End