<commit_before>package geonote.app.Fragments;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.location.Geocoder;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;

import java.util.Locale;

import geonote.app.Activity.MainActivity;
import geonote.app.Constants;
import geonote.app.NotesManager;
import geonote.app.NotesRepository;
import geonote.app.R;

public class SplashScreenFragment extends BaseFacebookHandlerFragment {

    View mCurrentView = null;
    NotesManager mNotesManager = null;
    NotesRepository mNotesRepository = null;
    TextView mSplashScreenTextView = null;
    Time startupTime = new Time();
    int splashScreenShowTimeMillis = 1*1000;

    public SplashScreenFragment() {
        startupTime.setToNow();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mCurrentView = inflater.inflate(R.layout.fragment_splash_screen, container, false);

        mSplashScreenTextView = (TextView) mCurrentView.findViewById(R.id.splashScreenText);

        return mCurrentView;
    }

    @Override
    public void onActivityCreated (Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);

        mNotesManager = new NotesManager();
        mNotesRepository = new NotesRepository(new Geocoder(getActivity().getBaseContext(), Locale.getDefault()));

        try {
            NotesRepository.SetInstance(mNotesRepository);
        } catch (Exception e) {
            e.printStackTrace();
        }

        mNotesManager.mOnNotesLoadedListener  = new NotesManager.OnNotesLoadedListener() {
            @Override
            public void onNotesLoaded() {
                logAndShowOnScreen("\nNotes loaded.");
                launchMainActivity();
            }
        };

        Session session = Session.getActiveSession();

        if(session!= null && session.isOpened()) {
            logAndShowOnScreen("\nLogging into facebook.");
        } else {
            logAndShowOnScreen("\nNo facebook app/login info found.");
            mNotesManager.loadNotes(getActivity(), mNotesRepository, null);
        }
    }

    private void logAndShowOnScreen(String logText) {
        Log.d("SplashScreen", logText);
        mSplashScreenTextView.append(logText);
    }

    public void loadNotes(Activity activity, final String userName) {

        // TODO: Load notes only if not already loaded
        logAndShowOnScreen("\nRetrieving notes.");
        mNotesManager.loadNotes(activity, mNotesRepository, userName);
    }

    protected void onSessionStateChange(Session session, SessionState state, Exception exception){
        if (session != null && session.isOpened()) {
            logAndShowOnScreen("\nLogged in. Getting user details.");
            Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user,
                                        Response response) {
                    if (user != null) {
                        System.out.println("onSessionStateChange: LoadNotes: session is open. username:"+user.getName());

                        loadNotes(getActivity(), getLoggedInUsername());
                    }
                }
            });
            Request.executeBatchAsync(request);
        } else {
            logAndShowOnScreen("\nUser not already logged in.");
            System.out.println("onSessionStateChange: LoadNotes: session was closed.");
            loadNotes(getActivity(), getLoggedInUsername());
        }
    }

    private void launchMainActivity() {
        logAndShowOnScreen("\nLaunching map view.");

        final Fragment currentFragment = this;
        final Handler timerHandler = new Handler();
        Runnable timerRunnable = new Runnable() {

            @Override
            public void run() {
                LaunchMainActivity(getActivity(), currentFragment);
                SplashScreenFragment.this.getActivity().finish();
            }
        };

        Time now = new Time();
        now.setToNow();
        timerHandler.postDelayed(timerRunnable,<commit_msg>Fix potential null ref issue as reported<commit_after>package geonote.app.Fragments;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.location.Geocoder;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;

import java.util.Locale;

import geonote.app.Activity.MainActivity;
import geonote.app.Constants;
import geonote.app.NotesManager;
import geonote.app.NotesRepository;
import geonote.app.R;

public class SplashScreenFragment extends BaseFacebookHandlerFragment {

    View mCurrentView = null;
    NotesManager mNotesManager = null;
    NotesRepository mNotesRepository = null;
    TextView mSplashScreenTextView = null;
    Time startupTime = new Time();
    int splashScreenShowTimeMillis = 1*1000;

    public SplashScreenFragment() {
        startupTime.setToNow();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mCurrentView = inflater.inflate(R.layout.fragment_splash_screen, container, false);

        mSplashScreenTextView = (TextView) mCurrentView.findViewById(R.id.splashScreenText);

        return mCurrentView;
    }

    @Override
    public void onActivityCreated (Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);

        mNotesManager = new NotesManager();
        mNotesRepository = new NotesRepository(new Geocoder(getActivity().getBaseContext(), Locale.getDefault()));

        try {
            NotesRepository.SetInstance(mNotesRepository);
        } catch (Exception e) {
            e.printStackTrace();
        }

        mNotesManager.mOnNotesLoadedListener  = new NotesManager.OnNotesLoadedListener() {
            @Override
            public void onNotesLoaded() {
                logAndShowOnScreen("\nNotes loaded.");
                launchMainActivity();
            }
        };

        Session session = Session.getActiveSession();

        if(session!= null && session.isOpened()) {
            logAndShowOnScreen("\nLogging into facebook.");
        } else {
            logAndShowOnScreen("\nNo facebook app/login info found.");
            mNotesManager.loadNotes(getActivity(), mNotesRepository, null);
        }
    }

    private void logAndShowOnScreen(String logText) {
        Log.d("SplashScreen", logText);
        mSplashScreenTextView.append(logText);
    }

    public void loadNotes(Activity activity, final String userName) {

        // TODO: Load notes only if not already loaded
        logAndShowOnScreen("\nRetrieving notes.");
        mNotesManager.loadNotes(activity, mNotesRepository, userName);
    }

    protected void onSessionStateChange(Session session, SessionState state, Exception exception){
        if (session != null && session.isOpened()) {
            logAndShowOnScreen("\nLogged in. Getting user details.");
            Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user,
                                        Response response) {
                    if (user != null) {
                        System.out.println("onSessionStateChange: LoadNotes: session is open. username:"+user.getName());

                        loadNotes(getActivity(), user.getId());
                    }
                }
            });
            Request.executeBatchAsync(request);
        } else {
            logAndShowOnScreen("\nUser not already logged in.");
            System.out.println("onSessionStateChange: LoadNotes: session was closed.");
            loadNotes(getActivity(), getLoggedInUsername());
        }
    }

    private void launchMainActivity() {
        logAndShowOnScreen("\nLaunching map view.");

        final Fragment currentFragment = this;
        final Handler timerHandler = new Handler();
        Runnable timerRunnable = new Runnable() {

            @Override
            public void run() {
                LaunchMainActivity(getActivity(), currentFragment);
                SplashScreenFragment.this.getActivity().finish();
            }
        };

        Time now = new Time();
        now.setToNow();
        timerHandler.postDelayed(timerRunnable,
{'fraction_non_alphanumeric': 0.09238783755049969, 'fraction_numerical': 0.0012757814161173718, 'mean_word_length': 2.6517857142857144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6989273', 'n_tokens_mistral': 2477, 'n_tokens_neox': 2305, 'n_words': 523}