Skip to content

Commit c871557

Browse files
committed
适配登录:Web登录的形式
1 parent 9567346 commit c871557

File tree

9 files changed

+255
-78
lines changed

9 files changed

+255
-78
lines changed

.idea/gradle.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="com.rae.cnblogs">
45

56

@@ -26,11 +27,11 @@
2627
android:name=".activity.LauncherActivity"
2728
android:screenOrientation="portrait"
2829
android:theme="@style/AppTheme.NoActionBar.FullScreen">
29-
<intent-filter>
30-
<action android:name="android.intent.action.MAIN"/>
30+
<intent-filter>
31+
<action android:name="android.intent.action.MAIN"/>
3132

32-
<category android:name="android.intent.category.LAUNCHER"/>
33-
</intent-filter>
33+
<category android:name="android.intent.category.LAUNCHER"/>
34+
</intent-filter>
3435
</activity>
3536

3637
<!--主界面-->
@@ -44,10 +45,10 @@
4445
android:label="博客园测试"
4546
android:screenOrientation="portrait"
4647
android:theme="@style/AppTheme.Dark">
47-
<!-- <intent-filter>
48-
<action android:name="android.intent.action.MAIN"/>
49-
<category android:name="android.intent.category.LAUNCHER"/>
50-
</intent-filter>-->
48+
<!-- <intent-filter>
49+
<action android:name="android.intent.action.MAIN"/>
50+
<category android:name="android.intent.category.LAUNCHER"/>
51+
</intent-filter>-->
5152
</activity>
5253

5354
<!--博文-->
@@ -60,7 +61,12 @@
6061
android:name=".activity.LoginActivity"
6162
android:launchMode="singleTop"
6263
android:screenOrientation="portrait"
63-
android:windowSoftInputMode="stateVisible"/>
64+
android:windowSoftInputMode="stateVisible">
65+
<!-- <intent-filter>
66+
<action android:name="android.intent.action.MAIN"/>
67+
<category android:name="android.intent.category.LAUNCHER"/>
68+
</intent-filter>-->
69+
</activity>
6470

6571

6672
<!--网页登录-->
@@ -202,18 +208,18 @@
202208
android:value="${UMENG_CHANNEL}"/>
203209

204210
<!--开始-快速开发需要移除下面的多进程-->
205-
<!-- <service
206-
android:name="com.squareup.leakcanary.internal.HeapAnalyzerService"
207-
android:enabled="false"
208-
tools:remove="process"/>
209-
<service
210-
android:name="com.tencent.tinker.lib.service.TinkerPatchService"
211-
android:exported="false"
212-
tools:remove="process"/>
213-
<service
214-
android:name="com.tencent.tinker.lib.service.TinkerPatchService$InnerService"
215-
android:exported="false"
216-
tools:remove="process"/>-->
211+
<service
212+
android:name="com.squareup.leakcanary.internal.HeapAnalyzerService"
213+
android:enabled="false"
214+
tools:remove="process"/>
215+
<service
216+
android:name="com.tencent.tinker.lib.service.TinkerPatchService"
217+
android:exported="false"
218+
tools:remove="process"/>
219+
<service
220+
android:name="com.tencent.tinker.lib.service.TinkerPatchService$InnerService"
221+
android:exported="false"
222+
tools:remove="process"/>
217223
<!--结束-快速开发需要移除下面的多进程-->
218224

219225
</application>

app/src/main/assets/js/rae-login.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* =====================================
3+
* 博客园登录脚本注入
4+
* ======================================
5+
***/
6+
7+
alert("登录脚本注入成功!");
8+
9+
var rae={
10+
11+
/*登录*/
12+
login:function(u,p,c){
13+
14+
alert("登录:"+u+p+c);
15+
16+
17+
}
18+
};

app/src/main/java/com/rae/cnblogs/activity/LauncherActivity.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515
import com.rae.cnblogs.presenter.ILauncherPresenter;
1616
import com.rae.cnblogs.sdk.bean.BlogType;
1717

18-
import java.util.concurrent.TimeUnit;
19-
2018
import butterknife.BindView;
2119
import butterknife.OnClick;
22-
import io.reactivex.Observable;
23-
import io.reactivex.functions.Consumer;
2420

