<commit_before>package com.khmelenko.lab.travisclient.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.khmelenko.lab.travisclient.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Shows raw logs
 *
 * @author <NAME>
 */
public class RawLogFragment extends Fragment {

    private static final String JOB_ID_KEY = "JobId";

    // TODO Use the resource from settings
    private static final String RAW_LOG_URL = "https://api.travis-ci.org/jobs/%1$s/log";

    @Bind(R.id.raw_log_webview)
    WebView mWebView;

    @Bind(R.id.progressbar)
    ProgressBar mProgressBar;

    private long mJobId;
    private OnRawLogFragmentListener mListener;

    /**
     * Creates an instance of the fragment
     *
     * @param jobId Job ID
     * @return Fragment instance
     */
    public static RawLogFragment newInstance(long jobId) {
        RawLogFragment fragment = new RawLogFragment();
        Bundle args = new Bundle();
        args.putLong(JOB_ID_KEY, jobId);
        fragment.setArguments(args);
        return fragment;
    }

    public RawLogFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mJobId = getArguments().getLong(JOB_ID_KEY);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_raw_log, container, false);
        ButterKnife.bind(this, view);

        mWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if(mListener != null) {
                    mListener.onLogLoaded();
                }

                // TODO Add scrolling to the botton
//                double height = Math.floor(mWebView.getContentHeight() * mWebView.getScaleY());
//                mWebView.scrollTo(0, (int)height);

                mProgressBar.setVisibility(View.GONE);
                mWebView.setVisibility(View.VISIBLE);
            }
        });

        mWebView.loadUrl(String.format(RAW_LOG_URL, String.valueOf(mJobId)));

        return view;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnRawLogFragmentListener) activity;<commit_msg>Url resource and path for the raw logs are splitted<commit_after>package com.khmelenko.lab.travisclient.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.khmelenko.lab.travisclient.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Shows raw logs
 *
 * @author <NAME>
 */
public class RawLogFragment extends Fragment {

    private static final String JOB_ID_KEY = "JobId";

    // TODO Use the resource from settings
    private static final String RAW_LOG_RESOURCE = "https://api.travis-ci.org";
    private static final String RAW_LOG_PATH = "/jobs/%1$s/log";

    @Bind(R.id.raw_log_webview)
    WebView mWebView;

    @Bind(R.id.progressbar)
    ProgressBar mProgressBar;

    private long mJobId;
    private OnRawLogFragmentListener mListener;

    /**
     * Creates an instance of the fragment
     *
     * @param jobId Job ID
     * @return Fragment instance
     */
    public static RawLogFragment newInstance(long jobId) {
        RawLogFragment fragment = new RawLogFragment();
        Bundle args = new Bundle();
        args.putLong(JOB_ID_KEY, jobId);
        fragment.setArguments(args);
        return fragment;
    }

    public RawLogFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mJobId = getArguments().getLong(JOB_ID_KEY);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_raw_log, container, false);
        ButterKnife.bind(this, view);

        mWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if (mListener != null) {
                    mListener.onLogLoaded();
                }

                // TODO Add scrolling to the botton
//                double height = Math.floor(mWebView.getContentHeight() * mWebView.getScaleY());
//                mWebView.scrollTo(0, (int)height);

                mProgressBar.setVisibility(View.GONE);
                mWebView.setVisibility(View.VISIBLE);
            }
        });

        String path = String.format(RAW_LOG_PATH, String.valueOf(mJobId));
        mWebView.loadUrl(RAW_LOG_RESOURCE + path);

        return view;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnRawLogFragmentListener) activity;
{'fraction_non_alphanumeric': 0.09248850281042412, 'fraction_numerical': 0.001021972406745018, 'mean_word_length': 2.499404052443385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4266910', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1631, 'n_words': 375}