it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound.SoundViewHelper Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* 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.
*
***********************************************************************************************************************
*
* $Id: SoundViewHelper.java,v a1005d8ae91d 2010/06/27 00:04:34 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.util.Date;
import java.text.DateFormat;
import it.tidalwave.util.As;
import it.tidalwave.util.AsException;
import it.tidalwave.util.Displayable;
import it.tidalwave.util.Identifiable;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.mobile.media.Media;
import android.view.View;
import android.widget.TextView;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.MediaViewHelper;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.observation.Observation;
import static it.tidalwave.util.Displayable.Displayable;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class SoundViewHelper extends MediaViewHelper
{
@Nonnull
protected final TextView tvLabel;
@Nonnull
protected final TextView tvLocationAndDate;
@Nonnull
protected final TextView tvAuthor;
@Nonnull
protected final TextView tvRights;
@Nonnull
protected final TextView tvDuration;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public SoundViewHelper (final @Nonnull View view)
{
super(view);
tvLabel = (TextView)view.findViewById(R.id.tvLabel);
tvLocationAndDate = (TextView)view.findViewById(R.id.tvLocationAndDate);
tvAuthor = (TextView)view.findViewById(R.id.tvAuthor);
tvRights = (TextView)view.findViewById(R.id.tvRights);
tvDuration = (TextView)view.findViewById(R.id.tvDuration);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public void setObservation (final @Nonnull Observation observation)
throws NotFoundException
{
super.setObservation(observation);
final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
final As author = observation.findObservers().result();
final As source = observation.getSource();
final As location = observation.getLocation();
final Date date = observation.getDate();
final String callType = observation.as(Displayable.class).getDisplayName();
final Media media = observation.as(Media.class);
String observationId = "";
try
{
observationId = observation.as(Identifiable.class).getId().stringValue();
observationId = observationId.replaceAll(".*/", "");
}
catch (AsException e)
{
// no id, never mind
}
tvLabel.setText(callType);
tvLocationAndDate.setText(location.as(Displayable).getDisplayName() + " " + df.format(date));
tvAuthor.setText(author.as(Displayable).getDisplayName() + ", " + source.as(Displayable).getDisplayName() + " " + observationId);
renderLicense(tvRights, media);
tvDuration.setText(formatDuration(media.get(Media.DURATION)));
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
private String formatDuration (final @Nonnegative int duration)
{
return String.format("%02d:%02d", duration / 60, duration % 60);
}
}