package org.stepic.droid.util;

import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.ProgressBar;

import org.stepic.droid.ui.dialogs.LoadingProgressDialog;

public class ProgressHelper {
    public static void dismiss(ProgressBar mProgressLogin) {

        if (mProgressLogin != null && mProgressLogin.getVisibility() != View.GONE) {
            mProgressLogin.setVisibility(View.GONE);
        }
    }

    public static void activate(ProgressBar progressBar) {
        if (progressBar != null)
            progressBar.setVisibility(View.VISIBLE);
    }

    public static void dismiss(SwipeRefreshLayout swipeRefreshLayout) {
        if (swipeRefreshLayout != null)
            swipeRefreshLayout.setRefreshing(false);
    }

    public static void activate(SwipeRefreshLayout swipeRefreshLayout) {
        if (swipeRefreshLayout != null)
            swipeRefreshLayout.setRefreshing(true);
    }

    public static void activate(LoadingProgressDialog progressDialog) {
        if (progressDialog != null && !progressDialog.isShowing()) {
            progressDialog.show();
        }
    }

    public static void dismiss(LoadingProgressDialog progressDialog) {
        if (progressDialog != null && progressDialog.isShowing()) {
            try {
                progressDialog.dismiss();
            } catch (Exception ignored) {
            }
        }
    }

    public static void activate(DialogFragment progressDialog, FragmentManager fragmentManager, String tag) {
        if (progressDialog != null && !progressDialog.isAdded())
            progressDialog.show(fragmentManager, tag);
    }

    public static void dismiss(FragmentManager fragmentManager, String tag) {
        if (fragmentManager != null) {
            try {
                DialogFragment fragment = (DialogFragment) fragmentManager.findFragmentByTag(tag);
                fragment.dismiss();
            } catch (Exception ignored) {
            }
        }
    }
}

@@ -1673,17 +1673,69 @@
 sAdded()
-)
+ && fragmentManager.findFragmentByTag(tag) == null) %7B
 %0A       
@@ -1778,24 +1778,34 @@
 ager, tag);%0A
+        %7D%0A
     %7D%0A%0A    p

fix progress helper