.
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package com.ssb.simplitend.apputils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
@@ -18,6 +23,16 @@ import com.ssb.simplitend.databinding.DoneBottomsheetBinding;
|
||||
|
||||
public abstract class AppUtil {
|
||||
|
||||
private static final String TAG = "AppUtil";
|
||||
|
||||
// fields
|
||||
|
||||
public static final String USER_DETAILS = "user_details";
|
||||
|
||||
public static final String USER_TOKEN = "user_token";
|
||||
|
||||
// util functions
|
||||
|
||||
// closes keyboard
|
||||
public static void closeKeyboard(Activity activity){
|
||||
if (activity != null){
|
||||
@@ -88,4 +103,42 @@ public abstract class AppUtil {
|
||||
}, doneInterval);
|
||||
}
|
||||
|
||||
// Show alert dialog
|
||||
public static synchronized void showAlert(@NonNull Context context,
|
||||
@NonNull String title, @NonNull String message,
|
||||
@NonNull String positiveText, @NonNull DialogInterface.OnClickListener positiveClickListener,
|
||||
String negativeText, DialogInterface.OnClickListener negativeClickListener) {
|
||||
|
||||
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
|
||||
|
||||
alertBuilder.setTitle(title);
|
||||
alertBuilder.setMessage(message);
|
||||
|
||||
alertBuilder.setPositiveButton(positiveText, positiveClickListener /* Call back*/);
|
||||
|
||||
if (negativeText != null && negativeClickListener != null) {
|
||||
// Negative button
|
||||
alertBuilder.setNegativeButton(negativeText, negativeClickListener);
|
||||
}
|
||||
|
||||
alertBuilder.create().show(); // Showing alert dialog
|
||||
}
|
||||
|
||||
public static void saveToken(String token, Context context){
|
||||
SharedPreferences sp = context.getSharedPreferences(USER_DETAILS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
editor.putString(USER_TOKEN, token);
|
||||
|
||||
editor.apply();
|
||||
|
||||
Log.d(TAG, "saveToken: user token saved successful");
|
||||
|
||||
}
|
||||
|
||||
public static String getUserToken(Context context){
|
||||
SharedPreferences sp = context.getSharedPreferences(USER_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getString(USER_TOKEN, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.ssb.simplitend.apputils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public abstract class RetrofitHelper {
|
||||
|
||||
// urls
|
||||
public static final String BASE_URL = "https://simplitend.betadelivery.com/";
|
||||
|
||||
public static final String REGISTER_PATIENT = "api/auth/patient-register";
|
||||
|
||||
public static final String GET_CONTACT_LIST = "api/patients-contact-list";
|
||||
|
||||
// util functions
|
||||
|
||||
private static Retrofit retrofit;
|
||||
|
||||
public static synchronized Retrofit getRetrofit(){
|
||||
if (retrofit == null){
|
||||
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())
|
||||
.build();
|
||||
}
|
||||
|
||||
return retrofit;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user