Advertisement
Guest User

onReceive AlarmReceiver

a guest
Jan 22nd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.21 KB | None | 0 0
  1.  @Override
  2.     public void onReceive(Context context, Intent intent) {
  3.         Calendar calendar = Calendar.getInstance();
  4.         int year = calendar.get(Calendar.YEAR);
  5.         int month = calendar.get(Calendar.MONTH);
  6.         int dayOfMonth = calendar.get(Calendar.DATE);
  7.         calendar.set(year, month, dayOfMonth);
  8.         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
  9.         String glte = dateFormat.format(calendar.getTime());
  10.  
  11.         BaseAPIService service = UtilsAPI.getApiService();
  12.  
  13.         String type = intent.getStringExtra(EXTRA_TYPE);
  14.         String message = intent.getStringExtra(EXTRA_MESSAGE);
  15.         int idNotification = type.equalsIgnoreCase(TYPE_DAILY) ? ID_DAILY : ID_RELEASE;
  16.         Log.d("type", " " + type);
  17.         Log.d("message", " " + message);
  18.         Log.d("id", " " + idNotification);
  19.         if (idNotification == ID_DAILY) {
  20.             showAlarmNotification(context, TYPE_DAILY, message, idNotification);
  21.         } else {
  22.             Log.d("masuk release a", " MASUKKKKK!!");
  23.             //retrofit
  24.             List<MovieResponse> listRelease = new ArrayList<>();
  25.             service.getReleaseMovie(MyViewModel.api_key, glte, glte)
  26.                     .enqueue(new Callback<MovieResponse>() {
  27.                         @Override
  28.                         public void onResponse(Call<MovieResponse> call, Response<MovieResponse> response) {
  29.                             if (response.isSuccessful()) {
  30.                                 listRelease.add(response.body());
  31.                                 String result = response.toString();
  32.                                 Log.d("Response", "not null" + response.toString());
  33.                                 Log.d("cek alarm req", " Good");
  34.                                 try {
  35.                                     final ArrayList<MovieItem> list = new ArrayList<>();
  36.                                     JSONObject object = new JSONObject(result);
  37.                                     JSONArray array = object.getJSONArray("results");
  38.  
  39.                                     for (int i = 0; i < array.length(); i++) {
  40.                                         JSONObject movieObj = array.getJSONObject(i);
  41.                                         MovieItem item = new MovieItem(movieObj);
  42.                                         list.add(item);
  43.                                         Log.d("listMpvie", " "+ list.size());
  44.                                     }
  45.                                 }catch (JSONException e){
  46.                                     e.printStackTrace();
  47.                                 }
  48.                             } else {
  49.                                 listRelease.add(null);
  50.                                 Log.d("Response : ", "null");
  51.                             }
  52.                         }
  53.  
  54.                         @Override
  55.                         public void onFailure(Call<MovieResponse> call, Throwable t) {
  56.                             listRelease.add(null);
  57.                             Log.d("Response : ", "null");
  58.                         }
  59.                     });
  60. //            List<MovieItem> movieItems;
  61. //            Log.d("bawah listmovie: ", " ");
  62. //            for (MovieResponse movieResponse : listRelease ){
  63. //                movieItems = movieResponse.getResults();
  64. //                Log.d("movieitem al: ", " "+movieItems.size());
  65. //            }
  66.  
  67. //            MainRepo repo = MainRepo.getInstance();
  68. //            List<MovieResponse> movieResponses = repo.getMovieRelease(MyViewModel.api_key, glte, glte);
  69. //            List<MovieItem> movieItems = new ArrayList<>();
  70. //            for (MovieResponse movieResponse : movieResponses){
  71. //                movieItems = movieResponse.getResults();
  72. //            }
  73. //            for (MovieItem item : movieItems){
  74. //                Log.d("title", " " + item.getTitle());
  75. //            }
  76.  
  77. //            new MainRepo.MyAsyncTask(output -> {
  78. //                for (int i = 0; i < output.size(); i++) {
  79. //                    MovieItem item = output.get(i);
  80. //                    showAlarmNotification(context, item.getTitle(), message, idNotification + i);
  81. //                }
  82. //            }).execute();
  83.         }
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement