.
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, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user