Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 5, 2024. It is now read-only.

Commit c2238eb

Browse files
committed
添加手机号码登录
1 parent eea42d3 commit c2238eb

File tree

18 files changed

+482
-11
lines changed

18 files changed

+482
-11
lines changed
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.rae.cnblogs.discover" />
2+
package="com.rae.cnblogs.discover">
3+
4+
<application>
5+
<activity
6+
android:name=".AntUserAuthActivity"
7+
android:windowSoftInputMode="adjustPan">
8+
<intent-filter>
9+
<action android:name="android.intent.action.MAIN" />
10+
<category android:name="android.intent.category.LAUNCHER" />
11+
</intent-filter>
12+
</activity>
13+
<activity
14+
android:name=".AntUserContractActivity"
15+
android:label="@string/label_ant_user_contract" />
16+
</application>
17+
</manifest>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.rae.cnblogs.discover;
2+
3+
import com.rae.cnblogs.sdk.ApiDefaultObserver;
4+
5+
/**
6+
* ant sdk observer
7+
* @param <T>
8+
*/
9+
public abstract class AntSdkDefaultObserver<T> extends ApiDefaultObserver<T> {
10+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.rae.cnblogs.discover;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.telephony.PhoneNumberFormattingTextWatcher;
6+
import android.widget.Button;
7+
import android.widget.EditText;
8+
import android.widget.TextView;
9+
10+
import com.alibaba.android.arouter.facade.annotation.Route;
11+
import com.rae.cnblogs.AppRoute;
12+
import com.rae.cnblogs.UICompat;
13+
import com.rae.cnblogs.activity.SwipeBackBasicActivity;
14+
import com.rae.cnblogs.discover.auth.AntUserAuthContract;
15+
import com.rae.cnblogs.discover.auth.AntUserAuthPresenterImpl;
16+
17+
import butterknife.BindView;
18+
import butterknife.OnClick;
19+
20+
@Route(path = AppRoute.PATH_DISCOVER_USER_AUTH)
21+
public class AntUserAuthActivity extends SwipeBackBasicActivity implements AntUserAuthContract.View {
22+
23+
@BindView(R2.id.tv_hello)
24+
TextView mHelloView;
25+
26+
@BindView(R2.id.tv_bind_phone)
27+
TextView mBindPhoneView;
28+
29+
@BindView(R2.id.et_phone)
30+
EditText mPhoneView;
31+
32+
@BindView(R2.id.btn_send)
33+
Button mSendButton;
34+
35+
private AntUserAuthContract.Presenter mPresenter;
36+
37+
@Override
38+
protected void onCreate(@Nullable Bundle savedInstanceState) {
39+
super.onCreate(savedInstanceState);
40+
setContentView(R.layout.activity_ant_user_auth);
41+
setTitle(" ");
42+
mPresenter = new AntUserAuthPresenterImpl(this);
43+
mPresenter.start();
44+
mPhoneView.addTextChangedListener(new PhoneNumberFormattingTextWatcher() {
45+
@Override
46+
public void onTextChanged(CharSequence s, int start, int before, int count) {
47+
super.onTextChanged(s, start, before, count);
48+
mSendButton.setEnabled(s.length() > 12);
49+
}
50+
});
51+
}
52+
53+
@OnClick(R2.id.btn_send)
54+
public void onSendClick() {
55+
UICompat.hideSoftInputFromWindow(this);
56+
mSendButton.setEnabled(false);
57+
mSendButton.setText(R.string.loading);
58+
mPresenter.send();
59+
}
60+
61+
@OnClick(R2.id.ll_contract)
62+
public void onContractClick() {
63+
AppRoute.routeToAntUserContract(this);
64+
}
65+
66+
@Override
67+
public String getPhoneNumber() {
68+
return mPhoneView.getText().toString().replace(" ", "");
69+
}
70+
71+
@Override
72+
public void onSendSuccess() {
73+
dismissLoading();
74+
UICompat.toastInCenter(this, "短信验证码发送成功");
75+
}
76+
77+
@Override
78+
public void onSendError(String message) {
79+
dismissLoading();
80+
UICompat.failed(this, message);
81+
}
82+
83+
private void dismissLoading() {
84+
mSendButton.setEnabled(true);
85+
mSendButton.setText(R.string.send_sms);
86+
}
87+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.rae.cnblogs.discover;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.text.TextUtils;
6+
7+
import com.alibaba.android.arouter.facade.annotation.Route;
8+
import com.antcode.sdk.AntCodeSDK;
9+
import com.antcode.sdk.model.AntAppConfigInfo;
10+
import com.rae.cnblogs.AppRoute;
11+
import com.rae.cnblogs.UICompat;
12+
import com.rae.cnblogs.activity.SwipeBackBasicActivity;
13+
import com.rae.cnblogs.web.WebViewFragment;
14+
15+
import butterknife.OnClick;
16+
17+
@Route(path = AppRoute.PATH_DISCOVER_USER_CONTRACT)
18+
public class AntUserContractActivity extends SwipeBackBasicActivity {
19+
20+
@Override
21+
protected void onCreate(@Nullable Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
setContentView(R.layout.activity_ant_user_contract);
24+
25+
AntCodeSDK.getInstance()
26+
.getUserApi()
27+
.getAppConfig()
28+
.with(this)
29+
.subscribe(new AntSdkDefaultObserver<AntAppConfigInfo>() {
30+
@Override
31+
protected void onError(String message) {
32+
33+
}
34+
35+
@Override
36+
protected void accept(AntAppConfigInfo antAppConfigInfo) {
37+
onLoadSuccess(antAppConfigInfo);
38+
}
39+
});
40+
41+
}
42+
43+
private void onLoadSuccess(AntAppConfigInfo config) {
44+
if (TextUtils.isEmpty(config.getUserContractUrl())) {
45+
UICompat.failed(this, "用户协议加载错误");
46+
return;
47+
}
48+
getSupportFragmentManager().beginTransaction().replace(R.id.container, WebViewFragment.newInstance(config.getUserContractUrl(), null)).commitNow();
49+
}
50+
51+
@OnClick(R2.id.btn_save)
52+
public void onConfirmClick() {
53+
finish();
54+
}
55+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.rae.cnblogs.discover.auth;
2+
3+
import com.rae.cnblogs.basic.IPresenter;
4+
import com.rae.cnblogs.basic.IPresenterView;
5+
6+
public interface AntUserAuthContract {
7+
8+
interface Presenter extends IPresenter {
9+
void send();
10+
}
11+
12+
interface View extends IPresenterView {
13+
14+
/**
15+
* 获取手机号码
16+
*/
17+
String getPhoneNumber();
18+
19+
/**
20+
* 发送成功
21+
*/
22+
void onSendSuccess();
23+
24+
/**
25+
* 发送失败
26+
*
27+
* @param message 错误消息
28+
*/
29+
void onSendError(String message);
30+
}
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.rae.cnblogs.discover.auth;
2+
3+
import android.support.annotation.Nullable;
4+
5+
import com.antcode.sdk.AntCodeSDK;
6+
import com.antcode.sdk.IAntUserApi;
7+
import com.antcode.sdk.model.AntAppConfigInfo;
8+
import com.antcode.sdk.model.AntEmptyInfo;
9+
import com.rae.cnblogs.discover.AntCodeBasicPresenter;
10+
import com.rae.cnblogs.discover.AntSdkDefaultObserver;
11+
12+
public class AntUserAuthPresenterImpl extends AntCodeBasicPresenter<AntUserAuthContract.View> implements AntUserAuthContract.Presenter {
13+
14+
private IAntUserApi mAntUserApi;
15+
@Nullable
16+
private AntAppConfigInfo mAntAppConfigInfo;
17+
18+
public AntUserAuthPresenterImpl(AntUserAuthContract.View view) {
19+
super(view);
20+
mAntUserApi = AntCodeSDK.getInstance().getUserApi();
21+
}
22+
23+
@Override
24+
protected void onStart() {
25+
26+
}
27+
28+
@Override
29+
public void send() {
30+
String phone = getView().getPhoneNumber();
31+
// 发送短信验证码
32+
mAntUserApi.sendSms(phone, IAntUserApi.SMS_TYPE_TOKEN).with(this).subscribe(new AntSdkDefaultObserver<AntEmptyInfo>() {
33+
@Override
34+
protected void onError(String message) {
35+
getView().onSendError(message);
36+
}
37+
38+
@Override
39+
protected void accept(AntEmptyInfo antEmptyInfo) {
40+
getView().onSendSuccess();
41+
}
42+
});
43+
}
44+
45+
@Nullable
46+
public AntAppConfigInfo getAntAppConfigInfo() {
47+
return mAntAppConfigInfo;
48+
}
49+
}

‎module-discover/src/main/java/com/rae/cnblogs/discover/home/DiscoverHomePresenterImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.antcode.sdk.model.AntAppConfigInfo;
99
import com.antcode.sdk.model.AntColumnInfo;
1010
import com.rae.cnblogs.discover.AntCodeBasicPresenter;
11-
import com.rae.cnblogs.sdk.ApiDefaultObserver;
11+
import com.rae.cnblogs.discover.AntSdkDefaultObserver;
1212

1313
import java.util.List;
1414

@@ -30,7 +30,7 @@ public DiscoverHomePresenterImpl(IDiscoverHomeContract.View view) {
3030
protected void onStart() {
3131
// load category
3232
mUserApi.getAppConfig().with(this)
33-
.subscribe(new ApiDefaultObserver<AntAppConfigInfo>() {
33+
.subscribe(new AntSdkDefaultObserver<AntAppConfigInfo>() {
3434
@Override
3535
protected void onError(String message) {
3636
}
@@ -45,7 +45,7 @@ protected void accept(AntAppConfigInfo antAppConfigInfo) {
4545
// load home ads
4646
mAdApi.getHomePageAds()
4747
.with(this)
48-
.subscribe(new ApiDefaultObserver<List<AntAdInfo>>() {
48+
.subscribe(new AntSdkDefaultObserver<List<AntAdInfo>>() {
4949
@Override
5050
protected void onError(String message) {
5151
}
@@ -58,7 +58,7 @@ protected void accept(List<AntAdInfo> ads) {
5858

5959
// load home columns
6060

61-
mColumnApi.getHomeColumns().with(this).subscribe(new ApiDefaultObserver<List<AntColumnInfo>>() {
61+
mColumnApi.getHomeColumns().with(this).subscribe(new AntSdkDefaultObserver<List<AntColumnInfo>>() {
6262
@Override
6363
protected void onError(String message) {
6464
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:color="#C0FFFFFF" android:state_enabled="false" />
4+
<item android:color="@color/white" />
5+
</selector>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_enabled="false">
4+
<shape>
5+
<solid android:color="#FDB244" />
6+
<corners android:radius="100dp" />
7+
</shape>
8+
</item>
9+
<item android:state_pressed="true">
10+
<shape>
11+
<solid android:color="@color/ant_color_press" />
12+
<corners android:radius="100dp" />
13+
</shape>
14+
</item>
15+
<item>
16+
<shape>
17+
<solid android:color="@color/ant_color_primary" />
18+
<corners android:radius="100dp" />
19+
</shape>
20+
</item>
21+
</selector>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item>
5+
<layer-list>
6+
<item>
7+
<color android:color="#FFEEEEEE" />
8+
</item>
9+
<item android:bottom="1dp">
10+
<color android:color="@color/white" />
11+
</item>
12+
</layer-list>
13+
</item>
14+
</selector>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /