<commit_before>/*
 * Copyright (c) 2015 <NAME>. All rights reserved.
 */

package com.ddiehl.android.htn.presenter;

import android.content.Context;
import android.util.Log;

import com.ddiehl.android.htn.BusProvider;
import com.ddiehl.android.htn.IdentityManager;
import com.ddiehl.android.htn.R;
import com.ddiehl.android.htn.events.requests.UserSignOutEvent;
import com.ddiehl.android.htn.events.responses.UserIdentitySavedEvent;
import com.ddiehl.android.htn.utils.BaseUtils;
import com.ddiehl.android.htn.view.MainView;
import com.ddiehl.reddit.identity.UserIdentity;
import com.flurry.android.FlurryAgent;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;

import java.util.HashMap;
import java.util.Map;

import retrofit.RetrofitError;

public class MainPresenterImpl implements MainPresenter {

    private Bus mBus;
    private Context mContext;

    private MainView mMainView;
    private IdentityManager mIdentityManager;
    private String mUsernameContext;

    public MainPresenterImpl(Context context, MainView view) {
        mBus = BusProvider.getInstance();
        mContext = context.getApplicationContext();

        mMainView = view;
        mIdentityManager = IdentityManager.getInstance(mContext);
    }

    @Subscribe
    public void onNetworkError(RetrofitError error) {
        Log.e("HTN", "RetrofitError: " + error.getKind().toString());
        Log.e("HTN", Log.getStackTraceString(error));
        mMainView.showToast(BaseUtils.getFriendlyError(mContext, error));

        // Log Flurry event
        Map<String, String> params = new HashMap<>();
        params.put("url", error.getUrl());
        params.put("kind", error.getKind().toString());
        FlurryAgent.logEvent("api error", params);
    }

    @Subscribe
    public void onUserIdentitySaved(UserIdentitySavedEvent event) {
        mMainView.updateUserIdentity();

        UserIdentity id = event.getUserIdentity();
        if (id != null) {
            mMainView.showToast(String.format(mContext.getString(R.string.welcome_user), id.getName()));
//            mIdentityManager.saveUserIdentity(id);
        }
    }

    @Subscribe
    public void onUserSignOut(UserSignOutEvent event) {
        mMainView.showToast(R.string.user_signed_out);
    }

    @Override
    public UserIdentity getAuthorizedUser() {
        return mIdentityManager.getUserIdentity();
    }
<commit_msg>Limiting welcome message to display on first sign for the session only<commit_after>/*
 * Copyright (c) 2015 <NAME>. All rights reserved.
 */

package com.ddiehl.android.htn.presenter;

import android.content.Context;
import android.util.Log;

import com.ddiehl.android.htn.BusProvider;
import com.ddiehl.android.htn.IdentityManager;
import com.ddiehl.android.htn.R;
import com.ddiehl.android.htn.events.requests.UserSignOutEvent;
import com.ddiehl.android.htn.events.responses.UserIdentitySavedEvent;
import com.ddiehl.android.htn.utils.BaseUtils;
import com.ddiehl.android.htn.view.MainView;
import com.ddiehl.reddit.identity.UserIdentity;
import com.flurry.android.FlurryAgent;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;

import java.util.HashMap;
import java.util.Map;

import retrofit.RetrofitError;

public class MainPresenterImpl implements MainPresenter {

    private Bus mBus;
    private Context mContext;

    private MainView mMainView;
    private IdentityManager mIdentityManager;
    private String mUsernameContext;
    private String mLastUser;

    public MainPresenterImpl(Context context, MainView view) {
        mBus = BusProvider.getInstance();
        mContext = context.getApplicationContext();

        mMainView = view;
        mIdentityManager = IdentityManager.getInstance(mContext);
    }

    @Subscribe
    public void onNetworkError(RetrofitError error) {
        Log.e("HTN", "RetrofitError: " + error.getKind().toString());
        Log.e("HTN", Log.getStackTraceString(error));
        mMainView.showToast(BaseUtils.getFriendlyError(mContext, error));

        // Log Flurry event
        Map<String, String> params = new HashMap<>();
        params.put("url", error.getUrl());
        params.put("kind", error.getKind().toString());
        FlurryAgent.logEvent("api error", params);
    }

    @Subscribe
    public void onUserIdentitySaved(UserIdentitySavedEvent event) {
        mMainView.updateUserIdentity();

        UserIdentity id = event.getUserIdentity();
        if (id != null && !id.getName().equals(mLastUser)) {
            mMainView.showToast(String.format(mContext.getString(R.string.welcome_user), id.getName()));
//            mIdentityManager.saveUserIdentity(id);
        }
    }

    @Subscribe
    public void onUserSignOut(UserSignOutEvent event) {
        mMainView.showToast(R.string.user_signed_out);
        mLastUser = null;
    }

    @Override
    public UserIdentity getAuthorizedUser() {
        return mIdentityManager.getUserIdentity();
    }

{'fraction_non_alphanumeric': 0.10876623376623376, 'fraction_numerical': 0.0016233766233766235, 'mean_word_length': 3.65, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7662017', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1457, 'n_words': 275}