Search in sources :

Example 1 with CheckInDialogFragment

use of com.battlelancer.seriesguide.ui.dialogs.CheckInDialogFragment in project SeriesGuide by UweTrottmann.

the class OverviewFragment method checkIn.

private void checkIn() {
    if (!isEpisodeDataAvailable) {
        return;
    }
    int episodeTvdbId = currentEpisodeCursor.getInt(EpisodeQuery._ID);
    // check in
    CheckInDialogFragment f = CheckInDialogFragment.newInstance(getActivity(), episodeTvdbId);
    // don't commit fragment change after onPause
    if (f != null && isResumed()) {
        f.show(getFragmentManager(), "checkin-dialog");
        Utils.trackAction(getActivity(), TAG, "Check-In");
    }
}
Also used : CheckInDialogFragment(com.battlelancer.seriesguide.ui.dialogs.CheckInDialogFragment)

Example 2 with CheckInDialogFragment

use of com.battlelancer.seriesguide.ui.dialogs.CheckInDialogFragment in project SeriesGuide by UweTrottmann.

the class EpisodeDetailsFragment method populateEpisodeData.

private void populateEpisodeData(Cursor cursor) {
    if (cursor == null || !cursor.moveToFirst()) {
        // no data to display
        if (mEpisodeContainer != null) {
            mEpisodeContainer.setVisibility(View.GONE);
        }
        return;
    }
    mShowTvdbId = cursor.getInt(DetailsQuery.SHOW_ID);
    mSeasonNumber = cursor.getInt(DetailsQuery.SEASON);
    mEpisodeNumber = cursor.getInt(DetailsQuery.NUMBER);
    mShowRunTime = cursor.getInt(DetailsQuery.SHOW_RUNTIME);
    mEpisodeReleaseTime = cursor.getLong(DetailsQuery.FIRST_RELEASE_MS);
    // title and description
    mEpisodeFlag = cursor.getInt(DetailsQuery.WATCHED);
    mEpisodeTitle = cursor.getString(DetailsQuery.TITLE);
    boolean hideDetails = EpisodeTools.isUnwatched(mEpisodeFlag) && DisplaySettings.preventSpoilers(getContext());
    if (hideDetails) {
        // just show the episode number "1x02"
        mTitle.setText(TextTools.getEpisodeNumber(getContext(), mSeasonNumber, mEpisodeNumber));
    } else {
        mTitle.setText(mEpisodeTitle);
    }
    String overview = cursor.getString(DetailsQuery.OVERVIEW);
    if (TextUtils.isEmpty(overview)) {
        // no description available, show no translation available message
        mDescription.setText(getString(R.string.no_translation, LanguageTools.getShowLanguageStringFor(getContext(), cursor.getString(DetailsQuery.SHOW_LANGUAGE)), getString(R.string.tvdb)));
    } else {
        if (hideDetails) {
            mDescription.setText(R.string.no_spoilers);
        } else {
            mDescription.setText(overview);
        }
    }
    // show title
    mShowTitle = cursor.getString(DetailsQuery.SHOW_TITLE);
    // release date, also build release time and day
    SpannableStringBuilder timeAndNumbersText = new SpannableStringBuilder();
    if (mEpisodeReleaseTime != -1) {
        Date actualRelease = TimeTools.applyUserOffset(getContext(), mEpisodeReleaseTime);
        mReleaseDate.setText(TimeTools.formatToLocalDateAndDay(getContext(), actualRelease));
        String dateTime;
        if (DisplaySettings.isDisplayExactDate(getContext())) {
            // "31. October 2010"
            dateTime = TimeTools.formatToLocalDate(getContext(), actualRelease);
        } else {
            // "in 15 mins"
            dateTime = TimeTools.formatToLocalRelativeTime(getContext(), actualRelease);
        }
        // append day: "in 15 mins (Fri)"
        timeAndNumbersText.append(getString(R.string.release_date_and_day, dateTime, TimeTools.formatToLocalDay(actualRelease)).toUpperCase(Locale.getDefault()));
        timeAndNumbersText.append("  ");
    } else {
        mReleaseDate.setText(R.string.unknown);
    }
    // absolute number (e.g. relevant for Anime): "ABSOLUTE 142"
    int numberStartIndex = timeAndNumbersText.length();
    int absoluteNumber = cursor.getInt(DetailsQuery.NUMBER_ABSOLUTE);
    if (absoluteNumber > 0) {
        timeAndNumbersText.append(getString(R.string.episode_number_absolute)).append(" ").append(String.valueOf(absoluteNumber));
        // de-emphasize number
        timeAndNumbersText.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_Caption_Dim), numberStartIndex, timeAndNumbersText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    mReleaseTime.setText(timeAndNumbersText);
    // guest stars
    Utils.setLabelValueOrHide(mLabelGuestStars, mGuestStars, TextTools.splitAndKitTVDBStrings(cursor.getString(DetailsQuery.GUESTSTARS)));
    // DVD episode number
    Utils.setLabelValueOrHide(mLabelDvd, mDvd, cursor.getDouble(DetailsQuery.NUMBER_DVD));
    // directors
    Utils.setValueOrPlaceholder(mDirectors, TextTools.splitAndKitTVDBStrings(cursor.getString(DetailsQuery.DIRECTORS)));
    // writers
    Utils.setValueOrPlaceholder(mWriters, TextTools.splitAndKitTVDBStrings(cursor.getString(DetailsQuery.WRITERS)));
    // last TVDb edit date
    long lastEditSeconds = cursor.getLong(DetailsQuery.LAST_EDITED);
    if (lastEditSeconds > 0) {
        mLastEdit.setText(DateUtils.formatDateTime(getActivity(), lastEditSeconds * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME));
    } else {
        mLastEdit.setText(R.string.unknown);
    }
    // ratings
    mRatingsContainer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            rateEpisode();
        }
    });
    CheatSheet.setup(mRatingsContainer, R.string.action_rate);
    // trakt rating
    mTextRating.setText(TraktTools.buildRatingString(cursor.getDouble(DetailsQuery.RATING_GLOBAL)));
    mTextRatingVotes.setText(TraktTools.buildRatingVotesString(getActivity(), cursor.getInt(DetailsQuery.RATING_VOTES)));
    // user rating
    mTextUserRating.setText(TraktTools.buildUserRatingString(getActivity(), cursor.getInt(DetailsQuery.RATING_USER)));
    loadTraktRatings();
    // episode image
    final String imagePath = cursor.getString(DetailsQuery.IMAGE);
    mImageContainer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), FullscreenImageActivity.class);
            intent.putExtra(FullscreenImageActivity.EXTRA_IMAGE, TvdbImageTools.fullSizeUrl(imagePath));
            Utils.startActivityWithAnimation(getActivity(), intent, v);
        }
    });
    loadImage(imagePath, hideDetails);
    // check in button
    final int episodeTvdbId = cursor.getInt(DetailsQuery._ID);
    buttonCheckin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // display a check-in dialog
            CheckInDialogFragment f = CheckInDialogFragment.newInstance(getActivity(), episodeTvdbId);
            if (f != null && isResumed()) {
                f.show(getFragmentManager(), "checkin-dialog");
                Utils.trackAction(getActivity(), TAG, "Check-In");
            }
        }
    });
    CheatSheet.setup(buttonCheckin);
    // hide check-in if not connected to trakt or hexagon is enabled
    boolean isConnectedToTrakt = TraktCredentials.get(getActivity()).hasCredentials();
    boolean displayCheckIn = isConnectedToTrakt && !HexagonSettings.isEnabled(getActivity());
    buttonCheckin.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    dividerEpisodeButtons.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    // watched button
    boolean isWatched = EpisodeTools.isWatched(mEpisodeFlag);
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonWatch, 0, isWatched ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatched) : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatch), 0, 0);
    buttonWatch.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onToggleWatched();
            Utils.trackAction(getActivity(), TAG, "Toggle watched");
        }
    });
    buttonWatch.setText(isWatched ? R.string.action_unwatched : R.string.action_watched);
    CheatSheet.setup(buttonWatch, isWatched ? R.string.action_unwatched : R.string.action_watched);
    // collected button
    mCollected = cursor.getInt(DetailsQuery.COLLECTED) == 1;
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonCollect, 0, mCollected ? R.drawable.ic_collected : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollect), 0, 0);
    buttonCollect.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onToggleCollected();
            Utils.trackAction(getActivity(), TAG, "Toggle collected");
        }
    });
    buttonCollect.setText(mCollected ? R.string.action_collection_remove : R.string.action_collection_add);
    CheatSheet.setup(buttonCollect, mCollected ? R.string.action_collection_remove : R.string.action_collection_add);
    // skip button
    boolean isSkipped = EpisodeTools.isSkipped(mEpisodeFlag);
    if (isWatched) {
        // if watched do not allow skipping
        buttonSkip.setVisibility(View.INVISIBLE);
    } else {
        buttonSkip.setVisibility(View.VISIBLE);
        Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonSkip, 0, isSkipped ? R.drawable.ic_skipped : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableSkip), 0, 0);
        buttonSkip.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onToggleSkipped();
                Utils.trackAction(getActivity(), TAG, "Toggle skipped");
            }
        });
        buttonSkip.setText(isSkipped ? R.string.action_dont_skip : R.string.action_skip);
        CheatSheet.setup(buttonSkip, isSkipped ? R.string.action_dont_skip : R.string.action_skip);
    }
    // service buttons
    ServiceUtils.setUpTraktEpisodeButton(mTraktButton, getEpisodeTvdbId(), TAG);
    // IMDb
    String imdbId = cursor.getString(DetailsQuery.IMDBID);
    if (TextUtils.isEmpty(imdbId)) {
        // fall back to show IMDb id
        imdbId = cursor.getString(DetailsQuery.SHOW_IMDBID);
    }
    ServiceUtils.setUpImdbButton(imdbId, mImdbButton, TAG);
    // TVDb
    final int seasonTvdbId = cursor.getInt(DetailsQuery.SEASON_ID);
    ServiceUtils.setUpTvdbButton(mShowTvdbId, seasonTvdbId, getEpisodeTvdbId(), mTvdbButton, TAG);
    // trakt comments
    mCommentsButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), TraktCommentsActivity.class);
            intent.putExtras(TraktCommentsActivity.createInitBundleEpisode(mEpisodeTitle, getEpisodeTvdbId()));
            Utils.startActivityWithAnimation(getActivity(), intent, v);
            Utils.trackAction(v.getContext(), TAG, "Comments");
        }
    });
    mEpisodeContainer.setVisibility(View.VISIBLE);
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) OnClickListener(android.view.View.OnClickListener) SpannableStringBuilder(android.text.SpannableStringBuilder) CheckInDialogFragment(com.battlelancer.seriesguide.ui.dialogs.CheckInDialogFragment)

Aggregations

CheckInDialogFragment (com.battlelancer.seriesguide.ui.dialogs.CheckInDialogFragment)2 Intent (android.content.Intent)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextAppearanceSpan (android.text.style.TextAppearanceSpan)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 Date (java.util.Date)1