Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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

Rev 62 Rev 63
Línea 7... Línea 7...
7
import androidx.cardview.widget.CardView;
7
import androidx.cardview.widget.CardView;
8
import androidx.fragment.app.Fragment;
8
import androidx.fragment.app.Fragment;
9
import androidx.recyclerview.widget.GridLayoutManager;
9
import androidx.recyclerview.widget.GridLayoutManager;
10
import androidx.recyclerview.widget.RecyclerView;
10
import androidx.recyclerview.widget.RecyclerView;
Línea -... Línea 11...
-
 
11
 
11
 
12
import android.os.Handler;
12
import android.text.Html;
13
import android.text.Html;
13
import android.util.Log;
14
import android.util.Log;
14
import android.view.LayoutInflater;
15
import android.view.LayoutInflater;
15
import android.view.View;
16
import android.view.View;
Línea 51... Línea 52...
51
import java.util.ArrayList;
52
import java.util.ArrayList;
52
import java.util.Calendar;
53
import java.util.Calendar;
53
import java.util.HashMap;
54
import java.util.HashMap;
54
import java.util.Random;
55
import java.util.Random;
55
import java.util.TimeZone;
56
import java.util.TimeZone;
-
 
57
import java.util.concurrent.TimeUnit;
Línea 56... Línea 58...
56
 
58
 
57
import okhttp3.Call;
59
import okhttp3.Call;
-
 
60
import okhttp3.FormBody;
58
import okhttp3.FormBody;
61
import okhttp3.Interceptor;
59
import okhttp3.OkHttpClient;
62
import okhttp3.OkHttpClient;
60
import okhttp3.Request;
63
import okhttp3.Request;
61
import okhttp3.RequestBody;
64
import okhttp3.RequestBody;
Línea 103... Línea 106...
103
 
106
 
Línea 104... Línea 107...
104
        adapter.setClickListener(this);
107
        adapter.setClickListener(this);
Línea -... Línea 108...
-
 
108
 
105
 
109
        loaddata();
Línea 106... Línea 110...
106
        loaddata();
110
 
Línea 107... Línea 111...
107
 
111
 
Línea 195... Línea 199...
195
        });
199
        });
Línea 196... Línea 200...
196
 
200
 
197
        return view;
201
        return view;
Línea -... Línea 202...
-
 
202
}
-
 
203
 
-
 
204
    private final Handler taskHandler = new android.os.Handler();
-
 
205
 
-
 
206
    private final Runnable repeatativeTaskRunnable = new Runnable() {
-
 
207
        public void run() {
-
 
208
                    loadComments();
-
 
209
                    Log.e("Ando","cargando comentarios");
-
 
210
        }
-
 
211
    };
-
 
212
 
-
 
213
    void startHandler() {
-
 
214
        taskHandler.postDelayed(repeatativeTaskRunnable, 5 * 1000);
-
 
215
    }
-
 
216
 
-
 
217
    void stopHandler() {
-
 
218
        taskHandler.removeCallbacks(repeatativeTaskRunnable);
198
}
219
    }
Línea 199... Línea 220...
199
 
220
 
Línea 200... Línea 221...
200
    public void loadComments(){
221
    public void loadComments(){
Línea 225... Línea 246...
225
                    public void onResponse(Call call, Response response)
246
                    public void onResponse(Call call, Response response)
226
                            throws IOException {
247
                            throws IOException {
227
                        Log.d("TAG", "Response :  " + response.body().toString());
248
                        Log.d("TAG", "Response :  " + response.body().toString());
Línea 228... Línea 249...
228
 
249
 
-
 
250
                        processResponseSyncToServer(response.body().string());
229
                        processResponseSyncToServer(response.body().string());
251
                        stopHandler();
Línea 230... Línea 252...
230
                    }
252
                    }
231
 
253
 
-
 
254
                    public void onFailure(Call call, IOException e) {
232
                    public void onFailure(Call call, IOException e) {
255
                        Log.d("Tag", "Error :  " + e.getMessage());
233
                        Log.d("Tag", "Error :  " + e.getMessage());
256
                        startHandler();
234
                    }
257
                    }
-
 
258
                });
235
                });
259
            } catch (Exception e) {
236
            } catch (Exception e) {
260
                Log.e("Exception load"," comentarios"+e);
237
            }
261
            }
238
        }
262
        }
239
        else
263
        else
240
        {
264
        {
-
 
265
            descripcion.setVisibility(View.VISIBLE);
241
            descripcion.setVisibility(View.VISIBLE);
266
            descripcion.setText("No tienes conexión en este momento");
Línea 242... Línea 267...
242
            descripcion.setText("No tienes conexión en este momento");
267
            startHandler();
Línea 285... Línea 310...
285
                        processResponseSyncToServer(response.body().string());
310
                        processResponseSyncToServer(response.body().string());
286
                    }
311
                    }
Línea 287... Línea 312...
287
 
312
 
