it.tidalwave.bluebill.mobile.android.observation.AndroidObservationsViewController 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.android.observation;
import javax.annotation.Nonnull;
import javax.inject.Provider;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.util.thread.ThreadAssertions;
import it.tidalwave.util.thread.annotation.ThreadConfined;
import it.tidalwave.netbeans.util.Locator;
import it.tidalwave.observation.ObservationManager;
import it.tidalwave.observation.ObservationSet;
import it.tidalwave.bluebill.mobile.observation.ui.spi.DefaultObservationsViewController;
import it.tidalwave.bluebill.mobile.observation.text.ObservationCountFormat;
import android.database.DataSetObserver;
import it.tidalwave.mobile.android.ui.AndroidFlowController;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.TaxonFactSheetControlFlow;
import lombok.Getter;
import static it.tidalwave.util.thread.ThreadType.*;
/***********************************************************************************************************************
*
* @stereotype Controller
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class AndroidObservationsViewController extends DefaultObservationsViewController
{
private static final String CLASS = AndroidObservationsViewController.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
@Getter
private final ObservationListAdapter listAdapter;
private final ObservationSet observationSet;
@Nonnull
private Provider observationManager = Locator.createProviderFor(ObservationManager.class);
private final ObservationCountFormat observationCountFormat = new ObservationCountFormat();
private final AndroidFlowController controlFlow;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@ThreadConfined(type=UI)
public AndroidObservationsViewController (final @Nonnull ObservationsActivity view)
{
super(view);
ThreadAssertions.assertThread(UI);
this.controlFlow = AndroidFlowController.forActivity(view);
observationSet = observationManager.get().findOrCreateObservationSetById(null);
listAdapter = new ObservationListAdapter(observationSet);
listAdapter.registerDataSetObserver(new DataSetObserver()
{
@Override
public void onChanged()
{
view.setFooterText(observationCountFormat.format(listAdapter.getGroupCount()));
}
});
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public void startNewObservationSequence()
{
logger.info("startNewObservationSequence()");
super.startNewObservationSequence();
controlFlow.start(AddObservationControlFlow.class);
}
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
@Override
public void browseToFactSheet()
{
logger.info("browseToFactSheet()");
super.browseToFactSheet();
controlFlow.start(TaxonFactSheetControlFlow.class);
}
}