package com.github.hisaichi5518.kise;


import android.support.annotation.NonNull;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;

public abstract class Unit<ActionParam> implements UnitActions<ActionParam> {
    private long cacheExpiration = 43200L; // 12 hours

    public void invoke(final ActionParam actionParam) {
        final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
        config.fetch(cacheExpiration)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        config.activateFetched();
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        // Ignore Exception
                    }
                })
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (config.getBoolean(key())) {
                            try {
                                customAction(actionParam);
                            } catch (Exception e) {
                                defaultAction(actionParam);
                            }
                        } else {
                            defaultAction(actionParam);
                        }
                    }
                });

        // TODO: Callback methods does not execute if Google play service is out date.
    }

    private String key() {
        return this.getClass().getSimpleName();
    }
}
@@ -37,260 +37,8 @@
 ;%0A%0A%0A
-import android.support.annotation.NonNull;%0A%0Aimport com.google.android.gms.tasks.OnCompleteListener;%0Aimport com.google.android.gms.tasks.OnFailureListener;%0Aimport com.google.android.gms.tasks.OnSuccessListener;%0Aimport com.google.android.gms.tasks.Task;%0A
 impo
@@ -95,16 +95,16 @@
 Config;%0A
+
 %0Apublic 
@@ -177,63 +177,8 @@
 m%3E %7B
-%0A    private long cacheExpiration = 43200L; // 12 hours
 %0A%0A  
@@ -315,727 +315,8 @@
 ();%0A
-        config.fetch(cacheExpiration)%0A                .addOnSuccessListener(new OnSuccessListener%3CVoid%3E() %7B%0A                    @Override%0A                    public void onSuccess(Void aVoid) %7B%0A                        config.activateFetched();%0A                    %7D%0A                %7D)%0A                .addOnFailureListener(new OnFailureListener() %7B%0A                    @Override%0A                    public void onFailure(@NonNull Exception e) %7B%0A                        // Ignore Exception%0A                    %7D%0A                %7D)%0A                .addOnCompleteListener(new OnCompleteListener%3CVoid%3E() %7B%0A                    @Override%0A                    public void onComplete(@NonNull Task%3CVoid%3E task) %7B%0A                
     
@@ -367,46 +367,14 @@
     
-     
-           try %7B%0A                
+try %7B%0A
     
@@ -412,32 +412,16 @@
 Param);%0A
-                
         
@@ -464,32 +464,16 @@
         
-            
-    
 defaultA
@@ -508,183 +508,76 @@
     
-                %7D%0A                        %7D else %7B%0A                            defaultAction(actionParam);%0A                        %7D%0A                    %7D%0A                %7D);%0A
+%7D%0A        %7D else %7B%0A            defaultAction(actionParam);%0A        %7D
 %0A   

Remove fetch logic from invoke method.