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