Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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

Rev 59 Rev 60
Línea 199... Línea 199...
199
 
199
 
Línea 200... Línea 200...
200
    public void loadComments(){
200
    public void loadComments(){
Línea -... Línea 201...
-
 
201
 
201
 
202
        commentList.clear();
202
        commentList.clear();
203
 
203
 
204
        if(iTwoGetSkills.isConnectedInternet()) {
204
        try {
205
            try {
Línea 205... Línea 206...
205
            TimeZone timeZone = TimeZone.getTimeZone("UTC");
206
                TimeZone timeZone = TimeZone.getTimeZone("UTC");
206
            Calendar calendar = Calendar.getInstance(timeZone);
207
                Calendar calendar = Calendar.getInstance(timeZone);
Línea 207... Línea 208...
207
            int created =  (int) (calendar.getTimeInMillis() / 1000);
208
                int created = (int) (calendar.getTimeInMillis() / 1000);
Línea 208... Línea 209...
208
 
209
 
209
            Random random = new Random(created);
210
                Random random = new Random(created);
Línea 210... Línea 211...
210
            int rand = 1000 + random.nextInt(8999);
211
                int rand = 1000 + random.nextInt(8999);
211
 
212
 
212
            String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' +  created + ':' + rand);
213
                String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
Línea 213... Línea 214...
213
 
214
 
214
            Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
215
                Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
215
            OkHttpClient client = http.getHttpClient(false);
216
                OkHttpClient client = http.getHttpClient(false);
216
 
217
 
217
            Request request = new Request.Builder()
218
                Request request = new Request.Builder()
Línea 218... Línea 219...
218
                    .url(Configuration.URL_COMMENTS+capsula.getUuid())
219
                        .url(Configuration.URL_COMMENTS + capsula.getUuid())
219
                    .build();
220
                        .build();
Línea 220... Línea 221...
220
 
221
 
221
 
222
 
222
            Call call = client.newCall(request);
223
                Call call = client.newCall(request);
223
            call.enqueue(new okhttp3.Callback() {
224
                call.enqueue(new okhttp3.Callback() {
224
                public void onResponse(Call call, Response response)
225
                    public void onResponse(Call call, Response response)
-
 
226
                            throws IOException {
-
 
227
                        Log.d("TAG", "Response :  " + response.body().toString());
-
 
228
 
-
 
229
                        processResponseSyncToServer(response.body().string());
-
 
230
                    }
-
 
231
 
225
                        throws IOException {
232
                    public void onFailure(Call call, IOException e) {
226
                    Log.d("TAG", "Response :  " +  response.body().toString());
-
 
Línea 227... Línea 233...
227
 
233
                        Log.d("Tag", "Error :  " + e.getMessage());
Línea 228... Línea 234...
228
                    processResponseSyncToServer(response.body().string());
234
                    }
229
                }
235
                });
230
 
236
            } catch (Exception e) {
231
                public void onFailure(Call call, IOException e) {
237
            }
Línea -... Línea 238...
-
 
238
        }
232
                    Log.d("Tag", "Error :  " +  e.getMessage());
239
        else
233
                }
240
        {
234
            });
241
            descripcion.setVisibility(View.VISIBLE);
235
        } catch (Exception e) {
242
            descripcion.setText("No tienes conexión en este momento");
236
        }
243
        }
237
 
244
 
238
 
245
 
239
 
246
    }
240
    }
247
 
241
 
248
 
242
 
249
    public void addComment(String capsuleUuid, String bodycomment, String rating)
243
    public void addComment(String capsuleUuid, String bodycomment, String rating)