288
                    public void onFailure(Call call, IOException e) {
313
                    public void onFailure(Call call, IOException e) {
-
 
314
                        Log.d("Tag", "Error :  " + e.getMessage());
289
                        Log.d("Tag", "Error :  " + e.getMessage());
315
 
290
                    }
316
                    }
291
                });
317
                });
292
            } catch (Exception e) {
318
            } catch (Exception e) {
293
            }
319
            }
Línea 316... Línea 342...
316
                if(jsonObjectData.has("message"))
342
                if(jsonObjectData.has("message"))
317
                {
343
                {
Línea 318... Línea 344...
318
 
344
 
319
                    if(jsonObjectData.getString("message").equals("El comentario ha sido borrado con éxito"))
345
                    if(jsonObjectData.getString("message").equals("El comentario ha sido borrado con éxito"))
320
                    {
346
                    {
321
                        getActivity().runOnUiThread(() -> Toast.makeText(getActivity().getApplicationContext(), "¡Comentario eliminado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
347
                        requireActivity().runOnUiThread(() -> Toast.makeText(requireActivity().getApplicationContext(), "¡Comentario eliminado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
322
                        loadComments();
348
                        loadComments();
323
                    }
349
                    }
324
                    else {
350
                    else {
325
                        getActivity().runOnUiThread(() -> Toast.makeText(getActivity().getApplicationContext(), "¡Comentario enviado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
351
                        requireActivity().runOnUiThread(() -> Toast.makeText(requireActivity().getApplicationContext(), "¡Comentario enviado, cargando comentarios..!", Toast.LENGTH_SHORT).show());
326
                        getActivity().runOnUiThread(() -> loaddata());
352
                        requireActivity().runOnUiThread(this::loaddata);
-
 
353
                        requireActivity().runOnUiThread(() -> tabscapsule.selectTab(tabscapsule.getTabAt(1), true));
-
 
354
                        requireActivity().runOnUiThread(() -> comentar.setText(""));
327
                        getActivity().runOnUiThread(() -> tabscapsule.selectTab(tabscapsule.getTabAt(1), true));
355
 
328
                    }
356
                    }
Línea 329... Línea 357...
329
                }
357
                }
330
 
358
 
Línea 356... Línea 384...
356
                    Log.e("Lista de comentarios"," "+commentList.toString());
384
                    Log.e("Lista de comentarios"," "+commentList.toString());
357
                  getActivity().runOnUiThread(new Runnable() {
385
                  getActivity().runOnUiThread(new Runnable() {
358
                      @Override
386
                      @Override
359
                      public void run() {
387
                      public void run() {
360
                          adapter.notifyDataSetChanged();
388
                          adapter.notifyDataSetChanged();
361
 
-
 
-
 
389
                          descripcion.setVisibility(View.GONE);
362
                      }
390
                      }
363
                  });
391
                  });
Línea 364... Línea 392...
364
 
392
 
Línea 386... Línea 414...
386
    public void onHiddenChanged(boolean hidden) {
414
    public void onHiddenChanged(boolean hidden) {
387
        super.onHiddenChanged(hidden);
415
        super.onHiddenChanged(hidden);
Línea 388... Línea 416...
388
 
416
 
Línea 389... Línea 417...
389
        if(!hidden) {
417
        if(!hidden) {
Línea 390... Línea 418...
390
 
418
 
-
 
419
            requireActivity().runOnUiThread(() -> {
Línea 391... Línea 420...
391
            getActivity().runOnUiThread(() -> {
420
 
Línea 493... Línea 522...
493
                                    String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
522
                                    String secret = MD5.generar(iTwoGetSkills.getPreference().getPassword() + ':' + created + ':' + rand);
Línea 494... Línea 523...
494
 
523
 
495
                                    Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
524
                                    Http http = new Http(getActivity().getCacheDir(), iTwoGetSkills.getPreference().getDeviceUuid(), secret, created, rand);
Línea -... Línea 525...
-
 
525
                                    OkHttpClient client = http.getHttpClient(false);
496
                                    OkHttpClient client = http.getHttpClient(false);
526
 
497
 
527
 
498
                                    RequestBody formBody = new FormBody.Builder()
528
                                    RequestBody formBody = new FormBody.Builder()
499
                                            .add("", "")
529
                                            .add("", "")
500
                                            .build();
530
                                            .build();
Línea 548... Línea 578...
548
            });
578
            });
Línea 549... Línea 579...
549
 
579
 
550
        }
580
        }
551
        else
581
        else
552
        {
582
        {
553
            Toast.makeText(getActivity().getApplicationContext(), "No tienes conexión en este momento para ver los detalles.", Toast.LENGTH_SHORT).show();
583
            Toast.makeText(requireActivity().getApplicationContext(), "No tienes conexión en este momento para ver los detalles.", Toast.LENGTH_SHORT).show();
554
        }
584
        }
555
    }
585
    }
556
}
586
}