1 |
gabriel |
1 |
package com.cesams.twogetskills.inconcert.fragment;
|
|
|
2 |
|
8 |
gabriel |
3 |
import android.app.AlertDialog;
|
|
|
4 |
import android.app.Dialog;
|
|
|
5 |
import android.content.DialogInterface;
|
1 |
gabriel |
6 |
import android.os.Bundle;
|
|
|
7 |
import android.util.Log;
|
|
|
8 |
import android.view.LayoutInflater;
|
|
|
9 |
import android.view.Menu;
|
|
|
10 |
import android.view.MenuInflater;
|
|
|
11 |
import android.view.View;
|
|
|
12 |
import android.view.ViewGroup;
|
|
|
13 |
import android.widget.Button;
|
|
|
14 |
import android.widget.ImageView;
|
|
|
15 |
import android.widget.TextView;
|
8 |
gabriel |
16 |
import android.widget.Toast;
|
1 |
gabriel |
17 |
|
|
|
18 |
import androidx.annotation.NonNull;
|
|
|
19 |
import androidx.annotation.Nullable;
|
|
|
20 |
import androidx.fragment.app.Fragment;
|
|
|
21 |
import androidx.lifecycle.LifecycleOwner;
|
|
|
22 |
import androidx.lifecycle.Observer;
|
|
|
23 |
import androidx.lifecycle.ViewModelProvider;
|
|
|
24 |
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
25 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
26 |
|
18 |
efrain |
27 |
|
1 |
gabriel |
28 |
import com.cesams.twogetskills.inconcert.Constants;
|
|
|
29 |
import com.cesams.twogetskills.inconcert.R;
|
8 |
gabriel |
30 |
import com.cesams.twogetskills.inconcert.activity.MainActivity;
|
1 |
gabriel |
31 |
import com.cesams.twogetskills.inconcert.adapter.UserProfileListViewAdapter;
|
|
|
32 |
import com.cesams.twogetskills.inconcert.dao.CompanyDao;
|
|
|
33 |
import com.cesams.twogetskills.inconcert.dao.UserExtendedDao;
|
|
|
34 |
import com.cesams.twogetskills.inconcert.entity.Company;
|
|
|
35 |
import com.cesams.twogetskills.inconcert.entity.UserExtended;
|
18 |
efrain |
36 |
import com.cesams.twogetskills.inconcert.library.ImageService;
|
8 |
gabriel |
37 |
import com.cesams.twogetskills.inconcert.skeleton.IReloadData;
|
1 |
gabriel |
38 |
import com.cesams.twogetskills.inconcert.viewdata.UserProfileViewData;
|
|
|
39 |
import com.cesams.twogetskills.inconcert.library.MD5;
|
|
|
40 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
41 |
import com.cesams.twogetskills.inconcert.viewmodel.UserProfileViewModel;
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
import java.util.ArrayList;
|
|
|
45 |
import java.util.Calendar;
|
|
|
46 |
import java.util.List;
|
|
|
47 |
import java.util.Random;
|
|
|
48 |
import java.util.TimeZone;
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
public class UserProfileFragment extends Fragment implements LifecycleOwner {
|
|
|
52 |
private final String TAG = "C2GS - UserInfoFragment";
|
|
|
53 |
private RecyclerView listView;
|
|
|
54 |
private UserProfileListViewAdapter adapter;
|
|
|
55 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
56 |
private ImageView
|
|
|
57 |
headerUserImage;
|
|
|
58 |
private TextView headerUserName;
|
|
|
59 |
private TextView headerUserEmail;
|
|
|
60 |
private UserProfileViewModel mUserProfileViewModel;
|
8 |
gabriel |
61 |
Button signout, biometriconfig;
|
1 |
gabriel |
62 |
|
|
|
63 |
|
|
|
64 |
@Override
|
|
|
65 |
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
66 |
super.onCreate(savedInstanceState);
|
|
|
67 |
setHasOptionsMenu(true);
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
@Override
|
|
|
73 |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
74 |
super.onCreateOptionsMenu(menu, inflater);
|
|
|
75 |
menu.clear();
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
80 |
|
|
|
81 |
return inflater.inflate(R.layout.fragment_userprofile, container, false);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
@Override
|
|
|
85 |
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
86 |
super.onViewCreated(view, savedInstanceState);
|
|
|
87 |
iTwoGetSkills = (ITwoGetSkills) getActivity();
|
|
|
88 |
iTwoGetSkills.setTitleActionBar(getActivity().getString(R.string.menu_user_profile));
|
|
|
89 |
|
|
|
90 |
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
|
|
|
91 |
layoutManager.scrollToPosition(0);
|
|
|
92 |
|
|
|
93 |
signout=view.findViewById(R.id.button2);
|
|
|
94 |
signout.setOnClickListener(new View.OnClickListener() {
|
|
|
95 |
@Override
|
|
|
96 |
public void onClick(View v) {
|
|
|
97 |
iTwoGetSkills.signout();
|
|
|
98 |
iTwoGetSkills.hideNavigationAndtoolbar();
|
|
|
99 |
}
|
|
|
100 |
});
|
|
|
101 |
|
8 |
gabriel |
102 |
|
|
|
103 |
biometriconfig=view.findViewById(R.id.button4);
|
|
|
104 |
biometriconfig.setOnClickListener(new View.OnClickListener() {
|
|
|
105 |
@Override
|
|
|
106 |
public void onClick(View view) {
|
|
|
107 |
|
|
|
108 |
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
|
|
|
109 |
alertDialogBuilder.setMessage("Configuración de OnRoom Fingerprint");
|
|
|
110 |
alertDialogBuilder.setView(R.layout.finger_options_config);
|
|
|
111 |
alertDialogBuilder.setPositiveButton("Activar",
|
|
|
112 |
new DialogInterface.OnClickListener() {
|
|
|
113 |
@Override
|
|
|
114 |
public void onClick(DialogInterface arg0, int arg1) {
|
|
|
115 |
|
|
|
116 |
iTwoGetSkills.getPreference().setBiometriclogin(true);
|
|
|
117 |
Toast.makeText(getContext(), "Fingerprint OnRoom Activado", Toast.LENGTH_SHORT).show();
|
|
|
118 |
}
|
|
|
119 |
});
|
|
|
120 |
|
|
|
121 |
alertDialogBuilder.setNegativeButton("Apagar", new DialogInterface.OnClickListener() {
|
|
|
122 |
@Override
|
|
|
123 |
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
124 |
iTwoGetSkills.getPreference().setBiometriclogin(false);
|
|
|
125 |
Toast.makeText(getContext(), "Fingerprint OnRoom Desactivado", Toast.LENGTH_SHORT).show();
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
});
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
132 |
alertDialog.show();
|
|
|
133 |
alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.teal_700, null));
|
|
|
134 |
alertDialog.getButton(alertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.textviewTopicProgress, null));
|
|
|
135 |
|
|
|
136 |
}
|
|
|
137 |
});
|
|
|
138 |
|
1 |
gabriel |
139 |
mUserProfileViewModel = new ViewModelProvider(requireActivity()).get(UserProfileViewModel.class);
|
|
|
140 |
adapter = new UserProfileListViewAdapter(getActivity(), mUserProfileViewModel.getUserProfileViewDataArrayList());
|
|
|
141 |
|
|
|
142 |
Observer<ArrayList<UserProfileViewData>> UserProfileArrayListUpdateObserver = new Observer<ArrayList<UserProfileViewData>>() {
|
|
|
143 |
@Override
|
|
|
144 |
public void onChanged(ArrayList<UserProfileViewData> UserProfileViewDataArrayList) {
|
|
|
145 |
adapter.notifyDataSetChanged();
|
|
|
146 |
}
|
|
|
147 |
};
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
mUserProfileViewModel.getUserProfileViewDataMutableLiveData().observe(requireActivity(),UserProfileArrayListUpdateObserver);
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
listView = getView().findViewById(R.id.fragment_userprofile_listview);
|
|
|
154 |
listView.setAdapter(adapter);
|
|
|
155 |
listView.setLayoutManager(layoutManager);
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
headerUserImage = getView().findViewById(R.id.fragment_userprofile_header_user_image);
|
|
|
159 |
|
18 |
efrain |
160 |
ImageService.retrieve(getContext(), iTwoGetSkills.getPreference().getImage(), headerUserImage);
|
1 |
gabriel |
161 |
|
|
|
162 |
headerUserName = getView().findViewById(R.id.fragment_userprofile_header_user_name);
|
|
|
163 |
headerUserName.setText((iTwoGetSkills.getPreference().getFirstName() + " " + iTwoGetSkills.getPreference().getLastName()).trim());
|
|
|
164 |
headerUserEmail = getView().findViewById(R.id.fragment_userprofile_header_header_user_email);
|
|
|
165 |
headerUserEmail.setText(iTwoGetSkills.getPreference().getEmail());
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
}
|
|
|
169 |
@Override
|
|
|
170 |
public void onResume() {
|
|
|
171 |
super.onResume();
|
|
|
172 |
|
|
|
173 |
Log.d(TAG, "onResume");
|
|
|
174 |
loadData();
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
@Override
|
|
|
181 |
public void onHiddenChanged(boolean hidden) {
|
|
|
182 |
super.onHiddenChanged(hidden);
|
|
|
183 |
|
|
|
184 |
Log.d(TAG, "onHiddenChanged : " + (hidden ? "true" : "false"));
|
|
|
185 |
|
|
|
186 |
if(!hidden) {
|
|
|
187 |
loadData();
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
private void loadData()
|
|
|
192 |
{
|
|
|
193 |
CompanyDao companyDao = iTwoGetSkills.getDatabase().getCompanyDao();
|
|
|
194 |
List<Company> companies = companyDao.selectAll();
|
|
|
195 |
|
|
|
196 |
mUserProfileViewModel.getUserProfileViewDataArrayList().clear();
|
|
|
197 |
UserProfileViewData userProfileViewData;
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
UserExtendedDao userExtendedDao = iTwoGetSkills.getDatabase().getUserExtendedDao();
|
|
|
201 |
List<UserExtended> dbUserExtendedData = userExtendedDao.selectAll();
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
int i = 0;
|
|
|
205 |
for(Company company : companies)
|
|
|
206 |
{
|
|
|
207 |
userProfileViewData = new UserProfileViewData();
|
|
|
208 |
userProfileViewData.setType(UserProfileViewData.TYPE_COMPANY);
|
|
|
209 |
userProfileViewData.setLabelOrCompanyName(company.getName());
|
|
|
210 |
userProfileViewData.setValueOrImage(company.getImage());
|
|
|
211 |
mUserProfileViewModel.getUserProfileViewDataArrayList().add(userProfileViewData);
|
|
|
212 |
|
|
|
213 |
for(UserExtended userExtended : dbUserExtendedData)
|
|
|
214 |
{
|
|
|
215 |
if(company.getUuid().equals(userExtended.getCompanyUuid()))
|
|
|
216 |
{
|
|
|
217 |
|
|
|
218 |
userProfileViewData = new UserProfileViewData();
|
|
|
219 |
userProfileViewData.setType(UserProfileViewData.TYPE_ITEM);
|
|
|
220 |
userProfileViewData.setLabelOrCompanyName(userExtended.getLabel());
|
|
|
221 |
userProfileViewData.setValueOrImage(userExtended.getValue());
|
|
|
222 |
mUserProfileViewModel.getUserProfileViewDataArrayList().add(userProfileViewData);
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
mUserProfileViewModel.getUserProfileViewDataMutableLiveData().setValue(mUserProfileViewModel.getUserProfileViewDataArrayList());
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
}
|