mirror of
https://github.com/leanote/leanote-android.git
synced 2026-01-14 07:00:23 +08:00
support sign up; extract strings
This commit is contained in:
@@ -28,25 +28,26 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.edit.NoteEditActivity"
|
||||
android:label="Edit" />
|
||||
android:label="@string/edit" />
|
||||
<activity
|
||||
android:name=".ui.NotePreviewActivity"
|
||||
android:label="Preview" />
|
||||
android:label="@string/preview" />
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:label="Notes" />
|
||||
android:label="@string/recent_notes" />
|
||||
<activity android:name=".ui.SignInActivity" />
|
||||
<activity
|
||||
android:name=".ui.SettingsActivity"
|
||||
android:label="Settings" />
|
||||
android:label="@string/settings" />
|
||||
|
||||
<activity android:name=".ui.AboutActivity"
|
||||
android:label="@string/about"/>
|
||||
|
||||
<service
|
||||
android:name=".background.NoteSyncService"
|
||||
android:enabled="true"
|
||||
android:exported="false"
|
||||
android:label="NoteSyncService"></service>
|
||||
|
||||
<activity android:name=".ui.AboutActivity"></activity>
|
||||
android:label="NoteSyncService" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -12,6 +12,10 @@ import rx.Observable;
|
||||
|
||||
public class AccountService {
|
||||
|
||||
public static Observable<BaseResponse> register(String email, String password) {
|
||||
return RetrofitUtils.create(ApiProvider.getInstance().getAuthApi().register(email, password));
|
||||
}
|
||||
|
||||
public static Observable<Authentication> login(String email, String password) {
|
||||
return RetrofitUtils.create(ApiProvider.getInstance().getAuthApi().login(email, password));
|
||||
}
|
||||
|
||||
@@ -16,16 +16,20 @@ import android.widget.TextView;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.model.Authentication;
|
||||
import org.houxg.leamonax.model.BaseResponse;
|
||||
import org.houxg.leamonax.network.ApiProvider;
|
||||
import org.houxg.leamonax.network.LeaFailure;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.utils.ToastUtils;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import rx.Observable;
|
||||
import rx.Observer;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action0;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class SignInActivity extends BaseActivity implements TextWatcher {
|
||||
@@ -43,14 +47,37 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
||||
EditText mPasswordEt;
|
||||
@BindView(R.id.tv_sign_in)
|
||||
View mSignInBtn;
|
||||
@BindView(R.id.tv_sign_up)
|
||||
View mSignUpBtn;
|
||||
@BindView(R.id.tv_custom_host)
|
||||
TextView mCustomHostBtn;
|
||||
@BindView(R.id.et_custom_host)
|
||||
EditText mHostEt;
|
||||
@BindView(R.id.ll_action)
|
||||
View mActionPanel;
|
||||
@BindView(R.id.progress)
|
||||
ProgressBar mProgress;
|
||||
@BindView(R.id.progress_sign_in)
|
||||
ProgressBar mSignInProgress;
|
||||
@BindView(R.id.progress_sign_up)
|
||||
ProgressBar mSignUpProgress;
|
||||
@BindView(R.id.rl_sign_up)
|
||||
View mSignUpPanel;
|
||||
|
||||
private Observer<Authentication> mSignInObserver = new Observer<Authentication>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Authentication authentication) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -142,7 +169,7 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
||||
mSignInBtn.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
animateSignInProgress();
|
||||
animateProgress(mSignInBtn, mSignInProgress);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -152,14 +179,14 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
||||
.subscribe(new Observer<Authentication>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
animateSignFinish();
|
||||
animateFinish(mSignInBtn, mSignInProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
e.printStackTrace();
|
||||
ToastUtils.showNetworkError(SignInActivity.this);
|
||||
animateSignFinish();
|
||||
animateFinish(mSignInBtn, mSignInProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,15 +204,82 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
||||
});
|
||||
}
|
||||
|
||||
private void animateSignInProgress() {
|
||||
mSignInBtn.animate()
|
||||
@OnClick(R.id.tv_sign_up)
|
||||
void clickedSignup() {
|
||||
final String email = mEmailEt.getText().toString();
|
||||
final String password = mPasswordEt.getText().toString();
|
||||
final String host = getHost();
|
||||
ApiProvider.getInstance().init(host);
|
||||
AccountService.register(email, password)
|
||||
.doOnSubscribe(new Action0() {
|
||||
@Override
|
||||
public void call() {
|
||||
mSignUpBtn.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
animateProgress(mSignUpBtn, mSignUpProgress);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.flatMap(new Func1<BaseResponse, Observable<Authentication>>() {
|
||||
@Override
|
||||
public Observable<Authentication> call(BaseResponse baseResponse) {
|
||||
if (baseResponse.isOk()) {
|
||||
return AccountService.login(email, password);
|
||||
} else {
|
||||
throw new LeaFailure(baseResponse);
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<Authentication>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
animateFinish(mSignUpBtn, mSignUpProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
e.printStackTrace();
|
||||
ToastUtils.showNetworkError(SignInActivity.this);
|
||||
animateFinish(mSignUpBtn, mSignUpProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Authentication authentication) {
|
||||
if (authentication.isOk()) {
|
||||
AccountService.saveToAccount(authentication, host);
|
||||
Intent intent = MainActivity.getOpenIntent(SignInActivity.this, true);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else {
|
||||
ToastUtils.show(SignInActivity.this, R.string.email_or_password_incorrect);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnClick(R.id.tv_sign_up)
|
||||
void clickedSignUp() {
|
||||
mSignUpPanel.animate()
|
||||
.scaleX(1)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.start();
|
||||
}
|
||||
|
||||
private void animateProgress(View button, final View progressBar) {
|
||||
button.animate()
|
||||
.scaleX(0)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.withEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mProgress.animate()
|
||||
progressBar.animate()
|
||||
.alpha(1)
|
||||
.setDuration(100)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
@@ -195,15 +289,15 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
||||
.start();
|
||||
}
|
||||
|
||||
private void animateSignFinish() {
|
||||
mProgress.animate()
|
||||
private void animateFinish(final View button, final View progressBar) {
|
||||
progressBar.animate()
|
||||
.alpha(0)
|
||||
.setDuration(100)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.withEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSignInBtn.animate()
|
||||
button.animate()
|
||||
.scaleX(1)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
|
||||
@@ -15,87 +15,108 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:background="#fff"
|
||||
android:hint="@string/email"
|
||||
android:padding="8dp"
|
||||
android:textSize="18sp" />
|
||||
style="@style/SignInEditText"
|
||||
android:hint="@string/email" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SignInEditText"
|
||||
android:layout_below="@id/et_email"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="#fff"
|
||||
android:hint="@string/password"
|
||||
android:inputType="textPassword"
|
||||
android:padding="8dp"
|
||||
android:textSize="18sp" />
|
||||
android:inputType="textPassword" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_custom_host"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SignInEditText"
|
||||
android:layout_below="@id/et_password"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:background="#fff"
|
||||
android:hint="@string/host_address"
|
||||
android:padding="8dp"
|
||||
android:scaleY="0"
|
||||
android:textSize="18sp" />
|
||||
android:scaleY="0" />
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_action"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/et_password"
|
||||
android:layout_marginTop="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sign_in"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="#757575"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:text="@string/sign_in"
|
||||
android:textColor="#EEEEEE"
|
||||
android:textSize="18sp" />
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingStart="16dp">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_alignBottom="@id/tv_sign_in"
|
||||
android:layout_alignTop="@id/tv_sign_in"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:alpha="0"
|
||||
android:indeterminate="true" />
|
||||
<RelativeLayout
|
||||
android:id="@+id/rl_sign_up"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sign_up"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@color/colorAccent"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:text="Sign up"
|
||||
android:textColor="#EEEEEE"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_sign_up"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:alpha="0"
|
||||
android:indeterminate="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sign_in"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="#757575"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:text="@string/sign_in"
|
||||
android:textColor="#EEEEEE"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_sign_in"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:alpha="0"
|
||||
android:indeterminate="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_forgot_password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tv_sign_in"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="4dp"
|
||||
android:padding="8dp"
|
||||
android:text="@string/forgot_password"
|
||||
android:textColor="#EEEEEE" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
@@ -114,7 +135,6 @@
|
||||
android:layout_marginBottom="16dp"
|
||||
android:src="@drawable/logo" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_custom_host"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
<item
|
||||
android:id="@+id/action_edit"
|
||||
app:showAsAction="always"
|
||||
android:title="@string/Edit"/>
|
||||
android:title="@string/edit"/>
|
||||
|
||||
</menu>
|
||||
@@ -7,7 +7,7 @@
|
||||
<string name="save_to_server">save to server</string>
|
||||
<string name="revert">Revert</string>
|
||||
<string name="reverting">Reverting</string>
|
||||
<string name="Edit">Edit</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="link">Link</string>
|
||||
<string name="confirm">Confirm</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
@@ -59,4 +59,5 @@
|
||||
<string name="license">License</string>
|
||||
<string name="version">Version</string>
|
||||
<string name="about">About</string>
|
||||
<string name="preview">Preview</string>
|
||||
</resources>
|
||||
|
||||
@@ -37,4 +37,16 @@
|
||||
<item name="android:padding">8dp</item>
|
||||
</style>
|
||||
|
||||
<style name="SignInEditText">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:padding">8dp</item>
|
||||
<item name="android:layout_marginEnd">16dp</item>
|
||||
<item name="android:layout_marginStart">16dp</item>
|
||||
<item name="android:background">#fff</item>
|
||||
<item name="android:fontFamily">sans-serif</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
<item name="android:textColorHint">@color/hint_text_light</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user