-
public final class CTXtensions
-
-
Field Summary
Fields Modifier and Type Field Description private final static IntegertargetSdkVersion
-
Method Summary
Modifier and Type Method Description final IntegergetTargetSdkVersion()final static BooleanisPackageAndOsTargetsAbove(Context $self, Integer apiLevel)final static BooleanisNotificationChannelEnabled(Context $self, String channelId)final static BooleanareAppNotificationsEnabled(Context $self)final static StringgetOrCreateChannel(NotificationManager $self, String msgChannel, Context context)Retrieves or creates the notification channel based on the given channel ID. final static UnitflushPushImpressionsOnPostAsyncSafely(CleverTapAPI $self, String logTag, String caller, Context context)Flushes push notification impressions on the CleverTap instance in blocking fashion on a postAsyncSafely executor. final static BooleanisInvalidIndex(JSONArray $self, Integer index)Checks whether the given index is a valid index within the JSONArray. final static BooleanhasData(SharedPreferences $self)Extension function to check if a SharedPreferences file has data. final static JSONArrayorEmptyArray(JSONArray $self)Returns the original JSONArray if not null, or an empty JSONArray if the original is null. final static <T extends Any> List<T>toList(JSONArray $self)Converts a JSONArray to a List of elements of type T. final static <T extends Any> Unititerator(JSONArray $self, Function1<T, Unit> foreach)Iterates over the elements of the JSONArray of type T. final static Pair<Boolean, JSONArray>safeGetJSONArrayOrNullIfEmpty(JSONObject $self, String key)Safely retrieves a JSONArray from the JSONObject using the specified key. final static Pair<Boolean, JSONArray>safeGetJSONArray(JSONObject $self, String key)Safely retrieves a JSONArray from the JSONObject using the specified key. final static UnitcopyFrom(JSONObject $self, JSONObject other)Copies all key-value pairs from the specified other JSONObject to this JSONObject. final static JSONObjectcopy(JSONObject $self)Copies all key-value pairs from this JSONObject to a new JSONObject. final static BooleanisNotNullAndEmpty(JSONObject $self)Checks if the JSONObject is not null and has at least one key-value pair. final static StringconcatIfNotNull(String $self, String other, String separator)Concatenates this String with another String if it is not null. final static BooleanisValid(Location $self)Checks if the Location is valid, i.e. final static JSONObjecttoJsonOrNull(String $self)final static BooleanisNotNullAndBlank(String $self)final static UnitapplyInsetsWithMarginAdjustment(View $self, Function2<Insets, ViewGroup.MarginLayoutParams, Unit> marginAdjuster)Adjusts the margins of the view based on the system bar insets (such as the status bar, navigation bar, or display cutout) using the provided margin adjustment logic. -
-
Method Detail
-
getTargetSdkVersion
final Integer getTargetSdkVersion()
-
isPackageAndOsTargetsAbove
final static Boolean isPackageAndOsTargetsAbove(Context $self, Integer apiLevel)
-
isNotificationChannelEnabled
final static Boolean isNotificationChannelEnabled(Context $self, String channelId)
-
areAppNotificationsEnabled
final static Boolean areAppNotificationsEnabled(Context $self)
-
getOrCreateChannel
final static String getOrCreateChannel(NotificationManager $self, String msgChannel, Context context)
Retrieves or creates the notification channel based on the given channel ID. If the given channel ID is not registered, it falls back to the manifest channel ID. If the manifest channel ID is not registered or not available, it creates and returns the default channel ID.
- Parameters:
msgChannel- The channel ID received in the push payload.context- The context of the application.
-
flushPushImpressionsOnPostAsyncSafely
final static Unit flushPushImpressionsOnPostAsyncSafely(CleverTapAPI $self, String logTag, String caller, Context context)
Flushes push notification impressions on the CleverTap instance in blocking fashion on a postAsyncSafely executor. postAsyncSafely executor will make sure that multiple flush operations occur in sequence.
- Parameters:
logTag- is tag name to identify the task state in logscaller- The caller.context- The application context.
-
isInvalidIndex
final static Boolean isInvalidIndex(JSONArray $self, Integer index)
Checks whether the given index is a valid index within the JSONArray.
- Parameters:
index- The index to be checked.
-
hasData
final static Boolean hasData(SharedPreferences $self)
Extension function to check if a SharedPreferences file has data.
-
orEmptyArray
final static JSONArray orEmptyArray(JSONArray $self)
Returns the original JSONArray if not null, or an empty JSONArray if the original is null.
-
toList
final static <T extends Any> List<T> toList(JSONArray $self)
Converts a JSONArray to a List of elements of type T.
-
iterator
final static <T extends Any> Unit iterator(JSONArray $self, Function1<T, Unit> foreach)
Iterates over the elements of the JSONArray of type T.
- Parameters:
foreach- Lambda function to be executed for each element of type T.
-
safeGetJSONArrayOrNullIfEmpty
final static Pair<Boolean, JSONArray> safeGetJSONArrayOrNullIfEmpty(JSONObject $self, String key)
Safely retrieves a JSONArray from the JSONObject using the specified key.
- Parameters:
key- The key to retrieve the JSONArray.
-
safeGetJSONArray
final static Pair<Boolean, JSONArray> safeGetJSONArray(JSONObject $self, String key)
Safely retrieves a JSONArray from the JSONObject using the specified key.
- Parameters:
key- The key to retrieve the JSONArray.
-
copyFrom
final static Unit copyFrom(JSONObject $self, JSONObject other)
Copies all key-value pairs from the specified other JSONObject to this JSONObject.
- Parameters:
other- The JSONObject to copy key-value pairs from.
-
copy
final static JSONObject copy(JSONObject $self)
Copies all key-value pairs from this JSONObject to a new JSONObject.
-
isNotNullAndEmpty
final static Boolean isNotNullAndEmpty(JSONObject $self)
Checks if the JSONObject is not null and has at least one key-value pair.
-
concatIfNotNull
final static String concatIfNotNull(String $self, String other, String separator)
Concatenates this String with another String if it is not null.
This extension function checks if both the receiver String (denoted by 'this') and the other String are not null. If both Strings are not null, they are concatenated using the specified separator. If either String is null, it returns the non-null String, or null if both are null.
- Parameters:
other- The String to concatenate with the receiver String.separator- The separator between the two Strings (default is an empty string).
-
isValid
final static Boolean isValid(Location $self)
Checks if the Location is valid, i.e., latitude is in the range -90.0, 90.0 and longitude is in the range -180.0, 180.0.
-
toJsonOrNull
final static JSONObject toJsonOrNull(String $self)
-
isNotNullAndBlank
final static Boolean isNotNullAndBlank(String $self)
-
applyInsetsWithMarginAdjustment
final static Unit applyInsetsWithMarginAdjustment(View $self, Function2<Insets, ViewGroup.MarginLayoutParams, Unit> marginAdjuster)
Adjusts the margins of the view based on the system bar insets (such as the status bar, navigation bar, or display cutout) using the provided margin adjustment logic.
This function sets a listener on the view to handle window insets and invokes the provided
marginAdjusterblock to allow custom margin adjustments. ThemarginAdjusterlambda receives the system bar insets and the view's margin layout parameters, allowing the caller to modify the margins as needed.- Parameters:
marginAdjuster- A lambda function that takes two parameters:bars: The insets for system bars and display cutouts, representing the space occupied by UI elements such as the status bar or navigation bar.mlp: TheMarginLayoutParamsof the view, which can be modified to adjust the margins based on the insets.
view.applyInsetsWithMarginAdjustment { insets, layoutParams -> layoutParams.leftMargin = insets.left layoutParams.rightMargin = insets.right layoutParams.topMargin = insets.top layoutParams.bottomMargin = insets.bottom }
-
-
-
-