package org.droiders.zoomeye.login;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import com.devspark.appmsg.AppMsg;
import com.jakewharton.rxbinding.view.RxView;
import javax.inject.Inject;
import org.droiders.zoomeye.R;
import org.droiders.zoomeye.ZoomEyeApp;
import org.droiders.zoomeye.databinding.ActivityLoginBinding;
import org.droiders.zoomeye.di.AppModule;
import org.droiders.zoomeye.search.SearchActivity;
import rx.android.schedulers.AndroidSchedulers;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

public class LoginActivity extends AppCompatActivity implements LoginContract.View {

  private ActivityLoginBinding binding;
  @Inject LoginPresenter mPresenter;

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_login);

    if (ZoomEyeApp.isLogin(this)) {

      startActivity(new Intent(this, SearchActivity.class));
      this.finish();

    } else {

      LoginComponent loginComponent = DaggerLoginComponent.builder()
          .loginModule(new LoginModule(this))
          .appModule(new AppModule(this))
          .build();
      loginComponent.inject(this);

      RxView.clicks(binding.buttonLogin)
          .debounce(300, MILLISECONDS)
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe(aVoid -> this.loginClick());
    }
  }

  @Override
  public void loginClick() {
    final String email = binding.etEmail.getText().toString();
    final String password = binding.etPassword.getText().toString();
    if (TextUtils.isEmpty(email)) {
      AppMsg.makeText(this, R.string.email_not_null, AppMsg.STYLE_ALERT).show();
      return;
    }
    if (TextUtils.isEmpty(password)) {
      AppMsg.makeText(this, R.string.password_not_null, AppMsg.STYLE_ALERT).show();
      return;
    }
    mPresenter.login(email, password);
  }

  @Override public void loginSuccess() {
    AppMsg.makeText(this, getString(R.string.login_success), AppMsg.STYLE_INFO).show();

    startActivity(new Intent(this, SearchActivity.class));

    finish();
  }

  @Override public void loginFail(String errorMessage) {
    AppMsg.makeText(this, errorMessage, AppMsg.STYLE_ALERT).show();

  }
}

@@ -292,16 +292,54 @@
 RxView;%0A
+import java.util.concurrent.TimeUnit;%0A
 import j
@@ -2203,24 +2203,168 @@
 O).show();%0A%0A
+    rx.Observable.just(%22%22).delay(300, TimeUnit.MILLISECONDS)%0A        .observeOn(AndroidSchedulers.mainThread())%0A        .subscribe(s -%3E %7B%0A      
     startAct
@@ -2410,17 +2410,22 @@
 lass));%0A
-%0A
+      
     fini
@@ -2430,16 +2430,28 @@
 nish();%0A
+        %7D);%0A
   %7D%0A%0A  @

修改 登录, 延迟跳转