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");
    }
  }
  private void handleStandardQueryIntent(Intent intent) {
    String query = intent.getStringExtra(SearchManager.QUERY);

    if (tangible.DotNetToJavaStringHelper.isNullOrEmpty(query)) {
      return;
    }

    if (mActionBar != null) {
      mActionBar.setTitle("Search results for '" + query + "'");
    }

    SearchQuery searchQuery = new SearchQuery();
    searchQuery.setUserId(MainApplication.getInstance().API.getCurrentUserId());
    searchQuery.setSearchTerm(query);

    MainApplication.getInstance().API.GetSearchHintsAsync(searchQuery, new SearchResultsResponse());
  }
Ejemplo n.º 4
0
 public ViewsAdapter(List<MenuEntity> libraryFolders) {
   mLibraryFolders = libraryFolders;
   try {
     mLayoutInflater =
         (LayoutInflater)
             MainApplication.getInstance().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
        @Override
        public void onResponse(BaseItemDto item) {

          if (item == null) return;

          Intent intent;
          if (item.getType().equalsIgnoreCase("musicartist")) {
            intent = new Intent(SearchResultsActivity.this, ArtistActivity.class);
            intent.putExtra("ArtistId", item.getId());
          } else if (item.getType().equalsIgnoreCase("musicalbum")) {
            intent = new Intent(SearchResultsActivity.this, MusicAlbumActivity.class);
            intent.putExtra("AlbumId", item.getId());
          } else { // It's a song
            MainApplication.getInstance()
                .API
                .GetItemAsync(
                    item.getParentId(),
                    MainApplication.getInstance().API.getCurrentUserId(),
                    getAlbumResponse);
            return;
          }
          startActivity(intent);
          SearchResultsActivity.this.finish();
        }
    @Override
    public void onResponse(final SearchHintResult results) {
      if (results == null)
        Toast.makeText(SearchResultsActivity.this, "Results is null", Toast.LENGTH_LONG).show();
      else {
        mLibraryGrid.setAdapter(
            new SearchResultsAdapter(
                SearchResultsActivity.this,
                Arrays.asList(results.getSearchHints()),
                MainApplication.getInstance().API));
        mLibraryGrid.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {

              @Override
              public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                processSearchHint(results.getSearchHints()[i]);
              }
            });
      }
    }
  @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();
 }