Skip to content

Commit 038660f

Browse files
committed
Applied feedback
1 parent 3a4b34c commit 038660f

File tree

8 files changed

+56
-334
lines changed

8 files changed

+56
-334
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ flutter_*.png
5454
linked_*.ds
5555
unlinked.ds
5656
unlinked_spec.ds
57+
pubspec.lock
5758

5859
# Android related
5960
**/android/**/gradle-wrapper.jar
@@ -96,3 +97,6 @@ unlinked_spec.ds
9697
!**/ios/**/default.pbxuser
9798
!**/ios/**/default.perspectivev3
9899
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
100+
101+
# Ignore coverage folder.
102+
coverage/

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ android {
3030
}
3131

3232
defaultConfig {
33-
minSdkVersion 16
33+
minSdkVersion 16
3434
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3535
}
3636
lintOptions {

android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityManager.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.google.android.gms.common.ConnectionResult;
1010
import com.google.android.gms.common.GoogleApiAvailability;
11+
import com.google.android.gms.tasks.Task;
1112

1213
import java.util.List;
1314

@@ -22,7 +23,7 @@ interface SuccessCallback {
2223

2324
@FunctionalInterface
2425
interface MakeGooglePlayServicesAvailableCallback {
25-
void onSuccess(boolean makeGooglePlayServicesAvailable);
26+
void onSuccess();
2627
}
2728

2829
@FunctionalInterface
@@ -37,7 +38,7 @@ interface isUserResolvableCallback {
3738

3839
@FunctionalInterface
3940
interface showErrorNotificationCallback {
40-
void onSuccess(boolean showErrorNotificationCallback);
41+
void onSuccess(Void v);
4142
}
4243

4344
@FunctionalInterface
@@ -51,37 +52,45 @@ interface ErrorCallback {
5152
}
5253

5354
void checkPlayServicesAvailability(Boolean showDialog, Activity activity, Context applicationContext, SuccessCallback successCallback, ErrorCallback errorCallback) {
54-
if (applicationContext == null || activity == null) {
55-
Log.d(GoogleApiAvailabilityConstants.LOG_TAG, "Context and/or activity cannot be null.");
56-
errorCallback.onError("GoogleApiAvailability.GoogleApiAvailabilityManager", "Android context and/or activity cannot be null.");
55+
if (applicationContext == null) {
56+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "The `ApplicationContext` cannot be null.");
57+
errorCallback.onError("GoogleApiAvailability.GoogleApiAvailabilityManager", "Android `ApplicationContext` cannot be null.");
5758
return;
5859
}
5960

6061
final int connectionResult = googleApiAvailability
6162
.isGooglePlayServicesAvailable(applicationContext);
6263

63-
if (showDialog != null && showDialog) {
64-
googleApiAvailability
65-
.showErrorDialogFragment(activity, connectionResult, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES);
64+
if (activity != null) {
65+
if (showDialog != null && showDialog) {
66+
googleApiAvailability
67+
.showErrorDialogFragment(activity, connectionResult, GoogleApiAvailabilityConstants.REQUEST_GOOGLE_PLAY_SERVICES);
68+
}
69+
} else {
70+
if (showDialog != null && showDialog) {
71+
// Only log warning when `showDialog` property was `true`.
72+
Log.w(GoogleApiAvailabilityConstants.LOG_TAG, "Unable to show dialog as `Activity` is not available.");
73+
}
6674
}
6775

6876
successCallback.onSuccess(GoogleApiAvailabilityConstants.toPlayServiceAvailability(connectionResult));
6977
}
7078

71-
void makeGooglePlayServicesAvailable(Activity activity, MakeGooglePlayServicesAvailableCallback successCallback, ErrorCallback errorCallback){
72-
if (activity == null){
73-
Log.d(GoogleApiAvailabilityConstants.LOG_TAG, "Activity cannot be null.");
79+
void makeGooglePlayServicesAvailable(Activity activity, MakeGooglePlayServicesAvailableCallback successCallback, ErrorCallback errorCallback) {
80+
if (activity == null) {
81+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Activity cannot be null.");
7482
errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", "Android Activity cannot be null.");
7583
return;
7684
}
7785

78-
final boolean status = googleApiAvailability.makeGooglePlayServicesAvailable(activity).isSuccessful();
79-
successCallback.onSuccess(status);
86+
googleApiAvailability.makeGooglePlayServicesAvailable(activity)
87+
.addOnFailureListener((Exception e) -> errorCallback.onError("GoogleApiAvailability.makeGooglePlayServicesAvailable", e.getMessage()))
88+
.addOnSuccessListener((Void t) -> successCallback.onSuccess());
8089
}
8190

82-
void getErrorString(Context applicationContext, getErrorStringCallback successCallback, ErrorCallback errorCallback){
83-
if (applicationContext == null){
84-
Log.d(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
91+
void getErrorString(Context applicationContext, getErrorStringCallback successCallback, ErrorCallback errorCallback) {
92+
if (applicationContext == null) {
93+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
8594
errorCallback.onError("GoogleApiAvailability.getErrorString", "Android context cannot be null.");
8695
return;
8796
}
@@ -91,9 +100,9 @@ void getErrorString(Context applicationContext, getErrorStringCallback successCa
91100
successCallback.onSuccess(errorString);
92101
}
93102

94-
void isUserResolvable(Context applicationContext, isUserResolvableCallback successCallback, ErrorCallback errorCallback){
95-
if (applicationContext == null){
96-
Log.d(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
103+
void isUserResolvable(Context applicationContext, isUserResolvableCallback successCallback, ErrorCallback errorCallback) {
104+
if (applicationContext == null) {
105+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
97106
errorCallback.onError("GoogleApiAvailability.isUserResolvable", "Android context cannot be null.");
98107
return;
99108
}
@@ -104,9 +113,9 @@ void isUserResolvable(Context applicationContext, isUserResolvableCallback succe
104113
successCallback.onSuccess(googleApiAvailability.isUserResolvableError(connectionResult));
105114
}
106115

107-
void showErrorNotification(Context applicationContext, showErrorNotificationCallback successCallback, ErrorCallback errorCallback){
108-
if (applicationContext == null){
109-
Log.d(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
116+
void showErrorNotification(Context applicationContext, showErrorNotificationCallback successCallback, ErrorCallback errorCallback) {
117+
if (applicationContext == null) {
118+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
110119
errorCallback.onError("GoogleApiAvailability.showErrorNotification", "Android context cannot be null.");
111120
return;
112121
}
@@ -116,20 +125,12 @@ void showErrorNotification(Context applicationContext, showErrorNotificationCall
116125

117126
googleApiAvailability.showErrorNotification(applicationContext, connectionResult);
118127

119-
if (connectionResult == GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED ||
120-
connectionResult == GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID ||
121-
connectionResult == GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING ||
122-
connectionResult == GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING ||
123-
connectionResult == GoogleApiAvailabilityConstants.GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED){
124-
successCallback.onSuccess(true);
125-
}
126-
127-
successCallback.onSuccess(false);
128+
successCallback.onSuccess(null);
128129
}
129130

130131
void showErrorDialogFragment(Context applicationContext, Activity activity, showErrorDialogFragmentCallback successCallback, ErrorCallback errorCallback) {
131132
if (applicationContext == null) {
132-
Log.d(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
133+
Log.e(GoogleApiAvailabilityConstants.LOG_TAG, "Context cannot be null.");
133134
errorCallback.onError("GoogleApiAvailability.showErrorDialogFragment", "Android context cannot be null.");
134135
return;
135136
}

coverage/lcov.info

Lines changed: 0 additions & 31 deletions
This file was deleted.

example/lib/main.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class MyApp extends StatefulWidget {
1818
class _MyAppState extends State<MyApp> {
1919
GooglePlayServicesAvailability _playStoreAvailability =
2020
GooglePlayServicesAvailability.unknown;
21-
bool _madeGooglePlayServiceAvailable = false;
2221
String _errorString = "unknown";
2322
bool _isUserResolvable = false;
2423
bool _errorNotificationShown = false;
@@ -48,22 +47,15 @@ class _MyAppState extends State<MyApp> {
4847
}
4948

5049
Future<void> makeGooglePlayServicesAvailable() async {
51-
bool madeGooglePlayServiceAvailable;
52-
5350
try {
54-
madeGooglePlayServiceAvailable = await GoogleApiAvailability.instance
55-
.makeGooglePlayServicesAvailable();
51+
await GoogleApiAvailability.instance.makeGooglePlayServicesAvailable();
5652
} on PlatformException {
57-
madeGooglePlayServiceAvailable = false;
53+
return;
5854
}
5955

6056
if (!mounted) {
6157
return;
6258
}
63-
64-
setState(() {
65-
_madeGooglePlayServiceAvailable = madeGooglePlayServiceAvailable;
66-
});
6759
}
6860

6961
Future<void> getErrorString() async {
@@ -169,12 +161,10 @@ class _MyAppState extends State<MyApp> {
169161
'Google Play Store status: ${_playStoreAvailability.toString().split('.').last}\n')),
170162
MaterialButton(
171163
onPressed: () => makeGooglePlayServicesAvailable(),
172-
child: const Text('Set Google Play Service to availabe'),
164+
child: const Text('Make Google Play Service availabe'),
173165
color: Colors.red,
174166
),
175-
Center(
176-
child: Text(
177-
'Made available: $_madeGooglePlayServiceAvailable\n')),
167+
const SizedBox(height: 30),
178168
MaterialButton(
179169
onPressed: () => getErrorString(),
180170
child: const Text('Get string of the error code'),

example/pubspec.lock

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)