Skip to content

Commit

Permalink
Updated progress dialog with utility methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
khaykov committed Apr 10, 2020
1 parent 4839fe9 commit 33e7ec2
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,42 @@ import android.app.Dialog
import android.app.ProgressDialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import org.wordpress.android.R
import org.wordpress.android.ui.posts.PostTimePickerDialogFragment

class PrivateAtCookieRefreshProgressDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return ProgressDialog.show(
activity, "", "Establishing access to media files on private site.", true, true
val dialogMessage = activity?.getString(R.string.media_accessing_progress);

return ProgressDialog.show(
activity, "", dialogMessage, true, true
)
}

fun isDialogVisible(): Boolean {
return dialog != null && dialog!!.isShowing
}

companion object {
const val TAG = "private_at_cookie_progress_dialog"

fun showIfNecessary(fragmentManager: FragmentManager?) {
fragmentManager.let {
val thisFragment = fragmentManager!!.findFragmentByTag(TAG)
if (thisFragment == null || (thisFragment is PrivateAtCookieRefreshProgressDialog && !thisFragment.isDialogVisible())) {
PrivateAtCookieRefreshProgressDialog().show(fragmentManager, TAG)
}
}
}

fun dismissIfNecessary(fragmentManager: FragmentManager?) {
fragmentManager.let {
val thisFragment = fragmentManager!!.findFragmentByTag(TAG)
if (thisFragment is PrivateAtCookieRefreshProgressDialog) {
thisFragment.dismiss()
}
}
}
}
}

0 comments on commit 33e7ec2

Please sign in to comment.