Last active
June 13, 2021 08:25
-
-
Save varundwarkani/2c49c63f3bb4a3ada3c6a78b374b8921 to your computer and use it in GitHub Desktop.
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 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