【问题标题】:Should we check for view visibility in Presenter or Activity in MVP pattern?我们应该在 MVP 模式中检查 Presenter 或 Activity 中的视图可见性吗?
【发布时间】:2018-05-31 17:24:43
【问题描述】:

所以,我遵循 MVP 模式,我将每个视图任务委托给演示者,这正是它应该完成的方式

例如。 :

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
    if(textureView.getVisibility != View.GONE)        
        mPresenter.onSurfaceTextureAvailable(surfaceTexture);
}

我想知道是否允许像这样在我的活动中直接检查视图的可见性(这是 MVP 中的视图)?

谢谢!

【问题讨论】:

    标签: android mvp


    【解决方案1】:

    View 层只负责向用户显示视图。它没有业务逻辑。 Presenter 层负责将数据从模型层呈现到视图层。它处理后台任务,调用模型操作和在视图中设置数据。您应该像这样在Activity 中检查它。

    public class YourActivity extends BaseActivity implements MainMvpView {
    
    @Inject YourPresenter yourPresenter;
    
    ......
    
    
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
        if(textureView.getVisibility != View.GONE)        
            mPresenter.onSurfaceTextureAvailable(surfaceTexture);
    }
    
    ......
    
    }
    

    【讨论】:

    • 我所做的和你所说的完全一样,我的问题是检查视图的可见性是否是视图应该负责的事情。
    • 是的,因为与用户的视觉交互
    • 如果你想测试这种情况,逻辑不应该在视图中! ,我不同意@EgeKuzubasioglu。但这取决于你和你的逻辑!
    猜你喜欢
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    相关资源
    最近更新 更多