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