<commit_before>/*
 * Copyright 2013-2015 The GDG Frisbee Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gdg.frisbee.android.onboarding;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.gdg.frisbee.android.R;
import org.gdg.frisbee.android.api.Callback;
import org.gdg.frisbee.android.api.model.plus.Person;
import org.gdg.frisbee.android.app.App;
import org.gdg.frisbee.android.common.BaseFragment;
import org.gdg.frisbee.android.view.BitmapBorderTransformation;

import butterknife.BindDimen;
import butterknife.BindView;
import butterknife.OnClick;

public class FirstStartStep2Fragment extends BaseFragment {

    private static final String KEY_INVITE = "invite";

    @BindView(R.id.invite_sender_container)
    View inviteContainer;
    @BindView(R.id.invite_sender_profile_image)
    ImageView inviteSenderImage;
    @BindView(R.id.invite_sender_message)
    TextView inviteSenderMessage;
    @BindDimen(R.dimen.navdrawer_user_picture_size)
    int profileImageSize;

    Step2Listener listener = Step2Listener.EMPTY;
    private Invite invite;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflateView(inflater, R.layout.fragment_welcome_step2, container);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        if (savedInstanceState != null) {
            invite = savedInstanceState.getParcelable(KEY_INVITE);
            if (invite != null) {
                loadInvite(invite);
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable(KEY_INVITE, invite);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        if (context instanceof Step2Listener) {
            listener = (Step2Listener) context;
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();

        listener = Step2Listener.EMPTY;
    }

    @OnClick(R.id.googleSignin)
    public void onSignedIn() {
        listener.onSignedIn();
    }

    @OnClick(R.id.skipSignin)
    public void onSkippedSignIn() {
        listener.onSkippedSignIn();
    }

    public void loadInvite(Invite inviteSender) {
        this.invite = inviteSender;
        if (!isContextValid()) {
            return;
        }


        if (TextUtils.isEmpty(invite.sender)) {
            displayUnknownSender();
            return;
        }

        App.getInstance().getPlusApi()
            .getPerson(inviteSender.sender)
            .enqueue(new Callback<Person>() {
                @Override
                public void success(Person sender) {
                    if (isContextValid()) {
                        displaySender(sender);
                    }
                }
            });
    }

    private void displayUnknownSender() {
        inviteContainer.setVisibility(View.VISIBLE);
        updateSenderName(getString(R.string.friend));
        inviteSenderImage.setImageResource(R.drawable.ic_no_avatar);
    }
<commit_msg>Show unknown UI if the loading of the sender fails<commit_after>/*
 * Copyright 2013-2015 The GDG Frisbee Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gdg.frisbee.android.onboarding;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.gdg.frisbee.android.R;
import org.gdg.frisbee.android.api.Callback;
import org.gdg.frisbee.android.api.model.plus.Person;
import org.gdg.frisbee.android.app.App;
import org.gdg.frisbee.android.common.BaseFragment;
import org.gdg.frisbee.android.view.BitmapBorderTransformation;

import butterknife.BindDimen;
import butterknife.BindView;
import butterknife.OnClick;

public class FirstStartStep2Fragment extends BaseFragment {

    private static final String KEY_INVITE = "invite";

    @BindView(R.id.invite_sender_container)
    View inviteContainer;
    @BindView(R.id.invite_sender_profile_image)
    ImageView inviteSenderImage;
    @BindView(R.id.invite_sender_message)
    TextView inviteSenderMessage;
    @BindDimen(R.dimen.navdrawer_user_picture_size)
    int profileImageSize;

    Step2Listener listener = Step2Listener.EMPTY;
    private Invite invite;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflateView(inflater, R.layout.fragment_welcome_step2, container);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        if (savedInstanceState != null) {
            invite = savedInstanceState.getParcelable(KEY_INVITE);
            if (invite != null) {
                loadInvite(invite);
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable(KEY_INVITE, invite);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        if (context instanceof Step2Listener) {
            listener = (Step2Listener) context;
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();

        listener = Step2Listener.EMPTY;
    }

    @OnClick(R.id.googleSignin)
    public void onSignedIn() {
        listener.onSignedIn();
    }

    @OnClick(R.id.skipSignin)
    public void onSkippedSignIn() {
        listener.onSkippedSignIn();
    }

    public void loadInvite(Invite inviteSender) {
        this.invite = inviteSender;
        if (!isContextValid()) {
            return;
        }

        if (TextUtils.isEmpty(invite.sender)) {
            displayUnknownSender();
            return;
        }

        App.getInstance().getPlusApi()
            .getPerson(inviteSender.sender)
            .enqueue(new Callback<Person>() {
                @Override
                public void success(Person sender) {
                    if (isContextValid()) {
                        displaySender(sender);
                    }
                }

                @Override
                public void failure(Throwable error) {
                    if (isContextValid()) {
                        displayUnknownSender();
                    }
                }

                @Override
                public void networkFailure(Throwable error) {
                    if (isContextValid()) {
                        displayUnknownSender();
                    }
                }
            });
    }

    private void displayUnknownSender() {
        inviteContainer.setVisibility(View.VISIBLE);
        updateSenderName(getString(R.string.friend));
        inviteSenderImage.setImageResource(R.drawable.ic_no_avatar);
    }

{'fraction_non_alphanumeric': 0.08677248677248678, 'fraction_numerical': 0.004703115814226925, 'mean_word_length': 2.6679603277274686, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2896375', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2308, 'n_words': 529}