zoo_app/app/src/main/java/com/example/jhalloran/zoo/ui/main/MainActivity.java
private void updateContentFromModel() {
    TextView zooTitle = findViewById(R.id.zooTitle);
    zooTitle.setText(zoo.getName());

    // Request data on a background thread to allow parallel processing
    ListenableFuture<Integer> numZookeepersFuture = ZooThreadPoolManager
        .getBackgroundThreadExecutor()
        .submit(new Callable<Integer>() {
          @Override
          public Integer call() throws Exception {
            return zoo.getZookeepers().size();
          }
        });
    // Update view on UI Thread once Future is complete
    Futures.addCallback(numZookeepersFuture, new FutureCallback<Integer>() {
          @Override
          public void onSuccess(Integer result) {
            TextView zooKeepersTitle = findViewById(R.id.zookeepersOverviewTitle);
            zooKeepersTitle.setText(getResources().getString(R.string.total_zookeepers, result));
          }

          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load zookeepers from model: %s", t));
          }
        },
        ZooThreadPoolManager.getMainThreadExecutor());

    // Request data on a background thread to allow parallel processing
    ListenableFuture<Integer> numPensFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<Integer>() {
          @Override
          public Integer call() throws Exception {
            return zoo.getPens().size();
          }
        });
    // Update view on UI Thread once Future is complete
    Futures.addCallback(numPensFuture, new FutureCallback<Integer>() {
          @Override
          public void onSuccess(Integer result) {
            TextView pensTitle = findViewById(R.id.pensOverviewTitle);
            pensTitle.setText(getResources().getString(R.string.total_pens, result));
          }

          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load pens from model: %s", t));
          }
        },
        ZooThreadPoolManager.getMainThreadExecutor());

    // Request data on a background thread to allow parallel processing
    ListenableFuture<Integer> numAnimalsFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<Integer>() {
          @Override
          public Integer call() throws Exception {
            return zoo.getAnimals().size();
          }
        });
    // Update view on UI Thread once Future is complete
    Futures.addCallback(numAnimalsFuture, new FutureCallback<Integer>() {
          @Override
          public void onSuccess(Integer result) {
            TextView animalsTitle = findViewById(R.id.animalsOverviewTitle);
            animalsTitle.setText(getResources().getString(R.string.total_animals, result));
          }

          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load animals from model: %s", t));
          }
        },
        ZooThreadPoolManager.getMainThreadExecutor());


  }
// Update view by querying Zoo model. Requests data in parallel.
Update view by querying Zoo model. Requests data in parallel.
Update view by querying Zoo model . Requests data in parallel .
private void updateContentFromModel() {
    TextView zooTitle = findViewById(R.id.zooTitle);
    zooTitle.setText(zoo.getName());
    ListenableFuture<Integer> numZookeepersFuture = ZooThreadPoolManager
        .getBackgroundThreadExecutor()
        .submit(new Callable<Integer>() {
          @Override
          public Integer call() throws Exception {
            return zoo.getZookeepers().size();
          }
        });
    Futures.addCallback(numZookeepersFuture, new FutureCallback<Integer>() {
          @Override
          public void onSuccess(Integer result) {
            TextView zooKeepersTitle = findViewById(R.id.zookeepersOverviewTitle);
            zooKeepersTitle.setText(getResources().getString(R.string.total_zookeepers, result));
          }
          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load zookeepers from model: %s", t));
          }
        },
        ZooThreadPoolManager.getMainThreadExecutor());
    ListenableFuture<Integer> numPensFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<Integer>() {
          @Override
          public Integer call() throws Exception {
            return zoo.getPens().size();
          }
        });
    Futures.addCallback(numPensFuture, new FutureCallback<Integer>() {
          @Override
          public void onSuccess(Integer result) {
            TextView pensTitle = findViewById(R.id.pensOverviewTitle);
            pensTitle.setText(getResources().getString(R.string.total_pens, result));
          }
          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load pens from model: %s", t));
          }
        },
        ZooThreadPoolManager.getMainThreadExecutor());
    ListenableFuture<Integer> numAnimalsFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<Integer>() {
          @Override
          public Integer call() throws Exception {
            return zoo.getAnimals().size();
          }
        });
    Futures.addCallback(numAnimalsFuture, new FutureCallback<Integer>() {
          @Override
          public void onSuccess(Integer result) {
            TextView animalsTitle = findViewById(R.id.animalsOverviewTitle);
            animalsTitle.setText(getResources().getString(R.string.total_animals, result));
          }
          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load animals from model: %s", t));
          }
        },
        ZooThreadPoolManager.getMainThreadExecutor());
  }
private void updateContentFromModel ( ) { TextView zooTitle = findViewById ( R . id . zooTitle ) ; zooTitle . setText ( zoo . getName ( ) ) ; ListenableFuture < Integer > numZookeepersFuture = ZooThreadPoolManager . getBackgroundThreadExecutor ( ) . submit ( new Callable < Integer > ( ) { @ Override public Integer call ( ) throws Exception { return zoo . getZookeepers ( ) . size ( ) ; } } ) ; Futures . addCallback ( numZookeepersFuture , new FutureCallback < Integer > ( ) { @ Override public void onSuccess ( Integer result ) { TextView zooKeepersTitle = findViewById ( R . id . zookeepersOverviewTitle ) ; zooKeepersTitle . setText ( getResources ( ) . getString ( R . string . total_zookeepers , result ) ) ; } @ Override public void onFailure ( Throwable t ) { Log . e ( TAG , String . format ( "Unable to load zookeepers from model: %s" , t ) ) ; } } , ZooThreadPoolManager . getMainThreadExecutor ( ) ) ; ListenableFuture < Integer > numPensFuture = ZooThreadPoolManager . getBackgroundThreadExecutor ( ) . submit ( new Callable < Integer > ( ) { @ Override public Integer call ( ) throws Exception { return zoo . getPens ( ) . size ( ) ; } } ) ; Futures . addCallback ( numPensFuture , new FutureCallback < Integer > ( ) { @ Override public void onSuccess ( Integer result ) { TextView pensTitle = findViewById ( R . id . pensOverviewTitle ) ; pensTitle . setText ( getResources ( ) . getString ( R . string . total_pens , result ) ) ; } @ Override public void onFailure ( Throwable t ) { Log . e ( TAG , String . format ( "Unable to load pens from model: %s" , t ) ) ; } } , ZooThreadPoolManager . getMainThreadExecutor ( ) ) ; ListenableFuture < Integer > numAnimalsFuture = ZooThreadPoolManager . getBackgroundThreadExecutor ( ) . submit ( new Callable < Integer > ( ) { @ Override public Integer call ( ) throws Exception { return zoo . getAnimals ( ) . size ( ) ; } } ) ; Futures . addCallback ( numAnimalsFuture , new FutureCallback < Integer > ( ) { @ Override public void onSuccess ( Integer result ) { TextView animalsTitle = findViewById ( R . id . animalsOverviewTitle ) ; animalsTitle . setText ( getResources ( ) . getString ( R . string . total_animals , result ) ) ; } @ Override public void onFailure ( Throwable t ) { Log . e ( TAG , String . format ( "Unable to load animals from model: %s" , t ) ) ; } } , ZooThreadPoolManager . getMainThreadExecutor ( ) ) ; }
Update view by querying Zoo model.
Update view by querying Zoo model .
// Request data on a background thread to allow parallel processing // Update view on UI Thread once Future is complete // Request data on a background thread to allow parallel processing // Update view on UI Thread once Future is complete // Request data on a background thread to allow parallel processing // Update view on UI Thread once Future is complete