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

it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.AndroidTaxonFactSheetViewSupport 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.taxonomy.factsheet;

import lombok.Getter;
import android.content.Context;
import android.util.AttributeSet;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import it.tidalwave.role.ui.PresentationModel;
import it.tidalwave.util.ui.UserNotificationWithFeedback;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.ui.TaxonFactSheetViewController;
import android.app.ProgressDialog;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import it.tidalwave.ui.android.widget.PresentationModelAdapter;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonRenderingOptions;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon;
import it.tidalwave.ui.android.app.AndroidViewHelper;
import it.tidalwave.ui.android.view.AndroidBindings;
import it.tidalwave.util.ui.UserNotification;
import lombok.extern.slf4j.Slf4j;
import static it.tidalwave.role.ui.android.TextViewRenderable.TextViewRenderable;

/***********************************************************************************************************************
 *
 * @stereotype View
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Slf4j
public abstract class AndroidTaxonFactSheetViewSupport extends LinearLayout
  {
    private final AndroidViewHelper viewHelper = new AndroidViewHelper(this);

    protected ProgressDialog progressDialog;
    
    protected TextView tvTaxon;
    
    protected TextView tvNoData;
    
    protected View llData;

    @Getter
    protected ListView lvList;

    @Getter
    protected Controller controller; 

    @CheckForNull @Getter
    protected PresentationModelAdapter listAdapter;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public AndroidTaxonFactSheetViewSupport (final @Nonnull Context context, final @Nonnull AttributeSet attrs) 
      {
        super(context, attrs);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public AndroidTaxonFactSheetViewSupport (final @Nonnull Context context) 
      {
        super(context);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    protected void initWidgets()
      {
        controller = createController(); 
        tvTaxon = (TextView)findViewById(R.id.tvTaxon);
        tvNoData = (TextView)findViewById(R.id.tvNoData);
        llData = findViewById(R.id.llData);
        lvList = (ListView)findViewById(R.id.list);
      }

//    /*******************************************************************************************************************
//     *
//       * FIXME: too late, the Activity needs lvList earlier.
//     *
//     ******************************************************************************************************************/
//    @Override
//    protected void onAttachedToWindow()
//      {
//        super.onAttachedToWindow();
//        tvTaxon = (TextView)findViewById(R.id.tvTaxon);
//        tvNoData = (TextView)findViewById(R.id.tvNoData);
//        llData = findViewById(R.id.llData);
//        lvList = (ListView)findViewById(R.id.list);
//      }
      
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void renderTaxon (final @Nonnull Taxon taxon)
      {
        post(new Runnable()
          {
            public void run()
              {
                log.info("renderTaxon({})", taxon);
                taxon.as(TextViewRenderable).renderTo(tvTaxon, TaxonRenderingOptions.PRIMARY_AND_SCIENTIFIC_NAME);
              }
          });
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void populate (final @Nonnull PresentationModel presentationModel)
      {
        post(new Runnable()
          {
            public void run()
              {
                log.info("populate({})", presentationModel);
                listAdapter = new PresentationModelAdapter(getContext(), presentationModel);  
                AndroidBindings.bind(lvList, listAdapter);
                tvNoData.setVisibility(View.GONE);
                llData.setVisibility(View.VISIBLE);
              }
          });
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     * 
     ******************************************************************************************************************/
    public void notifyNoData (final @Nonnull UserNotification notification) 
      {
        post(new Runnable()
          {
            public void run()
              {
                log.info("notifyNoData({})", notification);
                progressDialog.dismiss();
                tvNoData.setText(notification.getText());
                tvNoData.setVisibility(View.VISIBLE);
                llData.setVisibility(View.GONE);
              }
          });
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     * 
     ******************************************************************************************************************/
    public void lock (final @Nonnull UserNotification notification)
      {
        post(new Runnable() 
          {
            public void run() 
              {
                log.info("lock({})", notification);
                
                if (progressDialog == null)
                  {
                    progressDialog = ProgressDialog.show(getContext(), notification.getCaption(), notification.getText(), true);
                  }
              }
          });            
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     * 
     ******************************************************************************************************************/
    public void unlock()
      {
        post(new Runnable() 
          {
            public void run() 
              {
                log.info("unlock({})");
                
                if (progressDialog != null)
                  {
                    progressDialog.dismiss();
                    progressDialog = null;
                  }
              }
          });            
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     * 
     ******************************************************************************************************************/
    public void confirmToDownloadMedia (final @Nonnull UserNotificationWithFeedback notification) 
      {
        log.info("confirmToDownloadMedia({})", notification);
        viewHelper.showConfirmationDialog(notification);
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     * 
     ******************************************************************************************************************/
    public void confirmToDeleteMedia (final @Nonnull UserNotificationWithFeedback notification) 
      {
        log.info("confirmToDeleteMedia({})", notification);
        viewHelper.showConfirmationDialog(notification);
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     * 
     ******************************************************************************************************************/
    public void notifySdCardNotReady (final @Nonnull UserNotificationWithFeedback notification) 
      {
        log.info("notifySdCardNotReady({})", notification);
        viewHelper.showErrorDialog(notification);
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void notifyCompletion (final @Nonnull UserNotification notification)
      {
        log.info("notifyCompletion({})", notification);
        viewHelper.showLightNotification(notification);
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void notifyError (final @Nonnull UserNotification notification)
      {
        log.info("notifyError({})", notification);
        viewHelper.showLightNotification(notification);
      }
    
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void openWebPage (final @Nonnull String url) 
      {
        log.info("openWebPage({})", url);
        viewHelper.openWebPage(url);
      }
    
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    protected abstract Controller createController();
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy