Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 58 | Rev 60 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 58 Rev 59
Línea 62... Línea 62...
62
import okhttp3.Response;
62
import okhttp3.Response;
Línea 63... Línea 63...
63
 
63
 
Línea 64... Línea 64...
64
 
64
 
65
public class CapsuleDetail extends Fragment implements CommentListViewAdapter.ClickListener {
65
public class CapsuleDetail extends Fragment implements CommentListViewAdapter.ClickListener {
66
 
66
 
67
    private ITwoGetSkills iTwoGetSkills;  Capsule capsula;
67
    private ITwoGetSkills iTwoGetSkills;  Capsule capsula;  Progress progreso;
68
    TextView nombrecapsula, descripcion, puntuacion, comentarios, porcentaje,docomments;
68
    TextView nombrecapsula, descripcion, puntuacion, comentarios, porcentaje,docomments;
Línea 172... Línea 172...
172
 
172
 
173
            }
173
            }
Línea 174... Línea 174...
174
        });
174
        });
175
 
-
 
Línea 176... Línea 175...
176
        comentarBoton.setOnClickListener(v -> {
175
 
177
            Toast.makeText(getActivity().getApplicationContext(), "Enviando tu comentario..", Toast.LENGTH_SHORT).show();
176
        comentarBoton.setOnClickListener(v -> {
-
 
177
 
-
 
178
            if(progreso != null) {
Línea 178... Línea -...
178
 
-
 
179
            String bodyComment = comentar.getText().toString();
179
            if(progreso.getProgress() >0)
180
            String rating = String.valueOf(ratinglevel.getRating());
180
            {
Línea -... Línea 181...
-
 
181
                Toast.makeText(getActivity().getApplicationContext(), "Enviando tu comentario..", Toast.LENGTH_SHORT).show();
-
 
182
 
-
 
183
                String bodyComment = comentar.getText().toString();
-
 
184
                String rating = String.valueOf(ratinglevel.getRating());
Línea -... Línea 185...
-
 
185
 
-
 
186
                //Enviamos el comentario de la capsula
-
 
187
                addComment(capsula.getUuid(),
-
 
188
                        bodyComment,rating);
181
 
189
            }
Línea 182... Línea 190...
182
            //Enviamos el comentario de la capsula
190
 
183
            addComment(capsula.getUuid(),
191
            }
Línea 295... Línea 303...
295
 
303
 
296
 
304
 
Línea 297... Línea 305...
297
                if(jsonObjectData.has("message"))
305
                if(jsonObjectData.has("message"))
298
                {
306
                {
299
 
307
 
300
                    if(jsonObjectData.getString("message").equals("El comentario ha sido borrado con exito"))
308
                    if(jsonObjectData.getString("message").equals("El comentario ha sido borrado con éxito"))
301
                    {
309
                    {
302
                        getActivity().runOnUiThread(() -> Toast.makeText(getActivity().getApplicationContext(), "¡Comentario eliminado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
310
                        getActivity().runOnUiThread(() -> Toast.makeText(getActivity().getApplicationContext(), "¡Comentario eliminado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
Línea 382... Línea 390...
382
    public void loaddata(){
390
    public void loaddata(){
Línea 383... Línea 391...
383
 
391
 
384
    CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
392
    CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
Línea 385... Línea 393...
385
    ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
393
    ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
Línea 386... Línea 394...
386
 
394
 
Línea 387... Línea 395...
387
    Progress progreso = progressDao.selectByCapsuleUuid(iTwoGetSkills.getCapsuleUuidActive());
395
    progreso = progressDao.selectByCapsuleUuid(iTwoGetSkills.getCapsuleUuidActive());
388
 
396
 
389
 
397
 
390
    capsula = capsuleDao.selectByUuid(iTwoGetSkills.getCapsuleUuidActive());
398
    capsula = capsuleDao.selectByUuid(iTwoGetSkills.getCapsuleUuidActive());
-
 
399
 
-
 
400
    nombrecapsula.setText(capsula.getName()); descripcion.setText(Html.fromHtml(capsula.getDescription(), Html.FROM_HTML_MODE_COMPACT));
-
 
401
    comentarios.setText("Comentarios: "+capsula.getTotal_comments()); puntuacion.setText("Puntuación: "+capsula.getTotal_rating());
391
 
402
    ratinglevel.setMax(5); ratinglevel.setRating(capsula.getTotal_rating());
392
    nombrecapsula.setText(capsula.getName()); descripcion.setText(Html.fromHtml(capsula.getDescription(), Html.FROM_HTML_MODE_COMPACT));
403
    ratinglevel.setEnabled(false);
393
    comentarios.setText("Comentarios: "+capsula.getTotal_comments()); puntuacion.setText("Puntuación: "+capsula.getTotal_rating());
404
    if(progreso != null) {
Línea 394... Línea 405...
394
    ratinglevel.setMax(5); ratinglevel.setRating(capsula.getTotal_rating());
405
        mProgressbar.setMax(progreso.getTotalSlides());
395
    ratinglevel.setEnabled(false);
406
        mProgressbar.setProgress(progreso.getViewSlides());
396
    mProgressbar.setMax(progreso.getTotalSlides()); mProgressbar.setProgress(progreso.getViewSlides()); porcentaje.setText(mDecimalFormat.format(progreso.getProgress()) + " %");
407
        porcentaje.setText(mDecimalFormat.format(progreso.getProgress()) + " %");
Línea 446... Línea 457...
446
                new DialogInterface.OnClickListener() {
457
                new DialogInterface.OnClickListener() {
447
                    @Override
458
                    @Override
448
                    public void onClick(DialogInterface arg0, int arg1) {
459
                    public void onClick(DialogInterface arg0, int arg1) {
Línea 449... Línea 460...
449
 
460
 
-
 
461
                       String urldelete= commentList.get(position).get("urldelete");
-
 
462
                       String user =commentList.get(position).get("user");
-
 
463
 
-
 
464
                       if(user.equals(iTwoGetSkills.getPreference().getFirstName()+" "+iTwoGetSkills.getPreference().getLastName()))
-
 
465
                       {
-
 
466
                           try {
-
 
467
                               TimeZone timeZone = TimeZone.getTimeZone("UTC");
-
 
468
                               Calendar calendar = Calendar.getInstance(timeZone);
-
 
469
                               int created =  (int) (calendar.getTimeInMillis() / 1000);
-
 
470
 
-
 
471
                               Random random = new Random(created);
-
 
472
                               int rand = 1000 + random.nextInt(8999);
-
 
473
 
-
 
474
                               String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' +  created + ':' + rand);
-
 
475
 
-
 
476
                               Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
-
 
477
                               OkHttpClient client = http.getHttpClient(false);
-
 
478
 
-
 
479
                               RequestBody formBody = new FormBody.Builder()
-
 
480
                                       .add("",  "")
-
 
481
                                       .build();
-
 
482
                               assert urldelete != null;
-
 
483
                               Request request = new Request.Builder()
-
 
484
                                       .url(urldelete).post(formBody)
-
 
485
                                       .build();
-
 
486
 
-
 
487
 
-
 
488
                               Call call = client.newCall(request);
-
 
489
                               call.enqueue(new okhttp3.Callback() {
-
 
490
                                   public void onResponse(Call call, Response response)
-
 
491
                                           throws IOException {
-
 
492
                                       Log.d("TAG", "Response :  " +  response.body().toString());
-
 
493
 
-
 
494
                                       processResponseSyncToServer(response.body().string());
-
 
495
                                   }
-
 
496
 
-
 
497
                                   public void onFailure(Call call, IOException e) {
-
 
498
                                       Log.d("Tag", "Error :  " +  e.getMessage());
-
 
499
                                   }
-
 
500
                               });
-
 
501
                           } catch (Exception e) {
-
 
502
                           }
-
 
503
                       }
-
 
504
                       else
-
 
505
                       {
-
 
506
                           Log.e("No es mi "," comentario");
-
 
507
                       }
Línea 450... Línea -...
450
                       String urldelete= commentList.get(position).get("urldelete");
-
 
451
 
-
 
452
                        try {
-
 
453
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
-
 
454
                            Calendar calendar = Calendar.getInstance(timeZone);
-
 
455
                            int created =  (int) (calendar.getTimeInMillis() / 1000);
-
 
456
 
-
 
457
                            Random random = new Random(created);
-
 
458
                            int rand = 1000 + random.nextInt(8999);
-
 
459
 
-
 
460
                            String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' +  created + ':' + rand);
-
 
461
 
-
 
462
                            Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
-
 
463
                            OkHttpClient client = http.getHttpClient(false);
-
 
464
 
-
 
465
                            RequestBody formBody = new FormBody.Builder()
-
 
466
                                    .add("",  "")
-
 
467
                                    .build();
-
 
468
                            assert urldelete != null;
-
 
469
                            Request request = new Request.Builder()
-
 
470
                                    .url(urldelete).post(formBody)
-
 
471
                                    .build();
-
 
472
 
-
 
473
 
-
 
474
                            Call call = client.newCall(request);
-
 
475
                            call.enqueue(new okhttp3.Callback() {
-
 
476
                                public void onResponse(Call call, Response response)
-
 
477
                                        throws IOException {
-
 
478
                                    Log.d("TAG", "Response :  " +  response.body().toString());
-
 
479
 
-
 
480
                                    processResponseSyncToServer(response.body().string());
-
 
481
                                }
-
 
482
 
-
 
483
                                public void onFailure(Call call, IOException e) {
-
 
484
                                    Log.d("Tag", "Error :  " +  e.getMessage());
-
 
485
                                }
-
 
486
                            });
-
 
487
                        } catch (Exception e) {
508
 
488
                        }
509
 
Línea 489... Línea 510...
489
                    }
510
                    }