Android Open Source - EnklawaPlayer Nav Adapter






From Project

Back to project page EnklawaPlayer.

License

The source code is released under:

GNU General Public License

If you think the Android project EnklawaPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package macbury.pod.navigation_drawer;
/*from   w  w w  .j  a  v a 2s  . c  o  m*/
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.koushikdutta.ion.Ion;

import java.util.ArrayList;

import be.webelite.ion.IconView;
import macbury.pod.R;
import macbury.pod.db.models.Program;
import macbury.pod.navigation_drawer.items.FavoriteProgramNavItem;
import macbury.pod.navigation_drawer.items.NavItemFragment;

/**
 * Created by macbury on 11.09.14.
 */
public class NavAdapter extends BaseAdapter{
  private final ArrayList<NavBaseItem> items;
  private final ArrayList<Class<? extends NavBaseItem>> viewTypes;
  private final Context context;
  private int selected;

  public NavAdapter(Context context) {
    this.context    = context;
    this.items      = new ArrayList<NavBaseItem>();
    this.viewTypes  = new ArrayList<Class<? extends NavBaseItem>>();
  }

  public void add(NavBaseItem item) {
    items.add(item);
    if (!viewTypes.contains(item.getClass())) {
      viewTypes.add(item.getClass());
    }
  }

  public void clear() {
    viewTypes.clear();
    items.clear();
  }

  @Override
  public int getCount() {
    return items.size();
  }

  @Override
  public NavBaseItem getItem(int position) {
    return items.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    NavBaseItem item = getItem(position);
    if (isNavItemFragment(position)) {
      return getNavItemView((NavItemFragment)item, convertView, parent, position);
    } else if(isDivider(position)) {
      return getDividerItemView((NavDivider)item, convertView, parent);
    } else if(isNavFavoriteProgramItem(position)) {
      return getFavoriteProgramItemView((FavoriteProgramNavItem) item, convertView, parent, position);
    }
    return null;
  }

  public boolean isNavItemFragment(int position) {
    return NavItemFragment.class.isInstance(getItem(position));
  }

  public boolean isNavFavoriteProgramItem(int position) {
    return FavoriteProgramNavItem.class.isInstance(getItem(position));
  }

  private View getFavoriteProgramItemView(FavoriteProgramNavItem item, View convertView, ViewGroup parent, int position) {
    FavoriteProgramItemItemHolder holder = null;

    if (convertView == null) {
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView             = inflater.inflate(R.layout.nav_item_favorite_program, parent, false);
      holder                  = new FavoriteProgramItemItemHolder();
      holder.previewImage     = (ImageView)convertView.findViewById(R.id.program_preview);
      holder.titleView        = (TextView)convertView.findViewById(R.id.program_title);
      convertView.setTag(holder);
    } else {
      holder = (FavoriteProgramItemItemHolder) convertView.getTag();
    }

    Program program = item.getProgram();

    holder.titleView.setText(program.name);
    Ion.with(context).load(program.image).withBitmap().intoImageView(holder.previewImage);

    if (position == selected) {
      holder.titleView.setTypeface(null, Typeface.BOLD);
    } else {
      holder.titleView.setTypeface(null, Typeface.NORMAL);
    }

    return convertView;
  }

  private View getDividerItemView(NavDivider item, View convertView, ViewGroup parent) {
    DividerItemHolder holder = null;
    if (convertView == null) {
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView             = inflater.inflate(R.layout.nav_divider_item, parent, false);
      holder                  = new DividerItemHolder();
      holder.titleView        = (TextView)convertView.findViewById(R.id.nav_item_title_view);
      convertView.setTag(holder);
    } else {
      holder                  = (DividerItemHolder) convertView.getTag();
    }

    holder.titleView.setText(item.getTitle());

    return convertView;
  }

  private View getNavItemView(NavItemFragment item, View convertView, ViewGroup parent, int position) {
    SimpleNavItemHolder holder = null;

    if (convertView == null) {
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView             = inflater.inflate(R.layout.nav_item_simple, parent, false);
      holder                  = new SimpleNavItemHolder();
      holder.iconView         = (IconView) convertView.findViewById(R.id.nav_item_icon_view);
      holder.titleView        = (TextView) convertView.findViewById(R.id.nav_item_title_view);
      holder.countView        = (TextView) convertView.findViewById(R.id.nav_item_count_view);
      convertView.setTag(holder);
    } else {
      holder = (SimpleNavItemHolder) convertView.getTag();
    }

    holder.iconView.setTextColor(item.getColorResource());

    if (position == selected) {
      holder.titleView.setTypeface(null, Typeface.BOLD);
    } else {
      holder.titleView.setTypeface(null, Typeface.NORMAL);
    }
    int count = item.getCount();
    if (count <= 0) {
      holder.countView.setVisibility(View.INVISIBLE);
    } else {
      holder.countView.setText(String.valueOf(count));
      holder.countView.setVisibility(View.VISIBLE);
    }

    holder.titleView.setText(item.getTitle());
    holder.iconView.setIcon(item.getIcon());
    return convertView;
  }

  @Override
  public int getViewTypeCount() {
    return viewTypes.size();
  }

  @Override
  public int getItemViewType(int position) {
    return getItem(position).getType();
  }

