Challenge: Polishing Your App Some More

First, I declare a lateinit var to hold a reference to ProgressDialog

private lateinit var progressDialog:ProgressDialog

And I instantiate in onCreate

override fun onCreate(savedInstanceState: Bundle?) {
    progressDialog = ProgressDialog(requireContext())
    progressDialog.setTitle("Downloading photos")
    progressDialog.setMessage("It might take a few seconds..")

I used clearFocus to hide the keyboard, I also make the dialog visible. Then I also listen to focus change to collapse the searchview

    searchView.apply {
        setOnQueryTextListener(object : SearchView.OnQueryTextListener{
            override fun onQueryTextSubmit(queryText: String): Boolean {
                Log.d(TAG, "QueryTextSubmit: $queryText")
                return true
            override fun onQueryTextChange(queryText: String): Boolean {
                Log.d(TAG, "QueryTextChange: $queryText")
                return false
        setOnFocusChangeListener { v, hasFocus ->
            if (!hasFocus) {

Finally, onViewCreated, we dimiss the dialog after downloading the json

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        Observer {galleryItems ->
            Log.d(TAG, "Have gallery items from ViewModel $galleryItems")
            photoRecyclerView?.adapter = PhotoAdapter(galleryItems)