<commit_before>package me.vickychijwani.spectre.view.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.vickychijwani.spectre.R;
import me.vickychijwani.spectre.model.Post;
import me.vickychijwani.spectre.pref.UserPrefs;
import me.vickychijwani.spectre.util.AppUtils;
import me.vickychijwani.spectre.view.PostViewActivity;

public class PostViewFragment extends BaseFragment {

    @Bind(R.id.edit_post_btn)
    View mEditBtn;

    private OnEditClickListener mEditClickListener;
    private Post mPost;
    private int mMarkdownHashCode;
    private WebViewFragment mWebViewFragment;

    public interface OnEditClickListener {
        void onEditClicked();
    }


    @SuppressWarnings("unused")
    public static PostViewFragment newInstance() {
        return new PostViewFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_post_view, container, false);
        ButterKnife.bind(this, view);

        mPost = ((PostViewActivity) getActivity()).getPost();

        UserPrefs prefs = UserPrefs.getInstance(getActivity());
        String blogUrl = prefs.getString(UserPrefs.Key.BLOG_URL);

        mWebViewFragment = WebViewFragment.newInstance("file:///android_asset/post-preview.html");
        mWebViewFragment.setJSInterface(new Object() {
            @JavascriptInterface
            public String getMarkdown() {
                // FIXME dirty string-replacement hack!
                return mPost.getMarkdown().replaceAll("/content/images",
                        AppUtils.pathJoin(blogUrl, "/content/images"));
            }
        }, "POST");
        getChildFragmentManager()
                .beginTransaction()
                .add(R.id.web_view_container, mWebViewFragment)
                .commit();

        // set up edit button
        mEditBtn.setOnClickListener(v -> mEditClickListener.onEditClicked());

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        hide();
    }<commit_msg>Fix #99: Always launch external browser on tapping a link in the preview.<commit_after>package me.vickychijwani.spectre.view.fragments;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.vickychijwani.spectre.R;
import me.vickychijwani.spectre.model.Post;
import me.vickychijwani.spectre.pref.UserPrefs;
import me.vickychijwani.spectre.util.AppUtils;
import me.vickychijwani.spectre.view.PostViewActivity;

public class PostViewFragment extends BaseFragment {

    @Bind(R.id.edit_post_btn)
    View mEditBtn;

    private OnEditClickListener mEditClickListener;
    private Post mPost;
    private int mMarkdownHashCode;
    private WebViewFragment mWebViewFragment;

    public interface OnEditClickListener {
        void onEditClicked();
    }


    @SuppressWarnings("unused")
    public static PostViewFragment newInstance() {
        return new PostViewFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_post_view, container, false);
        ButterKnife.bind(this, view);

        mPost = ((PostViewActivity) getActivity()).getPost();

        UserPrefs prefs = UserPrefs.getInstance(getActivity());
        String blogUrl = prefs.getString(UserPrefs.Key.BLOG_URL);

        mWebViewFragment = WebViewFragment.newInstance("file:///android_asset/post-preview.html");
        mWebViewFragment.setJSInterface(new Object() {
            @JavascriptInterface
            public String getMarkdown() {
                // FIXME dirty string-replacement hack!
                return mPost.getMarkdown().replaceAll("/content/images",
                        AppUtils.pathJoin(blogUrl, "/content/images"));
            }
        }, "POST");
        mWebViewFragment.setWebViewClient(new WebViewFragment.DefaultWebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // launch links in external browser
                url = AppUtils.pathJoin(blogUrl, url);
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            }
        });

        getChildFragmentManager()
                .beginTransaction()
                .add(R.id.web_view_container, mWebViewFragment)
                .commit();

        // set up edit button
        mEditBtn.setOnClickListener(v -> mEditClickListener.onEditClicked());

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        hide();
    }
{'fraction_non_alphanumeric': 0.09147314305974118, 'fraction_numerical': 0.0003545470661230278, 'mean_word_length': 3.088405797101449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5530670', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1517, 'n_words': 309}