I was using MVP in a previous application with my View component essentially an RelativeLayout.
Anytime I would want to block any touch interaction on the RelativeLayout (for example while a network access) I would return true from touchIntercept like this.
public abstract class RootView<T> extends RelativeLayout implements BaseView<T> {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mIsScreenLocked)
return true;
else
return super.onInterceptTouchEvent(ev);
}
@Override
public void showProgress(boolean show, boolean lockScreen) {
ProgressBar progressBar = ((ProgressBar) findViewById(R.id.progress_bar));
if (progressBar != null) {
if (show) {
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.GONE);
}
}
mIsScreenLocked = lockScreen;
freezeBottomBar(show);
}
}
In my new application my views are Fragments , the base of which extends a fragment
public abstract class BaseFragment
{
}
I would like to achieve something similar , to block all touch interactions on the fragment when a user initiates any network access.
public abstract class BaseFragment
{
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mIsScreenLocked = true;
initializeControls();
attachListeners();
if (savedInstanceState == null)
onScreenInitializationComplete(getArguments());
else
onScreenInitializationComplete(getArguments(), savedInstanceState);
***createTouchInterceptor***(view);
//should we run ignition here?
}
private void createTouchInterceptor(View fragmentView) {
fragmentView.setOnTouchListener((view, motionEvent) -> {
if (mIsScreenLocked)
return true;
else
return false;
});
}
}
This ofcourse wont work , since when a button is pressed on the fragment , the button would receive the touch.
Any ideas?