Last active
September 10, 2016 00:15
-
-
Save LouisCAD/3327a3d7a31d019a076a54c9a2bb33fd to your computer and use it in GitHub Desktop.
Allows one-liner GoogleApiClient Callbacks logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle; | |
import android.support.annotation.NonNull; | |
import android.support.annotation.Nullable; | |
import com.google.android.gms.common.ConnectionResult; | |
import com.google.android.gms.common.api.GoogleApiClient; | |
import timber.log.Timber; | |
import xyz.louiscad.common.Constants; | |
public enum DebugConnectionCallbacks { | |
; | |
@NonNull | |
public static GoogleApiClient.ConnectionCallbacks | |
logIt(@NonNull final GoogleApiClient.ConnectionCallbacks callbacks) { | |
if (!Constants.DEBUG) return callbacks; | |
else return new GoogleApiClient.ConnectionCallbacks() { | |
@Override | |
public void onConnected(@Nullable Bundle connectionHint) { | |
Timber.d("onConnected(%s)", connectionHint); | |
callbacks.onConnected(connectionHint); | |
} | |
@Override | |
public void onConnectionSuspended(int cause) { | |
final String causeStr = cause == CAUSE_SERVICE_DISCONNECTED ? | |
"CAUSE_SERVICE_DISCONNECTED" : "CAUSE_NETWORK_LOST"; | |
Timber.d("onConnectionSuspended(%s)", causeStr); | |
callbacks.onConnectionSuspended(cause); | |
} | |
}; | |
} | |
@NonNull | |
public static GoogleApiClient.OnConnectionFailedListener | |
logFails(@NonNull final GoogleApiClient.OnConnectionFailedListener listener) { | |
if (!Constants.DEBUG) return listener; | |
else return new GoogleApiClient.OnConnectionFailedListener() { | |
@Override | |
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { | |
Timber.d("onConnectionFailed(%s)", connectionResult); | |
listener.onConnectionFailed(connectionResult); | |
} | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface DebugConstants { | |
/** | |
* Workaround for the always false BuildConfig.DEBUG value in libraries. | |
* Must be manually changed to false when build release apk.<br/> | |
* For non library modules, use BuildConfig.DEBUG instead, which value | |
* changes following buildType. | |
*/ | |
boolean DEBUG = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment