<commit_before>package com.pr0gramm.app.ui.views.viewer;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;

import com.pr0gramm.app.R;

import rx.functions.Action1;

/**
 */
@SuppressLint("ViewConstructor")
public abstract class ProxyMediaView extends MediaView {
    private MediaView child;

    public ProxyMediaView(Activity context, MediaUri uri, Runnable onViewListener) {
        super(context, R.layout.player_proxy, uri, onViewListener);
        showBusyIndicator();
    }

    public void setChild(MediaView child) {
        removeChildView();
        hideBusyIndicator();

        setChildView(child);

        bootupChild();

        // forward double clicks
        child.setTapListener(new ForwardingTapListener());
    }

    /**
     * Adds the proxied child above the preview.
     */
    private void setChildView(MediaView mediaView) {
        int idx = getChildCount();
        View previewView = getPreviewView();
        if (previewView != null && previewView.getParent() == this) {
            idx = indexOfChild(previewView) + 1;
        }

        // transfer the layout parameters
        mediaView.setLayoutParams(getLayoutParams());
        mediaView.setViewAspect(getViewAspect());
        addView(mediaView, idx);

        child = mediaView;
    }

    private void removeChildView() {
        if (child == null)
            return;

        teardownChild();
        removeView(child);

        child = null;
    }

    private void bootupChild() {
        if (child != null) {
            if (isResumed())
                child.onResume();

            if (isPlaying())
                child.playMedia();
        }
    }

    private void teardownChild() {
        if (child != null) {
            if (isPlaying())
                child.stopMedia();

            if (isResumed())
                child.onPause();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        propagate(MediaView::onResume);
    }

    @Override
    public void playMedia() {
        super.playMedia();
        propagate(MediaView::playMedia);
    }

    @Override
    public void stopMedia() {
        super.stopMedia();
        propagate(MediaView::stopMedia);
    }

    @Override
    public void rewind() {
        propagate(MediaView::rewind);
    }

    @Override
    public MediaView getActualMediaView() {
        return child != null ? child : this;
    }

    @Override
    protected void onMediaShown() {
        setViewAspect(-1);
        removePreviewImage();
        super.onMediaShown();
    }

    @Override
    public void onPause() {
        propagate(MediaView::onPause);
        super.onPause();
    }

    private void propagate(Action1<MediaView> action) {
        if (child != null)
            action.call(child);<commit_msg>Forward all the methods.<commit_after>package com.pr0gramm.app.ui.views.viewer;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.MotionEvent;
import android.view.View;

import com.pr0gramm.app.R;

/**
 */
@SuppressLint("ViewConstructor")
public abstract class ProxyMediaView extends MediaView {
    private MediaView child;

    public ProxyMediaView(Activity context, MediaUri uri, Runnable onViewListener) {
        super(context, R.layout.player_proxy, uri, onViewListener);
        showBusyIndicator();
    }

    public void setChild(MediaView child) {
        removeChildView();
        hideBusyIndicator();

        setChildView(child);

        bootupChild();

        // forward double clicks
        child.setTapListener(new ForwardingTapListener());
    }

    /**
     * Adds the proxied child above the preview.
     */
    private void setChildView(MediaView mediaView) {
        int idx = getChildCount();
        View previewView = getPreviewView();
        if (previewView != null && previewView.getParent() == this) {
            idx = indexOfChild(previewView) + 1;
        }

        // transfer the layout parameters
        mediaView.setLayoutParams(getLayoutParams());
        mediaView.setViewAspect(getViewAspect());
        addView(mediaView, idx);

        child = mediaView;
    }

    private void removeChildView() {
        if (child == null)
            return;

        teardownChild();
        removeView(child);

        child = null;
    }

    private void bootupChild() {
        if (child != null) {
            if (isResumed())
                child.onResume();

            if (isPlaying())
                child.playMedia();
        }
    }

    private void teardownChild() {
        if (child != null) {
            if (isPlaying())
                child.stopMedia();

            if (isResumed())
                child.onPause();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (child != null)
            child.onResume();
    }

    @Override
    public void playMedia() {
        super.playMedia();
        if (child != null)
            child.playMedia();
    }

    @Override
    public void stopMedia() {
        super.stopMedia();
        if (child != null)
            child.stopMedia();
    }

    @Override
    public void rewind() {
        if (child != null)
            child.rewind();
    }

    @Override
    public MediaView getActualMediaView() {
        return child != null ? child : this;
    }

    @Override
    protected void onMediaShown() {
        setViewAspect(-1);
        removePreviewImage();
        super.onMediaShown();
    }

    @Override
    public void onPause() {
        super.onPause();
        if (child != null)
            child.onPause();
    }

    @Override
    public boolean onTouchEvent(@NonNull MotionEvent event) {
        if (child != null) {
            event.offsetLocation(
                    child.getPaddingLeft() - getPaddingLeft(),
                    child.getPaddingTop() - getPaddingTop());

            return child.onTouchEvent(event);
        }

        return super.onTouchEvent(event);
{'fraction_non_alphanumeric': 0.10887827376050074, 'fraction_numerical': 0.001647175094712568, 'mean_word_length': 2.0239043824701195, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '376507', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1670, 'n_words': 369}