Last active
August 19, 2018 15:38
-
-
Save ibrahimsn98/ec7551108d3ff1ee1c4c81a57ac796ce to your computer and use it in GitHub Desktop.
android-mvvm-with-dagger-2
This file contains 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
public abstract class BaseFragment extends DaggerFragment { | |
private Unbinder unbinder; | |
private AppCompatActivity activity; | |
@LayoutRes | |
protected abstract int layoutRes(); | |
@Override | |
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(layoutRes(), container, false); | |
unbinder = ButterKnife.bind(this, view); | |
return view; | |
} | |
@Override | |
public void onAttach(Context context) { | |
super.onAttach(context); | |
activity = (AppCompatActivity) context; | |
} | |
@Override | |
public void onDetach() { | |
super.onDetach(); | |
activity = null; | |
} | |
public AppCompatActivity getBaseActivity() { | |
return activity; | |
} | |
@Override | |
public void onDestroyView() { | |
super.onDestroyView(); | |
if(unbinder != null) { | |
unbinder.unbind(); | |
unbinder = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment