Skip to content

Commit

Permalink
Improve support for product flavors
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Jul 24, 2024
1 parent 6fa12b6 commit 1890fc2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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),
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

/**
Expand All @@ -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);
}

Expand All @@ -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);
}

/**
Expand All @@ -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);
}

Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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.
* <p>It can be used to perform specific operations like supporting deeplink for
* third-party app stores.
*
* @return The build flavor.
*/
@DynamicFlavor String getProductFlavor();
}

0 comments on commit 1890fc2

Please sign in to comment.