|
@@ -8,6 +8,7 @@ import android.widget.Toast;
|
|
|
|
|
|
|
|
import androidx.lifecycle.Observer;
|
|
import androidx.lifecycle.Observer;
|
|
|
|
|
|
|
|
|
|
+import com.miekir.mvp.bean.DataResult;
|
|
|
import com.miekir.mvp.model.DataMethod;
|
|
import com.miekir.mvp.model.DataMethod;
|
|
|
import com.miekir.mvp.presenter.InjectPresenter;
|
|
import com.miekir.mvp.presenter.InjectPresenter;
|
|
|
import com.miekir.mvp.jetpack.MvpObserver;
|
|
import com.miekir.mvp.jetpack.MvpObserver;
|
|
@@ -15,7 +16,7 @@ import com.miekir.mvp.view.BaseMvpActivity;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
-public class MainActivity extends BaseMvpActivity {
|
|
|
|
|
|
|
+public class MainActivity extends BaseMvpActivity implements View.OnClickListener {
|
|
|
@InjectPresenter
|
|
@InjectPresenter
|
|
|
TestPresenter presenter;
|
|
TestPresenter presenter;
|
|
|
|
|
|
|
@@ -29,18 +30,7 @@ public class MainActivity extends BaseMvpActivity {
|
|
|
TextView tv_name = findViewById(R.id.tv_name);
|
|
TextView tv_name = findViewById(R.id.tv_name);
|
|
|
tv_name.setText("MainActivity");
|
|
tv_name.setText("MainActivity");
|
|
|
|
|
|
|
|
- findViewById(R.id.view_test).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View view) {
|
|
|
|
|
- // 点击之后,后台执行耗时操作
|
|
|
|
|
- presenter.go().observeOnce(new MvpObserver<TestBean1>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onDataChanged(TestBean1 testBean1) {
|
|
|
|
|
- Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_SHORT).show();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ findViewById(R.id.view_test).setOnClickListener(this);
|
|
|
|
|
|
|
|
findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {
|
|
findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
@Override
|
|
@@ -51,8 +41,20 @@ public class MainActivity extends BaseMvpActivity {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @DataMethod(dataSource = TestPresenter.SOURCE_LOGIN_RESULT)
|
|
|
|
|
- public void onDataCome(int code, String msg, List<TestBean1> data) {
|
|
|
|
|
- Toast.makeText(this, data.get(0).getName(), Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ switch (v.getId()) {
|
|
|
|
|
+ case R.id.view_test:
|
|
|
|
|
+ // 点击之后,后台执行耗时操作
|
|
|
|
|
+ presenter.go().observeOnce(new MvpObserver<DataResult<List<TestBean1>>>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDataChanged(DataResult<List<TestBean1>> result) {
|
|
|
|
|
+ Toast.makeText(getApplicationContext(), result.getBean().get(0).getName(), Toast.LENGTH_SHORT).show();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|