Blame view

footsafety/app/src/main/java/etelligens/com/foodsafety/utils/BaseFragment.java 3.91 KB
f7a13682   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  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() {
  
      }
  }