Skip to content

Latest commit

 

History

History
237 lines (170 loc) · 8.13 KB

SessionManager.md

File metadata and controls

237 lines (170 loc) · 8.13 KB

SessionManager

This API allows the user to manage the content displayed in base of the current scenario occurred

Implementation guide

To use the SessionManager API you have to follow this guide for a correct implementation

Creation of a viewmodel

To manage the scenarios available with the SessionManager you can create the logic in a routine of an EquinoxViewModel

class TestViewModel : EquinoxViewModel() {

    fun refreshRoutine() {
        execRefreshingRoutine(
            currentContext = Test::class.java,
            routine = {

                // your refresh routine

                // your logic to determine if the server is offline 
                val isServerOffline = boolean_value
                // then set that result with the below method
                SessionManager.setServerOfflineValue(isServerOffline)

                // your logic to determine if the user has been disconnected
                val hasBeenDisconnected = boolean_value
                // then set that result with the below method
                SessionManager.setHasBeenDisconnectedValue(hasBeenDisconnected)
            }
        )
    }

}

Set up the session

Mobile

  • In the AndroidManifest file you must declare the Internet permission:

    <uses-permission android:name="android.permission.INTERNET"/>
  • For one time only, using for example a custom SplashScreen, properly set up the session:

    @SuppressLint("CustomSplashScreen")
    class SplashScreen : ComponentActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            // enable the StrictMode
            val policy = ThreadPolicy.Builder().permitAll().build()
            StrictMode.setThreadPolicy(policy)
    
            setContent {
    
                // set up and customize the session 
                SessionManager.setUpSession(
                    serverOfflineMessage = "server_currently_offline_message",
                    serverOfflineMessageIcon = /* you can customize the icon if needed */
                    noInternetConnectionMessage = "no_internet_message",
                    noInternetConnectionIcon = ImageVector.vectorResource(id = R.drawable.no_internet),
                    hasBeenDisconnectedAction = {
                        // the action to execute when the user has been disconnected
                    }
                )
                
                // ... rest of the application
    
            }
        }
    
    }

    To use the no_internet drawable given by the library you have to download it and place in the drawable folder of your android application

    res
     |-- drawable
         |-- no_internet.xml

    You can download it here

  • Use the SessionManager API

     class Test {
         
          private val viewModel = TestViewModel()
    
          init {
              viewModel.setActiveContext(this::class.java)
              viewModel.refreshingRoutine()
          }
    
          @Composable
          fun Screen() {
    
              // invoke this method to use the SessionManager API automatically
              ManagedContent(
                  viewModel = viewModel,
                  content = {
                      // the normal content to display
                  }
              )
          }
     
    }        
    Appearance (the theme is relative) no_internet server_offline

Desktop & Web/Jvm

  • In the build.gradle.kts file you have to implement the kotlinx-coroutines-swing library:

    desktopMain.dependencies {      
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.8.1")
    }
  • For one time only, placing for example the code in the Main.kt file, properly set up the session:

    fun main() = application {
        Window(
            onCloseRequest = ::exitApplication,
            title = "app_name"
        ) {
    
            // set up the session with the default values 
            SessionManager.setUpSession()
    
            // or
    
            // set up and customize the session 
            SessionManager.setUpSession(
                serverOfflineMessage = "server_currently_offline_message",
                serverOfflineMessageIcon = /* you can customize the icon if needed */
                noInternetConnectionMessage = "no_internet_message",
                noInternetConnectionIcon = /* you can customize the icon if needed */,
                hasBeenDisconnectedAction = {
                    // the action to execute when the user has been disconnected
                }
            )
    
            // then invoke the App method to launch the application
            App()
        }
    }
  • Use the SessionManager API

     class Test {
         
          private val viewModel = TestViewModel()
    
          init {
              viewModel.setActiveContext(this::class.java)
              viewModel.refreshingRoutine()
          }
    
          @Composable
          fun Screen() {
    
              // invoke this method to use the SessionManager API automatically
              ManagedContent(
                  viewModel = viewModel,
                  content = {
                      // the normal content to display
                  }
              )
          }
     
    }        
    Appearance (the theme is relative) no_internet server_offline

Support

If you need help using the library or encounter any problems or bugs, please contact us via the following links:

Thank you for your help!

Badges

Twitter

Donations

If you want support project and developer

Crypto Address Network
3H3jyCzcRmnxroHthuXh22GXXSmizin2yp Bitcoin
0x1b45bc41efeb3ed655b078f95086f25fc83345c4 Ethereum
AtPjUnxYFHw3a6Si9HinQtyPTqsdbfdKX3dJ1xiDjbrL Solana

If you want support project and developer with PayPal

Copyright © 2025 Tecknobit