mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-16 15:28:38 +00:00
add better tips for custom host; fix issue that user can’t sign up by app
This commit is contained in:
@@ -22,11 +22,14 @@ import org.houxg.leamonax.network.LeaFailure;
|
|||||||
import org.houxg.leamonax.service.AccountService;
|
import org.houxg.leamonax.service.AccountService;
|
||||||
import org.houxg.leamonax.utils.ToastUtils;
|
import org.houxg.leamonax.utils.ToastUtils;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Observer;
|
import rx.Observer;
|
||||||
|
import rx.Subscriber;
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.functions.Action0;
|
import rx.functions.Action0;
|
||||||
import rx.functions.Func1;
|
import rx.functions.Func1;
|
||||||
@@ -62,6 +65,8 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
ProgressBar mSignUpProgress;
|
ProgressBar mSignUpProgress;
|
||||||
@BindView(R.id.rl_sign_up)
|
@BindView(R.id.rl_sign_up)
|
||||||
View mSignUpPanel;
|
View mSignUpPanel;
|
||||||
|
@BindView(R.id.tv_example)
|
||||||
|
TextView mEampleTv;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@@ -85,6 +90,22 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
mActionPanel.setY(actionPanelOffsetY);
|
mActionPanel.setY(actionPanelOffsetY);
|
||||||
mHostEt.setScaleY(isCustomHost ? 1 : 0);
|
mHostEt.setScaleY(isCustomHost ? 1 : 0);
|
||||||
mHostEt.setText(host);
|
mHostEt.setText(host);
|
||||||
|
mHostEt.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
mEampleTv.setText(String.format(Locale.US, "For example, login api will be:\n%s/api/login", s.toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,6 +132,7 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
void switchHost() {
|
void switchHost() {
|
||||||
boolean isCustomHost = !(boolean) mCustomHostBtn.getTag();
|
boolean isCustomHost = !(boolean) mCustomHostBtn.getTag();
|
||||||
mCustomHostBtn.setTag(isCustomHost);
|
mCustomHostBtn.setTag(isCustomHost);
|
||||||
|
mEampleTv.setVisibility(isCustomHost ? View.VISIBLE : View.GONE);
|
||||||
if (isCustomHost) {
|
if (isCustomHost) {
|
||||||
mCustomHostBtn.setText(R.string.use_leanote_host);
|
mCustomHostBtn.setText(R.string.use_leanote_host);
|
||||||
mHostEt.animate()
|
mHostEt.animate()
|
||||||
@@ -156,11 +178,16 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
|
|
||||||
@OnClick(R.id.tv_sign_in)
|
@OnClick(R.id.tv_sign_in)
|
||||||
void signIn() {
|
void signIn() {
|
||||||
String email = mEmailEt.getText().toString();
|
final String email = mEmailEt.getText().toString();
|
||||||
String password = mPasswordEt.getText().toString();
|
final String password = mPasswordEt.getText().toString();
|
||||||
final String host = getHost();
|
final String host = getHost();
|
||||||
ApiProvider.getInstance().init(host);
|
initHost()
|
||||||
AccountService.login(email, password)
|
.flatMap(new Func1<String, Observable<Authentication>>() {
|
||||||
|
@Override
|
||||||
|
public Observable<Authentication> call(String s) {
|
||||||
|
return AccountService.login(email, password);
|
||||||
|
}
|
||||||
|
})
|
||||||
.doOnSubscribe(new Action0() {
|
.doOnSubscribe(new Action0() {
|
||||||
@Override
|
@Override
|
||||||
public void call() {
|
public void call() {
|
||||||
@@ -183,8 +210,12 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
ToastUtils.showNetworkError(SignInActivity.this);
|
if (e instanceof IllegalHostException) {
|
||||||
animateFinish(mSignInBtn, mSignInProgress);
|
ToastUtils.show(SignInActivity.this, R.string.illegal_host);
|
||||||
|
} else {
|
||||||
|
ToastUtils.showNetworkError(SignInActivity.this);
|
||||||
|
animateFinish(mSignInBtn, mSignInProgress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -203,12 +234,17 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.tv_sign_up)
|
@OnClick(R.id.tv_sign_up)
|
||||||
void clickedSignup() {
|
void clickedSignUp() {
|
||||||
final String email = mEmailEt.getText().toString();
|
final String email = mEmailEt.getText().toString();
|
||||||
final String password = mPasswordEt.getText().toString();
|
final String password = mPasswordEt.getText().toString();
|
||||||
final String host = getHost();
|
final String host = getHost();
|
||||||
ApiProvider.getInstance().init(host);
|
initHost()
|
||||||
AccountService.register(email, password)
|
.flatMap(new Func1<String, Observable<BaseResponse>>() {
|
||||||
|
@Override
|
||||||
|
public Observable<BaseResponse> call(String s) {
|
||||||
|
return AccountService.register(email, password);
|
||||||
|
}
|
||||||
|
})
|
||||||
.doOnSubscribe(new Action0() {
|
.doOnSubscribe(new Action0() {
|
||||||
@Override
|
@Override
|
||||||
public void call() {
|
public void call() {
|
||||||
@@ -241,8 +277,12 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
ToastUtils.showNetworkError(SignInActivity.this);
|
if (e instanceof IllegalHostException) {
|
||||||
animateFinish(mSignUpBtn, mSignUpProgress);
|
ToastUtils.show(SignInActivity.this, R.string.illegal_host);
|
||||||
|
} else {
|
||||||
|
ToastUtils.showNetworkError(SignInActivity.this);
|
||||||
|
animateFinish(mSignUpBtn, mSignUpProgress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -260,13 +300,25 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.tv_sign_up)
|
private Observable<String> initHost() {
|
||||||
void clickedSignUp() {
|
return Observable.create(new Observable.OnSubscribe<String>() {
|
||||||
mSignUpPanel.animate()
|
@Override
|
||||||
.scaleX(1)
|
public void call(Subscriber<? super String> subscriber) {
|
||||||
.setDuration(200)
|
if (!subscriber.isUnsubscribed()) {
|
||||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
String host = getHost();
|
||||||
.start();
|
if (host.matches("^(http|https)://[^\\s]+")) {
|
||||||
|
ApiProvider.getInstance().init(host);
|
||||||
|
subscriber.onNext(host);
|
||||||
|
subscriber.onCompleted();
|
||||||
|
} else {
|
||||||
|
subscriber.onError(new IllegalHostException());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class IllegalHostException extends Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animateProgress(View button, final View progressBar) {
|
private void animateProgress(View button, final View progressBar) {
|
||||||
|
@@ -135,15 +135,32 @@
|
|||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:src="@drawable/logo" />
|
android:src="@drawable/logo" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/tv_custom_host"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:text="@string/use_custom_host"
|
android:orientation="vertical">
|
||||||
android:textColor="#EEEEEE"
|
|
||||||
android:textSize="16sp" />
|
<TextView
|
||||||
|
android:id="@+id/tv_custom_host"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/use_custom_host"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:textColor="#EEEEEE"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_example"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:textColor="#EEEEEE"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@@ -64,4 +64,5 @@
|
|||||||
<string name="change_user_name_successful">Change user name successful</string>
|
<string name="change_user_name_successful">Change user name successful</string>
|
||||||
<string name="search">Search</string>
|
<string name="search">Search</string>
|
||||||
<string name="notebooks">Notebooks</string>
|
<string name="notebooks">Notebooks</string>
|
||||||
|
<string name="illegal_host">Illegal host, please check again</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user