From 1890fc233f281e2b17f920679f7ab5377b47e51a Mon Sep 17 00:00:00 2001 From: Pranav Pandey Date: Wed, 24 Jul 2024 18:24:19 +0530 Subject: [PATCH] Improve support for product flavors --- .../dynamic/util/DynamicLinkUtils.java | 41 +++++++++---------- .../android/dynamic/util/DynamicSdkUtils.java | 16 -------- .../dynamic/util/product/DynamicFlavor.java | 38 +++++++++++++++++ .../util/product/DynamicProductFlavor.java | 32 +++++++++++++++ 4 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicFlavor.java create mode 100644 dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicProductFlavor.java diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicLinkUtils.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicLinkUtils.java index fa0afa7..66a5016 100644 --- a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicLinkUtils.java +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicLinkUtils.java @@ -34,6 +34,8 @@ import androidx.core.content.ContextCompat; import androidx.core.net.MailTo; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; + import java.util.ArrayList; /** @@ -193,7 +195,7 @@ public static boolean copyToClipboard(@NonNull Context context, */ public static boolean share(@Nullable Context context, @Nullable String title, @Nullable String message, @Nullable Uri uri, @Nullable String mimeType, - @DynamicSdkUtils.DynamicFlavor String flavor) { + @DynamicFlavor String flavor) { if (context == null) { return false; } @@ -208,7 +210,7 @@ public static boolean share(@Nullable Context context, @Nullable String title, } if (message == null) { - if (DynamicSdkUtils.DynamicFlavor.EXTERNAL.equals(flavor) + if (DynamicFlavor.EXTERNAL.equals(flavor) && DynamicDeviceUtils.isSamsungOneUI()) { message = String.format(context.getString( R.string.adu_share_desc_samsung_galaxy_store), @@ -256,9 +258,8 @@ public static boolean share(@Nullable Context context, @Nullable String title, * * @see Intent#ACTION_SEND */ - public static boolean share(@Nullable Context context, - @Nullable String title, @Nullable String message, @Nullable Uri image, - @DynamicSdkUtils.DynamicFlavor String flavor) { + public static boolean share(@Nullable Context context, @Nullable String title, + @Nullable String message, @Nullable Uri image, @DynamicFlavor String flavor) { return share(context, title, message, image, "image/*", flavor); } @@ -278,7 +279,7 @@ public static boolean share(@Nullable Context context, */ public static boolean share(@Nullable Context context, @Nullable String title, @Nullable String message, @Nullable Uri image) { - return share(context, title, message, image, DynamicSdkUtils.DynamicFlavor.GOOGLE); + return share(context, title, message, image, DynamicFlavor.DEFAULT); } /** @@ -296,7 +297,7 @@ public static boolean share(@Nullable Context context, @Nullable String title, * @see Intent#ACTION_SEND */ public static boolean share(@Nullable Context context, @Nullable String title, - @Nullable String message, @DynamicSdkUtils.DynamicFlavor String flavor) { + @Nullable String message, @DynamicFlavor String flavor) { return share(context, title, message, null, flavor); } @@ -315,7 +316,7 @@ public static boolean share(@Nullable Context context, @Nullable String title, */ public static boolean share(@Nullable Context context, @Nullable String title, @Nullable String message) { - return share(context, title, message, DynamicSdkUtils.DynamicFlavor.GOOGLE); + return share(context, title, message, DynamicFlavor.DEFAULT); } /** @@ -329,8 +330,7 @@ public static boolean share(@Nullable Context context, * * @see #share(Context, String, String) */ - public static boolean shareApp(@Nullable Context context, - @DynamicSdkUtils.DynamicFlavor String flavor) { + public static boolean shareApp(@Nullable Context context, @DynamicFlavor String flavor) { return share(context, null, null, flavor); } @@ -345,7 +345,7 @@ public static boolean shareApp(@Nullable Context context, * @see #share(Context, String, String) */ public static boolean shareApp(@Nullable Context context) { - return shareApp(context, DynamicSdkUtils.DynamicFlavor.GOOGLE); + return shareApp(context, DynamicFlavor.DEFAULT); } /** @@ -425,11 +425,11 @@ public static boolean viewInSamsungGalaxyStore(@Nullable Context context, * * @see #viewInGooglePlay(Context, String) * @see #viewInSamsungGalaxyStore(Context, String) - * @see DynamicSdkUtils.DynamicFlavor + * @see DynamicFlavor */ - public static boolean viewApp(@Nullable Context context, @NonNull String packageName, - @DynamicSdkUtils.DynamicFlavor String flavor) { - if (DynamicSdkUtils.DynamicFlavor.EXTERNAL.equals(flavor)) { + public static boolean viewApp(@Nullable Context context, + @NonNull String packageName, @DynamicFlavor String flavor) { + if (DynamicFlavor.EXTERNAL.equals(flavor)) { return viewAppExternal(context, packageName); } else if (context == null) { return false; @@ -456,10 +456,10 @@ public static boolean viewApp(@Nullable Context context, @NonNull String package * @return {@code true} on successful operation. * * @see #viewApp(Context, String, String) - * @see DynamicSdkUtils.DynamicFlavor#GOOGLE + * @see DynamicFlavor#GOOGLE */ public static boolean viewApp(@Nullable Context context, @NonNull String packageName) { - return viewApp(context, packageName, DynamicSdkUtils.DynamicFlavor.GOOGLE); + return viewApp(context, packageName, DynamicFlavor.DEFAULT); } /** @@ -503,10 +503,9 @@ && viewInSamsungGalaxyStore(context, packageName)) { * @return {@code true} on successful operation. * * @see #viewApp(Context, String, String) - * @see DynamicSdkUtils.DynamicFlavor + * @see DynamicFlavor */ - public static boolean rateApp(@Nullable Context context, - @DynamicSdkUtils.DynamicFlavor String flavor) { + public static boolean rateApp(@Nullable Context context, @DynamicFlavor String flavor) { if (context == null) { return false; } @@ -527,7 +526,7 @@ public static boolean rateApp(@Nullable Context context, * @see #rateApp(Context, String) */ public static boolean rateApp(@Nullable Context context) { - return rateApp(context, DynamicSdkUtils.DynamicFlavor.GOOGLE); + return rateApp(context, DynamicFlavor.DEFAULT); } /** diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicSdkUtils.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicSdkUtils.java index 1422ec8..15780a2 100644 --- a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicSdkUtils.java +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/DynamicSdkUtils.java @@ -28,22 +28,6 @@ @TargetApi(Build.VERSION_CODES.M) public class DynamicSdkUtils { - /** - * Product flavors to support external app stores. - */ - public @interface DynamicFlavor { - - /** - * Constant for the Google Play Store. - */ - String GOOGLE = "google"; - - /** - * Constant for the external app store. - */ - String EXTERNAL = "external"; - } - /** * Detects if the current API version is a preview. * diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicFlavor.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicFlavor.java new file mode 100644 index 0000000..2bb7300 --- /dev/null +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicFlavor.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017-2024 Pranav Pandey + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.pranavpandey.android.dynamic.util.product; + +/** + * Product flavors to support external app stores. + */ +public @interface DynamicFlavor { + + /** + * Constant for the Google Play Store. + */ + String GOOGLE = "google"; + + /** + * Constant for the external app store. + */ + String EXTERNAL = "external"; + + /** + * Constant for the default flavor. + */ + String DEFAULT = GOOGLE; +} diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicProductFlavor.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicProductFlavor.java new file mode 100644 index 0000000..cbf8bbf --- /dev/null +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/util/product/DynamicProductFlavor.java @@ -0,0 +1,32 @@ +/* + * Copyright 2017-2024 Pranav Pandey + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.pranavpandey.android.dynamic.util.product; + +/** + * An interface to provide product flavors. + */ +public interface DynamicProductFlavor { + + /** + * This method will be called to get the build flavor. + *

It can be used to perform specific operations like supporting deeplink for + * third-party app stores. + * + * @return The build flavor. + */ + @DynamicFlavor String getProductFlavor(); +}