<commit_before>package com.github.kubatatami.judonetworking;


import android.app.Fragment;

import com.github.kubatatami.judonetworking.exceptions.JudoException;

/**
 * Created with IntelliJ IDEA.
 * User: jbogacki
 * Date: 23.04.2013
 * Time: 11:40
 */
public class FragmentCallback<T> extends Callback<T> {

    private final Fragment fragment;
    private AsyncResult asyncResult;

    public FragmentCallback(Fragment fragment) {
        this.fragment = fragment;
    }

    @Override
    public final void onStart(boolean isCached, AsyncResult asyncResult) {
        this.asyncResult = asyncResult;
        if (fragment.getActivity() != null) {
            onSafeStart(isCached, asyncResult);
        } else if (asyncResult != null) {
            asyncResult.cancel();
        }
    }

    @Override
    public final void onSuccess(T result) {
        if (fragment.getActivity() != null) {
            onSafeSuccess(result);
        } else if (asyncResult != null) {
            asyncResult.cancel();
        }
    }

    @Override
    public final void onError(JudoException e) {
        if (fragment.getActivity() != null) {
            onSafeError(e);
        } else if (asyncResult != null) {
            asyncResult.cancel();
        }
    }

    @Override
    public final void onProgress(int progress) {
        if (fragment.getActivity() != null) {
            onSafeProgress(progress);
        } else if (asyncResult != null) {
            asyncResult.cancel();
        }
    }

    @Override
    public final void onFinish() {
        if (fragment.getActivity() != null) {
            onSafeFinish();
        } else if (asyncResult != null) {
            asyncResult.cancel();
        }
    }

    public void onSafeStart(boolean isCached, AsyncResult asyncResult) {

    }

    public void onSafeProgress(int progress) {

    }

    public void onSafeSuccess(T result) {

    }

    public void onSafeFinish() {

    }

    public void onSafeError(JudoException e) {

    }
}
<commit_msg>port SupportFragmentCallback function to FragmentCallback<commit_after>package com.github.kubatatami.judonetworking;

import android.app.Fragment;
import android.app.FragmentManager;

import com.github.kubatatami.judonetworking.exceptions.JudoException;

/**
 * Created with IntelliJ IDEA.
 * User: jbogacki
 * Date: 23.04.2013
 * Time: 11:40
 */
public class FragmentCallback<T> extends Callback<T> implements FragmentManager.OnBackStackChangedListener {

    private final Fragment fragment;
    private AsyncResult asyncResult;
    private FragmentManager manager;

    public FragmentCallback(Fragment fragment) {
        this.fragment = fragment;
        this.manager = fragment.getFragmentManager();
        manager.addOnBackStackChangedListener(this);
    }

    @Override
    public final void onStart(boolean isCached, AsyncResult asyncResult) {
        this.asyncResult = asyncResult;
        if (fragment.getActivity() != null) {
            onSafeStart(isCached, asyncResult);
        } else {
            tryCancel();
        }
    }

    @Override
    public final void onSuccess(T result) {
        if (fragment.getActivity() != null) {
            onSafeSuccess(result);
        } else {
            tryCancel();
        }
    }

    @Override
    public final void onError(JudoException e) {
        if (fragment.getActivity() != null) {
            onSafeError(e);
        } else {
            tryCancel();
        }
    }

    @Override
    public final void onProgress(int progress) {
        if (fragment.getActivity() != null) {
            onSafeProgress(progress);
        } else {
            tryCancel();
        }
    }

    @Override
    public final void onFinish() {
        if (fragment.getActivity() != null) {
            onSafeFinish();
        } else {
            tryCancel();
        }
        manager.removeOnBackStackChangedListener(this);
    }

    protected void tryCancel() {
        if (asyncResult != null) {
            asyncResult.cancel();
            manager.removeOnBackStackChangedListener(this);
        }
    }

    public void onSafeStart(boolean isCached, AsyncResult asyncResult) {

    }

    public void onSafeProgress(int progress) {

    }

    public void onSafeSuccess(T result) {

    }

    public void onSafeFinish() {

    }

    public void onSafeError(JudoException e) {

    }


    @Override
    public void onBackStackChanged() {
        if (fragment.getActivity() == null) {
            tryCancel();
        }
    }
}

{'fraction_non_alphanumeric': 0.09897686832740213, 'fraction_numerical': 0.005338078291814947, 'mean_word_length': 2.2445887445887447, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6647788', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1227, 'n_words': 282}