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 |
|
|
|
27 |
import com.bumptech.glide.Glide;
|
|
|
28 |
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
29 |
import com.bumptech.glide.load.model.GlideUrl;
|
|
|
30 |
import com.bumptech.glide.load.model.LazyHeaders;
|
|
|
31 |
import com.bumptech.glide.request.RequestOptions;
|
|
|
32 |
import com.cesams.twogetskills.inconcert.Constants;
|
|
|
33 |
import com.cesams.twogetskills.inconcert.R;
|
8 |
gabriel |
34 |
import com.cesams.twogetskills.inconcert.activity.MainActivity;
|
1 |
gabriel |
35 |
import com.cesams.twogetskills.inconcert.adapter.UserProfileListViewAdapter;
|
|
|
36 |
import com.cesams.twogetskills.inconcert.dao.CompanyDao;
|
|
|
37 |
import com.cesams.twogetskills.inconcert.dao.UserExtendedDao;
|
|
|
38 |
import com.cesams.twogetskills.inconcert.entity.Company;
|
|
|
39 |
import com.cesams.twogetskills.inconcert.entity.UserExtended;
|
8 |
gabriel |
40 |
import com.cesams.twogetskills.inconcert.skeleton.IReloadData;
|
1 |
gabriel |
41 |
import com.cesams.twogetskills.inconcert.viewdata.UserProfileViewData;
|
|
|
42 |
import com.cesams.twogetskills.inconcert.library.MD5;
|
|
|
43 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
44 |
import com.cesams.twogetskills.inconcert.viewmodel.UserProfileViewModel;
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
import java.util.ArrayList;
|
|
|
48 |
import java.util.Calendar;
|
|
|
49 |
import java.util.List;
|
|
|
50 |
import java.util.Random;
|
|
|
51 |
import java.util.TimeZone;
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
public class UserProfileFragment extends Fragment implements LifecycleOwner {
|
|
|
55 |
private final String TAG = "C2GS - UserInfoFragment";
|
|
|
56 |
private RecyclerView listView;
|
|
|
57 |
private UserProfileListViewAdapter adapter;
|
|
|
58 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
59 |
private ImageView
|
|
|
60 |
headerUserImage;
|
|
|
61 |
private TextView headerUserName;
|
|
|
62 |
private TextView headerUserEmail;
|
|
|
63 |
private UserProfileViewModel mUserProfileViewModel;
|
8 |
gabriel |
64 |
Button signout, biometriconfig;
|
1 |
gabriel |
65 |
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
69 |
super.onCreate(savedInstanceState);
|
|
|
70 |
setHasOptionsMenu(true);
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
@Override
|
|
|
76 |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
77 |
super.onCreateOptionsMenu(menu, inflater);
|
|
|
78 |
menu.clear();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
@Override
|
|
|
82 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
83 |
|
|
|
84 |
return inflater.inflate(R.layout.fragment_userprofile, container, false);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
@Override
|
|
|
88 |
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
89 |
super.onViewCreated(view, savedInstanceState);
|
|
|
90 |
iTwoGetSkills = (ITwoGetSkills) getActivity();
|
|
|
91 |
iTwoGetSkills.setTitleActionBar(getActivity().getString(R.string.menu_user_profile));
|
|
|
92 |
|
|
|
93 |
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
|
|
|
94 |
layoutManager.scrollToPosition(0);
|
|
|
95 |
|
|
|
96 |
signout=view.findViewById(R.id.button2);
|
|
|
97 |
signout.setOnClickListener(new View.OnClickListener() {
|
|
|
98 |
@Override
|
|
|
99 |
public void onClick(View v) {
|
|
|
100 |
iTwoGetSkills.signout();
|
|
|
101 |
iTwoGetSkills.hideNavigationAndtoolbar();
|
|
|
102 |
}
|
|
|
103 |
});
|
|
|
104 |
|
8 |
gabriel |
105 |
|
|
|
106 |
biometriconfig=view.findViewById(R.id.button4);
|
|
|
107 |
biometriconfig.setOnClickListener(new View.OnClickListener() {
|
|
|
108 |
@Override
|
|
|
109 |
public void onClick(View view) {
|
|
|
110 |
|
|
|
111 |
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
|
|
|
112 |
alertDialogBuilder.setMessage("Configuración de OnRoom Fingerprint");
|
|
|
113 |
alertDialogBuilder.setView(R.layout.finger_options_config);
|
|
|
114 |
alertDialogBuilder.setPositiveButton("Activar",
|
|
|
115 |
new DialogInterface.OnClickListener() {
|
|
|
116 |
@Override
|
|
|
117 |
public void onClick(DialogInterface arg0, int arg1) {
|
|
|
118 |
|
|
|
119 |
iTwoGetSkills.getPreference().setBiometriclogin(true);
|
|
|
120 |
Toast.makeText(getContext(), "Fingerprint OnRoom Activado", Toast.LENGTH_SHORT).show();
|
|
|
121 |
}
|
|
|
122 |
});
|
|
|
123 |
|
|
|
124 |
alertDialogBuilder.setNegativeButton("Apagar", new DialogInterface.OnClickListener() {
|
|
|
125 |
@Override
|
|
|
126 |
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
127 |
iTwoGetSkills.getPreference().setBiometriclogin(false);
|
|
|
128 |
Toast.makeText(getContext(), "Fingerprint OnRoom Desactivado", Toast.LENGTH_SHORT).show();
|
|
|
129 |
|
|
|
130 |
}
|
|
|
131 |
});
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
135 |
alertDialog.show();
|
|
|
136 |
alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.teal_700, null));
|
|
|
137 |
alertDialog.getButton(alertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.textviewTopicProgress, null));
|
|
|
138 |
|
|
|
139 |
}
|
|
|
140 |
});
|
|
|
141 |
|
1 |
gabriel |
142 |
mUserProfileViewModel = new ViewModelProvider(requireActivity()).get(UserProfileViewModel.class);
|
|
|
143 |
adapter = new UserProfileListViewAdapter(getActivity(), mUserProfileViewModel.getUserProfileViewDataArrayList());
|
|
|
144 |
|
|
|
145 |
Observer<ArrayList<UserProfileViewData>> UserProfileArrayListUpdateObserver = new Observer<ArrayList<UserProfileViewData>>() {
|
|
|
146 |
@Override
|
|
|
147 |
public void onChanged(ArrayList<UserProfileViewData> UserProfileViewDataArrayList) {
|
|
|
148 |
adapter.notifyDataSetChanged();
|
|
|
149 |
}
|
|
|
150 |
};
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
mUserProfileViewModel.getUserProfileViewDataMutableLiveData().observe(requireActivity(),UserProfileArrayListUpdateObserver);
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
listView = getView().findViewById(R.id.fragment_userprofile_listview);
|
|
|
157 |
listView.setAdapter(adapter);
|
|
|
158 |
listView.setLayoutManager(layoutManager);
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
headerUserImage = getView().findViewById(R.id.fragment_userprofile_header_user_image);
|
|
|
162 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
163 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
164 |
TimeZone tz = calendar.getTimeZone();
|
|
|
165 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
166 |
|
|
|
167 |
Random random = new Random(created);
|
|
|
168 |
int rand = 1000 + random.nextInt(8999);
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
|
|
|
172 |
String password = iTwoGetSkills.getPreference().getPassword();
|
|
|
173 |
|
|
|
174 |
Log.d(TAG, "token = " + deviceUuid);
|
|
|
175 |
Log.d(TAG, "created = " + created);
|
|
|
176 |
Log.d(TAG, "rand = " + rand);
|
|
|
177 |
Log.d(TAG, "calc = " + password + ':' + created + ':' + rand);
|
|
|
178 |
|
|
|
179 |
String secret = MD5.generar(password + ':' + created + ':' + rand);
|
|
|
180 |
|
|
|
181 |
GlideUrl url = new GlideUrl(iTwoGetSkills.getPreference().getImage(), new LazyHeaders.Builder()
|
|
|
182 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
183 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
|
|
|
184 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
185 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
186 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
187 |
.build());
|
|
|
188 |
|
|
|
189 |
RequestOptions options = new RequestOptions()
|
|
|
190 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
191 |
|
|
|
192 |
/*
|
|
|
193 |
Glide.with(requireActivity()).load(url)
|
|
|
194 |
.thumbnail()
|
|
|
195 |
.apply(options)
|
|
|
196 |
.into(headerUserImage);
|
|
|
197 |
|
|
|
198 |
*/
|
|
|
199 |
|
|
|
200 |
Glide.with(requireActivity()).load(url)
|
|
|
201 |
.apply(options)
|
|
|
202 |
.into(headerUserImage);
|
|
|
203 |
|
|
|
204 |
headerUserName = getView().findViewById(R.id.fragment_userprofile_header_user_name);
|
|
|
205 |
headerUserName.setText((iTwoGetSkills.getPreference().getFirstName() + " " + iTwoGetSkills.getPreference().getLastName()).trim());
|
|
|
206 |
headerUserEmail = getView().findViewById(R.id.fragment_userprofile_header_header_user_email);
|
|
|
207 |
headerUserEmail.setText(iTwoGetSkills.getPreference().getEmail());
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
}
|
|
|
211 |
@Override
|
|
|
212 |
public void onResume() {
|
|
|
213 |
super.onResume();
|
|
|
214 |
|
|
|
215 |
Log.d(TAG, "onResume");
|
|
|
216 |
loadData();
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
@Override
|
|
|
223 |
public void onHiddenChanged(boolean hidden) {
|
|
|
224 |
super.onHiddenChanged(hidden);
|
|
|
225 |
|
|
|
226 |
Log.d(TAG, "onHiddenChanged : " + (hidden ? "true" : "false"));
|
|
|
227 |
|
|
|
228 |
if(!hidden) {
|
|
|
229 |
loadData();
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
private void loadData()
|
|
|
234 |
{
|
|
|
235 |
CompanyDao companyDao = iTwoGetSkills.getDatabase().getCompanyDao();
|
|
|
236 |
List<Company> companies = companyDao.selectAll();
|
|
|
237 |
|
|
|
238 |
mUserProfileViewModel.getUserProfileViewDataArrayList().clear();
|
|
|
239 |
UserProfileViewData userProfileViewData;
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
UserExtendedDao userExtendedDao = iTwoGetSkills.getDatabase().getUserExtendedDao();
|
|
|
243 |
List<UserExtended> dbUserExtendedData = userExtendedDao.selectAll();
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
int i = 0;
|
|
|
247 |
for(Company company : companies)
|
|
|
248 |
{
|
|
|
249 |
userProfileViewData = new UserProfileViewData();
|
|
|
250 |
userProfileViewData.setType(UserProfileViewData.TYPE_COMPANY);
|
|
|
251 |
userProfileViewData.setLabelOrCompanyName(company.getName());
|
|
|
252 |
userProfileViewData.setValueOrImage(company.getImage());
|
|
|
253 |
mUserProfileViewModel.getUserProfileViewDataArrayList().add(userProfileViewData);
|
|
|
254 |
|
|
|
255 |
for(UserExtended userExtended : dbUserExtendedData)
|
|
|
256 |
{
|
|
|
257 |
if(company.getUuid().equals(userExtended.getCompanyUuid()))
|
|
|
258 |
{
|
|
|
259 |
|
|
|
260 |
userProfileViewData = new UserProfileViewData();
|
|
|
261 |
userProfileViewData.setType(UserProfileViewData.TYPE_ITEM);
|
|
|
262 |
userProfileViewData.setLabelOrCompanyName(userExtended.getLabel());
|
|
|
263 |
userProfileViewData.setValueOrImage(userExtended.getValue());
|
|
|
264 |
mUserProfileViewModel.getUserProfileViewDataArrayList().add(userProfileViewData);
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
mUserProfileViewModel.getUserProfileViewDataMutableLiveData().setValue(mUserProfileViewModel.getUserProfileViewDataArrayList());
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
}
|