0

I am using retrofit API to fetch data from my backend:

    OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
            .callTimeout(2, TimeUnit.MINUTES)
            .connectTimeout(2, TimeUnit.MINUTES)
            .readTimeout(3, TimeUnit.MINUTES)
            .writeTimeout(3, TimeUnit.MINUTES);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(server_interface.JSONURL)
            .addConverterFactory(ScalarsConverterFactory.create())
            .client(httpClient.build())
            .build();

    server_interface api = retrofit.create(server_interface.class);

    Call<String> call = api.fetch_details();

    if (call != null) {

        call.enqueue(new Callback<String>() {

            //The user should be able to see a dialog that shows that 
              he/she has to wait for x minutes to get the data

            @Override
            public void onResponse(Call<String> call, Response<String> response) {

            }

            @Override
            public void onFailure(@NonNull Call<String> call, Throwable t) {

            }
        }
    }

I want to show the user that they have to wait for x minutes to see the response. How do I calculate that time?

1 Answers1

0

Try this!

if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        httpClient.addInterceptor(httpLoggingInterceptor);
    }

and also add

compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' 

Sample response:

Date: Fri, 12 Aug 2016 07:33:23 GMT
OkHttp-Sent-Millis: 1470987074283
OkHttp-Received-Millis: 1470987074422
Harshil
  • 162
  • 11
  • I want the user to know the time that will be required, while the response is being fetched, not after it's been fetched. –  Aug 01 '22 at 10:40