2521
/**
2622
* 启动页
@@ -47,25 +43,25 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4743
@Override
4844
protected void onResume() {
4945
super.onResume();
50-
51-
// 判断主界面退出时间是否过短
52-
long mainExitTimeMillis = config().getMainExitTimeMillis();
53-
long span = System.currentTimeMillis() - mainExitTimeMillis;
54-
55-
// 第一次或者是程序退出的时间超过1分钟(60000),就启动当前界面
56-
if (mainExitTimeMillis <= 0 || span > 60000) {
57-
mLauncherPresenter.start();
58-
} else {
59-
// 跳过启动界面
60-
AppRoute.jumpToMain(this);
61-
Observable.timer(500, TimeUnit.MILLISECONDS)
62-
.subscribe(new Consumer<Long>() {
63-
@Override
64-
public void accept(Long aLong) throws Exception {
65-
finish();
66-
}
67-
});
68-
}
46+
mLauncherPresenter.start();
47+
// // 判断主界面退出时间是否过短
48+
// long mainExitTimeMillis = config().getMainExitTimeMillis();
49+
// long span = System.currentTimeMillis() - mainExitTimeMillis;
50+
//
51+
// // 第一次或者是程序退出的时间超过1分钟(60000),就启动当前界面
52+
// if (mainExitTimeMillis <= 0 || span > 60000) {
53+
// mLauncherPresenter.start();
54+
// } else {
55+
// // 跳过启动界面
56+
// AppRoute.jumpToMain(this);
57+
// Observable.timer(500, TimeUnit.MILLISECONDS)
58+
// .subscribe(new Consumer<Long>() {
59+
// @Override
60+
// public void accept(Long aLong) throws Exception {
61+
// finish();
62+
// }
63+
// });
64+
// }
6965

7066
}
7167

@@ -128,7 +124,7 @@ public void onAdClick() {
128124

129125
@Override
130126
public void onJumpToMain() {
131-
AppRoute.jumpToMain(this);
132-
finish();
127+
// AppRoute.jumpToMain(this);
128+
// finish();
133129
}
134130
}

app/src/main/java/com/rae/cnblogs/activity/LoginActivity.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.rae.cnblogs.dialog.IAppDialog;
2626
import com.rae.cnblogs.dialog.IAppDialogClickListener;
2727
import com.rae.cnblogs.dialog.impl.HintCardDialog;
28+
import com.rae.cnblogs.fragment.WebLoginFragment;
2829
import com.rae.cnblogs.presenter.CnblogsPresenterFactory;
2930
import com.rae.cnblogs.presenter.ILoginPresenter;
3031
import com.rae.cnblogs.sdk.bean.UserInfoBean;
@@ -36,7 +37,7 @@
3637
* 登录
3738
* Created by ChenRui on 2017/1/19 0019 9:59.
3839
*/
39-
public class LoginActivity extends BaseActivity implements ILoginPresenter.ILoginView {
40+
public class LoginActivity extends BaseActivity implements ILoginPresenter.ILoginView, WebLoginFragment.WebLoginListener {
4041

4142
@BindView(com.rae.cnblogs.R.id.ll_login_container)
4243
View mLoginLayout;
@@ -73,6 +74,7 @@ public class LoginActivity extends BaseActivity implements ILoginPresenter.ILogi
7374
protected HintCardDialog mLoginContractDialog;
7475

7576
private int mErrorTime; // 登录错误次数,达到3次以上提示用户是否跳转网页登录
77+
private WebLoginFragment mWebLoginFragment;
7678

7779
@Override
7880
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -141,6 +143,16 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
141143
mLoginContractDialog = new HintCardDialog(this);
142144
mLoginContractDialog.setMessage(getString(R.string.login_contract_content));
143145
mLoginContractDialog.setEnSureText(getString(R.string.agree));
146+
147+
// 加载网页登录
148+
mWebLoginFragment = WebLoginFragment.newInstance("https://passport.cnblogs.com/user/signin");
149+
getSupportFragmentManager()
150+
.beginTransaction()
151+
.add(R.id.fl_web_login, mWebLoginFragment)
152+
.commit();
153+
154+
mUserNameView.setText("abc");
155+
mPasswordView.setText("123456");
144156
}
145157

146158
private void addAccountTextListener(AccountTextWatcher watcher) {
@@ -171,7 +183,7 @@ public void onPasswordDeleteClick() {
171183
*/
172184
@OnClick(R.id.tv_forget_password)
173185
public void onForgetPasswordClick() {
174-
AppMobclickAgent.onClickEvent(this,"ForgetPassword");
186+
AppMobclickAgent.onClickEvent(this, "ForgetPassword");
175187
AppRoute.jumpToWeb(this, getString(R.string.forget_password_url));
176188
}
177189

@@ -180,7 +192,7 @@ public void onForgetPasswordClick() {
180192
*/
181193
@OnClick(R.id.tv_reg)
182194
public void onRegClick() {
183-
AppMobclickAgent.onClickEvent(this,"Reg");
195+
AppMobclickAgent.onClickEvent(this, "Reg");
184196
AppRoute.jumpToWeb(this, getString(R.string.reg_url));
185197
}
186198

@@ -211,7 +223,8 @@ public void onDismiss(DialogInterface dialog) {
211223

212224
private void preformLogin() {
213225
showLoading();
214-
mLoginPresenter.login();
226+
// mLoginPresenter.login();
227+
mWebLoginFragment.performLogin(getUserName(), getPassword(), null);
215228
removeAccountTextListener(mAccountTextWatcher);
216229
mLoginButton.setEnabled(false);
217230
}
@@ -240,6 +253,22 @@ public void onLoginSuccess(UserInfoBean userInfo) {
240253
finish();
241254
}
242255

256+
@Override
257+
public void onWebLoadingFinish() {
258+
AppUI.toastInCenter(getContext(), "onWebLoadingFinish");
259+
}
260+
261+
@Override
262+
public void onLoginVerifyCodeError(String url) {
263+
AppUI.toastInCenter(getContext(), "onLoginVerifyCodeError:" + url);
264+
265+
}
266+
267+
@Override
268+
public void onNeedVerifyCode(String url) {
269+
AppUI.toastInCenter(getContext(), "onNeedVerifyCode:" + url);
270+
}
271+
243272
@Override
244273
public void onLoginError(String message) {
245274
onLoginCallback();
@@ -253,6 +282,11 @@ public void onLoginError(String message) {
253282
mErrorTime++;
254283
}
255284

285+
@Override
286+
public void onLoggingIn(String msg) {
287+
288+
}
289+
256290
@Override
257291
public void onLoginVerifyCodeError() {
258292
onLoginCallback();

0 commit comments

Comments
 (0)