14 |
gabriel |
1 |
package com.cesams.twogetskills.inconcert.fragment;
|
|
|
2 |
|
|
|
3 |
import android.app.AlertDialog;
|
|
|
4 |
import android.content.DialogInterface;
|
|
|
5 |
import android.os.Bundle;
|
|
|
6 |
|
|
|
7 |
import androidx.cardview.widget.CardView;
|
|
|
8 |
import androidx.fragment.app.Fragment;
|
|
|
9 |
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
10 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
11 |
|
|
|
12 |
import android.os.Handler;
|
|
|
13 |
import android.text.Html;
|
|
|
14 |
import android.util.Log;
|
|
|
15 |
import android.view.LayoutInflater;
|
|
|
16 |
import android.view.View;
|
|
|
17 |
import android.view.ViewGroup;
|
|
|
18 |
import android.widget.Button;
|
|
|
19 |
import android.widget.EditText;
|
|
|
20 |
import android.widget.ImageView;
|
|
|
21 |
import android.widget.ProgressBar;
|
|
|
22 |
import android.widget.RatingBar;
|
|
|
23 |
import android.widget.TextView;
|
|
|
24 |
import android.widget.Toast;
|
|
|
25 |
|
18 |
efrain |
26 |
|
14 |
gabriel |
27 |
import com.cesams.twogetskills.inconcert.Configuration;
|
|
|
28 |
import com.cesams.twogetskills.inconcert.Constants;
|
|
|
29 |
import com.cesams.twogetskills.inconcert.R;
|
|
|
30 |
import com.cesams.twogetskills.inconcert.activity.MainActivity;
|
|
|
31 |
import com.cesams.twogetskills.inconcert.adapter.CommentListViewAdapter;
|
|
|
32 |
import com.cesams.twogetskills.inconcert.dao.CapsuleDao;
|
|
|
33 |
import com.cesams.twogetskills.inconcert.dao.ProgressDao;
|
|
|
34 |
import com.cesams.twogetskills.inconcert.entity.Capsule;
|
|
|
35 |
import com.cesams.twogetskills.inconcert.entity.Progress;
|
|
|
36 |
import com.cesams.twogetskills.inconcert.library.Http;
|
18 |
efrain |
37 |
import com.cesams.twogetskills.inconcert.library.ImageService;
|
14 |
gabriel |
38 |
import com.cesams.twogetskills.inconcert.library.MD5;
|
|
|
39 |
import com.cesams.twogetskills.inconcert.skeleton.IReloadData;
|
|
|
40 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
41 |
import com.google.android.material.tabs.TabLayout;
|
|
|
42 |
|
|
|
43 |
import org.json.JSONArray;
|
|
|
44 |
import org.json.JSONException;
|
|
|
45 |
import org.json.JSONObject;
|
|
|
46 |
|
|
|
47 |
import java.io.IOException;
|
|
|
48 |
import java.text.DecimalFormat;
|
|
|
49 |
import java.util.ArrayList;
|
|
|
50 |
import java.util.Calendar;
|
|
|
51 |
import java.util.HashMap;
|
|
|
52 |
import java.util.Random;
|
|
|
53 |
import java.util.TimeZone;
|
|
|
54 |
import java.util.concurrent.TimeUnit;
|
|
|
55 |
|
|
|
56 |
import okhttp3.Call;
|
|
|
57 |
import okhttp3.FormBody;
|
|
|
58 |
import okhttp3.Interceptor;
|
|
|
59 |
import okhttp3.OkHttpClient;
|
|
|
60 |
import okhttp3.Request;
|
|
|
61 |
import okhttp3.RequestBody;
|
|
|
62 |
import okhttp3.Response;
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
public class CapsuleDetail extends Fragment implements CommentListViewAdapter.ClickListener {
|
|
|
66 |
|
|
|
67 |
private ITwoGetSkills iTwoGetSkills; Capsule capsula; Progress progreso;
|
|
|
68 |
TextView nombrecapsula, descripcion, puntuacion, comentarios, porcentaje,docomments;
|
|
|
69 |
ImageView capsuleImage; ProgressBar mProgressbar; private DecimalFormat mDecimalFormat; CardView tarjeta;
|
|
|
70 |
TabLayout tabscapsule; RecyclerView listadecomentarios; EditText comentar; Button comentarBoton, continuar; RatingBar ratinglevel;
|
|
|
71 |
CommentListViewAdapter adapter; ArrayList<HashMap<String, String>> commentList;
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
public CapsuleDetail() {
|
|
|
75 |
// Required empty public constructor
|
|
|
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 |
View view = inflater.inflate(R.layout.fragment_capsule_detail, container, false);
|
|
|
87 |
|
|
|
88 |
iTwoGetSkills = (ITwoGetSkills) getActivity();
|
|
|
89 |
ratinglevel = view.findViewById(R.id.ratingBar); continuar= view.findViewById(R.id.continuarbutton); tarjeta= view.findViewById(R.id.cardView3);
|
|
|
90 |
capsuleImage = view.findViewById(R.id.imageView4); mProgressbar= view.findViewById(R.id.progressBar3);
|
|
|
91 |
nombrecapsula = view.findViewById(R.id.textView19); descripcion = view.findViewById(R.id.textView20);
|
|
|
92 |
comentarios = view.findViewById(R.id.textView21); puntuacion = view.findViewById(R.id.textView22);
|
|
|
93 |
porcentaje = view.findViewById(R.id.textView17); mDecimalFormat = new DecimalFormat("#.##");
|
|
|
94 |
tabscapsule = view.findViewById(R.id.tabLayout2); listadecomentarios = view.findViewById(R.id.recyclerView);
|
|
|
95 |
comentar = view.findViewById(R.id.editTextComentar); comentarBoton = view.findViewById(R.id.button4); docomments=view.findViewById(R.id.textView23);
|
|
|
96 |
|
|
|
97 |
commentList = new ArrayList<>();
|
|
|
98 |
adapter = new CommentListViewAdapter(getContext(),commentList);
|
|
|
99 |
|
|
|
100 |
GridLayoutManager layoutcomments = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
|
|
|
101 |
listadecomentarios.setLayoutManager(layoutcomments);
|
|
|
102 |
listadecomentarios.setAdapter(adapter);
|
|
|
103 |
|
|
|
104 |
adapter.setClickListener(this);
|
|
|
105 |
|
|
|
106 |
loaddata();
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
comentar.setOnFocusChangeListener((v, hasFocus) -> {
|
|
|
110 |
|
|
|
111 |
if(hasFocus){
|
|
|
112 |
|
|
|
113 |
tarjeta.setVisibility(View.GONE);
|
|
|
114 |
}
|
|
|
115 |
else
|
|
|
116 |
{
|
|
|
117 |
tarjeta.setVisibility(View.VISIBLE);
|
|
|
118 |
iTwoGetSkills.hideKeyboard(v);
|
|
|
119 |
}
|
|
|
120 |
});
|
|
|
121 |
|
|
|
122 |
continuar.setOnClickListener(v -> iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES));
|
|
|
123 |
|
|
|
124 |
tabscapsule.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
125 |
@Override
|
|
|
126 |
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
127 |
int position = tab.getPosition();
|
|
|
128 |
|
|
|
129 |
if (position == 0) {
|
|
|
130 |
descripcion.setVisibility(View.VISIBLE);
|
|
|
131 |
descripcion.setText(Html.fromHtml(capsula.getDescription(), Html.FROM_HTML_MODE_COMPACT));
|
|
|
132 |
listadecomentarios.setVisibility(View.GONE);
|
|
|
133 |
comentar.setVisibility(View.GONE);
|
|
|
134 |
comentarBoton.setVisibility(View.GONE); ratinglevel.setVisibility(View.VISIBLE);
|
|
|
135 |
ratinglevel.setEnabled(false);
|
|
|
136 |
docomments.setVisibility(View.GONE);
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
} else if (position == 1) {
|
|
|
140 |
descripcion.setVisibility(View.GONE);
|
|
|
141 |
listadecomentarios.setVisibility(View.VISIBLE);
|
|
|
142 |
comentar.setVisibility(View.GONE);
|
|
|
143 |
ratinglevel.setVisibility(View.GONE);
|
18 |
efrain |
144 |
if(capsula.getTotalComments()==0)
|
14 |
gabriel |
145 |
{
|
|
|
146 |
descripcion.setVisibility(View.VISIBLE);
|
|
|
147 |
descripcion.setText(R.string.no_comments);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
comentarBoton.setVisibility(View.GONE);
|
|
|
151 |
docomments.setVisibility(View.GONE);
|
|
|
152 |
|
|
|
153 |
loadComments();
|
|
|
154 |
|
|
|
155 |
} else if (position == 2) {
|
|
|
156 |
descripcion.setVisibility(View.GONE);
|
|
|
157 |
listadecomentarios.setVisibility(View.GONE);
|
|
|
158 |
comentar.setVisibility(View.VISIBLE);
|
|
|
159 |
comentarBoton.setVisibility(View.VISIBLE); ratinglevel.setVisibility(View.VISIBLE);
|
|
|
160 |
ratinglevel.setEnabled(true);
|
|
|
161 |
docomments.setVisibility(View.VISIBLE);
|
|
|
162 |
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
@Override
|
|
|
167 |
public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
168 |
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
@Override
|
|
|
172 |
public void onTabReselected(TabLayout.Tab tab) {
|
|
|
173 |
|
|
|
174 |
}
|
|
|
175 |
});
|
|
|
176 |
|
|
|
177 |
comentarBoton.setOnClickListener(v -> {
|
|
|
178 |
|
|
|
179 |
if(progreso != null) {
|
|
|
180 |
if(progreso.getProgress() >0)
|
|
|
181 |
{
|
|
|
182 |
Toast.makeText(getActivity().getApplicationContext(), "Enviando tu comentario..", Toast.LENGTH_SHORT).show();
|
|
|
183 |
|
|
|
184 |
String bodyComment = comentar.getText().toString();
|
|
|
185 |
String rating = String.valueOf(ratinglevel.getRating());
|
|
|
186 |
|
|
|
187 |
// Log.e("La added_on"," "+capsula.getAddedOn());
|
|
|
188 |
//Enviamos el comentario de la capsula
|
|
|
189 |
addComment(capsula.getUuid(),
|
|
|
190 |
bodyComment,rating, capsula.getAddedOn());
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
}
|
|
|
194 |
else{
|
|
|
195 |
Toast.makeText(getActivity().getApplicationContext(), "Toma tiempo para ver esta cápsula antes de comentar", Toast.LENGTH_SHORT).show();
|
|
|
196 |
}
|
|
|
197 |
});
|
|
|
198 |
|
|
|
199 |
return view;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
private final Handler taskHandler = new android.os.Handler();
|
|
|
203 |
|
|
|
204 |
private final Runnable repeatativeTaskRunnable = new Runnable() {
|
|
|
205 |
public void run() {
|
|
|
206 |
loadComments();
|
|
|
207 |
Log.e("Ando","cargando comentarios");
|
|
|
208 |
}
|
|
|
209 |
};
|
|
|
210 |
|
|
|
211 |
void startHandler() {
|
|
|
212 |
taskHandler.postDelayed(repeatativeTaskRunnable, 5 * 1000);
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
void stopHandler() {
|
|
|
216 |
taskHandler.removeCallbacks(repeatativeTaskRunnable);
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public void loadComments(){
|
|
|
220 |
|
|
|
221 |
commentList.clear();
|
|
|
222 |
|
|
|
223 |
if(iTwoGetSkills.isConnectedInternet()) {
|
|
|
224 |
try {
|
|
|
225 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
226 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
227 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
228 |
|
|
|
229 |
Random random = new Random(created);
|
|
|
230 |
int rand = 1000 + random.nextInt(8999);
|
|
|
231 |
|
|
|
232 |
String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
|
|
|
233 |
|
|
|
234 |
Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
|
|
|
235 |
OkHttpClient client = http.getHttpClient(false);
|
|
|
236 |
|
|
|
237 |
Request request = new Request.Builder()
|
|
|
238 |
.url(Configuration.URL_COMMENTS + capsula.getUuid())
|
|
|
239 |
.build();
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
Call call = client.newCall(request);
|
|
|
243 |
call.enqueue(new okhttp3.Callback() {
|
|
|
244 |
public void onResponse(Call call, Response response)
|
|
|
245 |
throws IOException {
|
|
|
246 |
Log.d("TAG", "Response : " + response.body().toString());
|
|
|
247 |
|
|
|
248 |
processResponseSyncToServer(response.body().string());
|
|
|
249 |
stopHandler();
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
public void onFailure(Call call, IOException e) {
|
|
|
253 |
Log.d("Tag", "Error : " + e.getMessage());
|
|
|
254 |
startHandler();
|
|
|
255 |
}
|
|
|
256 |
});
|
|
|
257 |
} catch (Exception e) {
|
|
|
258 |
Log.e("Exception load"," comentarios"+e);
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
else
|
|
|
262 |
{
|
|
|
263 |
descripcion.setVisibility(View.VISIBLE);
|
|
|
264 |
descripcion.setText("No tienes conexión en este momento");
|
|
|
265 |
startHandler();
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
public void addComment(String capsuleUuid, String bodycomment, String rating, String added_on)
|
|
|
273 |
{
|
|
|
274 |
//Preparo el numero
|
|
|
275 |
rating= rating.substring(0,1);
|
|
|
276 |
|
|
|
277 |
if(iTwoGetSkills.isConnectedInternet()) {
|
|
|
278 |
try {
|
|
|
279 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
280 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
281 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
282 |
|
|
|
283 |
Random random = new Random(created);
|
|
|
284 |
int rand = 1000 + random.nextInt(8999);
|
|
|
285 |
|
|
|
286 |
String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
|
|
|
287 |
|
|
|
288 |
Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
|
|
|
289 |
OkHttpClient client = http.getHttpClient(false);
|
|
|
290 |
|
|
|
291 |
RequestBody formBody = new FormBody.Builder()
|
|
|
292 |
.add("comment", bodycomment)
|
|
|
293 |
.add("rating", rating)
|
|
|
294 |
.add("added_on",added_on)
|
|
|
295 |
.build();
|
|
|
296 |
|
|
|
297 |
Request request = new Request.Builder()
|
|
|
298 |
.url(Configuration.URL_COMMENTS + capsuleUuid + "/add")
|
|
|
299 |
.post(formBody)
|
|
|
300 |
.build();
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
Call call = client.newCall(request);
|
|
|
304 |
call.enqueue(new okhttp3.Callback() {
|
|
|
305 |
public void onResponse(Call call, Response response)
|
|
|
306 |
throws IOException {
|
|
|
307 |
Log.d("TAG", "Response : " + response.body().toString());
|
|
|
308 |
|
|
|
309 |
processResponseSyncToServer(response.body().string());
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
public void onFailure(Call call, IOException e) {
|
|
|
313 |
Log.d("Tag", "Error : " + e.getMessage());
|
|
|
314 |
|
|
|
315 |
}
|
|
|
316 |
});
|
|
|
317 |
} catch (Exception e) {
|
|
|
318 |
}
|
|
|
319 |
}else
|
|
|
320 |
{
|
|
|
321 |
Toast.makeText(getActivity().getApplicationContext(), "En este momento no tienes conexión para enviar el comentario", Toast.LENGTH_SHORT).show();
|
|
|
322 |
}
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
private void processResponseSyncToServer(String dataString)
|
|
|
327 |
{
|
|
|
328 |
boolean success = false;
|
|
|
329 |
long sync_id = 0;
|
|
|
330 |
JSONArray comentariosarray;
|
|
|
331 |
|
|
|
332 |
try {
|
|
|
333 |
JSONObject objJSON = new JSONObject(dataString);
|
|
|
334 |
success = objJSON.has("success") ? objJSON.getBoolean("success") : false;
|
|
|
335 |
if(success && objJSON.has("data")) {
|
|
|
336 |
JSONObject jsonObjectData = objJSON.getJSONObject("data");
|
|
|
337 |
|
|
|
338 |
Log.e("Respuesta server:", jsonObjectData.toString());
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
if(jsonObjectData.has("message"))
|
|
|
342 |
{
|
|
|
343 |
|
|
|
344 |
if(jsonObjectData.getString("message").equals("El comentario ha sido borrado con éxito"))
|
|
|
345 |
{
|
|
|
346 |
requireActivity().runOnUiThread(() -> Toast.makeText(requireActivity().getApplicationContext(), "¡Comentario eliminado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
|
|
|
347 |
loadComments();
|
|
|
348 |
}
|
|
|
349 |
else {
|
|
|
350 |
requireActivity().runOnUiThread(() -> Toast.makeText(requireActivity().getApplicationContext(), "¡Comentario enviado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
|
|
|
351 |
requireActivity().runOnUiThread(this::loaddata);
|
|
|
352 |
requireActivity().runOnUiThread(() -> tabscapsule.selectTab(tabscapsule.getTabAt(1), true));
|
|
|
353 |
requireActivity().runOnUiThread(() -> comentar.setText(""));
|
|
|
354 |
|
|
|
355 |
}
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
if(jsonObjectData.has("comments"))
|
|
|
359 |
{
|
|
|
360 |
//getActivity().runOnUiThread(() -> Toast.makeText(getActivity().getApplicationContext(), "Hay comentarios nuevos", Toast.LENGTH_SHORT).show());
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
comentariosarray = jsonObjectData.getJSONArray("comments");
|
|
|
364 |
Log.e("Comentarios",""+comentariosarray);
|
|
|
365 |
|
|
|
366 |
for(int i = 0; i < comentariosarray.length(); i++)
|
|
|
367 |
{
|
|
|
368 |
JSONObject objects = comentariosarray.getJSONObject(i);
|
|
|
369 |
HashMap<String, String> m_li;
|
|
|
370 |
m_li = new HashMap<>();
|
|
|
371 |
m_li.put("user", objects.getString("fullname"));
|
|
|
372 |
m_li.put("body", objects.getString("comment"));
|
|
|
373 |
m_li.put("fecha", objects.getString("date"));
|
|
|
374 |
m_li.put("rating", objects.getString("rating"));
|
|
|
375 |
m_li.put("image", objects.getString("image"));
|
|
|
376 |
m_li.put("urldelete", objects.getString("link_delete"));
|
|
|
377 |
|
|
|
378 |
commentList.add(m_li);
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
Log.e("Lista de comentarios"," "+commentList.toString());
|
|
|
384 |
getActivity().runOnUiThread(new Runnable() {
|
|
|
385 |
@Override
|
|
|
386 |
public void run() {
|
15 |
gabriel |
387 |
if(commentList.size() >0)
|
|
|
388 |
{
|
|
|
389 |
adapter.notifyDataSetChanged();
|
|
|
390 |
descripcion.setVisibility(View.GONE);
|
|
|
391 |
}
|
14 |
gabriel |
392 |
}
|
|
|
393 |
});
|
|
|
394 |
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
JSONObject capsule_update= jsonObjectData.getJSONObject("capsule");
|
|
|
399 |
|
|
|
400 |
CapsuleDao updatecapsule = iTwoGetSkills.getDatabase().getCapsuleDao();
|
|
|
401 |
updatecapsule.updateByUuid(capsula.getUuid(),capsule_update.getString("total_comments"),capsule_update.getString("total_rating"));
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
}
|
|
|
405 |
else
|
|
|
406 |
{
|
|
|
407 |
Log.e("Ocurrio un problema",objJSON.toString());
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
} catch (JSONException e) {
|
|
|
411 |
e.printStackTrace();
|
|
|
412 |
}
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
@Override
|
|
|
416 |
public void onHiddenChanged(boolean hidden) {
|
|
|
417 |
super.onHiddenChanged(hidden);
|
|
|
418 |
|
|
|
419 |
if(!hidden) {
|
|
|
420 |
|
|
|
421 |
requireActivity().runOnUiThread(() -> {
|
|
|
422 |
|
|
|
423 |
loaddata();
|
|
|
424 |
tabscapsule.selectTab(tabscapsule.getTabAt(0), true);
|
|
|
425 |
|
|
|
426 |
|
|
|
427 |
});
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
}
|
|
|
431 |
}
|
|
|
432 |
|
|
|
433 |
public void loaddata(){
|
|
|
434 |
|
|
|
435 |
CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
|
|
|
436 |
ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
|
|
|
437 |
|
|
|
438 |
progreso = progressDao.selectByCapsuleUuid(iTwoGetSkills.getCapsuleUuidActive());
|
|
|
439 |
|
|
|
440 |
|
|
|
441 |
capsula = capsuleDao.selectByUuid(iTwoGetSkills.getCapsuleUuidActive());
|
|
|
442 |
|
|
|
443 |
|
|
|
444 |
nombrecapsula.setText(capsula.getName()); descripcion.setText(Html.fromHtml(capsula.getDescription(), Html.FROM_HTML_MODE_COMPACT));
|
18 |
efrain |
445 |
comentarios.setText("Comentarios: "+capsula.getTotalComments()); puntuacion.setText("Puntuación: "+capsula.getTotalRating());
|
|
|
446 |
ratinglevel.setMax(5); ratinglevel.setRating(capsula.getTotalRating());
|
14 |
gabriel |
447 |
ratinglevel.setEnabled(false);
|
|
|
448 |
if(progreso != null) {
|
|
|
449 |
mProgressbar.setMax(progreso.getTotalSlides());
|
|
|
450 |
mProgressbar.setProgress(progreso.getViewSlides());
|
|
|
451 |
porcentaje.setText(mDecimalFormat.format(progreso.getProgress()) + " %");
|
|
|
452 |
}
|
|
|
453 |
else
|
|
|
454 |
{
|
|
|
455 |
mProgressbar.setMax(100);
|
|
|
456 |
mProgressbar.setProgress(0);
|
|
|
457 |
porcentaje.setText("0%");
|
|
|
458 |
}
|
|
|
459 |
iTwoGetSkills.setTitleActionBar(capsula.getName());
|
|
|
460 |
|
18 |
efrain |
461 |
ImageService.retrieve(getContext(), capsula.getImage(), capsuleImage);
|
14 |
gabriel |
462 |
|
18 |
efrain |
463 |
}
|
14 |
gabriel |
464 |
|
|
|
465 |
@Override
|
|
|
466 |
public void onResume() {
|
|
|
467 |
super.onResume();
|
|
|
468 |
loaddata();
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
@Override
|
|
|
472 |
public void onItemClick(int position, View v) {
|
|
|
473 |
|
|
|
474 |
Log.e("On", "click");
|
|
|
475 |
if (iTwoGetSkills.isConnectedInternet()) {
|
|
|
476 |
|
|
|
477 |
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
|
|
|
478 |
alertDialogBuilder.setMessage("¿Deseas eliminar este comentario?");
|
|
|
479 |
alertDialogBuilder.setPositiveButton("Si, eliminarlo",
|
|
|
480 |
new DialogInterface.OnClickListener() {
|
|
|
481 |
@Override
|
|
|
482 |
public void onClick(DialogInterface arg0, int arg1) {
|
|
|
483 |
|
|
|
484 |
String urldelete = commentList.get(position).get("urldelete");
|
|
|
485 |
String user = commentList.get(position).get("user");
|
|
|
486 |
|
|
|
487 |
if (user.equals(iTwoGetSkills.getPreference().getFirstName() + " " + iTwoGetSkills.getPreference().getLastName())) {
|
|
|
488 |
try {
|
|
|
489 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
490 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
491 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
492 |
|
|
|
493 |
Random random = new Random(created);
|
|
|
494 |
int rand = 1000 + random.nextInt(8999);
|
|
|
495 |
|
|
|
496 |
String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
|
|
|
497 |
|
|
|
498 |
Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
|
|
|
499 |
OkHttpClient client = http.getHttpClient(false);
|
|
|
500 |
|
|
|
501 |
|
|
|
502 |
RequestBody formBody = new FormBody.Builder()
|
|
|
503 |
.add("", "")
|
|
|
504 |
.build();
|
|
|
505 |
assert urldelete != null;
|
|
|
506 |
Request request = new Request.Builder()
|
|
|
507 |
.url(urldelete).post(formBody)
|
|
|
508 |
.build();
|
|
|
509 |
|
|
|
510 |
|
|
|
511 |
Call call = client.newCall(request);
|
|
|
512 |
call.enqueue(new okhttp3.Callback() {
|
|
|
513 |
public void onResponse(Call call, Response response)
|
|
|
514 |
throws IOException {
|
|
|
515 |
Log.d("TAG", "Response : " + response.body().toString());
|
|
|
516 |
|
|
|
517 |
processResponseSyncToServer(response.body().string());
|
|
|
518 |
}
|
|
|
519 |
|
|
|
520 |
public void onFailure(Call call, IOException e) {
|
|
|
521 |
Log.d("Tag", "Error : " + e.getMessage());
|
|
|
522 |
}
|
|
|
523 |
});
|
|
|
524 |
} catch (Exception e) {
|
|
|
525 |
}
|
|
|
526 |
} else {
|
|
|
527 |
Log.e("No es mi ", " comentario");
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
|
|
|
531 |
}
|
|
|
532 |
});
|
|
|
533 |
|
|
|
534 |
|
|
|
535 |
alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
536 |
@Override
|
|
|
537 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
538 |
|
|
|
539 |
}
|
|
|
540 |
});
|
|
|
541 |
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
542 |
alertDialog.show();
|
|
|
543 |
alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.design_default_color_error, null));
|
|
|
544 |
alertDialog.getButton(alertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorTextColor, null));
|
|
|
545 |
|
|
|
546 |
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
547 |
@Override
|
|
|
548 |
public void onDismiss(DialogInterface dialogInterface) {
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
}
|
|
|
552 |
});
|
|
|
553 |
|
|
|
554 |
}
|
|
|
555 |
else
|
|
|
556 |
{
|
|
|
557 |
Toast.makeText(requireActivity().getApplicationContext(), "No tienes conexión en este momento para ver los detalles.", Toast.LENGTH_SHORT).show();
|
|
|
558 |
}
|
|
|
559 |
}
|
|
|
560 |
}
|