All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.mobile.taxonomy.factsheet.ui.sound.DefaultTaxonSoundFactSheetViewController Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - open source birding
 * Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://bluebill.tidalwave.it/mobile
 * SCM: https://java.net/hg/bluebill-mobile~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.taxonomy.factsheet.ui.sound;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.io.IOException;
import it.tidalwave.util.thread.annotation.ThreadConfined;
import it.tidalwave.role.ui.ActionProvider;
import it.tidalwave.observation.Observation;
import it.tidalwave.mobile.media.Media;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.spi.TaxonFactSheetViewControllerSupport;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.impl.sound.PlayController;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.impl.sound.SoundActionProvider;
import lombok.extern.slf4j.Slf4j;
import static it.tidalwave.util.thread.ThreadType.*;
import static it.tidalwave.role.ui.Presentable.Presentable;
import static it.tidalwave.mobile.media.Media.Media;
import static it.tidalwave.observation.Observation.Observation;

/***********************************************************************************************************************
 *
 * @stereotype Controller
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Slf4j
public class DefaultTaxonSoundFactSheetViewController extends TaxonFactSheetViewControllerSupport 
                                                               implements TaxonSoundFactSheetViewController
  {
    private final PlayController playController;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public DefaultTaxonSoundFactSheetViewController (final @Nonnull TaxonSoundFactSheetView view)
      {
        super(view);
        playController = new PlayController(this, view);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void disposePlayer()
      {
        log.info("disposePlayer()");
        playController.stop();   
      }
    
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    Media getMedia (final @Nonnegative int index)
      {
        return getObservation(index).as(Media);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    Observation getObservation (final @Nonnegative int index)
      {
        return getPresentationModel(index).as(Observation);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @ThreadConfined(type=NOT_UI)
    protected void createPresentationModels (final @Nonnull Taxon taxon)
      throws IOException 
      {
        log.info("createPresentationModels({})", taxon);
        
        for (final Observation observation : loadObservationSet(taxon).find(Observation).results())
          {
            final Media media = observation.as(Media);
            final ActionProvider actionProvider = new SoundActionProvider(DefaultTaxonSoundFactSheetViewController.this, view, playController, media, observation);
            addPresentationModel(media.as(Presentable).createPresentationModel(observation, actionProvider));
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void notifyStatusChanged()
      {
        populateView(); // FIXME: this re-reners all; refresh the involved element only
        // FIXME: shouldn't be handled there, but by property change by PresentationModelAdapter
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy