<commit_before>/*
 * Copyright 2015-2018 The twitlatte authors
 *
 * 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 com.github.moko256.twitlatte;

import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.Toast;

import com.github.moko256.twitlatte.entity.AccessToken;
import com.github.moko256.twitlatte.entity.Type;
import com.github.moko256.twitlatte.model.base.OAuthModel;
import com.github.moko256.twitlatte.text.TwitterStringUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.internal.disposables.CancellableDisposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by moko256 on 2016/04/29.
 *
 * @author moko256
 */
public class OAuthActivity extends AppCompatActivity {

    private static final String STATE_CLIENT_TYPE = "state_client_type";
    private static final String STATE_REQUIRE_PIN = "state_require_pin";
    private static final String STATE_URL_ENTER_DIALOG_SHOWN = "state_url_enter_dialog_shown";
    private static final String STATE_LAST_URL = "state_last_url";
    private static final String STATE_ENTERING_PIN = "state_entering_pin";

    @Type.ClientTypeInt
    private int authClientType = -1;

    private OAuthModel model;

    private boolean requirePin=false;

    private AlertDialog pinDialog;

    private CompositeDisposable compositeDisposable;

    private boolean isUrlEnterDialogShown = false;

    @NonNull
    private String lastUrl = "";

    @NonNull
    private String enteringPin = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_oauth);

        compositeDisposable = new CompositeDisposable();

        if (savedInstanceState != null) {
            lastUrl = savedInstanceState.getString(STATE_LAST_URL, "");

            enteringPin = savedInstanceState.getString(STATE_ENTERING_PIN, "");

            requirePin = savedInstanceState.getBoolean(STATE_REQUIRE_PIN, false);

            int type = savedInstanceState.getInt(STATE_CLIENT_TYPE, -1);

            if (type != -1) {
                initType(type);
                model.restoreInstanceState(savedInstanceState);
                if (requirePin){
                    showPinDialog();
                }
            } else {
                isUrlEnterDialogShown = savedInstanceState.getBoolean(STATE_URL_ENTER_DIALOG_SHOWN, false);
                if (isUrlEnterDialogShown) {
                    onStartMastodonAuthClick(null);
                }
            }
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (requirePin) {
            outState.putBoolean(STATE_REQUIRE_PIN, true);
        }
        if (model != null && model.isRestartable()) {
            outState.putInt(STATE_CLIENT_TYPE, authClientType);
            model.saveInstanceState(outState);
        }
        if (isUrlEnterDialogShown) {
            outState.putBoolean(STATE_URL_ENTER_DIALOG_SHOWN, true);
        }
        if (!enteringPin.isEmpty()) {
            outState.putString(STATE_ENTERING_PIN, enteringPin);
        }
        if (!lastUrl.isEmpty()) {
            outState.putString(STATE_LAST_URL, lastUrl);
        }
    }

    @Override
    protected void onDestroy() {
        closePinDialog();
        compositeDisposable.dispose();
        super.onDestroy();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Uri uri = intent.getData();
        if (!requirePin
                && uri != null
                && uri.getScheme().equals(getString(R.string.app_name))
                && uri.getHost().equals("OAuthActivity")
        ) {<commit_msg>fix: crash when no model had<commit_after>/*
 * Copyright 2015-2018 The twitlatte authors
 *
 * 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 com.github.moko256.twitlatte;

import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.Toast;

import com.github.moko256.twitlatte.entity.AccessToken;
import com.github.moko256.twitlatte.entity.Type;
import com.github.moko256.twitlatte.model.base.OAuthModel;
import com.github.moko256.twitlatte.text.TwitterStringUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.internal.disposables.CancellableDisposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by moko256 on 2016/04/29.
 *
 * @author moko256
 */
public class OAuthActivity extends AppCompatActivity {

    private static final String STATE_CLIENT_TYPE = "state_client_type";
    private static final String STATE_REQUIRE_PIN = "state_require_pin";
    private static final String STATE_URL_ENTER_DIALOG_SHOWN = "state_url_enter_dialog_shown";
    private static final String STATE_LAST_URL = "state_last_url";
    private static final String STATE_ENTERING_PIN = "state_entering_pin";

    @Type.ClientTypeInt
    private int authClientType = -1;

    private OAuthModel model;

    private boolean requirePin=false;

    private AlertDialog pinDialog;

    private CompositeDisposable compositeDisposable;

    private boolean isUrlEnterDialogShown = false;

    @NonNull
    private String lastUrl = "";

    @NonNull
    private String enteringPin = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_oauth);

        compositeDisposable = new CompositeDisposable();

        if (savedInstanceState != null) {
            lastUrl = savedInstanceState.getString(STATE_LAST_URL, "");

            enteringPin = savedInstanceState.getString(STATE_ENTERING_PIN, "");

            requirePin = savedInstanceState.getBoolean(STATE_REQUIRE_PIN, false);

            int type = savedInstanceState.getInt(STATE_CLIENT_TYPE, -1);

            if (type != -1) {
                initType(type);
                model.restoreInstanceState(savedInstanceState);
                if (requirePin){
                    showPinDialog();
                }
            } else {
                isUrlEnterDialogShown = savedInstanceState.getBoolean(STATE_URL_ENTER_DIALOG_SHOWN, false);
                if (isUrlEnterDialogShown) {
                    onStartMastodonAuthClick(null);
                }
            }
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (requirePin) {
            outState.putBoolean(STATE_REQUIRE_PIN, true);
        }
        if (model != null && model.isRestartable()) {
            outState.putInt(STATE_CLIENT_TYPE, authClientType);
            model.saveInstanceState(outState);
        }
        if (isUrlEnterDialogShown) {
            outState.putBoolean(STATE_URL_ENTER_DIALOG_SHOWN, true);
        }
        if (!enteringPin.isEmpty()) {
            outState.putString(STATE_ENTERING_PIN, enteringPin);
        }
        if (!lastUrl.isEmpty()) {
            outState.putString(STATE_LAST_URL, lastUrl);
        }
    }

    @Override
    protected void onDestroy() {
        closePinDialog();
        compositeDisposable.dispose();
        super.onDestroy();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Uri uri = intent.getData();
        if (model != null
                && !requirePin
                && uri != null
                && uri.getScheme().equals(getString(R.string.app_name))
                && uri.getHost().equals("OAuthActivity")
        ) {
{'fraction_non_alphanumeric': 0.08771752326993121, 'fraction_numerical': 0.009510319708619992, 'mean_word_length': 3.0612161051766638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2014614', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2695, 'n_words': 605}