package eu.tesseractsoft.mintimedialog;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;

/**
 * Created by Adam Kuszczak on 11/02/2017.
 */

public class MinTimeDialog extends ProgressDialog {

    // === Configuration option ===
    private int mMinShownTimeMs;
    private boolean mSilentDismiss;

    // === Internal flags ===
    private Handler mHandler;
    private boolean mDismissAlreadyRequested;
    private boolean mMinShowingTimeAchieved;


    public MinTimeDialog(Context context) {
        super(context);
        init();
    }

    public MinTimeDialog(Context context, int theme) {
        super(context, theme);
        init();
    }

    private void init(){
        mMinShownTimeMs = 0;
        mSilentDismiss = false;

        mHandler = new Handler();
        mDismissAlreadyRequested = false;
        mMinShowingTimeAchieved = false;
    }

    public void setMinShownTimeMs(int minShownTimeMs) {
        this.mMinShownTimeMs = minShownTimeMs;
    }

    public void setSilentDismiss(boolean silentDismiss) {
        this.mSilentDismiss = silentDismiss;
    }

    @Override
    public void show() {
        mHandler.postDelayed(minShowingTimeTimeout, mMinShownTimeMs);
        super.show();
    }

    @Override
    public void dismiss() {
        mDismissAlreadyRequested = true;
        if(mMinShowingTimeAchieved) {
            super.dismiss();
        }
    }

    @Override
    public void setOnDismissListener(OnDismissListener listener) {
        if(!mSilentDismiss) {
            super.setOnDismissListener(listener);
        }
    }

    public void dismissForced(){
        mHandler.removeCallbacks(minShowingTimeTimeout);
        super.dismiss();
    }

    Runnable minShowingTimeTimeout = new Runnable() {
        @Override
        public void run() {
            mMinShowingTimeAchieved = true;
            if(mDismissAlreadyRequested){
                MinTimeDialog.super.dismiss();
            }
        }
    };



    public static MinTimeDialog createMinTimeDialog(Context context, String message, int minShownTimeMs){
        MinTimeDialog dialog = new MinTimeDialog(context);
        dialog.setMessage(message);
        dialog.setMinShownTimeMs(minShownTimeMs);
        return dialog;
    }
}

@@ -1159,24 +1159,62 @@
 id show() %7B%0A
+        if(mMinShownTimeMs %3E 0) %7B%0A    
         mHan
@@ -1263,32 +1263,42 @@
 inShownTimeMs);%0A
+        %7D%0A
         super.sh
@@ -1327,32 +1327,45 @@
 ride%0A    public 
+synchronized 
 void dismiss() %7B
@@ -1675,24 +1675,37 @@
 %0A    public 
+synchronized 
 void dismiss
@@ -1807,16 +1807,24 @@
  %7D%0A%0A    
+private 
 Runnable
@@ -2017,35 +2017,21 @@
     
-MinTimeDialog.super.
 dismiss
+Forced
 ();%0A
@@ -2062,16 +2062,74 @@
     %7D;%0A%0A
+%0A    // =========== Static builder methods ===============
 %0A%0A    pu

Make some methods synchronized and some other improvements