1 |
gabriel |
1 |
package com.cesams.twogetskills.inconcert.fragment;
|
|
|
2 |
|
|
|
3 |
import android.os.Bundle;
|
|
|
4 |
|
|
|
5 |
import androidx.fragment.app.Fragment;
|
|
|
6 |
import androidx.lifecycle.LifecycleOwner;
|
|
|
7 |
import androidx.lifecycle.ViewModelProvider;
|
|
|
8 |
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
9 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
10 |
|
|
|
11 |
import android.text.Editable;
|
|
|
12 |
import android.text.TextWatcher;
|
|
|
13 |
import android.util.Log;
|
|
|
14 |
import android.view.LayoutInflater;
|
|
|
15 |
import android.view.View;
|
|
|
16 |
import android.view.ViewGroup;
|
|
|
17 |
import android.widget.Button;
|
|
|
18 |
import android.widget.EditText;
|
|
|
19 |
import android.widget.ImageView;
|
|
|
20 |
import android.widget.ProgressBar;
|
|
|
21 |
import android.widget.TextView;
|
|
|
22 |
import android.widget.Toast;
|
|
|
23 |
|
|
|
24 |
import com.bumptech.glide.Glide;
|
|
|
25 |
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
26 |
import com.bumptech.glide.load.model.GlideUrl;
|
|
|
27 |
import com.bumptech.glide.load.model.LazyHeaders;
|
|
|
28 |
import com.bumptech.glide.request.RequestOptions;
|
|
|
29 |
import com.cesams.twogetskills.inconcert.Constants;
|
|
|
30 |
import com.cesams.twogetskills.inconcert.R;
|
|
|
31 |
import com.cesams.twogetskills.inconcert.adapter.TabsCapsulesAdapter;
|
|
|
32 |
import com.cesams.twogetskills.inconcert.dao.CapsuleDao;
|
|
|
33 |
import com.cesams.twogetskills.inconcert.dao.ProgressDao;
|
|
|
34 |
import com.cesams.twogetskills.inconcert.dao.SlideDao;
|
|
|
35 |
import com.cesams.twogetskills.inconcert.dao.TopicDao;
|
|
|
36 |
import com.cesams.twogetskills.inconcert.entity.Capsule;
|
|
|
37 |
import com.cesams.twogetskills.inconcert.entity.Progress;
|
|
|
38 |
import com.cesams.twogetskills.inconcert.entity.Slide;
|
|
|
39 |
import com.cesams.twogetskills.inconcert.entity.Topic;
|
|
|
40 |
import com.cesams.twogetskills.inconcert.library.MD5;
|
|
|
41 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
42 |
import com.cesams.twogetskills.inconcert.viewmodel.SlideRefreshUIViewModel;
|
|
|
43 |
import com.google.android.material.tabs.TabLayout;
|
|
|
44 |
|
|
|
45 |
import java.text.Normalizer;
|
|
|
46 |
import java.util.ArrayList;
|
|
|
47 |
import java.util.Calendar;
|
|
|
48 |
import java.util.HashMap;
|
|
|
49 |
import java.util.List;
|
|
|
50 |
import java.util.Random;
|
|
|
51 |
import java.util.TimeZone;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* A simple {@link Fragment} subclass.
|
|
|
55 |
* Use the {@link WelcomeFragment#newInstance} factory method to
|
|
|
56 |
* create an instance of this fragment.
|
|
|
57 |
*/
|
|
|
58 |
public class WelcomeFragment extends Fragment implements TabsCapsulesAdapter.ClickListener, LifecycleOwner {
|
|
|
59 |
|
|
|
60 |
TextView username, titulotarjeta, progresoporcentaje, empezar; ProgressBar progresotarjeta;
|
|
|
61 |
private ITwoGetSkills iTwoGetSkills; View card;
|
|
|
62 |
ArrayList<HashMap<String, String>> capsuleList;
|
|
|
63 |
ImageView imagetarjeta;
|
|
|
64 |
TabsCapsulesAdapter adapter2;
|
|
|
65 |
RecyclerView categorizados;
|
|
|
66 |
EditText busqueda; TextView textowelcome; Button continuar;
|
|
|
67 |
TabLayout tabs; String tabactual="pendientes"; private SlideRefreshUIViewModel mSlideRefreshUi;
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
public WelcomeFragment() {
|
|
|
71 |
// Required empty public constructor
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
public static WelcomeFragment newInstance() {
|
|
|
75 |
WelcomeFragment fragment = new WelcomeFragment();
|
|
|
76 |
return fragment;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
@Override
|
|
|
80 |
public void onCreate(Bundle savedInstanceState) {
|
|
|
81 |
super.onCreate(savedInstanceState);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
@Override
|
|
|
85 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
86 |
Bundle savedInstanceState) {
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
iTwoGetSkills = (ITwoGetSkills) getActivity();
|
|
|
90 |
|
|
|
91 |
View view= inflater.inflate(R.layout.fragment_welcome, container, false);
|
|
|
92 |
|
|
|
93 |
username=view.findViewById(R.id.textView14);
|
|
|
94 |
textowelcome= view.findViewById(R.id.textView15);
|
|
|
95 |
busqueda=view.findViewById(R.id.busqueda);
|
|
|
96 |
card= view.findViewById(R.id.include); empezar= view.findViewById(R.id.titlenotifi); tabs=view.findViewById(R.id.tabLayout);
|
|
|
97 |
capsuleList = new ArrayList<>();
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
mSlideRefreshUi = new ViewModelProvider(requireActivity()).get(SlideRefreshUIViewModel.class);
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
//Tarjeta Principal
|
|
|
106 |
titulotarjeta = view.findViewById(R.id.description); progresotarjeta= view.findViewById(R.id.progressBar2); imagetarjeta= view.findViewById(R.id.imagelist);
|
|
|
107 |
continuar = view.findViewById(R.id.button); progresoporcentaje = view.findViewById(R.id.textView16);
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
username.setText("¡Hola, "+(iTwoGetSkills.getPreference().getFirstName() +"!"));
|
|
|
111 |
|
|
|
112 |
tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
113 |
@Override
|
|
|
114 |
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
115 |
int position=tab.getPosition();
|
|
|
116 |
|
|
|
117 |
capsuleList.clear();
|
|
|
118 |
adapter2.notifyDataSetChanged();
|
|
|
119 |
|
|
|
120 |
if(position==0)
|
|
|
121 |
{
|
|
|
122 |
tabactual="pendientes";
|
|
|
123 |
loadData(tabactual,"");
|
|
|
124 |
adapter2.notifyDataSetChanged();
|
|
|
125 |
}
|
|
|
126 |
else if(position==1)
|
|
|
127 |
{
|
|
|
128 |
tabactual="cursando";
|
|
|
129 |
loadData("cursando","");
|
|
|
130 |
adapter2.notifyDataSetChanged();
|
|
|
131 |
}
|
|
|
132 |
else if(position==2)
|
|
|
133 |
{
|
|
|
134 |
tabactual="finalizados";
|
|
|
135 |
loadData("finalizados","");
|
|
|
136 |
adapter2.notifyDataSetChanged();
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
@Override
|
|
|
141 |
public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
142 |
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
@Override
|
|
|
146 |
public void onTabReselected(TabLayout.Tab tab) {
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
});
|
|
|
150 |
|
|
|
151 |
loadData("pendientes","");
|
|
|
152 |
|
|
|
153 |
busqueda.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
|
154 |
@Override
|
|
|
155 |
public void onFocusChange(View v, boolean hasFocus) {
|
|
|
156 |
if(hasFocus)
|
|
|
157 |
{
|
|
|
158 |
card.setVisibility(View.GONE);
|
|
|
159 |
username.setVisibility(View.GONE);
|
|
|
160 |
textowelcome.setVisibility(View.GONE);
|
|
|
161 |
Log.e("Tengo foco"," Oculto");
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
});
|
|
|
166 |
|
|
|
167 |
busqueda.addTextChangedListener(new TextWatcher() {
|
|
|
168 |
@Override
|
|
|
169 |
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
170 |
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
@Override
|
|
|
174 |
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
175 |
// Log.e("El texto","buscado: "+s);
|
|
|
176 |
capsuleList.clear();
|
|
|
177 |
adapter2.notifyDataSetChanged();
|
|
|
178 |
loadData(tabactual, s.toString());
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
@Override
|
|
|
182 |
public void afterTextChanged(Editable s) {
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
}
|
|
|
187 |
});
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
adapter2 = new TabsCapsulesAdapter(getContext(),capsuleList);
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
categorizados = view.findViewById(R.id.categorizados);
|
|
|
195 |
GridLayoutManager layoutcategoria = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
|
|
|
196 |
categorizados.setLayoutManager(layoutcategoria);
|
|
|
197 |
categorizados.setAdapter(adapter2);
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
adapter2.setClickListener(this);
|
|
|
201 |
|
|
|
202 |
categorizados.setOnFlingListener(new RecyclerView.OnFlingListener() {
|
|
|
203 |
@Override
|
|
|
204 |
public boolean onFling(int velocityX, int velocityY) {
|
|
|
205 |
|
|
|
206 |
if (categorizados.canScrollVertically(-1) ) {
|
|
|
207 |
|
|
|
208 |
// Log.e("Se activa", "On fling");
|
|
|
209 |
card.setVisibility(View.GONE);
|
|
|
210 |
username.setVisibility(View.GONE);
|
|
|
211 |
textowelcome.setVisibility(View.GONE);
|
|
|
212 |
}else
|
|
|
213 |
{
|
|
|
214 |
card.setVisibility(View.VISIBLE);
|
|
|
215 |
username.setVisibility(View.VISIBLE);
|
|
|
216 |
textowelcome.setVisibility(View.VISIBLE);
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
return false;
|
|
|
220 |
}
|
|
|
221 |
});
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
/* categorizados.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
|
|
225 |
@Override
|
|
|
226 |
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
|
|
227 |
|
|
|
228 |
if (!categorizados.canScrollVertically(-1)) {
|
|
|
229 |
// Toast.makeText(getActivity(), "Last", Toast.LENGTH_LONG).show();
|
|
|
230 |
capsulas.setVisibility(View.VISIBLE);
|
|
|
231 |
username.setVisibility(View.VISIBLE);
|
|
|
232 |
textowelcome.setVisibility(View.VISIBLE);
|
|
|
233 |
Log.e("On scroll"," se activa");
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
}
|
|
|
237 |
});
|
|
|
238 |
*/
|
|
|
239 |
getActivity().runOnUiThread(() -> {
|
|
|
240 |
String message = capsuleList.size() == 1
|
|
|
241 |
? "Hay 1 cápsula nueva disponible"
|
|
|
242 |
: "Tiene " + capsuleList.size() + " cápsulas pendientes para ver";
|
|
|
243 |
|
|
|
244 |
Toast.makeText(getContext(), ""+message, Toast.LENGTH_LONG).show();
|
|
|
245 |
|
|
|
246 |
iTwoGetSkills.saveNotificationCenter("Contenidos disponibles","",message);
|
|
|
247 |
|
|
|
248 |
});
|
8 |
gabriel |
249 |
iTwoGetSkills.showNavigationAndToolbar();
|
|
|
250 |
|
1 |
gabriel |
251 |
return view;
|
8 |
gabriel |
252 |
|
1 |
gabriel |
253 |
}
|
|
|
254 |
|
|
|
255 |
@Override
|
|
|
256 |
public void onResume() {
|
|
|
257 |
super.onResume();
|
|
|
258 |
getActivity().runOnUiThread(() -> {
|
|
|
259 |
loadContinuecard();
|
|
|
260 |
});
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
@Override
|
|
|
264 |
public void onHiddenChanged(boolean hidden) {
|
|
|
265 |
super.onHiddenChanged(hidden);
|
|
|
266 |
|
|
|
267 |
// Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
|
|
|
268 |
|
|
|
269 |
if(!hidden) {
|
|
|
270 |
// Log.e("Esta oculto", "el fragmento");
|
|
|
271 |
|
|
|
272 |
getActivity().runOnUiThread(() -> {
|
|
|
273 |
|
|
|
274 |
capsuleList.clear();
|
|
|
275 |
|
|
|
276 |
loadContinuecard();
|
|
|
277 |
loadData("pendientes","");
|
|
|
278 |
|
|
|
279 |
adapter2.notifyDataSetChanged();
|
|
|
280 |
|
|
|
281 |
tabs.getTabAt(0).select();
|
|
|
282 |
|
|
|
283 |
});
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
}
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
private void loadContinuecard(){
|
|
|
290 |
|
|
|
291 |
//Log.e("Cargo datos"," en tarjeta principal");
|
|
|
292 |
|
|
|
293 |
//Capsula de primera tarjeta
|
|
|
294 |
CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
|
|
|
295 |
boolean continues=false;
|
|
|
296 |
Progress progress;
|
|
|
297 |
ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
List<Capsule> dbCapsules= capsuleDao.selectAll();
|
|
|
301 |
for(Capsule dbCapsule : dbCapsules)
|
|
|
302 |
{
|
|
|
303 |
progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
|
|
|
304 |
|
|
|
305 |
if (progress != null) {
|
|
|
306 |
|
|
|
307 |
if (progress.getProgress() < 100) {
|
|
|
308 |
// Log.e("Es menor"," a 100");
|
|
|
309 |
continues=true;
|
|
|
310 |
titulotarjeta.setText(dbCapsule.getName());
|
|
|
311 |
progresotarjeta.setVisibility(View.VISIBLE);
|
|
|
312 |
progresoporcentaje.setVisibility(View.VISIBLE);
|
|
|
313 |
progresotarjeta.setProgress((int) progress.getProgress());
|
|
|
314 |
progresoporcentaje.setText("" + progress.getProgress() + " %");
|
|
|
315 |
empezar.setText("En curso");
|
|
|
316 |
|
|
|
317 |
iTwoGetSkills.getPreference().setOrigennavigation("welcome");
|
|
|
318 |
|
|
|
319 |
int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
|
|
|
320 |
|
|
|
321 |
if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
|
|
|
322 |
) {
|
|
|
323 |
return;
|
|
|
324 |
}
|
|
|
325 |
iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
|
|
|
326 |
// Log.e("La capsula","activa en loadcurso"+dbCapsule.getUuid());
|
|
|
327 |
|
|
|
328 |
iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
|
|
|
329 |
|
|
|
330 |
if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
|
|
|
331 |
|
|
|
332 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
333 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
334 |
TimeZone tz = calendar.getTimeZone();
|
|
|
335 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
336 |
|
|
|
337 |
Random random = new Random(created);
|
|
|
338 |
int rand = 1000 + random.nextInt(8999);
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
|
|
|
342 |
String password = iTwoGetSkills.getPreference().getPassword();
|
|
|
343 |
|
|
|
344 |
|
|
|
345 |
String secret = MD5.generar(password + ':' + created + ':' + rand);
|
|
|
346 |
GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
|
|
|
347 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
348 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
|
|
|
349 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
350 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
351 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
352 |
.build());
|
|
|
353 |
|
|
|
354 |
RequestOptions options = new RequestOptions()
|
|
|
355 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
356 |
|
|
|
357 |
Glide.with(getContext()).load(url)
|
|
|
358 |
.thumbnail()
|
|
|
359 |
.apply(options)
|
|
|
360 |
.into(imagetarjeta);
|
|
|
361 |
}
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
|
|
|
367 |
}
|
|
|
368 |
if(titulotarjeta.getText().equals(""))
|
|
|
369 |
{
|
|
|
370 |
// Log.e("Nombre","vacio");
|
|
|
371 |
SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
//Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
|
|
|
375 |
// vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
for(Capsule dbCapsule : dbCapsules)
|
|
|
379 |
{
|
|
|
380 |
List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
|
|
|
381 |
|
|
|
382 |
if (slides.isEmpty()) {
|
|
|
383 |
|
|
|
384 |
} else {
|
|
|
385 |
progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
|
|
|
386 |
|
|
|
387 |
// Log.e("Capsula","Es omitida, no tiene slides");
|
|
|
388 |
|
|
|
389 |
if (progress == null) {
|
|
|
390 |
|
|
|
391 |
// Log.e("Es nueva","");
|
|
|
392 |
|
|
|
393 |
titulotarjeta.setText(dbCapsule.getName());
|
|
|
394 |
progresotarjeta.setVisibility(View.INVISIBLE);
|
|
|
395 |
progresoporcentaje.setVisibility(View.INVISIBLE);
|
|
|
396 |
empezar.setText("Nueva");
|
|
|
397 |
continuar.setText("Ver cápsula");
|
|
|
398 |
|
|
|
399 |
iTwoGetSkills.getPreference().setOrigennavigation("welcome");
|
|
|
400 |
|
|
|
401 |
int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
|
|
|
402 |
|
|
|
403 |
if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
|
|
|
404 |
) {
|
|
|
405 |
return;
|
|
|
406 |
}
|
|
|
407 |
iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
|
|
|
408 |
// Log.e("La capsula","activa en load"+dbCapsule.getUuid());
|
|
|
409 |
iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
|
|
|
410 |
|
|
|
411 |
if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
|
|
|
412 |
|
|
|
413 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
414 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
415 |
TimeZone tz = calendar.getTimeZone();
|
|
|
416 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
417 |
|
|
|
418 |
Random random = new Random(created);
|
|
|
419 |
int rand = 1000 + random.nextInt(8999);
|
|
|
420 |
|
|
|
421 |
|
|
|
422 |
String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
|
|
|
423 |
String password = iTwoGetSkills.getPreference().getPassword();
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
String secret = MD5.generar(password + ':' + created + ':' + rand);
|
|
|
427 |
GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
|
|
|
428 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
429 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
|
|
|
430 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
431 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
432 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
433 |
.build());
|
|
|
434 |
|
|
|
435 |
RequestOptions options = new RequestOptions()
|
|
|
436 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
437 |
|
|
|
438 |
Glide.with(getContext()).load(url)
|
|
|
439 |
.thumbnail()
|
|
|
440 |
.apply(options)
|
|
|
441 |
.into(imagetarjeta);
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
}
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
|
|
|
450 |
|
|
|
451 |
}
|
|
|
452 |
else if (!titulotarjeta.getText().equals("") && !continues)
|
|
|
453 |
{
|
|
|
454 |
// Log.e("Nombre","vacio");
|
|
|
455 |
SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
|
|
|
456 |
|
|
|
457 |
|
|
|
458 |
//Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
|
|
|
459 |
// vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
|
|
|
460 |
|
|
|
461 |
|
|
|
462 |
for(Capsule dbCapsule : dbCapsules)
|
|
|
463 |
{
|
|
|
464 |
List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
|
|
|
465 |
|
|
|
466 |
if (slides.isEmpty()) {
|
|
|
467 |
|
|
|
468 |
} else {
|
|
|
469 |
progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
|
|
|
470 |
|
|
|
471 |
// Log.e("Capsula","Es omitida, no tiene slides");
|
|
|
472 |
|
|
|
473 |
if (progress == null) {
|
|
|
474 |
|
|
|
475 |
// Log.e("Es nueva","");
|
|
|
476 |
|
|
|
477 |
titulotarjeta.setText(dbCapsule.getName());
|
|
|
478 |
progresotarjeta.setVisibility(View.INVISIBLE);
|
|
|
479 |
progresoporcentaje.setVisibility(View.INVISIBLE);
|
|
|
480 |
empezar.setText("Nueva");
|
|
|
481 |
continuar.setText("Ver cápsula");
|
|
|
482 |
|
|
|
483 |
iTwoGetSkills.getPreference().setOrigennavigation("welcome");
|
|
|
484 |
|
|
|
485 |
|
|
|
486 |
int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
|
|
|
487 |
|
|
|
488 |
if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
|
|
|
489 |
) {
|
|
|
490 |
return;
|
|
|
491 |
}
|
|
|
492 |
iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
|
|
|
493 |
// Log.e("La capsula","activa en load"+dbCapsule.getUuid());
|
|
|
494 |
iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
|
|
|
495 |
|
|
|
496 |
if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
|
|
|
497 |
|
|
|
498 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
499 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
500 |
TimeZone tz = calendar.getTimeZone();
|
|
|
501 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
502 |
|
|
|
503 |
Random random = new Random(created);
|
|
|
504 |
int rand = 1000 + random.nextInt(8999);
|
|
|
505 |
|
|
|
506 |
|
|
|
507 |
String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
|
|
|
508 |
String password = iTwoGetSkills.getPreference().getPassword();
|
|
|
509 |
|
|
|
510 |
|
|
|
511 |
String secret = MD5.generar(password + ':' + created + ':' + rand);
|
|
|
512 |
GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
|
|
|
513 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
514 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
|
|
|
515 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
516 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
517 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
518 |
.build());
|
|
|
519 |
|
|
|
520 |
RequestOptions options = new RequestOptions()
|
|
|
521 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
522 |
|
|
|
523 |
Glide.with(getContext()).load(url)
|
|
|
524 |
.thumbnail()
|
|
|
525 |
.apply(options)
|
|
|
526 |
.into(imagetarjeta);
|
|
|
527 |
}
|
|
|
528 |
|
|
|
529 |
}
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
}
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
continuar.setOnClickListener(v -> {
|
|
|
536 |
|
|
|
537 |
|
|
|
538 |
// Log.e("Guardo",""+iTwoGetSkills.getPreference().getOrigenNavigation());
|
|
|
539 |
Log.e("Capsule","active"+iTwoGetSkills.getPreference().getCapsuleUuidActive());
|
|
|
540 |
iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
|
|
|
541 |
});
|
|
|
542 |
|
|
|
543 |
//Fin de primer tarjeta
|
|
|
544 |
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
private void loadData(String tabposition, String buscar)
|
|
|
548 |
{
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
|
|
|
552 |
ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
|
|
|
553 |
|
|
|
554 |
List<Capsule> dbCapsules;
|
|
|
555 |
CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
|
|
|
556 |
|
|
|
557 |
ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
|
|
|
558 |
SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
|
|
|
559 |
|
|
|
560 |
|
|
|
561 |
if (tabposition.equals("pendientes"))
|
|
|
562 |
{
|
|
|
563 |
for (Topic dbTopic : dbTopics) {
|
|
|
564 |
|
|
|
565 |
dbCapsules = capsuleDao.selectAllByTopicUuidandOrder(dbTopic.getUuid());
|
|
|
566 |
|
|
|
567 |
Capsule capsule;
|
|
|
568 |
Progress progress;
|
|
|
569 |
|
|
|
570 |
HashMap<String, String> m_li;
|
|
|
571 |
|
|
|
572 |
|
|
|
573 |
|
|
|
574 |
for(Capsule dbCapsule : dbCapsules) {
|
|
|
575 |
capsule = new Capsule();
|
|
|
576 |
capsule.setTopicUuid(dbCapsule.getTopicUuid());
|
|
|
577 |
capsule.setUuid(dbCapsule.getUuid());
|
|
|
578 |
capsule.setName(dbCapsule.getName());
|
|
|
579 |
capsule.setDescription(dbCapsule.getDescription());
|
|
|
580 |
capsule.setImage(dbCapsule.getImage());
|
|
|
581 |
capsule.setPosition(dbCapsule.getPosition());
|
|
|
582 |
capsule.setUpdatedOn(dbCapsule.getUpdatedOn());
|
|
|
583 |
|
|
|
584 |
m_li = new HashMap<>();
|
|
|
585 |
|
|
|
586 |
|
|
|
587 |
//m_li.put("copyright",copy);
|
|
|
588 |
|
|
|
589 |
progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
|
|
|
590 |
|
|
|
591 |
if (progress != null) {
|
|
|
592 |
capsule.setCompleted(progress.getCompleted());
|
|
|
593 |
capsule.setViewSlides(progress.getViewSlides());
|
|
|
594 |
|
|
|
595 |
capsule.setTotalSlides(progress.getTotalSlides());
|
|
|
596 |
capsule.setProgress(progress.getProgress());
|
|
|
597 |
capsule.setAddedOn(progress.getAddedOn());
|
|
|
598 |
|
|
|
599 |
// Log.e("Agregado en"," "+progress.getAddedOn());
|
|
|
600 |
// m_li.put("addedon",progress.getAddedOn());
|
|
|
601 |
m_li.put("view", String.valueOf(progress.getViewSlides()));
|
|
|
602 |
m_li.put("total", String.valueOf(progress.getTotalSlides()));
|
|
|
603 |
m_li.put("progress", String.valueOf(progress.getProgress()));
|
|
|
604 |
m_li.put("completado",String.valueOf(progress.getCompleted()));
|
|
|
605 |
m_li.put("agregado",progress.getAddedOn());
|
|
|
606 |
|
|
|
607 |
}
|
|
|
608 |
|
|
|
609 |
m_li.put("imagen", capsule.getImage());
|
|
|
610 |
m_li.put("nombre", capsule.getName());
|
|
|
611 |
m_li.put("uuid", capsule.getUuid());
|
|
|
612 |
m_li.put("topicuuid", capsule.getTopicUuid());
|
|
|
613 |
m_li.put("description", capsule.getDescription());
|
|
|
614 |
|
|
|
615 |
|
|
|
616 |
//Lleno la lista segun el requerimiento de filtro accionado por el usuario
|
|
|
617 |
|
|
|
618 |
List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
|
|
|
619 |
|
|
|
620 |
if (slides.isEmpty()) {
|
|
|
621 |
|
|
|
622 |
// Log.e("Capsula","Es omitida, no tiene slides");
|
|
|
623 |
} else {
|
|
|
624 |
|
|
|
625 |
|
|
|
626 |
if (progress == null) {
|
|
|
627 |
|
|
|
628 |
if (buscar.equals("")) {
|
|
|
629 |
|
|
|
630 |
capsuleList.add(m_li);
|
|
|
631 |
|
|
|
632 |
|
|
|
633 |
} else {
|
|
|
634 |
String nombre= capsule.getName();
|
|
|
635 |
String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
|
|
|
636 |
normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
|
|
|
637 |
if (normalizada.matches("(?i).*" + buscar + ".*")) {
|
|
|
638 |
capsuleList.add(m_li);
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
}
|
|
|
642 |
|
|
|
643 |
}
|
|
|
644 |
|
|
|
645 |
}
|
|
|
646 |
|
|
|
647 |
}
|
|
|
648 |
|
|
|
649 |
|
|
|
650 |
|
|
|
651 |
}
|
|
|
652 |
|
|
|
653 |
}
|
|
|
654 |
else if (tabposition.equals("cursando"))
|
|
|
655 |
{
|
|
|
656 |
|
|
|
657 |
HashMap<String, String> m_li;
|
|
|
658 |
List<Progress> progress;
|
|
|
659 |
Capsule capsule;
|
|
|
660 |
|
|
|
661 |
|
|
|
662 |
|
|
|
663 |
progress = progressDao.selectAllCapsulesProgress();
|
|
|
664 |
|
|
|
665 |
for(Progress dbProgress : progress) {
|
|
|
666 |
m_li = new HashMap<>();
|
|
|
667 |
|
|
|
668 |
capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
|
|
|
669 |
|
|
|
670 |
m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
|
|
|
671 |
m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
|
|
|
672 |
m_li.put("progress", String.valueOf(dbProgress.getProgress()));
|
|
|
673 |
m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
|
|
|
674 |
m_li.put("agregado",dbProgress.getAddedOn());
|
|
|
675 |
|
|
|
676 |
|
6 |
gabriel |
677 |
if(capsule == null)
|
|
|
678 |
{
|
|
|
679 |
Log.e("El objeto es"," nulo");
|
|
|
680 |
}
|
|
|
681 |
else {
|
|
|
682 |
m_li.put("imagen", capsule.getImage());
|
|
|
683 |
m_li.put("nombre", capsule.getName());
|
|
|
684 |
m_li.put("uuid", capsule.getUuid());
|
|
|
685 |
m_li.put("topicuuid", capsule.getTopicUuid());
|
|
|
686 |
m_li.put("description", capsule.getDescription());
|
1 |
gabriel |
687 |
|
|
|
688 |
|
6 |
gabriel |
689 |
|
1 |
gabriel |
690 |
//Log.e("Lista",""+m_li);
|
|
|
691 |
//Lleno la lista segun el requerimiento de filtro accionado por el usuario
|
|
|
692 |
|
|
|
693 |
List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
|
|
|
694 |
|
|
|
695 |
if (slides.isEmpty()) {
|
|
|
696 |
|
|
|
697 |
// Log.e("Capsula","Es omitida, no tiene slides");
|
|
|
698 |
} else {
|
|
|
699 |
|
|
|
700 |
if(dbProgress.getProgress() <= 100 && dbProgress.getCompleted()==0)
|
|
|
701 |
{
|
|
|
702 |
if (buscar.equals("")) {
|
|
|
703 |
capsuleList.add(m_li);
|
|
|
704 |
|
|
|
705 |
} else {
|
|
|
706 |
String nombre= capsule.getName();
|
|
|
707 |
String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
|
|
|
708 |
normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
|
|
|
709 |
if (normalizada.matches("(?i).*" + buscar + ".*")) {
|
|
|
710 |
capsuleList.add(m_li);
|
|
|
711 |
}
|
|
|
712 |
|
|
|
713 |
}
|
|
|
714 |
}}
|
6 |
gabriel |
715 |
}}}
|
1 |
gabriel |
716 |
|
|
|
717 |
else if (tabposition.equals("finalizados")){
|
|
|
718 |
|
|
|
719 |
HashMap<String, String> m_li;
|
|
|
720 |
List<Progress> progress;
|
|
|
721 |
Capsule capsule;
|
|
|
722 |
|
|
|
723 |
|
|
|
724 |
|
|
|
725 |
progress = progressDao.selectAllCapsulesProgress();
|
|
|
726 |
|
|
|
727 |
for(Progress dbProgress : progress) {
|
|
|
728 |
m_li = new HashMap<>();
|
|
|
729 |
|
|
|
730 |
capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
|
|
|
731 |
|
|
|
732 |
m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
|
|
|
733 |
m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
|
|
|
734 |
m_li.put("progress", String.valueOf(dbProgress.getProgress()));
|
|
|
735 |
m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
|
|
|
736 |
m_li.put("agregado",dbProgress.getAddedOn());
|
|
|
737 |
|
6 |
gabriel |
738 |
if(capsule == null)
|
|
|
739 |
{
|
|
|
740 |
Log.e("El objeto esta", "nulo");
|
|
|
741 |
}
|
|
|
742 |
else{
|
1 |
gabriel |
743 |
|
|
|
744 |
m_li.put("imagen", capsule.getImage());
|
|
|
745 |
m_li.put("nombre", capsule.getName());
|
|
|
746 |
m_li.put("uuid", capsule.getUuid());
|
|
|
747 |
m_li.put("topicuuid", capsule.getTopicUuid());
|
|
|
748 |
m_li.put("description", capsule.getDescription());
|
|
|
749 |
|
|
|
750 |
//Lleno la lista segun el requerimiento de filtro accionado por el usuario
|
|
|
751 |
|
|
|
752 |
List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
|
|
|
753 |
|
|
|
754 |
if (slides.isEmpty()) {
|
|
|
755 |
|
|
|
756 |
// Log.e("Capsula","Es omitida, no tiene slides");
|
|
|
757 |
} else {
|
|
|
758 |
if(dbProgress.getProgress() >= 100 && dbProgress.getCompleted()==1){
|
|
|
759 |
|
|
|
760 |
if (buscar.equals("")) {
|
|
|
761 |
//capsule.getCompleted();
|
|
|
762 |
capsuleList.add(m_li);
|
|
|
763 |
|
|
|
764 |
} else {
|
|
|
765 |
String nombre= capsule.getName();
|
|
|
766 |
String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
|
|
|
767 |
normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
|
|
|
768 |
if (normalizada.matches("(?i).*" + buscar + ".*")) {
|
|
|
769 |
capsuleList.add(m_li);
|
|
|
770 |
}
|
|
|
771 |
|
|
|
772 |
}
|
|
|
773 |
}
|
|
|
774 |
}
|
6 |
gabriel |
775 |
}}}
|
1 |
gabriel |
776 |
|
|
|
777 |
|
|
|
778 |
}
|
|
|
779 |
|
|
|
780 |
|
|
|
781 |
@Override
|
|
|
782 |
public void onItemClick(int position, View v) {
|
|
|
783 |
|
|
|
784 |
// Log.e("Evento","del click"+position);
|
|
|
785 |
|
|
|
786 |
|
|
|
787 |
iTwoGetSkills.getPreference().setCapsuleUuidActive(capsuleList.get(position).get("uuid"));
|
|
|
788 |
iTwoGetSkills.getPreference().setTopicUuidActive(capsuleList.get(position).get("topicuuid"));
|
|
|
789 |
iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
|
|
|
790 |
|
|
|
791 |
iTwoGetSkills.getPreference().setOrigennavigation("welcome");
|
8 |
gabriel |
792 |
iTwoGetSkills.hideKeyboard(v); //Ocultamos el teclado
|
1 |
gabriel |
793 |
// Log.e("Completada",""+capsuleList.get(position).get("completado"));
|
|
|
794 |
|
|
|
795 |
// Log.e("Capsula","topic active"+mDataSet.get(viewHolder.getAbsoluteAdapterPosition()).get("topicuuid"));
|
|
|
796 |
|
|
|
797 |
}
|
|
|
798 |
}
|