app/src/main/java/cl/ucn/disc/dsm/thenews/activities/MainActivity.java
@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main);

    // Inflate the layout
    this.binding = ActivityMainBinding.inflate(getLayoutInflater());

    // Assign to the main view.
    setContentView(binding.getRoot());

    // Set the toolbar
    {
      this.setSupportActionBar(binding.toolbar);
    }

    // The Adapter + RecyclerView
    {
      // The Adapter
      this.noticiaAdapter = new NoticiaAdapter();

      // The Adapter
      this.binding.rvNoticias.setAdapter(this.noticiaAdapter);

      // The layout (ListView)
      this.binding.rvNoticias.setLayoutManager(new LinearLayoutManager(this));

      // The separator (line)
      this.binding.rvNoticias
          .addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    }

    // The ViewModel
    {
      // Build the NoticiaViewModel.
      this.noticiaViewModel = new ViewModelProvider(this).get(NoticiaViewModel.class);

      // Observe the list of noticia
      this.noticiaViewModel.getNoticias().observe(this,
          noticias -> this.noticiaAdapter.setNoticias(noticias));

      // Observe the exception
      this.noticiaViewModel.getException().observe(this, this:: showException);

    }

    // The refresh
    {
      this.binding.swlRefresh.setOnRefreshListener(() -> {
        log.debug("Refreshing ..");

        // Run in background
        AsyncTask.execute(() -> {

          // All ok
          final int size = this.noticiaViewModel.refresh();
          if (size != -1) {

            // In the UI
            runOnUiThread(() -> {

              // Hide the loading
              this.binding.swlRefresh.setRefreshing(false);

              // Show a message.
              Toasty.success(this, "Noticias fetched: "
                  + size, Toast.LENGTH_SHORT, true).show();

            });
          }

        });

      });
    }


  }
/**
   * The onCreate.
   * @param savedInstanceState to use.
   */
The onCreate.
@param savedInstanceState to use.
The onCreate . @param savedInstanceState to use .
@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    {
      this.setSupportActionBar(binding.toolbar);
    }
    {
      this.noticiaAdapter = new NoticiaAdapter();
      this.binding.rvNoticias.setAdapter(this.noticiaAdapter);
      this.binding.rvNoticias.setLayoutManager(new LinearLayoutManager(this));
      this.binding.rvNoticias
          .addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    }
    {
      this.noticiaViewModel = new ViewModelProvider(this).get(NoticiaViewModel.class);
      this.noticiaViewModel.getNoticias().observe(this,
          noticias -> this.noticiaAdapter.setNoticias(noticias));
      this.noticiaViewModel.getException().observe(this, this:: showException);
    }
    {
      this.binding.swlRefresh.setOnRefreshListener(() -> {
        log.debug("Refreshing ..");
        AsyncTask.execute(() -> {
          final int size = this.noticiaViewModel.refresh();
          if (size != -1) {
            runOnUiThread(() -> {
              this.binding.swlRefresh.setRefreshing(false);
              Toasty.success(this, "Noticias fetched: "
                  + size, Toast.LENGTH_SHORT, true).show();
            });
          }
        });
      });
    }
  }
@ Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; this . binding = ActivityMainBinding . inflate ( getLayoutInflater ( ) ) ; setContentView ( binding . getRoot ( ) ) ; { this . setSupportActionBar ( binding . toolbar ) ; } { this . noticiaAdapter = new NoticiaAdapter ( ) ; this . binding . rvNoticias . setAdapter ( this . noticiaAdapter ) ; this . binding . rvNoticias . setLayoutManager ( new LinearLayoutManager ( this ) ) ; this . binding . rvNoticias . addItemDecoration ( new DividerItemDecoration ( this , DividerItemDecoration . VERTICAL ) ) ; } { this . noticiaViewModel = new ViewModelProvider ( this ) . get ( NoticiaViewModel . class ) ; this . noticiaViewModel . getNoticias ( ) . observe ( this , noticias -> this . noticiaAdapter . setNoticias ( noticias ) ) ; this . noticiaViewModel . getException ( ) . observe ( this , this :: showException ) ; } { this . binding . swlRefresh . setOnRefreshListener ( ( ) -> { log . debug ( "Refreshing .." ) ; AsyncTask . execute ( ( ) -> { final int size = this . noticiaViewModel . refresh ( ) ; if ( size != - 1 ) { runOnUiThread ( ( ) -> { this . binding . swlRefresh . setRefreshing ( false ) ; Toasty . success ( this , "Noticias fetched: " + size , Toast . LENGTH_SHORT , true ) . show ( ) ; } ) ; } } ) ; } ) ; } }
The onCreate.
The onCreate .
//setContentView(R.layout.activity_main); // Inflate the layout // Assign to the main view. // Set the toolbar // The Adapter + RecyclerView // The Adapter // The Adapter // The layout (ListView) // The separator (line) // The ViewModel // Build the NoticiaViewModel. // Observe the list of noticia // Observe the exception // The refresh // Run in background // All ok // In the UI // Hide the loading // Show a message.