Skip to content

Instantly share code, notes, and snippets.

@varundwarkani
Last active June 13, 2021 08:25
Show Gist options
  • Save varundwarkani/2c49c63f3bb4a3ada3c6a78b374b8921 to your computer and use it in GitHub Desktop.
Save varundwarkani/2c49c63f3bb4a3ada3c6a78b374b8921 to your computer and use it in GitHub Desktop.
public class QuizOverFragment extends DialogFragment {
private DialogQuizOverBinding binding;
private QuizOverViewModel quizOverViewModel;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
quizOverViewModel = new ViewModelProvider(requireActivity()).get(QuizOverViewModel.class);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DialogQuizOverBinding.inflate(inflater, container, false);
binding.setViewModel(quizOverViewModel);
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setObservers();
}
@Override
public void onResume() {
super.onResume();
if (getDialog() == null) return;
Window window = getDialog().getWindow();
if (window == null) return;
int width = (int) (getResources().getDisplayMetrics().widthPixels * 0.4);
WindowManager.LayoutParams params = window.getAttributes();
params.width = width;
window.setAttributes(params);
}
private void setObservers() {
quizOverViewModel.isCancelled.observe(getViewLifecycleOwner(), aBoolean -> {
dismiss();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment