BaseFragment.java 3.91 KB
package etelligens.com.foodsafety.utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.inputmethod.InputMethodManager;


import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.util.Objects;

import etelligens.com.foodsafety.R;
import etelligens.com.foodsafety.activities.dashboard.Dashboard;
import etelligens.com.foodsafety.activities.user.PopUpForOutletByUser;

import static etelligens.com.foodsafety.utils.Keyword.DB_LOGIN_USER_DATA;
import static etelligens.com.foodsafety.utils.Keyword.PREF_LANG;
import static etelligens.com.foodsafety.utils.Keyword.PREF_NAME;

public class BaseFragment extends Fragment {

    private ProgressDialog progress = null;
    private Intent intent = null;
    public SharedPreferences DBuserData, langData;
    public String userId, userImg, userName, currentLang, roleName, empID, userEmail, userMob, loginToken, roleID, outletID, partnerID, isAdmin;

    public BaseFragment() {
        super();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSavedData();
    }

    @Override
    public void onPause() {
        super.onPause();

        final InputMethodManager inputMethodManager = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputMethodManager != null && inputMethodManager.isActive()) {
            if (requireActivity().getCurrentFocus() != null) {
                inputMethodManager.hideSoftInputFromWindow(requireActivity().getCurrentFocus().getWindowToken(), 0);
            }
        }
    }

    public void hideKeyBoard(){
        final InputMethodManager inputMethodManager = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputMethodManager != null && inputMethodManager.isActive()) {
            if (requireActivity().getCurrentFocus() != null) {
                inputMethodManager.hideSoftInputFromWindow(requireActivity().getCurrentFocus().getWindowToken(), 0);
            }
        }
    }
    public void gotoDashboard(Activity context) {
        Intent i = new Intent(context, Dashboard.class);
        startActivity(i);
        context.finish();
    }

    public void loaderShow(Activity context) {
        if (progress == null) {
            progress = new ProgressDialog(context, R.style.progressTheme);
        }

        progress.setTitle("Food Safety");
        progress.setMessage(getString(R.string.loading));
        progress.setCancelable(false);
        progress.show();
    }

    public void loaderHide(Activity context) {
        if (progress == null) {
            progress = new ProgressDialog(context);
        }
        progress.dismiss();
    }

    public void getSavedData() {
        DBuserData = requireActivity().getSharedPreferences(DB_LOGIN_USER_DATA, Context.MODE_PRIVATE);
        userId = DBuserData.getString("USERID", null);
        userImg = DBuserData.getString("userIMG", null);
        userName = DBuserData.getString("UserName", null);
        roleName = DBuserData.getString("roleName", null);
        empID = DBuserData.getString("EmpID", null);
        userEmail = DBuserData.getString("userEmail", null);
        userMob = DBuserData.getString("phone", null);
        loginToken = DBuserData.getString("LoginToken", null);
        roleID = DBuserData.getString("roleID", null);
        outletID = DBuserData.getString("outletID", null);
        partnerID = DBuserData.getString("partnerID", null);
        isAdmin = DBuserData.getString("isAdmin", null);
    }

    public void getselectedLanguage() {
        langData = getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        currentLang = langData.getString(PREF_LANG, null);
    }

    public void onBackPressed() {

    }
}