Class HelperKt

  • All Implemented Interfaces:

    
    public final class HelperKt
    
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final static Unit setPreference(Context context, String key, String value) Save a string preference in shared preferences.
      final static Unit setPreference(Context context, String key, Object value) Save an object preference in shared preferences.
      final static String getPreference(Context context, String key) Retrieve a string preference from shared preferences.
      final static String getPreference(Context context, String key, String defaultValue) Retrieve a string preference from shared preferences with a default value.
      final static String getDeviceId(Context context) Create or retrive the device ID from shared preferences.
      final static Unit setDeviceId(Context context, String deviceId) Set the device ID manually in shared preferences.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • setPreference

         final static Unit setPreference(Context context, String key, String value)

        Save a string preference in shared preferences.

        Parameters:
        context - The context from which to access shared preferences
        key - The key for the preference
        value - The value to set
      • setPreference

         final static Unit setPreference(Context context, String key, Object value)

        Save an object preference in shared preferences. The value should be serializable using Kotlin serialization.

        Parameters:
        context - The context from which to access shared preferences
        key - The key for the preference
      • getPreference

         final static String getPreference(Context context, String key)

        Retrieve a string preference from shared preferences.

        Parameters:
        context - The context from which to access shared preferences
        key - The key for the preference
        Returns:

        The value of the preference, or null if not found

      • getPreference

         final static String getPreference(Context context, String key, String defaultValue)

        Retrieve a string preference from shared preferences with a default value.

        Parameters:
        context - The context from which to access shared preferences
        key - The key for the preference
        defaultValue - The default value to return if the preference is not found
        Returns:

        The value of the preference, or the default value if not found

      • getDeviceId

         final static String getDeviceId(Context context)

        Create or retrive the device ID from shared preferences. If it doesn't exist, it generates a new UUID and saves it.

        Parameters:
        context - The context from which to access shared preferences
        Returns:

        The device ID as a string

      • setDeviceId

         final static Unit setDeviceId(Context context, String deviceId)

        Set the device ID manually in shared preferences.

        Parameters:
        context - The context from which to access shared preferences
        deviceId - The device ID to set