Skip to content

Commit 1890fc2

Browse files
committed
Improve support for product flavors
1 parent 6fa12b6 commit 1890fc2

File tree

4 files changed

+90
-37
lines changed

4 files changed

+90
-37
lines changed

dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicLinkUtils.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import androidx.core.content.ContextCompat;
3535
import androidx.core.net.MailTo;
3636

37+
import com.pranavpandey.android.dynamic.util.product.DynamicFlavor;
38+
3739
import java.util.ArrayList;
3840

3941
/**
@@ -193,7 +195,7 @@ public static boolean copyToClipboard(@NonNull Context context,
193195
*/
194196
public static boolean share(@Nullable Context context, @Nullable String title,
195197
@Nullable String message, @Nullable Uri uri, @Nullable String mimeType,
196-
@DynamicSdkUtils.DynamicFlavor String flavor) {
198+
@DynamicFlavor String flavor) {
197199
if (context == null) {
198200
return false;
199201
}
@@ -208,7 +210,7 @@ public static boolean share(@Nullable Context context, @Nullable String title,
208210
}
209211

210212
if (message == null) {
211-
if (DynamicSdkUtils.DynamicFlavor.EXTERNAL.equals(flavor)
213+
if (DynamicFlavor.EXTERNAL.equals(flavor)
212214
&& DynamicDeviceUtils.isSamsungOneUI()) {
213215
message = String.format(context.getString(
214216
R.string.adu_share_desc_samsung_galaxy_store),
@@ -256,9 +258,8 @@ public static boolean share(@Nullable Context context, @Nullable String title,
256258
*
257259
* @see Intent#ACTION_SEND
258260
*/
259-
public static boolean share(@Nullable Context context,
260-
@Nullable String title, @Nullable String message, @Nullable Uri image,
261-
@DynamicSdkUtils.DynamicFlavor String flavor) {
261+
public static boolean share(@Nullable Context context, @Nullable String title,
262+
@Nullable String message, @Nullable Uri image, @DynamicFlavor String flavor) {
262263
return share(context, title, message, image, "image/*", flavor);
263264
}
264265

@@ -278,7 +279,7 @@ public static boolean share(@Nullable Context context,
278279
*/
279280
public static boolean share(@Nullable Context context, @Nullable String title,
280281
@Nullable String message, @Nullable Uri image) {
281-
return share(context, title, message, image, DynamicSdkUtils.DynamicFlavor.GOOGLE);
282+
return share(context, title, message, image, DynamicFlavor.DEFAULT);
282283
}
283284

284285
/**
@@ -296,7 +297,7 @@ public static boolean share(@Nullable Context context, @Nullable String title,
296297
* @see Intent#ACTION_SEND
297298
*/
298299
public static boolean share(@Nullable Context context, @Nullable String title,
299-
@Nullable String message, @DynamicSdkUtils.DynamicFlavor String flavor) {
300+
@Nullable String message, @DynamicFlavor String flavor) {
300301
return share(context, title, message, null, flavor);
301302
}
302303

@@ -315,7 +316,7 @@ public static boolean share(@Nullable Context context, @Nullable String title,
315316
*/
316317
public static boolean share(@Nullable Context context,
317318
@Nullable String title, @Nullable String message) {
318-
return share(context, title, message, DynamicSdkUtils.DynamicFlavor.GOOGLE);
319+
return share(context, title, message, DynamicFlavor.DEFAULT);
319320
}
320321

321322
/**
@@ -329,8 +330,7 @@ public static boolean share(@Nullable Context context,
329330
*
330331
* @see #share(Context, String, String)
331332
*/
332-
public static boolean shareApp(@Nullable Context context,
333-
@DynamicSdkUtils.DynamicFlavor String flavor) {
333+
public static boolean shareApp(@Nullable Context context, @DynamicFlavor String flavor) {
334334
return share(context, null, null, flavor);
335335
}
336336

@@ -345,7 +345,7 @@ public static boolean shareApp(@Nullable Context context,
345345
* @see #share(Context, String, String)
346346
*/
347347
public static boolean shareApp(@Nullable Context context) {
348-
return shareApp(context, DynamicSdkUtils.DynamicFlavor.GOOGLE);
348+
return shareApp(context, DynamicFlavor.DEFAULT);
349349
}
350350

351351
/**
@@ -425,11 +425,11 @@ public static boolean viewInSamsungGalaxyStore(@Nullable Context context,
425425
*
426426
* @see #viewInGooglePlay(Context, String)
427427
* @see #viewInSamsungGalaxyStore(Context, String)
428-
* @see DynamicSdkUtils.DynamicFlavor
428+
* @see DynamicFlavor
429429
*/
430-
public static boolean viewApp(@Nullable Context context, @NonNull String packageName,
431-
@DynamicSdkUtils.DynamicFlavor String flavor) {
432-
if (DynamicSdkUtils.DynamicFlavor.EXTERNAL.equals(flavor)) {
430+
public static boolean viewApp(@Nullable Context context,
431+
@NonNull String packageName, @DynamicFlavor String flavor) {
432+
if (DynamicFlavor.EXTERNAL.equals(flavor)) {
433433
return viewAppExternal(context, packageName);
434434
} else if (context == null) {
435435
return false;
@@ -456,10 +456,10 @@ public static boolean viewApp(@Nullable Context context, @NonNull String package
456456
* @return {@code true} on successful operation.
457457
*
458458
* @see #viewApp(Context, String, String)
459-
* @see DynamicSdkUtils.DynamicFlavor#GOOGLE
459+
* @see DynamicFlavor#GOOGLE
460460
*/
461461
public static boolean viewApp(@Nullable Context context, @NonNull String packageName) {
462-
return viewApp(context, packageName, DynamicSdkUtils.DynamicFlavor.GOOGLE);
462+
return viewApp(context, packageName, DynamicFlavor.DEFAULT);
463463
}
464464

465465
/**
@@ -503,10 +503,9 @@ && viewInSamsungGalaxyStore(context, packageName)) {
503503
* @return {@code true} on successful operation.
504504
*
505505
* @see #viewApp(Context, String, String)
506-
* @see DynamicSdkUtils.DynamicFlavor
506+
* @see DynamicFlavor
507507
*/
508-
public static boolean rateApp(@Nullable Context context,
509-
@DynamicSdkUtils.DynamicFlavor String flavor) {
508+
public static boolean rateApp(@Nullable Context context, @DynamicFlavor String flavor) {
510509
if (context == null) {
511510
return false;
512511
}
@@ -527,7 +526,7 @@ public static boolean rateApp(@Nullable Context context,
527526
* @see #rateApp(Context, String)
528527
*/
529528
public static boolean rateApp(@Nullable Context context) {
530-
return rateApp(context, DynamicSdkUtils.DynamicFlavor.GOOGLE);
529+
return rateApp(context, DynamicFlavor.DEFAULT);
531530
}
532531

533532
/**

dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicSdkUtils.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@
2828
@TargetApi(Build.VERSION_CODES.M)
2929
public class DynamicSdkUtils {
3030

31-
/**
32-
* Product flavors to support external app stores.
33-
*/
34-
public @interface DynamicFlavor {
35-
36-
/**
37-
* Constant for the Google Play Store.
38-
*/
39-
String GOOGLE = "google";
40-
41-
/**
42-
* Constant for the external app store.
43-
*/
44-
String EXTERNAL = "external";
45-
}
46-
4731
/**
4832
* Detects if the current API version is a preview.
4933
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2017-2024 Pranav Pandey
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.pranavpandey.android.dynamic.util.product;
18+
19+
/**
20+
* Product flavors to support external app stores.
21+
*/
22+
public @interface DynamicFlavor {
23+
24+
/**
25+
* Constant for the Google Play Store.
26+
*/
27+
String GOOGLE = "google";
28+
29+
/**
30+
* Constant for the external app store.
31+
*/
32+
String EXTERNAL = "external";
33+
34+
/**
35+
* Constant for the default flavor.
36+
*/
37+
String DEFAULT = GOOGLE;
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2017-2024 Pranav Pandey
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.pranavpandey.android.dynamic.util.product;
18+
19+
/**
20+
* An interface to provide product flavors.
21+
*/
22+
public interface DynamicProductFlavor {
23+
24+
/**
25+
* This method will be called to get the build flavor.
26+
* <p>It can be used to perform specific operations like supporting deeplink for
27+
* third-party app stores.
28+
*
29+
* @return The build flavor.
30+
*/
31+
@DynamicFlavor String getProductFlavor();
32+
}

0 commit comments

Comments
 (0)