public HomeScreenItemsAdapter(BaseItemDto[] items, boolean forceShowTitle) { mItems = items; this.forceShowTitle = forceShowTitle; try { mLayoutInflater = (LayoutInflater) MainApplication.getInstance().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int mScreenWidth = MainApplication.getInstance().getResources().getDisplayMetrics().widthPixels; int mColumns = MainApplication.getInstance() .getResources() .getInteger(R.integer.homescreen_item_columns); mWidth = mScreenWidth / mColumns; mHeight = (mWidth / 16) * 9; imageEnhancersEnabled = PreferenceManager.getDefaultSharedPreferences(MainApplication.getInstance()) .getBoolean("pref_enable_image_enhancers", true); } catch (Exception e) { AppLogger.getLogger().ErrorException("error initializing adapter properties", e); } }
private void processSearchHint(SearchHint hint) { if (hint == null) return; Intent intent; if (hint.getType().equalsIgnoreCase("series")) { intent = new Intent(SearchResultsActivity.this, SeriesViewActivity.class); } else if (hint.getType().equalsIgnoreCase("musicartist") || hint.getType().equalsIgnoreCase("musicalbum") || hint.getType().equalsIgnoreCase("audio")) { MainApplication.getInstance() .API .GetItemAsync( hint.getItemId(), MainApplication.getInstance().API.getCurrentUserId(), getItemResponse); return; } else if (hint.getType().equalsIgnoreCase("photo")) { intent = new Intent(SearchResultsActivity.this, PhotoDetailsActivity.class); } else if (hint.getType().equalsIgnoreCase("book")) { intent = new Intent(SearchResultsActivity.this, BookDetailsActivity.class); } else if (hint.getType().equalsIgnoreCase("folder") || hint.getType().equalsIgnoreCase("boxset")) { intent = new Intent(SearchResultsActivity.this, LibraryPresentationActivity.class); } else if (hint.getType().equalsIgnoreCase("movie") || hint.getType().equalsIgnoreCase("episode")) { intent = new Intent(SearchResultsActivity.this, MediaDetailsActivity.class); } else if (hint.getType().equalsIgnoreCase("person")) { intent = new Intent(SearchResultsActivity.this, ActorBioActivity.class); intent.putExtra("ActorName", hint.getName()); intent.putExtra("ActorId", hint.getItemId()); } else { Toast.makeText(SearchResultsActivity.this, "Type is: " + hint.getType(), Toast.LENGTH_LONG) .show(); intent = null; } if (intent != null) { BaseItemDto item = new BaseItemDto(); item.setId(hint.getItemId()); item.setName(hint.getName()); item.setType(hint.getType()); String jsonData = MainApplication.getInstance().getJsonSerializer().SerializeToString(item); intent.putExtra("Item", jsonData); startActivity(intent); this.finish(); } else { AppLogger.getLogger().Info("intent is null"); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_homescreen); mViewPager = (ViewPager) findViewById(R.id.vpEhsViewPager); AppLogger.getLogger().Info("HomeScreen Activity: onCreate"); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); drawer.setFocusableInTouchMode(false); NavigationMenuFragment fragment = (NavigationMenuFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer); if (fragment != null && fragment.isInLayout()) { fragment.setDrawerLayout(drawer); } mDrawerToggle = new ActionBarDrawerToggle( this, drawer, R.string.abc_action_bar_home_description, R.string.abc_action_bar_up_description) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); // getActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // getActionBar().setTitle(mDrawerTitle); } }; drawer.setDrawerListener(mDrawerToggle); mMini = (MiniController) findViewById(R.id.miniController1); mCastManager.addMiniController(mMini); }
private void buildUI() { if (isFresh) { HomeScreenPagerAdapter mHomeScreenPagerAdapter = new HomeScreenPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mHomeScreenPagerAdapter); try { String tabIndex = PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_home_default_tab", "1"); mViewPager.setCurrentItem(Integer.valueOf(tabIndex), true); } catch (Exception e) { AppLogger.getLogger().ErrorException("Error setting view pager index", e); } mViewPager.requestFocus(); isFresh = false; } }
@Override public View getView(int i, View convertView, ViewGroup viewGroup) { ViewHolder holder; if (convertView == null) { convertView = mLayoutInflater.inflate(R.layout.widget_library_tile_large, viewGroup, false); holder = new ViewHolder(); if (convertView != null) { holder.CollectionImage = (NetworkImageView) convertView.findViewById(R.id.ivLibraryTilePrimaryImage); holder.Gradient = (ImageView) convertView.findViewById(R.id.ivGradient); holder.CollectionName = (TextView) convertView.findViewById(R.id.tvLibraryTileTitle); holder.CollectionSecondaryText = (TextView) convertView.findViewById(R.id.tvLibraryTileSubTitle); holder.CollectionProgress = (ProgressBar) convertView.findViewById(R.id.pbPlaybackProgress); holder.UnwatchedCount = (TextView) convertView.findViewById(R.id.tvOverlay); holder.CollectionImage.setLayoutParams( new RelativeLayout.LayoutParams((int) mWidth, (int) mHeight)); holder.CollectionImage.setDefaultImageResId(R.drawable.default_video_landscape); convertView.setTag(holder); } } else { holder = (ViewHolder) convertView.getTag(); holder.UnwatchedCount.setVisibility(View.INVISIBLE); } if (mItems[i].getType().equalsIgnoreCase("episode") && mItems[i].getParentIndexNumber() != null && mItems[i].getIndexNumber() != null) { try { holder.CollectionName.setText( String.valueOf(mItems[i].getParentIndexNumber()) + "." + String.valueOf(mItems[i].getIndexNumber()) + " - " + mItems[i].getName()); } catch (Exception e) { AppLogger.getLogger().ErrorException("Error setting episode text", e); holder.CollectionName.setText(mItems[i].getName()); } } else { holder.CollectionName.setText(mItems[i].getName()); } if (mItems[i].getType().equalsIgnoreCase("episode") || mItems[i].getType().equalsIgnoreCase("season")) holder.CollectionSecondaryText.setText(mItems[i].getSeriesName()); else if (mItems[i].getProductionYear() != null && mItems[i].getProductionYear() != 0) holder.CollectionSecondaryText.setText(String.valueOf(mItems[i].getProductionYear())); else holder.CollectionSecondaryText.setText(""); if (mItems[i].getType() != null && (mItems[i].getType().equalsIgnoreCase("series") || mItems[i].getType().equalsIgnoreCase("season") || mItems[i].getType().equalsIgnoreCase("boxset"))) { if (mItems[i].getUserData() != null && mItems[i].getUserData().getUnplayedItemCount() != null && mItems[i].getUserData().getUnplayedItemCount() > 0) { holder.UnwatchedCount.setText( String.valueOf(mItems[i].getUserData().getUnplayedItemCount())); holder.UnwatchedCount.setVisibility(View.VISIBLE); } } boolean showText = false; try { String imageUrl = ""; ImageOptions options = new ImageOptions(); if ((mItems[i].getType().equalsIgnoreCase("photo")) && mItems[i].getHasPrimaryImage()) { options.setImageType(ImageType.Primary); options.setEnableImageEnhancers(imageEnhancersEnabled); if (mItems[i].getPrimaryImageAspectRatio() > 1.777) { options.setHeight((int) mHeight); } else { options.setWidth((int) mWidth); } imageUrl = MainApplication.getInstance().API.GetImageUrl(mItems[i], options); } else if (mItems[i].getHasThumb()) { options.setImageType(ImageType.Thumb); options.setWidth((int) mWidth); options.setEnableImageEnhancers(imageEnhancersEnabled); imageUrl = MainApplication.getInstance().API.GetImageUrl(mItems[i], options); } else if (mItems[i].getBackdropCount() > 0) { options.setImageType(ImageType.Backdrop); options.setWidth((int) mWidth); imageUrl = MainApplication.getInstance().API.GetImageUrl(mItems[i], options); showText = true; } else if (mItems[i].getSeriesThumbImageTag() != null) { options.setImageType(ImageType.Thumb); options.setWidth((int) mWidth); imageUrl = MainApplication.getInstance().API.GetImageUrl(mItems[i].getSeriesId(), options); } else if (mItems[i].getParentBackdropImageTags() != null && mItems[i].getParentBackdropImageTags().size() > 0) { options.setImageType(ImageType.Backdrop); options.setWidth((int) mWidth); imageUrl = MainApplication.getInstance() .API .GetImageUrl(mItems[i].getParentBackdropItemId(), options); showText = true; } else if (mItems[i].getHasPrimaryImage()) { options.setImageType(ImageType.Primary); options.setEnableImageEnhancers(imageEnhancersEnabled); if (mItems[i].getPrimaryImageAspectRatio() != null && mItems[i].getPrimaryImageAspectRatio() > 1.777) { options.setHeight((int) mHeight); } else { options.setWidth((int) mWidth); } imageUrl = MainApplication.getInstance().API.GetImageUrl(mItems[i], options); showText = true; } if (options.getImageType() != null) { holder.CollectionImage.setImageUrl( imageUrl, MainApplication.getInstance().API.getImageLoader()); } else { holder.CollectionImage.setImageUrl( null, MainApplication.getInstance().API.getImageLoader()); } } catch (Exception e) { AppLogger.getLogger().ErrorException("Error setting image: ", e); } if (showText || forceShowTitle) { holder.CollectionName.setVisibility(View.VISIBLE); holder.CollectionSecondaryText.setVisibility(View.VISIBLE); holder.Gradient.setVisibility(View.VISIBLE); } else { holder.CollectionName.setVisibility(View.INVISIBLE); holder.CollectionSecondaryText.setVisibility(View.INVISIBLE); holder.Gradient.setVisibility(View.INVISIBLE); } try { if (mItems[i].getUserData() != null && mItems[i].getUserData().getPlaybackPositionTicks() > 0) { holder.CollectionProgress.setVisibility(View.VISIBLE); holder.CollectionProgress.setMax(100); double percentWatched = (double) mItems[i].getUserData().getPlaybackPositionTicks() / (double) mItems[i].getRunTimeTicks(); int roundedValue = (int) (percentWatched * 100); holder.CollectionProgress.setProgress(roundedValue); } else { holder.CollectionProgress.setVisibility(View.INVISIBLE); } } catch (Exception e) { holder.CollectionProgress.setVisibility(View.INVISIBLE); AppLogger.getLogger().ErrorException("Error setting progressbar value", e); } return convertView; }
@Override public void onDestroy() { super.onDestroy(); AppLogger.getLogger().Info("HomeScreen Activity: onDestroy"); MainApplication.getAudioService().Terminate(); }
@Override public void onPause() { super.onPause(); AppLogger.getLogger().Info("HomeScreen Activity: onPause"); // mMini.removeOnMiniControllerChangedListener(mCastManager); }