2023-06-29 17:54:41 +05:30
|
|
|
package com.ssb.simplitend.apputils;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.Context;
|
2023-07-07 21:07:04 +05:30
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.view.LayoutInflater;
|
2023-06-29 17:54:41 +05:30
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
|
2023-07-07 21:07:04 +05:30
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.RawRes;
|
|
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
|
|
|
|
import com.ssb.simplitend.R;
|
|
|
|
|
import com.ssb.simplitend.databinding.DecisionBottomsheetBinding;
|
|
|
|
|
import com.ssb.simplitend.databinding.DoneBottomsheetBinding;
|
|
|
|
|
|
2023-06-29 17:54:41 +05:30
|
|
|
public abstract class AppUtil {
|
|
|
|
|
|
|
|
|
|
// closes keyboard
|
|
|
|
|
public static void closeKeyboard(Activity activity){
|
|
|
|
|
if (activity != null){
|
|
|
|
|
View view = activity.getCurrentFocus();
|
|
|
|
|
if (view != null) {
|
|
|
|
|
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 21:07:04 +05:30
|
|
|
// show decision dialog
|
|
|
|
|
public static void showSOSDecision(@NonNull Context context,
|
|
|
|
|
@NonNull String decisionText,
|
|
|
|
|
@NonNull String positiveText, @NonNull String negativeText,
|
|
|
|
|
View.OnClickListener positiveClickListener,
|
|
|
|
|
View.OnClickListener negativeClickListener) {
|
|
|
|
|
|
|
|
|
|
DecisionBottomsheetBinding binding = DecisionBottomsheetBinding.inflate(LayoutInflater.from(context));
|
|
|
|
|
|
|
|
|
|
BottomSheetDialog bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
|
|
|
|
bsd.setContentView(binding.getRoot());
|
|
|
|
|
bsd.setCancelable(false);
|
|
|
|
|
|
|
|
|
|
binding.text.setText(decisionText);
|
|
|
|
|
|
|
|
|
|
binding.positiveBtn.setText(positiveText);
|
|
|
|
|
binding.negativeBtn.setText(negativeText);
|
|
|
|
|
|
|
|
|
|
binding.negativeBtn.setOnClickListener(v -> {
|
|
|
|
|
bsd.dismiss();
|
|
|
|
|
negativeClickListener.onClick(v);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
binding.positiveBtn.setOnClickListener(v -> {
|
|
|
|
|
bsd.dismiss();
|
|
|
|
|
positiveClickListener.onClick(v);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bsd.show();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void showAnimateDBS(@NonNull Context context,
|
|
|
|
|
@NonNull String title,
|
|
|
|
|
@RawRes int rawRes, long doneInterval,
|
|
|
|
|
@NonNull View.OnClickListener doneListener){
|
|
|
|
|
DoneBottomsheetBinding binding = DoneBottomsheetBinding.inflate(LayoutInflater.from(context));
|
|
|
|
|
|
|
|
|
|
BottomSheetDialog bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
|
|
|
|
bsd.setContentView(binding.getRoot());
|
|
|
|
|
bsd.setCancelable(false);
|
|
|
|
|
|
|
|
|
|
binding.text.setText(title);
|
|
|
|
|
|
|
|
|
|
Glide.with(context)
|
|
|
|
|
.asGif()
|
|
|
|
|
.load(rawRes)
|
|
|
|
|
.into(binding.doneAnim);
|
|
|
|
|
|
|
|
|
|
bsd.show();
|
|
|
|
|
|
|
|
|
|
new Handler().postDelayed(() -> {
|
|
|
|
|
|
|
|
|
|
bsd.dismiss();
|
|
|
|
|
doneListener.onClick(null);
|
|
|
|
|
|
|
|
|
|
}, doneInterval);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-29 17:54:41 +05:30
|
|
|
}
|