TikChat v1.0.1版本的 MD5 值为:6387a5d2555771afeaa25f490c6460b7

以下内容为反编译后的 UsernameLoginActivity.java 源代码,内容仅作参考


package org.telegram.ui;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;
import android.util.TypedValue;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import chat.zhifeiji.R;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import org.json.JSONObject;
import org.telegram.common.ErrorHandler;
import org.telegram.common.utils.DigestUtils;
import org.telegram.common.utils.ToastUtils;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC$TL_auth_authorization;
import org.telegram.tgnet.TLRPC$TL_error;
import org.telegram.tgnet.TLRPC$TL_hilamg_signIn;
import org.telegram.tgnet.TLRPC$Tl_hilamg_signInResp;
import org.telegram.tgnet.TLRPC$User;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.SimpleTextView;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.LayoutHelper;
public class UsernameLoginActivity extends BaseFragment {
    private volatile String ip;
    private Handler mWorkHandler;

    public UsernameLoginActivity() {
        super(null);
    }

    public UsernameLoginActivity(int i) {
    }

    @Override
    public View createView(Context context) {
        this.actionBar.setVisibility(8);
        this.actionBar = null;
        ScrollView scrollView = new ScrollView(context);
        scrollView.setBackgroundColor(Theme.getColor("windowBackgroundWhite"));
        this.fragmentView = scrollView;
        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setPadding(0, (int) TypedValue.applyDimension(1, 100.0f, linearLayout.getResources().getDisplayMetrics()), 0, 0);
        linearLayout.setOrientation(1);
        scrollView.addView(linearLayout);
        addLanguageView(linearLayout);
        SimpleTextView simpleTextView = new SimpleTextView(context);
        simpleTextView.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
        simpleTextView.setTypeface(Typeface.defaultFromStyle(1));
        simpleTextView.setTextSize(24);
        simpleTextView.setText(LocaleController.getString("Login", R.string.Login));
        linearLayout.addView(simpleTextView, LayoutHelper.createLinear(-2, -2, 16.0f, 30.0f, 0.0f, 0.0f));
        SimpleTextView simpleTextView2 = new SimpleTextView(context);
        simpleTextView2.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
        simpleTextView2.setTypeface(Typeface.defaultFromStyle(1));
        simpleTextView2.setTextSize(18);
        simpleTextView2.setText(LocaleController.getString("Username", R.string.Username));
        linearLayout.addView(simpleTextView2, LayoutHelper.createLinear(-2, -2, 16.0f, 48.0f, 16.0f, 0.0f));
        final EditText editText = new EditText(context);
        editText.setInputType(1);
        editText.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
        editText.setHintTextColor(Theme.getColor("windowBackgroundWhiteHintText"));
        editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
        editText.setPadding(0, 0, 0, 0);
        editText.setTextSize(1, 16.0f);
        editText.setMaxLines(1);
        editText.setGravity(19);
        editText.setImeOptions(268435461);
        editText.setHint(LocaleController.getString("InputUsername", R.string.InputUsername));
        linearLayout.addView(editText, LayoutHelper.createLinear(-1, 36, 16.0f, 8.0f, 16.0f, 0.0f));
        SimpleTextView simpleTextView3 = new SimpleTextView(context);
        simpleTextView3.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
        simpleTextView3.setTypeface(Typeface.defaultFromStyle(1));
        simpleTextView3.setTextSize(18);
        simpleTextView3.setText(LocaleController.getString("Password", R.string.Password));
        linearLayout.addView(simpleTextView3, LayoutHelper.createLinear(-2, -2, 16.0f, 24.0f, 0.0f, 0.0f));
        FrameLayout frameLayout = new FrameLayout(context);
        linearLayout.addView(frameLayout);
        final EditText editText2 = new EditText(context);
        editText2.setInputType(128);
        editText2.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
        editText2.setHintTextColor(Theme.getColor("windowBackgroundWhiteHintText"));
        editText2.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
        editText2.setPadding(0, 0, 0, 0);
        editText2.setTextSize(1, 16.0f);
        editText2.setMaxLines(1);
        editText2.setMaxEms(16);
        editText2.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
        editText2.setGravity(19);
        editText2.setImeOptions(268435461);
        editText2.setTransformationMethod(new PasswordTransformationMethod());
        editText2.setHint(LocaleController.getString("InputPassword", R.string.InputPassword));
        frameLayout.addView(editText2, LayoutHelper.createLinear(-1, 46, 16.0f, 8.0f, 16.0f, 0.0f));
        final ImageView imageView = new ImageView(context);
        int dp = AndroidUtilities.dp(4.0f);
        imageView.setPadding(dp, dp, dp, dp);
        imageView.setImageResource(R.drawable.ic_invisible);
        frameLayout.addView(imageView, LayoutHelper.createFrame(32, 32.0f, 8388629, 0.0f, 0.0f, 32.0f, 0.0f));
        imageView.setOnClickListener(new View.OnClickListener(this) {
            @Override
            public void onClick(View view) {
                view.setSelected(!view.isSelected());
                if (view.isSelected()) {
                    imageView.setImageResource(R.drawable.ic_visible);
                    editText2.setTransformationMethod(new SingleLineTransformationMethod());
                } else {
                    imageView.setImageResource(R.drawable.ic_invisible);
                    editText2.setTransformationMethod(new PasswordTransformationMethod());
                }
                EditText editText3 = editText2;
                editText3.setSelection(editText3.getText().length());
            }
        });
        SimpleTextView simpleTextView4 = new SimpleTextView(context);
        simpleTextView4.setTextColor(Theme.getColor("dialogTextBlue2"));
        simpleTextView4.setTextSize(13);
        simpleTextView4.setText(LocaleController.getString("ForgetPassword", R.string.ForgetPassword));
        linearLayout.addView(simpleTextView4, LayoutHelper.createLinear(-2, -2, 16.0f, 6.0f, 0.0f, 0.0f));
        simpleTextView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UsernameLoginActivity.this.presentFragment(new ModifyPasswordActivity());
            }
        });
        TextView textView = new TextView(context);
        textView.setText(LocaleController.getString("Confirm", R.string.Confirm));
        textView.setGravity(17);
        textView.setTextColor(-1);
        textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        textView.setTextSize(1, 16.0f);
        textView.setBackground(Theme.createSimpleSelectorRoundRectDrawable(8, Theme.getActiveTheme().getAccent(false).accentColor, Theme.getColor("windowBackgroundWhiteGreenText")));
        textView.setPadding(AndroidUtilities.dp(34.0f), 0, AndroidUtilities.dp(34.0f), 0);
        linearLayout.addView(textView, LayoutHelper.createLinear(-1, 42, 1, 10, 48, 10, 0));
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UsernameLoginActivity.this.login(editText, editText2);
            }
        });
        LinearLayout linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(0);
        linearLayout2.setGravity(17);
        linearLayout.addView(linearLayout2);
        TextView textView2 = new TextView(context);
        textView2.setText(LocaleController.getString("LoginByPhone", R.string.LoginByPhone));
        textView2.setGravity(8388611);
        textView2.setTextColor(Theme.getColor("dialogTextBlue2"));
        textView2.setTextSize(16.0f);
        linearLayout2.addView(textView2, LayoutHelper.createLinear(-2, 45, 17, 0, 18, 20, 0));
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UsernameLoginActivity.this.presentFragment(new PhoneLoginActivity());
            }
        });
        TextView textView3 = new TextView(context);
        textView3.setText(LocaleController.getString("FreeRegist", R.string.FreeRegist));
        textView3.setGravity(8388613);
        textView3.setTextColor(Theme.getColor("dialogTextGray2"));
        textView3.setTextSize(16.0f);
        linearLayout2.addView(textView3, LayoutHelper.createLinear(-2, 45, 17, 20, 18, 0, 0));
        textView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UsernameLoginActivity.this.presentFragment(new UsernameRegisterActivity());
            }
        });
        SimpleTextView simpleTextView5 = new SimpleTextView(context);
        simpleTextView5.setText(LocaleController.getString("LoginFailedTips", R.string.LoginFailedTips));
        simpleTextView5.setGravity(17);
        simpleTextView5.setTextColor(Theme.getColor("dialogTextGray2"));
        simpleTextView5.setTextSize(13);
        linearLayout.addView(simpleTextView5, LayoutHelper.createLinear(-1, 45, 0.0f, 24.0f, 0.0f, 24.0f));
        simpleTextView5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UsernameLoginActivity.this.presentFragment(new LoginTipsActivity());
            }
        });
        Bundle bundle = this.arguments;
        if (bundle != null) {
            String string = bundle.getString("account");
            if (!TextUtils.isEmpty(string)) {
                editText.setText(string);
            }
        }
        return this.fragmentView;
    }

    private void addLanguageView(LinearLayout linearLayout) {
        Context context = linearLayout.getContext();
        LinearLayout linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(0);
        linearLayout.addView(linearLayout2, LayoutHelper.createLinear(120, 45, 8388613, 0, 0, 0, 0));
        linearLayout2.addView(new ImageView(context));
        SimpleTextView simpleTextView = new SimpleTextView(context);
        simpleTextView.setText(LocaleController.getString("LanguageName", R.string.LanguageName));
        simpleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        simpleTextView.setTextSize(16);
        simpleTextView.setGravity(8388613);
        simpleTextView.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
        linearLayout2.addView(simpleTextView, LayoutHelper.createLinear(-2, -1, 8388613, 0, 0, 20, 0));
        linearLayout2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UsernameLoginActivity.this.presentFragment(new LanguageSelectActivity());
            }
        });
    }

    @Override
    public void onFragmentDestroy() {
        super.onFragmentDestroy();
        Handler handler = this.mWorkHandler;
        if (handler != null) {
            handler.getLooper().quitSafely();
        }
        this.mWorkHandler = null;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (this.mWorkHandler == null) {
            HandlerThread handlerThread = new HandlerThread("getIp");
            handlerThread.start();
            this.mWorkHandler = new Handler(handlerThread.getLooper());
        }
        this.mWorkHandler.post(new Runnable() {
            @Override
            public void run() {
                if (UsernameLoginActivity.this.isFinishing()) {
                    return;
                }
                UsernameLoginActivity usernameLoginActivity = UsernameLoginActivity.this;
                usernameLoginActivity.ip = usernameLoginActivity.getMyIp();
            }
        });
    }

    public String getMyIp() {
        HttpURLConnection httpURLConnection;
        InputStream inputStream;
        try {
            httpURLConnection = (HttpURLConnection) new URL("https://ip.cn/api/index?ip=&type=0").openConnection();
            try {
                httpURLConnection.setConnectTimeout(5000);
                httpURLConnection.setReadTimeout(15000);
                httpURLConnection.setRequestMethod("GET");
                inputStream = httpURLConnection.getInputStream();
                try {
                    byte[] bArr = new byte[512];
                    int i = 0;
                    while (i < 512) {
                        int read = inputStream.read(bArr, i, 512 - i);
                        if (read <= 0) {
                            break;
                        }
                        i += read;
                    }
                    JSONObject jSONObject = new JSONObject(new String(bArr, 0, i));
                    if (jSONObject.optInt("code") == 0 && jSONObject.optInt("rs") > 0) {
                        return jSONObject.optString("ip");
                    }
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException e) {
                            FileLog.e(e);
                        }
                    }
                } catch (Throwable th) {
                    th = th;
                    try {
                        FileLog.e(th);
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e2) {
                                FileLog.e(e2);
                            }
                        }
                    } finally {
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e3) {
                                FileLog.e(e3);
                            }
                        }
                        if (httpURLConnection != null) {
                            httpURLConnection.disconnect();
                        }
                    }
                }
            } catch (Throwable th2) {
                th = th2;
                inputStream = null;
            }
        } catch (Throwable th3) {
            th = th3;
            httpURLConnection = null;
            inputStream = null;
        }
    }

    public void login(TextView textView, TextView textView2) {
        String charSequence = textView.getText().toString();
        if (TextUtils.isEmpty(charSequence)) {
            ToastUtils.showShort(LocaleController.getString("LoginIdCannotBeNull", R.string.LoginIdCannotBeNull));
            return;
        }
        String charSequence2 = textView2.getText().toString();
        if (TextUtils.isEmpty(charSequence2)) {
            ToastUtils.showShort(LocaleController.getString("PasswordCannotBeNull", R.string.PasswordCannotBeNull));
        } else {
            login(charSequence, charSequence2);
        }
    }

    private void login(String str, String str2) {
        TLRPC$TL_hilamg_signIn tLRPC$TL_hilamg_signIn = new TLRPC$TL_hilamg_signIn();
        tLRPC$TL_hilamg_signIn.hilamgId = str;
        tLRPC$TL_hilamg_signIn.passwd = DigestUtils.md5sum(str2.getBytes());
        tLRPC$TL_hilamg_signIn.ip = TextUtils.isEmpty(this.ip) ? "" : this.ip;
        ConnectionsManager.getInstance(this.currentAccount).sendRequest(tLRPC$TL_hilamg_signIn, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC$TL_error tLRPC$TL_error) {
                UsernameLoginActivity.this.lambda$login$1$UsernameLoginActivity(tLObject, tLRPC$TL_error);
            }
        }, 10);
        showLoadingDialog();
    }

    public void lambda$login$1$UsernameLoginActivity(final TLObject tLObject, final TLRPC$TL_error tLRPC$TL_error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                UsernameLoginActivity.this.lambda$null$0$UsernameLoginActivity(tLRPC$TL_error, tLObject);
            }
        });
    }

    public void lambda$null$0$UsernameLoginActivity(TLRPC$TL_error tLRPC$TL_error, TLObject tLObject) {
        hideLoadingDialog();
        if (tLRPC$TL_error != null) {
            String str = tLRPC$TL_error.text;
            if (TextUtils.isEmpty(str)) {
                str = LocaleController.getString("ServerError", R.string.ServerError);
            }
            ToastUtils.showShort(str);
            return;
        }
        TLRPC$Tl_hilamg_signInResp tLRPC$Tl_hilamg_signInResp = (TLRPC$Tl_hilamg_signInResp) tLObject;
        int i = tLRPC$Tl_hilamg_signInResp.code;
        if (i != 0) {
            ErrorHandler.handleError(i);
        } else {
            onAuthSuccess(tLRPC$Tl_hilamg_signInResp.authorization);
        }
    }

    private void onAuthSuccess(TLRPC$TL_auth_authorization tLRPC$TL_auth_authorization) {
        ConnectionsManager.getInstance(this.currentAccount).setUserId(tLRPC$TL_auth_authorization.user.id);
        UserConfig.getInstance(this.currentAccount).clearConfig();
        MessagesController.getInstance(this.currentAccount).cleanup();
        UserConfig.getInstance(this.currentAccount).syncContacts = true;
        UserConfig.getInstance(this.currentAccount).setCurrentUser(tLRPC$TL_auth_authorization.user);
        UserConfig.getInstance(this.currentAccount).saveConfig(true);
        MessagesStorage.getInstance(this.currentAccount).cleanup(true);
        ArrayList<TLRPC$User> arrayList = new ArrayList<>();
        arrayList.add(tLRPC$TL_auth_authorization.user);
        MessagesStorage.getInstance(this.currentAccount).putUsersAndChats(arrayList, null, true, true);
        MessagesController.getInstance(this.currentAccount).putUser(tLRPC$TL_auth_authorization.user, false);
        ContactsController.getInstance(this.currentAccount).checkAppAccount();
        MessagesController.getInstance(this.currentAccount).checkPromoInfo(true);
        ConnectionsManager.getInstance(this.currentAccount).updateDcSettings();
        needFinishActivity(tLRPC$TL_auth_authorization.user.phone);
        MessagesController.getInstance(this.currentAccount).registerForPush(SharedConfig.pushString);
    }

    private void needFinishActivity(String str) {
        clearCurrentState();
        if (getParentActivity() instanceof LaunchActivity) {
            if (TextUtils.isEmpty(str)) {
                presentFragment(new BindPhoneActivity());
            } else {
                Bundle bundle = new Bundle();
                bundle.putBoolean("afterSignup", false);
                presentFragment(new DialogsFragment(bundle), true);
            }
            NotificationCenter.getInstance(this.currentAccount).postNotificationName(NotificationCenter.mainUserInfoChanged, new Object[0]);
        } else if (getParentActivity() instanceof ExternalActionActivity) {
            ((ExternalActionActivity) getParentActivity()).onFinishLogin();
        }
    }

    private void clearCurrentState() {
        ApplicationLoader.applicationContext.getSharedPreferences("logininfo2", 0).edit().clear().apply();
    }
}