/**
 * AppLovin Interstitial SDK Mediation for MoPub
 * 
 * @author Matt Szaro
 * @version 1.2
 **/

package YOUR_PACKAGE_NAME;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import com.applovin.adview.AppLovinAdView;
import com.applovin.sdk.*;
import com.mopub.mobileads.CustomEventInterstitial;
import com.mopub.mobileads.MoPubErrorCode;

import java.util.Map;

public class AppLovinInterstitial extends CustomEventInterstitial
        implements AppLovinAdLoadListener
{
    private CustomEventInterstitial.CustomEventInterstitialListener mInterstitialListener;
    private Activity                                                parentActivity;
    private AppLovinAdService                                       adService;
    private AppLovinAd                                              lastReceived;

    /*
     * Abstract methods from CustomEventInterstitial
     */
    @Override
    public void loadInterstitial(Context context, CustomEventInterstitial.CustomEventInterstitialListener interstitialListener, Map<String, Object> localExtras, Map<String, String> serverExtras)
    {
        mInterstitialListener = interstitialListener;

        if ( context instanceof Activity )
        {
            parentActivity = (Activity) context;
        }
        else
        {
            mInterstitialListener.onInterstitialFailed( MoPubErrorCode.INTERNAL_ERROR );
            return;
        }


        Log.d( "AppLovinAdapter", "Request received for new interstitial." );

        adService = AppLovinSdk.getInstance( context ).getAdService();
        adService.loadNextAd( AppLovinAdSize.INTERSTITIAL, this );
    }

    @Override
    public void showInterstitial()
    {
        final AppLovinAd adToRender = lastReceived;

        if ( adToRender != null )
        {
            Log.d( "MoPub", "Showing AppLovin interstitial ad..." );

            parentActivity.runOnUiThread( new Runnable() {
                public void run()
                {
                    AppLovinAdView adView = new AppLovinAdView( AppLovinAdSize.BANNER, parentActivity );

                    adView.setAdClickListener( new AppLovinAdClickListener() {
                        @Override
                        public void adClicked(AppLovinAd appLovinAd)
                        {
                            mInterstitialListener.onLeaveApplication();
                        }
                    } );

                    adView.setAdDisplayListener( new AppLovinAdDisplayListener() {
                        @Override
                        public void adDisplayed(AppLovinAd appLovinAd)
                        {
                            mInterstitialListener.onInterstitialShown();
                        }

                        @Override
                        public void adHidden(AppLovinAd appLovinAd)
                        {
                            mInterstitialListener.onInterstitialDismissed();
                        }
                    } );
                    adView.renderAd( adToRender );
                }
            } );
        }
    }

    @Override
    public void onInvalidate()
    {

    }

    @Override
    public void adReceived(AppLovinAd ad)
    {
        Log.d( "MoPub", "AppLovin interstitial loaded successfully." );

        lastReceived = ad;

        parentActivity.runOnUiThread( new Runnable() {
            public void run()
            {
                mInterstitialListener.onInterstitialLoaded();
            }
        } );
    }

    @Override
    public void failedToReceiveAd(int errorCode)
    {
 
        parentActivity.runOnUiThread( new Runnable() {
            int errorCode = 0;
            
            public void run() {
            
                if ( errorCode == 202 )
                {
                    mInterstitialListener.onInterstitialFailed( MoPubErrorCode.NO_FILL );
                }
                else if ( errorCode >= 500 )
                {
                    mInterstitialListener.onInterstitialFailed( MoPubErrorCode.SERVER_ERROR );
                }
                else if ( errorCode < 0 )
                {
                    mInterstitialListener.onInterstitialFailed( MoPubErrorCode.INTERNAL_ERROR );
                }
                else
                {
                    mInterstitialListener.onInterstitialFailed( MoPubErrorCode.UNSPECIFIED );
                }
            }
            
            public Runnable Init(int error)
            {
                this.errorCode = error;
                return this;
            }
        }.Init(errorCode));
    }
}
@@ -3571,16 +3571,22 @@
 ceiveAd(
+final 
 int erro
@@ -3598,18 +3598,16 @@
 )%0A    %7B%0A
- %0A
         
@@ -3657,52 +3657,8 @@
 ) %7B%0A
-            int errorCode = 0;%0A            %0A
     
@@ -3685,29 +3685,16 @@
 run() %7B%0A
-            %0A
         
@@ -3721,17 +3721,17 @@
 de == 20
-2
+4
  )%0A     
@@ -4375,189 +4375,9 @@
     
-        %0A            public Runnable Init(int error)%0A            %7B%0A                this.errorCode = error;%0A                return this;%0A            %7D%0A        %7D.Init(errorCode));%0A    %7D
+%7D);
 %0A%7D

Remove inner constructor from pull request