Created
August 28, 2019 03:23
-
-
Save milaptank/530345c11752f0cfda1c23887ca3b5a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Milap Tank | |
BaseFragment.java is for | |
* @since 28/12/17 5:48 PM | |
*/ | |
public abstract class BaseFragment extends Fragment { | |
protected BaseActivity baseActivity; | |
protected Bundle fragmentBundle; | |
private View rootView; | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
fragmentBundle = getArguments(); | |
} | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
rootView = inflater.inflate(getFragmentLayoutId(), container, false); | |
return rootView; | |
} | |
@Override | |
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
initActivityHandling(); | |
activityCreated(savedInstanceState); | |
} | |
@Override | |
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
bindView(view); | |
} | |
private void initActivityHandling() { | |
baseActivity = (BaseActivity) getActivity(); | |
baseActivity.setBackIcon(isBackIcon(), isDrawerIcon()); | |
baseActivity.setSelectedFragment(getFragment()); | |
if (getToolbarTitle() != null) | |
baseActivity.setTitle(getToolbarTitle()); | |
} | |
public Bundle getFragmentBundle() { | |
return fragmentBundle; | |
} | |
public void isBackupIcon(boolean isBackupIcon, boolean isSetDrawerIcon) { | |
baseActivity.setBackIcon(isBackupIcon, isSetDrawerIcon); | |
} | |
public abstract int getFragmentLayoutId(); | |
public abstract void bindView(View view); | |
public abstract void activityCreated(Bundle savedInstanceState); | |
public abstract String getTagText(); | |
public abstract boolean onBackPressed(); | |
public abstract boolean isBackIcon(); | |
public abstract boolean isDrawerIcon(); | |
public abstract String getToolbarTitle(); | |
public void setToolbarTitle(String toolbarTitle) { | |
toolbarTitle = !TextUtils.isEmpty(toolbarTitle) ? toolbarTitle : getToolbarTitle(); | |
baseActivity.setTitle(toolbarTitle); | |
} | |
public abstract BaseFragment getFragment(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment