NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public class ApiClient {
private static Retrofit retrofit = null;
public static ApiInterface getApiInterface(Activity activity) {
return getRetrofitInstance(activity).create(ApiInterface.class);
}
private static Retrofit getRetrofitInstance(Activity activity){
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(300, TimeUnit.SECONDS)
.readTimeout(300, TimeUnit.SECONDS)
.writeTimeout(300, TimeUnit.SECONDS)
.addInterceptor(new ConnectivityInterceptor(activity))
.addInterceptor(loggingInterceptor)
.build();
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(URLs.BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();
}
return retrofit;
}
}
=============================
public interface ApiInterface {
@GET("deals/city/{city_slug}")
Observable<Response<DealsEntity>> getDealByCity(@Path("city_slug") String citySlug);
}==================
public class ConnectivityInterceptor implements Interceptor {
private Context context;
ConnectivityInterceptor(Context context) {
this.context = context;
}
@Override
public Response intercept(Chain chain) throws IOException {
boolean isNetworkActive = UDF.isOnline(context);
if (!isNetworkActive) {
throw new NoConnectivityException();
} else {
return chain.proceed(chain.request());
}
}
public static class NoConnectivityException extends IOException {
@Override
public String getMessage() {
return "No network available, please check your WiFi or Data connection";
}
}
}
=============
public static boolean isOnline(Context context) {
Boolean isConnected = false;
try {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
isConnected = cm != null && cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected();
if (isConnected) {
return isConnected;
}
} catch (Exception e) {
e.printStackTrace();
}
return isConnected;
}
==================
public class ProgressDialogUtils {
public static void showProgressDialog(Activity activity, ProgressDialog progressDialog) {
if (!activity.isFinishing() && progressDialog != null && !progressDialog.isShowing()) {
progressDialog.setMessage("Please Wait");
progressDialog.setCancelable(false);
progressDialog.show();
}
}
public static void dismissProgressDialog(Activity activity, ProgressDialog progressDialog) {
if (!activity.isFinishing() && progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
} }}
==========================
mCompositeDisposable = new CompositeDisposable();
progressDialog = new ProgressDialog(activity);
private void mappingData() {

mCompositeDisposable.add(getApiInterface(activity)
.getDealByCity("dubai")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(disposable -> ProgressDialogUtils.showProgressDialog(activity, progressDialog))
.doOnComplete(() -> ProgressDialogUtils.dismissProgressDialog(activity, progressDialog))
.subscribe(this::handleResponse, this::handleError));
}
@Override
protected void onDestroy() {
super.onDestroy();
mCompositeDisposable.dispose();
}
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.8'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.9.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
========================
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.