package org.ccci.gto.android.common.util;

import android.annotation.TargetApi;
import android.os.AsyncTask;
import android.os.Build;
import androidx.annotation.NonNull;

import org.ccci.gto.android.common.concurrent.NamedThreadFactory;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class AsyncTaskCompat {
    @NonNull
    private static final Compat COMPAT;
    static {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            COMPAT = new GingerbreadCompat();
        } else {
            COMPAT = new HoneycombCompat();
        }
    }

    public static final Executor SERIAL_EXECUTOR = COMPAT.serialExecutor();

    public static void execute(@NonNull final Runnable task) {
        COMPAT.execute(task);
    }

    interface Compat {
        void execute(@NonNull Runnable task);

        @NonNull
        Executor serialExecutor();
    }

    static class GingerbreadCompat implements Compat {
        private Executor mExecutor;

        @NonNull
        private synchronized Executor getExecutor() {
            if (mExecutor == null) {
                mExecutor = Executors.newFixedThreadPool(1, new NamedThreadFactory("AsyncTaskCompat"));
                if (mExecutor instanceof ThreadPoolExecutor) {
                    ((ThreadPoolExecutor) mExecutor).setKeepAliveTime(30, TimeUnit.SECONDS);
                    ((ThreadPoolExecutor) mExecutor).allowCoreThreadTimeOut(true);
                }
            }

            return mExecutor;
        }

        @Override
        public void execute(@NonNull final Runnable task) {
            getExecutor().execute(task);
        }

        @NonNull
        @Override
        public Executor serialExecutor() {
            return getExecutor();
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    static class HoneycombCompat extends GingerbreadCompat {
        @Override
        public void execute(@NonNull Runnable task) {
            AsyncTask.execute(task);
        }

        @NonNull
        @Override
        public Executor serialExecutor() {
            return AsyncTask.SERIAL_EXECUTOR;
        }
    }
}

@@ -55,185 +55,20 @@
 oid.
-annotation.TargetApi;%0Aimport android.os.AsyncTask;%0Aimport android.os.Build;%0Aimport androidx.annotation.NonNull;%0A%0Aimport org.ccci.gto.android.common.concurrent.NamedThreadFactory
+os.AsyncTask
 ;%0A%0Ai
@@ -108,1743 +108,252 @@
 or;%0A
+%0A
 import 
-java.util.concurrent.Executors;%0Aimport java.util.concurrent.ThreadPoolExecutor;%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class AsyncTaskCompat %7B%0A    @NonNull%0A    private static final Compat COMPAT;%0A    static %7B%0A        if (Build.VERSION.SDK_INT %3C Build.VERSION_CODES.HONEYCOMB) %7B%0A            COMPAT = new GingerbreadCompat();%0A        %7D else %7B%0A            COMPAT = new HoneycombCompat();%0A        %7D%0A    %7D%0A%0A    public static final Executor SERIAL_EXECUTOR = COMPAT.serialExecutor();%0A%0A    public static void execute(@NonNull final Runnable task) %7B%0A        COMPAT.execute(task);%0A    %7D%0A%0A    interface Compat %7B%0A        void execute(@NonNull Runnable task);%0A%0A        @NonNull%0A        Executor serialExecutor();%0A    %7D%0A%0A    static class GingerbreadCompat implements Compat %7B%0A        private Executor mExecutor;%0A%0A        @NonNull%0A        private synchronized Executor getExecutor() %7B%0A            if (mExecutor == null) %7B%0A                mExecutor = Executors.newFixedThreadPool(1, new NamedThreadFactory(%22AsyncTaskCompat%22));%0A                if (mExecutor instanceof ThreadPoolExecutor) %7B%0A                    ((ThreadPoolExecutor) mExecutor).setKeepAliveTime(30, TimeUnit.SECONDS);%0A                    ((ThreadPoolExecutor) mExecutor).allowCoreThreadTimeOut(true);%0A                %7D%0A            %7D%0A%0A            return mExecutor;%0A        %7D%0A%0A        @Override%0A        public void execute(@NonNull final Runnable task) %7B%0A            getExecutor().execute(task);%0A        %7D%0A%0A        @NonNull%0A        @Override%0A        public Executor serialExecutor() %7B%0A            return getExecutor();%0A        %7D%0A    %7D%0A%0A    @TargetApi(Build.VERSION_CODES.HONEYCOMB)%0A    static class HoneycombCompat extends GingerbreadCompat %7B%0A        @Override%0A        publ
+androidx.annotation.NonNull;%0A%0A/**%0A * @deprecated Since v3.0.0, use %7B@link AsyncTask%7D directly.%0A */%0A@Deprecated%0Apublic class AsyncTaskCompat %7B%0A    public static final Executor SERIAL_EXECUTOR = AsyncTask.SERIAL_EXECUTOR;%0A%0A    public stat
 ic v
@@ -373,16 +373,22 @@
 NonNull 
+final 
 Runnable
@@ -392,28 +392,24 @@
 ble task) %7B%0A
-    
         Asyn
@@ -433,153 +433,8 @@
 k);%0A
-        %7D%0A%0A        @NonNull%0A        @Override%0A        public Executor serialExecutor() %7B%0A            return AsyncTask.SERIAL_EXECUTOR;%0A        %7D%0A
     

remove old logic and deprecate the AsyncTaskCompat class