package com.vijay.jsonwizard.mvp; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.View; import android.view.inputmethod.InputMethodManager; public abstract class MvpFragment<P extends MvpPresenter, VS extends ViewState> extends BaseFragment<VS> implements MvpView { protected P presenter; @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // Create the presenter if needed if (presenter == null) { presenter = createPresenter(); } presenter.attachView(this); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } @Override public void onDestroyView() { super.onDestroyView(); presenter.detachView(getRetainInstance()); } protected abstract P createPresenter(); public void hideSoftKeyboard() { // Check if no view has focus: View view = getActivity().getCurrentFocus(); if (view != null) { InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService( Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }