
it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.TaxonFactSheetActivitySupport Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* 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://kenai.com/hg/bluebill~android-src
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.factsheet;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.role.ui.PresentationModel;
import it.tidalwave.mobile.ui.QuestionWithFeedback;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.TaxonFactSheetViewController;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonRenderingOptions;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import it.tidalwave.ui.android.app.AndroidActivityHelper;
import it.tidalwave.ui.android.widget.PresentationModelAdapter;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.taxonomy.TaxonIntentHelper;
import it.tidalwave.bluebill.mobile.android.util.CommonOptionsMenuController;
import it.tidalwave.ui.android.view.Bindings;
import lombok.RequiredArgsConstructor;
import static it.tidalwave.role.ui.android.TextViewRenderable.TextViewRenderable;
/***********************************************************************************************************************
*
* @stereotype View
* @stereotype Activity
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@RequiredArgsConstructor
public abstract class TaxonFactSheetActivitySupport extends Activity
{
private static final Logger log = LoggerFactory.getLogger(TaxonFactSheetActivitySupport.class);
@CheckForNull
protected Taxon taxon;
private final AndroidActivityHelper activityHelper = new AndroidActivityHelper(this);
private final CommonOptionsMenuController commonOptionsMenuController = new CommonOptionsMenuController(this);
protected ProgressDialog progressDialog;
protected TextView tvNoData;
protected View llData;
protected ListView lvList;
protected final Controller controller = createController();
private final int contentViewId;
@CheckForNull
protected PresentationModelAdapter listAdapter;
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void populate (final @Nonnull PresentationModel presentationModel)
{
runOnUiThread(new Runnable()
{
public void run()
{
log.info("populate({})", presentationModel);
listAdapter = new PresentationModelAdapter(TaxonFactSheetActivitySupport.this, presentationModel);
Bindings.bind(lvList, listAdapter);
tvNoData.setVisibility(View.GONE);
llData.setVisibility(View.VISIBLE);
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void notifyNoData (final @Nonnull String message)
{
runOnUiThread(new Runnable()
{
public void run()
{
log.info("notifyNoData({})", message);
progressDialog.dismiss();
tvNoData.setText(message);
tvNoData.setVisibility(View.VISIBLE);
llData.setVisibility(View.GONE);
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void showPleaseWaitAndLockUI (final @Nonnull String message)
{
runOnUiThread(new Runnable()
{
public void run()
{
log.info("showPleaseWaitAndLockUI({})", message);
if (progressDialog == null)
{
progressDialog = ProgressDialog.show(TaxonFactSheetActivitySupport.this, "", message, true);
}
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void dismissPleaseWaitAndUnlockUI()
{
runOnUiThread(new Runnable()
{
public void run()
{
log.info("dismissPleaseWaitAndUnlockUI({})");
if (progressDialog != null)
{
progressDialog.dismiss();
progressDialog = null;
}
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void confirmToDownloadMedia (final @Nonnull QuestionWithFeedback questionWithFeedback)
{
log.info("confirmToDownloadMedia({})", questionWithFeedback);
activityHelper.showConfirmationDialog(questionWithFeedback);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void confirmToDeleteMedia (final @Nonnull QuestionWithFeedback questionWithFeedback)
{
log.info("confirmToDeleteMedia({})", questionWithFeedback);
activityHelper.showConfirmationDialog(questionWithFeedback);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void notifySdCardNotReady (final @Nonnull QuestionWithFeedback questionWithFeedback)
{
log.info("notifySdCardNotReady({})", questionWithFeedback);
activityHelper.showErrorDialog(questionWithFeedback);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void notifyCompletion (final @Nonnull String message)
{
log.info("notifyCompletion({})", message);
activityHelper.showLightNotification(message);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void notifyError (final @Nonnull String message)
{
log.info("notifyError({})", message);
activityHelper.showLightNotification(message);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void openWebPage (final @Nonnull String url)
{
log.info("openWebPage({})", url);
activityHelper.openWebPage(url);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public void onCreate (final @Nonnull Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(contentViewId);
tvNoData = (TextView)findViewById(R.id.tvNoData);
llData = findViewById(R.id.llData);
lvList = (ListView)findViewById(R.id.list);
if (lvList != null) // some subclasses might not use it
{
registerForContextMenu(lvList);
}
try
{
taxon = TaxonIntentHelper.getTaxon(getIntent());
final TextView textView = (TextView)findViewById(R.id.tvTaxon);
taxon.as(TextViewRenderable).renderTo(textView, TaxonRenderingOptions.PRIMARY_AND_SCIENTIFIC_NAME);
// factSheetProvider = new FactSheetProvider()
// {
// @Nonnull
// public FactSheet findFactSheetFor (final @Nonnull As as)
// throws IOException
// {
//// try
//// {
// throw new IOException("BBC Fact sheet disabled");
//// return new BbcFactSheetProvider().createFactSheet(taxon);
//// }
//// catch (NotFoundException e)
//// {
//// throw new IOException(e.toString()); // FIXME: return empty fact sheet
//// }
// }
// };
}
catch (NotFoundException e)
{
throw new RuntimeException("Can't find taxon", e);
// TODO: logging
}
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public void onResume()
{
super.onResume();
try
{
controller.initialize(taxon);
}
catch (Exception e)
{
log.warn("While setting up {}", e.toString());
log.warn("", e);
// FIXME: diags
}
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public boolean onCreateOptionsMenu (final @Nonnull Menu menu)
{
getMenuInflater().inflate(R.menu.common_options_menu, menu);
return true;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public boolean onOptionsItemSelected (final @Nonnull MenuItem item)
{
return commonOptionsMenuController.onOptionsItemSelected(item);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public void onCreateContextMenu (final @Nonnull ContextMenu menu,
final @Nonnull View view,
final @Nonnull ContextMenuInfo menuInfo)
{
// android:icon="@android:drawable/ic_media_play" FIXME ICONS
// android:icon="@android:drawable/ic_menu_delete"
listAdapter.onCreateContextMenu(menu, view, menuInfo);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public boolean onContextItemSelected (final @Nonnull MenuItem item)
{
return listAdapter.onContextItemSelected(item);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
protected abstract Controller createController();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy