| 2 |
gabriel |
1 |
package com.cesams.twogetskills.fragment;
|
|
|
2 |
|
|
|
3 |
import android.os.Bundle;
|
|
|
4 |
|
| 9 |
gabriel |
5 |
import androidx.annotation.Nullable;
|
| 2 |
gabriel |
6 |
import androidx.fragment.app.Fragment;
|
|
|
7 |
import androidx.lifecycle.LifecycleOwner;
|
|
|
8 |
import androidx.lifecycle.Observer;
|
|
|
9 |
import androidx.lifecycle.ViewModelProvider;
|
|
|
10 |
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
11 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
12 |
|
| 9 |
gabriel |
13 |
import android.text.Layout;
|
| 2 |
gabriel |
14 |
import android.util.Log;
|
| 8 |
gabriel |
15 |
import android.view.DragEvent;
|
| 2 |
gabriel |
16 |
import android.view.LayoutInflater;
|
|
|
17 |
import android.view.View;
|
|
|
18 |
import android.view.ViewGroup;
|
| 9 |
gabriel |
19 |
import android.widget.Button;
|
| 8 |
gabriel |
20 |
import android.widget.EditText;
|
| 9 |
gabriel |
21 |
import android.widget.ImageView;
|
|
|
22 |
import android.widget.ProgressBar;
|
| 2 |
gabriel |
23 |
import android.widget.TextView;
|
| 8 |
gabriel |
24 |
import android.widget.Toast;
|
| 2 |
gabriel |
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;
|
| 8 |
gabriel |
33 |
import com.cesams.twogetskills.activity.MainActivity;
|
| 2 |
gabriel |
34 |
import com.cesams.twogetskills.adapter.CapsuleListViewAdapter;
|
|
|
35 |
import com.cesams.twogetskills.adapter.CardViewAdapter;
|
| 4 |
gabriel |
36 |
import com.cesams.twogetskills.adapter.TabsCapsulesAdapter;
|
| 2 |
gabriel |
37 |
import com.cesams.twogetskills.dao.CapsuleDao;
|
|
|
38 |
import com.cesams.twogetskills.dao.ProgressDao;
|
|
|
39 |
import com.cesams.twogetskills.dao.TopicDao;
|
|
|
40 |
import com.cesams.twogetskills.entity.Capsule;
|
|
|
41 |
import com.cesams.twogetskills.entity.Progress;
|
|
|
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;
|
|
|
45 |
import com.cesams.twogetskills.viewmodel.CapsuleViewModel;
|
|
|
46 |
|
|
|
47 |
import java.util.ArrayList;
|
| 9 |
gabriel |
48 |
import java.util.Calendar;
|
| 2 |
gabriel |
49 |
import java.util.HashMap;
|
|
|
50 |
import java.util.List;
|
| 9 |
gabriel |
51 |
import java.util.Random;
|
|
|
52 |
import java.util.TimeZone;
|
| 2 |
gabriel |
53 |
|
|
|
54 |
/**
|
|
|
55 |
* A simple {@link Fragment} subclass.
|
|
|
56 |
* Use the {@link WelcomeFragment#newInstance} factory method to
|
|
|
57 |
* create an instance of this fragment.
|
|
|
58 |
*/
|
|
|
59 |
public class WelcomeFragment extends Fragment implements CapsuleListViewAdapter.ItemClickListener, LifecycleOwner {
|
|
|
60 |
|
| 9 |
gabriel |
61 |
TextView username, titulotarjeta, progresoporcentaje; ProgressBar progresotarjeta;
|
|
|
62 |
private ITwoGetSkills iTwoGetSkills; View card;
|
| 2 |
gabriel |
63 |
ArrayList<HashMap<String, String>> capsuleList;
|
| 9 |
gabriel |
64 |
private CardViewAdapter adapter; ImageView imagetarjeta;
|
| 4 |
gabriel |
65 |
private TabsCapsulesAdapter adapter2;
|
|
|
66 |
RecyclerView capsulas, categorizados;
|
| 9 |
gabriel |
67 |
EditText busqueda; TextView textowelcome; Button continuar;
|
| 2 |
gabriel |
68 |
|
|
|
69 |
public WelcomeFragment() {
|
|
|
70 |
// Required empty public constructor
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public static WelcomeFragment newInstance() {
|
|
|
74 |
WelcomeFragment fragment = new WelcomeFragment();
|
|
|
75 |
return fragment;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
public void onCreate(Bundle savedInstanceState) {
|
|
|
80 |
super.onCreate(savedInstanceState);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
@Override
|
|
|
84 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
85 |
Bundle savedInstanceState) {
|
|
|
86 |
|
| 8 |
gabriel |
87 |
|
| 2 |
gabriel |
88 |
iTwoGetSkills = (ITwoGetSkills) getActivity();
|
| 8 |
gabriel |
89 |
iTwoGetSkills.showNavigationAndToolbar();
|
| 2 |
gabriel |
90 |
|
|
|
91 |
View view= inflater.inflate(R.layout.fragment_welcome, container, false);
|
|
|
92 |
|
|
|
93 |
username=view.findViewById(R.id.textView14);
|
| 8 |
gabriel |
94 |
textowelcome= view.findViewById(R.id.textView15);
|
|
|
95 |
busqueda=view.findViewById(R.id.busqueda);
|
| 9 |
gabriel |
96 |
card= view.findViewById(R.id.include);
|
| 8 |
gabriel |
97 |
capsuleList = new ArrayList<>();
|
| 2 |
gabriel |
98 |
|
| 9 |
gabriel |
99 |
//Tarjeta Principal
|
|
|
100 |
titulotarjeta = view.findViewById(R.id.titleview); progresotarjeta= view.findViewById(R.id.progressBar2); imagetarjeta= view.findViewById(R.id.imagelist);
|
|
|
101 |
continuar = view.findViewById(R.id.button); progresoporcentaje = view.findViewById(R.id.textView16);
|
|
|
102 |
|
|
|
103 |
|
| 2 |
gabriel |
104 |
username.setText("¡Hola, "+(iTwoGetSkills.getPreference().getFirstName() +"!"));
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
loadData();
|
|
|
108 |
|
| 8 |
gabriel |
109 |
busqueda.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
|
110 |
@Override
|
|
|
111 |
public void onFocusChange(View v, boolean hasFocus) {
|
|
|
112 |
if(hasFocus)
|
|
|
113 |
{
|
| 9 |
gabriel |
114 |
card.setVisibility(View.GONE);
|
| 8 |
gabriel |
115 |
username.setVisibility(View.GONE);
|
|
|
116 |
textowelcome.setVisibility(View.GONE);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
}
|
|
|
120 |
});
|
|
|
121 |
|
|
|
122 |
|
| 2 |
gabriel |
123 |
adapter = new CardViewAdapter(getContext(),capsuleList);
|
| 4 |
gabriel |
124 |
adapter2 = new TabsCapsulesAdapter(getContext(),capsuleList);
|
| 2 |
gabriel |
125 |
|
|
|
126 |
capsulas = view.findViewById(R.id.capsulescontinuos);
|
|
|
127 |
GridLayoutManager layoutausar = new GridLayoutManager(getContext(),1,GridLayoutManager.HORIZONTAL, false);
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
capsulas.setLayoutManager(layoutausar);
|
|
|
131 |
capsulas.setAdapter(adapter);
|
|
|
132 |
|
| 4 |
gabriel |
133 |
categorizados = view.findViewById(R.id.categorizados);
|
|
|
134 |
GridLayoutManager layoutcategoria = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
|
|
|
135 |
categorizados.setLayoutManager(layoutcategoria);
|
|
|
136 |
categorizados.setAdapter(adapter2);
|
|
|
137 |
|
| 8 |
gabriel |
138 |
categorizados.setOnFlingListener(new RecyclerView.OnFlingListener() {
|
|
|
139 |
@Override
|
|
|
140 |
public boolean onFling(int velocityX, int velocityY) {
|
|
|
141 |
|
|
|
142 |
if (categorizados.canScrollVertically(-1) ) {
|
|
|
143 |
|
|
|
144 |
Log.e("Se activa", "On fling");
|
| 9 |
gabriel |
145 |
card.setVisibility(View.GONE);
|
| 8 |
gabriel |
146 |
username.setVisibility(View.GONE);
|
|
|
147 |
textowelcome.setVisibility(View.GONE);
|
|
|
148 |
}else
|
|
|
149 |
{
|
| 9 |
gabriel |
150 |
card.setVisibility(View.VISIBLE);
|
| 8 |
gabriel |
151 |
username.setVisibility(View.VISIBLE);
|
|
|
152 |
textowelcome.setVisibility(View.VISIBLE);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
return false;
|
|
|
156 |
}
|
|
|
157 |
});
|
|
|
158 |
|
|
|
159 |
/* categorizados.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
|
|
160 |
@Override
|
|
|
161 |
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
|
|
162 |
|
|
|
163 |
if (!categorizados.canScrollVertically(-1)) {
|
|
|
164 |
// Toast.makeText(getActivity(), "Last", Toast.LENGTH_LONG).show();
|
|
|
165 |
capsulas.setVisibility(View.VISIBLE);
|
|
|
166 |
username.setVisibility(View.VISIBLE);
|
|
|
167 |
textowelcome.setVisibility(View.VISIBLE);
|
|
|
168 |
Log.e("On scroll"," se activa");
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
}
|
|
|
172 |
});
|
|
|
173 |
*/
|
| 2 |
gabriel |
174 |
return view;
|
|
|
175 |
}
|
|
|
176 |
|
| 9 |
gabriel |
177 |
@Override
|
|
|
178 |
public void onResume() {
|
|
|
179 |
super.onResume();
|
|
|
180 |
loadContinuecard();
|
|
|
181 |
}
|
| 2 |
gabriel |
182 |
|
| 9 |
gabriel |
183 |
@Override
|
|
|
184 |
public void onHiddenChanged(boolean hidden) {
|
|
|
185 |
super.onHiddenChanged(hidden);
|
|
|
186 |
|
|
|
187 |
Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
|
|
|
188 |
|
|
|
189 |
if(!hidden) {
|
|
|
190 |
loadContinuecard();
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
private void loadContinuecard(){
|
|
|
195 |
|
|
|
196 |
Log.e("Cargo datos"," en tarjeta principal");
|
|
|
197 |
|
|
|
198 |
//Capsula de primera tarjeta
|
|
|
199 |
CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
|
|
|
200 |
|
|
|
201 |
Progress progress;
|
|
|
202 |
ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
|
|
|
203 |
|
|
|
204 |
List<Capsule> dbCapsules= capsuleDao.selectAll();
|
|
|
205 |
for(Capsule dbCapsule : dbCapsules)
|
|
|
206 |
{
|
|
|
207 |
progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
|
|
|
208 |
|
|
|
209 |
if (progress != null) {
|
|
|
210 |
|
|
|
211 |
Log.e("Progreso", ": " + progress.getProgress());
|
|
|
212 |
|
|
|
213 |
if (progress.getProgress() < 100) {
|
|
|
214 |
titulotarjeta.setText(dbCapsule.getName());
|
|
|
215 |
progresotarjeta.setProgress((int) progress.getProgress());
|
|
|
216 |
progresoporcentaje.setText("" + progress.getProgress() + " %");
|
|
|
217 |
|
|
|
218 |
iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
|
|
|
219 |
iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
|
|
|
220 |
|
|
|
221 |
if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
|
|
|
222 |
|
|
|
223 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
224 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
225 |
TimeZone tz = calendar.getTimeZone();
|
|
|
226 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
227 |
|
|
|
228 |
Random random = new Random(created);
|
|
|
229 |
int rand = 1000 + random.nextInt(8999);
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
|
|
|
233 |
String password = iTwoGetSkills.getPreference().getPassword();
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
String secret = MD5.generar(password + ':' + created + ':' + rand);
|
|
|
237 |
GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
|
|
|
238 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
239 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
|
|
|
240 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
241 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
242 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
243 |
.build());
|
|
|
244 |
|
|
|
245 |
RequestOptions options = new RequestOptions()
|
|
|
246 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
247 |
|
|
|
248 |
Glide.with(getContext()).load(url)
|
|
|
249 |
.thumbnail()
|
|
|
250 |
.apply(options)
|
|
|
251 |
.into(imagetarjeta);
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
continuar.setOnClickListener(v -> {
|
|
|
260 |
|
|
|
261 |
iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
|
|
|
262 |
});
|
|
|
263 |
|
|
|
264 |
//Fin de primer tarjeta
|
|
|
265 |
|
|
|
266 |
}
|
|
|
267 |
|
| 2 |
gabriel |
268 |
private void loadData()
|
|
|
269 |
{
|
|
|
270 |
|
|
|
271 |
TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
|
|
|
272 |
ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
|
|
|
273 |
|
|
|
274 |
List<Capsule> dbCapsules;
|
|
|
275 |
CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
|
|
|
276 |
|
| 9 |
gabriel |
277 |
|
|
|
278 |
|
|
|
279 |
|
| 2 |
gabriel |
280 |
for (Topic dbTopic : dbTopics) {
|
|
|
281 |
|
|
|
282 |
dbCapsules = capsuleDao.selectAllByTopicUuid(dbTopic.getUuid());
|
|
|
283 |
|
| 9 |
gabriel |
284 |
|
| 2 |
gabriel |
285 |
Capsule capsule;
|
|
|
286 |
Progress progress;
|
|
|
287 |
ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
|
|
|
288 |
|
|
|
289 |
HashMap<String, String> m_li;
|
|
|
290 |
|
| 9 |
gabriel |
291 |
|
|
|
292 |
|
| 2 |
gabriel |
293 |
for(Capsule dbCapsule : dbCapsules)
|
|
|
294 |
{
|
|
|
295 |
capsule = new Capsule();
|
|
|
296 |
capsule.setTopicUuid(dbCapsule.getTopicUuid());
|
|
|
297 |
capsule.setUuid(dbCapsule.getUuid());
|
|
|
298 |
capsule.setName(dbCapsule.getName());
|
|
|
299 |
capsule.setDescription(dbCapsule.getDescription());
|
|
|
300 |
capsule.setImage(dbCapsule.getImage());
|
|
|
301 |
capsule.setPosition(dbCapsule.getPosition());
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
m_li = new HashMap<>();
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
//m_li.put("copyright",copy);
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
|
|
|
312 |
if(progress != null) {
|
|
|
313 |
capsule.setCompleted( progress.getCompleted());
|
|
|
314 |
capsule.setViewSlides(progress.getViewSlides());
|
|
|
315 |
|
|
|
316 |
capsule.setTotalSlides( progress.getTotalSlides());
|
|
|
317 |
capsule.setProgress(progress.getProgress());
|
|
|
318 |
|
|
|
319 |
m_li.put("view", String.valueOf(progress.getViewSlides()));
|
|
|
320 |
m_li.put("total", String.valueOf(progress.getTotalSlides()));
|
|
|
321 |
m_li.put("progress", String.valueOf(progress.getProgress()));
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
m_li.put("imagen",capsule.getImage());
|
|
|
326 |
m_li.put("nombre",capsule.getName());
|
|
|
327 |
|
|
|
328 |
capsuleList.add(m_li);
|
|
|
329 |
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
@Override
|
|
|
340 |
public void onItemClick(View view, int position) {
|
|
|
341 |
|
|
|
342 |
}
|
|
|
343 |
}
|