Ejemplo n.º 1
0
  private void displaySpeakersData(SessionDetailModel data) {
    final ViewGroup speakersGroup =
        (ViewGroup) getActivity().findViewById(R.id.session_speakers_block);

    // Remove all existing speakers (everything but first child, which is the header)
    for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) {
      speakersGroup.removeViewAt(i);
    }

    final LayoutInflater inflater = getActivity().getLayoutInflater();

    boolean hasSpeakers = false;

    List<SessionDetailModel.Speaker> speakers = data.getSpeakers();

    for (final SessionDetailModel.Speaker speaker : speakers) {

      String speakerHeader = speaker.getName();
      if (!TextUtils.isEmpty(speaker.getCompany())) {
        speakerHeader += ", " + speaker.getCompany();
      }

      final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false);
      final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header);
      final ImageView speakerImageView = (ImageView) speakerView.findViewById(R.id.speaker_image);
      final TextView speakerAbstractView =
          (TextView) speakerView.findViewById(R.id.speaker_abstract);
      final ImageView plusOneIcon = (ImageView) speakerView.findViewById(R.id.gplus_icon_box);
      final ImageView twitterIcon = (ImageView) speakerView.findViewById(R.id.twitter_icon_box);

      setUpSpeakerSocialIcon(
          speaker,
          twitterIcon,
          speaker.getTwitterUrl(),
          UIUtils.TWITTER_COMMON_NAME,
          UIUtils.TWITTER_PACKAGE_NAME);

      setUpSpeakerSocialIcon(
          speaker,
          plusOneIcon,
          speaker.getPlusoneUrl(),
          UIUtils.GOOGLE_PLUS_COMMON_NAME,
          UIUtils.GOOGLE_PLUS_PACKAGE_NAME);

      // A speaker may have both a Twitter and GPlus page, only a Twitter page or only a
      // GPlus page, or neither. By default, align the Twitter icon to the right and the GPlus
      // icon to its left. If only a single icon is displayed, align it to the right.
      determineSocialIconPlacement(plusOneIcon, twitterIcon);

      if (!TextUtils.isEmpty(speaker.getImageUrl()) && mSpeakersImageLoader != null) {
        mSpeakersImageLoader.loadImage(speaker.getImageUrl(), speakerImageView);
      }

      speakerHeaderView.setText(speakerHeader);
      speakerImageView.setContentDescription(
          getString(R.string.speaker_googleplus_profile, speakerHeader));
      UIUtils.setTextMaybeHtml(speakerAbstractView, speaker.getAbstract());

      if (!TextUtils.isEmpty(speaker.getUrl())) {
        speakerImageView.setEnabled(true);
        speakerImageView.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                Intent speakerProfileIntent =
                    new Intent(Intent.ACTION_VIEW, Uri.parse(speaker.getUrl()));
                speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                UIUtils.preferPackageForIntent(
                    getActivity(), speakerProfileIntent, UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                startActivity(speakerProfileIntent);
              }
            });
      } else {
        speakerImageView.setEnabled(false);
        speakerImageView.setOnClickListener(null);
      }

      speakersGroup.addView(speakerView);
      hasSpeakers = true;
    }

    speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE);
    updateEmptyView(data);
  }
Ejemplo n.º 2
0
  private void displaySessionData(final SessionDetailModel data) {
    mTitle.setText(data.getSessionTitle());
    mSubtitle.setText(data.getSessionSubtitle());

    mPhotoViewContainer.setBackgroundColor(
        UIUtils.scaleSessionColorToDefaultBG(data.getSessionColor()));

    if (data.hasPhotoUrl()) {
      mHasPhoto = true;
      mNoPlaceholderImageLoader.loadImage(
          data.getPhotoUrl(),
          mPhotoView,
          new RequestListener<String, Bitmap>() {
            @Override
            public boolean onException(
                Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
              mHasPhoto = false;
              recomputePhotoAndScrollingMetrics();
              return false;
            }

            @Override
            public boolean onResourceReady(
                Bitmap resource,
                String model,
                Target<Bitmap> target,
                boolean isFromMemoryCache,
                boolean isFirstResource) {
              // Trigger image transition
              recomputePhotoAndScrollingMetrics();
              return false;
            }
          });
      recomputePhotoAndScrollingMetrics();
    } else {
      mHasPhoto = false;
      recomputePhotoAndScrollingMetrics();
    }

    tryExecuteDeferredUiOperations();

    // Handle Keynote as a special case, where the user cannot remove it
    // from the schedule (it is auto added to schedule on sync)
    mAddScheduleButton.setVisibility(
        (AccountUtils.hasActiveAccount(getContext()) && !data.isKeynote())
            ? View.VISIBLE
            : View.INVISIBLE);

    displayTags(data);

    if (!data.isKeynote()) {
      showStarredDeferred(data.isInSchedule(), false);
    }

    if (!TextUtils.isEmpty(data.getSessionAbstract())) {
      UIUtils.setTextMaybeHtml(mAbstract, data.getSessionAbstract());
      mAbstract.setVisibility(View.VISIBLE);
    } else {
      mAbstract.setVisibility(View.GONE);
    }

    // Build requirements section
    final View requirementsBlock = getActivity().findViewById(R.id.session_requirements_block);
    final String sessionRequirements = data.getRequirements();
    if (!TextUtils.isEmpty(sessionRequirements)) {
      UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
      requirementsBlock.setVisibility(View.VISIBLE);
    } else {
      requirementsBlock.setVisibility(View.GONE);
    }

    final ViewGroup relatedVideosBlock =
        (ViewGroup) getActivity().findViewById(R.id.related_videos_block);
    relatedVideosBlock.setVisibility(View.GONE);

    updateEmptyView(data);

    updateTimeBasedUi(data);

    if (data.getLiveStreamVideoWatched()) {
      mPhotoView.setColorFilter(getContext().getResources().getColor(R.color.video_scrim_watched));
      mLiveStreamPlayIconAndText.setText(getString(R.string.session_replay));
    }

    if (data.hasLiveStream()) {
      mLiveStreamPlayIconAndText.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              String videoId =
                  YouTubeUtils.getVideoIdFromSessionData(
                      data.getYouTubeUrl(), data.getLiveStreamId());
              YouTubeUtils.showYouTubeVideo(videoId, getActivity());
            }
          });
    }

    fireAnalyticsScreenView(data.getSessionTitle());

    mHandler.post(
        new Runnable() {
          @Override
          public void run() {
            onScrollChanged(0, 0); // trigger scroll handling
            mScrollViewChild.setVisibility(View.VISIBLE);
            // mAbstract.setTextIsSelectable(true);
          }
        });

    mTimeHintUpdaterRunnable =
        new Runnable() {
          @Override
          public void run() {
            if (getActivity() == null) {
              // Do not post a delayed message if the activity is detached.
              return;
            }
            updateTimeBasedUi(data);
            mHandler.postDelayed(
                mTimeHintUpdaterRunnable, SessionDetailConstants.TIME_HINT_UPDATE_INTERVAL);
          }
        };
    mHandler.postDelayed(
        mTimeHintUpdaterRunnable, SessionDetailConstants.TIME_HINT_UPDATE_INTERVAL);
  }