Skip to content
Jude edited this page Oct 7, 2015 · 10 revisions

BeamDataActivity & BeamDataActivityPresenter & BeamDataFragment & BeamDataFragmentPresenter

数据模型式的Activity与Fragment模板。支持Rx函数式调用。

data
例。对于这样的数据展示页面。本模板能极大简化工作。

##API Activity&Fragment 重写以下2个方法:
public void setData(M data){}数据加载成功时回调。根据数据刷新UI。
public void setError(Throwable e){}数据加载失败时的回调。修改UI。

Presenter
void publishObject(M data)手动发布数据。可多次调用。如果发布时View没有注册。会等到View注册时再发布。
void publishError(Throwable e)发布错误,同上。

Rx订阅
BeamDataActivityPresenter实现了Observer在任何地方都可以,当发布时会自动通知View层
PlaceModel.getInstance().getPlaceDetail().subscribe(this);

##例子## Activity:

    @RequiresPresenter(PlaceDetailPresenter.class)
public class PlaceDetailActivity extends BeamDataActivity<PlaceDetailPresenter, PlaceDetail> {

    @InjectView(R.id.toolbar)
    Toolbar toolbar;
    @InjectView(R.id.picture)
    RollPagerView picture;
    @InjectView(R.id.score)
    ScoreView score;
    @InjectView(R.id.score_text)
    TextView scoreText;
    @InjectView(R.id.evaluate)
    TAGView evaluate;
    @InjectView(R.id.address)
    TextView address;
    @InjectView(R.id.fish_type)
    TextView fishType;
    @InjectView(R.id.tel)
    TextView tel;
    @InjectView(R.id.price)
    TextView price;
    @InjectView(R.id.content)
    TextView content;
    @InjectView(R.id.server)
    ExGridView server;
    TAGView commentCount;
    PictureAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.place_activity_detail);
        getExpansion().showProgressPage();
        ButterKnife.inject(this);
        picture.setAdapter(adapter = new PictureAdapter());
    }

    @Override
    public void setData(PlaceDetail data) {
        getExpansion().dismissProgressPage();
        commentCount.setText(data.getEvaluateCount()+"");
        score.setScore(data.getScore());
        scoreText.setText(data.getScore() + "");
        address.setText(data.getAddress());
        fishType.setText(data.getFishType());
        tel.setText(data.getTel());
        price.setText("人均消费:" + data.getCost() + "元");
        content.setText(data.getContent());
        adapter.setPath(data.getPicture());
    }
}

Presenter:

public class PlaceDetailPresenter extends BeamDataActivityPresenter<PlaceDetailActivity,PlaceDetail> {

    @Override
    protected void onCreate(PlaceDetailActivity view, Bundle savedState) {
        super.onCreate(view, savedState);
        PlaceModel.getInstance().getPlaceDetail(getView().getIntent().getIntExtra("id",0)).subscribe(this);
    }
}
Clone this wiki locally