This commit is contained in:
ADITYA
2023-07-18 19:38:59 +05:30
parent abc3070b18
commit 868f0512f2
33 changed files with 1103 additions and 323 deletions

View File

@@ -30,6 +30,7 @@ public abstract class AppUtil {
public static final String USER_DETAILS = "user_details";
public static final String USER_TOKEN = "user_token";
public static final String PATIENT_UID = "patient_uid";
// util functions
@@ -124,16 +125,20 @@ public abstract class AppUtil {
alertBuilder.create().show(); // Showing alert dialog
}
public static void saveToken(String token, Context context){
public static void saveUserCache(String token, int patient_uid, Context context){
SharedPreferences sp = context.getSharedPreferences(USER_DETAILS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(USER_TOKEN, token);
editor.putInt(PATIENT_UID, patient_uid);
editor.apply();
Log.d(TAG, "saveToken: user token saved successful");
// TODO: 17-07-2023 remove below line afterwards
Log.d(TAG, "saveUserCache: " + token);
}
public static String getUserToken(Context context){
@@ -141,4 +146,9 @@ public abstract class AppUtil {
return sp.getString(USER_TOKEN, "");
}
public static int getPatientUid(Context context){
SharedPreferences sp = context.getSharedPreferences(USER_DETAILS, Context.MODE_PRIVATE);
return sp.getInt(PATIENT_UID, -1);
}
}

View File

@@ -1,11 +1,14 @@
package com.ssb.simplitend.apputils;
import com.ssb.simplitend.BuildConfig;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
@@ -18,25 +21,38 @@ public abstract class RetrofitHelper {
public static final String GET_CONTACT_LIST = "api/patients-contact-list";
public static final String CREATE_CONTACT = "api/contact-create";
public static final String UPDATE_CONTACT = "api/patient-contact-update/";
// util functions
private static Retrofit retrofit;
public static synchronized Retrofit getRetrofit(){
if (retrofit == null){
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.addInterceptor(chain -> {
Request request = chain.request().newBuilder()
.addHeader("Accept", "*/*")
.addHeader("Accept-Encoding", "gzip, deflate, br")
.addHeader("Connection", "keep-alive")
.addHeader("Content-Type", "multipart/form-data")
.build();
return chain.proceed(request);
});
if (BuildConfig.DEBUG){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(interceptor);
}
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(new OkHttpClient.Builder()
.addInterceptor(chain -> {
Request request = chain.request().newBuilder()
.addHeader("Accept", "*/*")
.addHeader("Accept-Encoding", "gzip, deflate, br")
.addHeader("Connection", "keep-alive")
.addHeader("Content-Type", "multipart/form-data")
.build();
return chain.proceed(request);
}).build())
.client(builder.build())
.build();
}