Package 

Class CTXtensions

    • Method Detail

      • 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 logs
        caller - 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.
      • 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.
      • 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.

      • 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.

      • 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 marginAdjuster block to allow custom margin adjustments. The marginAdjuster lambda 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: The MarginLayoutParams of the view, which can be modified to adjust the margins based on the insets.

        Example usage:
        view.applyInsetsWithMarginAdjustment { insets, layoutParams ->
            layoutParams.leftMargin = insets.left
            layoutParams.rightMargin = insets.right
            layoutParams.topMargin = insets.top
            layoutParams.bottomMargin = insets.bottom
        }