250
    {
244
    {
251
        //Preparo el numero
245
        //Preparo el numero
252
        rating= rating.substring(0,1);
246
        rating= rating.substring(0,1);
253
 
247
 
254
        if(iTwoGetSkills.isConnectedInternet()) {
248
        try {
255
            try {
-
 
256
                TimeZone timeZone = TimeZone.getTimeZone("UTC");
-
 
257
                Calendar calendar = Calendar.getInstance(timeZone);
-
 
258
                int created = (int) (calendar.getTimeInMillis() / 1000);
-
 
259
 
-
 
260
                Random random = new Random(created);
-
 
261
                int rand = 1000 + random.nextInt(8999);
-
 
262
 
-
 
263
                String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
-
 
264
 
-
 
265
                Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
-
 
266
                OkHttpClient client = http.getHttpClient(false);
-
 
267
 
Línea 249... Línea -...
249
            TimeZone timeZone = TimeZone.getTimeZone("UTC");
-
 
250
            Calendar calendar = Calendar.getInstance(timeZone);
-
 
251
            int created =  (int) (calendar.getTimeInMillis() / 1000);
-
 
252
 
-
 
253
            Random random = new Random(created);
-
 
254
            int rand = 1000 + random.nextInt(8999);
-
 
255
 
-
 
256
            String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' +  created + ':' + rand);
-
 
257
 
-
 
258
            Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
-
 
259
            OkHttpClient client = http.getHttpClient(false);
-
 
260
 
-
 
261
            RequestBody formBody = new FormBody.Builder()
268
                RequestBody formBody = new FormBody.Builder()
262
                    .add("comment",  bodycomment)
269
                        .add("comment", bodycomment)
Línea 263... Línea 270...
263
                    .add("rating", rating)
270
                        .add("rating", rating)
264
                    .build();
271
                        .build();
265
 
272
 
266
            Request request = new Request.Builder()
273
                Request request = new Request.Builder()
267
                    .url(Configuration.URL_COMMENTS+capsuleUuid+"/add")
274
                        .url(Configuration.URL_COMMENTS + capsuleUuid + "/add")
-
 
275
                        .post(formBody)
-
 
276
                        .build();
-
 
277
 
-
 
278
 
268
                    .post(formBody)
279
                Call call = client.newCall(request);
269
                    .build();
280
                call.enqueue(new okhttp3.Callback() {
Línea 270... Línea 281...
270
 
281
                    public void onResponse(Call call, Response response)
Línea 448... Línea 459...
448
    }
459
    }
Línea 449... Línea 460...
449
 
460
 
450
    @Override
461
    @Override
Línea 451... Línea 462...
451
    public void onItemClick(int position, View v) {
462
    public void onItemClick(int position, View v) {
452
 
-
 
453
        Log.e("On","click");
-
 
454
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
-
 
455
        alertDialogBuilder.setMessage("¿Deseas eliminar este comentario?");
463
 
456
        alertDialogBuilder.setPositiveButton("Si, eliminarlo",
-
 
457
                new DialogInterface.OnClickListener() {
-
 
458
                    @Override
-
 
459
                    public void onClick(DialogInterface arg0, int arg1) {
-
 
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
                       }
-
 
508
 
-
 
509
 
-
 
510
                    }
-
 
Línea -... Línea 464...
-
 
464
        Log.e("On", "click");
-
 
465
        if (iTwoGetSkills.isConnectedInternet()) {
-
 
466
 
511
                });
467
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
512
 
468
            alertDialogBuilder.setMessage("¿Deseas eliminar este comentario?");
513
 
469
            alertDialogBuilder.setPositiveButton("Si, eliminarlo",
-
 
470
                    new DialogInterface.OnClickListener() {
-
 
471
                        @Override
-
 
472
                        public void onClick(DialogInterface arg0, int arg1) {
514
        alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
473
 
-
 
474
                            String urldelete = commentList.get(position).get("urldelete");
515
            @Override
475
                            String user = commentList.get(position).get("user");
-
 
476
 
-
 
477
                            if (user.equals(iTwoGetSkills.getPreference().getFirstName() + " " + iTwoGetSkills.getPreference().getLastName())) {
-
 
478
                                try {
-
 
479
                                    TimeZone timeZone = TimeZone.getTimeZone("UTC");
-
 
480
                                    Calendar calendar = Calendar.getInstance(timeZone);
-
 
481
                                    int created = (int) (calendar.getTimeInMillis() / 1000);
-
 
482
 
-
 
483
                                    Random random = new Random(created);
-
 
484
                                    int rand = 1000 + random.nextInt(8999);
-
 
485
 
-
 
486
                                    String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
-
 
487
 
-
 
488
                                    Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
-
 
489
                                    OkHttpClient client = http.getHttpClient(false);
516
            public void onClick(DialogInterface dialog, int which) {
490
 
517
 
491
                                    RequestBody formBody = new FormBody.Builder()
-
 
492
                                            .add("", "")
-
 
493
                                            .build();
518
            }
494
                                    assert urldelete != null;
-
 
495
                                    Request request = new Request.Builder()
-
 
496
                                            .url(urldelete).post(formBody)
-
 
497
                                            .build();
-
 
498
 
-
 
499
 
-
 
500
                                    Call call = client.newCall(request);
519
        });
501
                                    call.enqueue(new okhttp3.Callback() {
-
 
502
                                        public void onResponse(Call call, Response response)
520
        AlertDialog alertDialog = alertDialogBuilder.create();
503
                                                throws IOException {
-
 
504
                                            Log.d("TAG", "Response :  " + response.body().toString());
-
 
505
 
-
 
506
                                            processResponseSyncToServer(response.body().string());
-
 
507
                                        }
-
 
508
 
-
 
509
                                        public void onFailure(Call call, IOException e) {
-
 
510
                                            Log.d("Tag", "Error :  " + e.getMessage());
-
 
511
                                        }
-
 
512
                                    });
-
 
513
                                } catch (Exception e) {
-
 
514
                                }
-
 
515
                            } else {
-
 
516
                                Log.e("No es mi ", " comentario");
-
 
517
                            }
-
 
518
 
-
 
519
 
521
        alertDialog.show();
520
                        }
522
        alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.design_default_color_error, null));
521
                    });
523
        alertDialog.getButton(alertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorTextColor, null));
522
 
524
 
523
 
Línea -... Línea 524...
-
 
524
            alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
-
 
525
                @Override
-
 
526
                public void onClick(DialogInterface dialog, int which) {
-
 
527
 
-
 
528
                }
-
 
529
            });
-
 
530
            AlertDialog alertDialog = alertDialogBuilder.create();
-
 
531
            alertDialog.show();
-
 
532
            alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.design_default_color_error, null));
-
 
533
            alertDialog.getButton(alertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorTextColor, null));
Línea 525... Línea 534...
525
        alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
534
 
526
            @Override
535
            alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
Línea -... Línea 536...
-
 
536
                @Override
-
 
537
                public void onDismiss(DialogInterface dialogInterface) {
-
 
538
 
-
 
539
 
-
 
540
                }
527
            public void onDismiss(DialogInterface dialogInterface) {
541
            });
528
 
542
 
529
 
543
        }