TikChat v1.0.1版本的 MD5 值为:6387a5d2555771afeaa25f490c6460b7
以下内容为反编译后的 PhoneLoginActivity.java 源代码,内容仅作参考
package org.telegram.ui;
import android.content.Context;
import android.graphics.Color;
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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
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.ActionBar;
import org.telegram.ui.ActionBar.BackDrawable;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.SimpleTextView;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.CountrySelectActivity;
import org.telegram.ui.PhoneLoginActivity;
public class PhoneLoginActivity extends BaseFragment {
private String countryCode;
private volatile String ip;
private Handler mWorkHandler;
private ArrayList<String> countriesArray = new ArrayList<>();
private HashMap<String, String> countriesMap = new HashMap<>();
private HashMap<String, String> codesMap = new HashMap<>();
private HashMap<String, String> phoneFormatMap = new HashMap<>();
public void selectCountry(SimpleTextView simpleTextView, String str, String str2) {
if (this.countriesArray.indexOf(str) != -1) {
this.countryCode = this.countriesMap.get(str);
simpleTextView.setText("+" + this.countryCode);
}
}
@Override
public View createView(Context context) {
this.actionBar.setBackButtonDrawable(new BackDrawable(false));
this.actionBar.setCastShadows(false);
this.actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int i) {
if (i == -1) {
PhoneLoginActivity.this.finishFragment();
}
}
});
HashMap hashMap = new HashMap();
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open(LocaleController.getCountryFileName())));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
String[] split = readLine.split(";");
this.countriesArray.add(0, split[2]);
this.countriesMap.put(split[2], split[0]);
this.codesMap.put(split[0], split[2]);
if (split.length > 3) {
this.phoneFormatMap.put(split[0], split[3]);
}
hashMap.put(split[1], split[2]);
}
bufferedReader.close();
} catch (Exception e) {
FileLog.e(e);
}
Collections.sort(this.countriesArray, $$Lambda$Ds7dtVnGrflEw4LvNOxA0cDT4Y.INSTANCE);
String str = null;
if (UserConfig.getActivatedAccountsCount() > 0) {
TLRPC$User currentUser = UserConfig.getInstance(this.currentAccount).getCurrentUser();
if (!TextUtils.isEmpty(currentUser.phone)) {
Iterator<String> it = this.phoneFormatMap.keySet().iterator();
while (true) {
if (!it.hasNext()) {
break;
}
String next = it.next();
if (currentUser.phone.startsWith(next)) {
this.countryCode = next;
str = currentUser.phone.substring(next.length());
break;
}
}
}
}
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, 42.0f, linearLayout.getResources().getDisplayMetrics()), 0, 0);
linearLayout.setOrientation(1);
scrollView.addView(linearLayout);
SimpleTextView simpleTextView = new SimpleTextView(context);
simpleTextView.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
simpleTextView.setTypeface(Typeface.defaultFromStyle(1));
simpleTextView.setTextSize(24);
simpleTextView.setText(LocaleController.getString("PhonePasswordLogin", R.string.PhonePasswordLogin));
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.setTextSize(18);
simpleTextView2.setGravity(3);
simpleTextView2.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
simpleTextView2.setText(LocaleController.getString("Phone", R.string.Phone));
linearLayout.addView(simpleTextView2, LayoutHelper.createLinear(-2, -2, 51, 16, 48, 0, 0));
FrameLayout frameLayout = new FrameLayout(context);
linearLayout.addView(frameLayout, LayoutHelper.createLinear(-1, 48, 51, 16, 8, 16, 0));
View view = new View(context);
view.setBackgroundColor(Color.parseColor("#ededed"));
frameLayout.addView(view, LayoutHelper.createFrame(1, -1.0f, 16, 64.0f, 12.0f, 0.0f, 12.0f));
final EditText editText = new EditText(context);
editText.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
editText.setHintTextColor(Theme.getColor("windowBackgroundWhiteHintText"));
editText.setTextSize(1, 14.0f);
editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
editText.setGravity(16);
editText.setPadding(AndroidUtilities.dp(84.0f), 0, 0, 0);
editText.setInputType(2);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(11)});
editText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
editText.setHint(LocaleController.getString("InputPhone", R.string.InputPhone));
frameLayout.addView(editText, LayoutHelper.createFrame(-1, -1, 19));
if (!TextUtils.isEmpty(str)) {
editText.setText(str);
editText.setEnabled(false);
}
SimpleTextView simpleTextView3 = new SimpleTextView(context);
simpleTextView3.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
simpleTextView3.setTextSize(14);
simpleTextView3.setGravity(17);
simpleTextView3.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
frameLayout.addView(simpleTextView3, LayoutHelper.createFrame(64, -2, 19));
simpleTextView3.setOnClickListener(new AnonymousClass2(simpleTextView3));
if (!TextUtils.isEmpty(this.countryCode)) {
simpleTextView3.setEnabled(false);
} else {
this.countryCode = "86";
}
simpleTextView3.setText("+" + this.countryCode);
SimpleTextView simpleTextView4 = new SimpleTextView(context);
simpleTextView4.setTextColor(Theme.getColor("windowBackgroundWhiteBlackText"));
simpleTextView4.setTypeface(Typeface.defaultFromStyle(1));
simpleTextView4.setTextSize(18);
simpleTextView4.setText(LocaleController.getString("Password", R.string.Password));
linearLayout.addView(simpleTextView4, LayoutHelper.createLinear(-2, -2, 16.0f, 24.0f, 0.0f, 0.0f));
FrameLayout frameLayout2 = new FrameLayout(context);
linearLayout.addView(frameLayout2);
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));
frameLayout2.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);
frameLayout2.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 view2) {
view2.setSelected(!view2.isSelected());
if (view2.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 simpleTextView5 = new SimpleTextView(context);
simpleTextView5.setTextColor(Theme.getColor("dialogTextBlue2"));
simpleTextView5.setTextSize(13);
simpleTextView5.setText(LocaleController.getString("ForgetPassword", R.string.ForgetPassword));
linearLayout.addView(simpleTextView5, LayoutHelper.createLinear(-2, -2, 16.0f, 6.0f, 0.0f, 0.0f));
simpleTextView5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
PhoneLoginActivity.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 view2) {
PhoneLoginActivity.this.login(editText, editText2);
}
});
Bundle bundle = this.arguments;
if (bundle != null) {
String string = bundle.getString("phone_number");
if (!TextUtils.isEmpty(string)) {
editText.setText(string);
}
}
return this.fragmentView;
}
public class AnonymousClass2 implements View.OnClickListener {
final SimpleTextView val$phonePrefixLabel;
AnonymousClass2(SimpleTextView simpleTextView) {
this.val$phonePrefixLabel = simpleTextView;
}
@Override
public void onClick(View view) {
CountrySelectActivity countrySelectActivity = new CountrySelectActivity(true);
final SimpleTextView simpleTextView = this.val$phonePrefixLabel;
countrySelectActivity.setCountrySelectActivityDelegate(new CountrySelectActivity.CountrySelectActivityDelegate() {
@Override
public final void didSelectCountry(String str, String str2) {
PhoneLoginActivity.AnonymousClass2.this.lambda$onClick$0$PhoneLoginActivity$2(simpleTextView, str, str2);
}
});
PhoneLoginActivity.this.presentFragment(countrySelectActivity);
}
public void lambda$onClick$0$PhoneLoginActivity$2(SimpleTextView simpleTextView, String str, String str2) {
PhoneLoginActivity.this.selectCountry(simpleTextView, str, str2);
}
}
@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 (PhoneLoginActivity.this.isFinishing()) {
return;
}
PhoneLoginActivity phoneLoginActivity = PhoneLoginActivity.this;
phoneLoginActivity.ip = phoneLoginActivity.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("PhoneCannotBeNull", R.string.PhoneCannotBeNull));
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.phone = this.countryCode + 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) {
PhoneLoginActivity.this.lambda$login$1$PhoneLoginActivity(tLObject, tLRPC$TL_error);
}
}, 10);
showLoadingDialog();
}
public void lambda$login$1$PhoneLoginActivity(final TLObject tLObject, final TLRPC$TL_error tLRPC$TL_error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
PhoneLoginActivity.this.lambda$null$0$PhoneLoginActivity(tLRPC$TL_error, tLObject);
}
});
}
public void lambda$null$0$PhoneLoginActivity(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();
}
}