  public boolean isDivider(int position) {
    return NavDivider.class.isInstance(getItem(position));
  }

  public void setSelected(int selected) {
    this.selected = selected;
    this.notifyDataSetChanged();
  }

  public int getSelected() {
    return selected;
  }

  public class SimpleNavItemHolder {
    public IconView         iconView;
    public TextView         titleView;
    public TextView         countView;
  }

  public class FavoriteProgramItemItemHolder {
    public TextView         titleView;
    public ImageView previewImage;
  }

  public class DividerItemHolder {
    public TextView         titleView;
  }
}




Java Source Code List

macbury.pod.ApplicationTest.java
macbury.pod.activities.DonateActivity.java
macbury.pod.activities.ProgramEpisodesActivity.java
macbury.pod.activities.SettingsActivity.java
macbury.pod.activities.ext.AccentFragmentActivity.java
macbury.pod.activities.main.MainActivityActionBarToggle.java
macbury.pod.activities.main.MainActivity.java
macbury.pod.activities.main.NavigationController.java
macbury.pod.activities.main.NavigationListener.java
macbury.pod.activities.player.PlayerActivity.java
macbury.pod.activities.player.RadioActivity.java
macbury.pod.adapters.EpisodesAdapterListener.java
macbury.pod.adapters.EpisodesAdapter.java
macbury.pod.adapters.ProgramsAdapter.java
macbury.pod.api.APICategory.java
macbury.pod.api.APIEpisode.java
macbury.pod.api.APIProgram.java
macbury.pod.api.APIResponse.java
macbury.pod.api.APIThread.java
macbury.pod.db.DatabaseCRUDListener.java
macbury.pod.db.models.EnqueueEpisode.java
macbury.pod.db.models.EpisodeFile.java
macbury.pod.db.models.Episode.java
macbury.pod.db.models.ForumThread.java
macbury.pod.db.models.Program.java
macbury.pod.db.scopes.AbstractScope.java
macbury.pod.db.scopes.EnqueueEpisodeScope.java
macbury.pod.db.scopes.EpisodeFilesScope.java
macbury.pod.db.scopes.EpisodesScope.java
macbury.pod.db.scopes.ProgramsScope.java
macbury.pod.db.scopes.ThreadScope.java
macbury.pod.dialogs.EpisodeAboutDialog.java
macbury.pod.dialogs.ProgramAboutDialog.java
macbury.pod.extensions.Converter.java
macbury.pod.extensions.DateDeserializer.java
macbury.pod.extensions.SleepTimer.java
macbury.pod.fragments.SettingsFragment.java
macbury.pod.fragments.main.AbstractEpisodesFragment.java
macbury.pod.fragments.main.AllProgramsFragment.java
macbury.pod.fragments.main.EnklawaBaseAbstractListFragment.java
macbury.pod.fragments.main.episodes.DownloadedEpisodesFragment.java
macbury.pod.fragments.main.episodes.NewestEpisodesFragment.java
macbury.pod.fragments.main.episodes.PlaylistFragment.java
macbury.pod.fragments.main.episodes.ProgramEpisodesFragment.java
macbury.pod.fragments.player.ExternalPlayerFragment.java
macbury.pod.fragments.player.PlayerArtworkAndInfoFragment.java
macbury.pod.fragments.player.PlayerControllerFragment.java
macbury.pod.managers.AlarmsManager.java
macbury.pod.managers.App.java
macbury.pod.managers.BroadcastsManager.java
macbury.pod.managers.DatabaseManager.java
macbury.pod.managers.IntentManager.java
macbury.pod.managers.NotificationsManager.java
macbury.pod.managers.ServiceManager.java
macbury.pod.managers.SettingsManager.java
macbury.pod.managers.StorageManager.java
macbury.pod.managers.download.DownloadEpisode.java
macbury.pod.managers.download.DownloadManagerListener.java
macbury.pod.managers.download.DownloadManager.java
macbury.pod.managers.player.PlaybackStatus.java
macbury.pod.managers.player.PlayerManagerListener.java
macbury.pod.managers.player.PlayerManager.java
macbury.pod.managers.player.sources.AbstractMediaSource.java
macbury.pod.managers.player.sources.EpisodeMediaSource.java
macbury.pod.managers.player.sources.RadioMediaSource.java
macbury.pod.navigation_drawer.NavAdapter.java
macbury.pod.navigation_drawer.NavBaseItem.java
macbury.pod.navigation_drawer.NavDivider.java
macbury.pod.navigation_drawer.items.AllProgramsNavItem.java
macbury.pod.navigation_drawer.items.DownloadedEpisodesNavItem.java
macbury.pod.navigation_drawer.items.FavoriteProgramNavItem.java
macbury.pod.navigation_drawer.items.ForumNavItem.java
macbury.pod.navigation_drawer.items.NavItemFragment.java
macbury.pod.navigation_drawer.items.NewestEpisodesNavItem.java
macbury.pod.navigation_drawer.items.PlayQueueNavItem.java
macbury.pod.receivers.BootReceiver.java
macbury.pod.receivers.MediaButtonReceiver.java
macbury.pod.services.DownloadService.java
macbury.pod.services.PlayerService.java
macbury.pod.services.SyncPodService.java
macbury.pod.tutorial.MainActivityTutorial.java
macbury.pod.views.TappableFrameLayout.java