B4J Question [BANano] [SOLVED] Can I use AssetsLoadWait in a b4xlib?

Mashiane

Expert
Licensed User
Longtime User
Ola

Is it possible to use this kind of code inside a lib or should I use this inside the user project?

In AppStart

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    'initialize banano for first use
    BANano.Initialize("BANano", AppName, DateTime.now)
    BANano.Header.Title = AppName
    'online installation
    'BANano.Header.AddCSSFile("https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900")
    'BANano.Header.AddCSSFile("https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css")
    'BANano.Header.AddCSSFile("https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css")
    'BANano.Header.AddJavascriptFile("https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.min.js")
    'BANano.Header.AddJavascriptFile("https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.js")
    'BANano.Header.AddJavascriptFile("https://cdn.jsdelivr.net/npm/vue-router@3.4.7/dist/vue-router.min.js")
    'BANano.Header.AddJavascriptFile("https://cdn.jsdelivr.net/npm/dayjs@1.9.4/dayjs.min.js")
    'BANano.Header.AddJavascriptFile("https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js")
    '
    'load assets for later
    BANano.Header.AddCSSFileForLater("https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900")
    BANano.Header.AddCSSFileForLater("https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css")
    BANano.Header.AddCSSFileForLater("https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css")
    BANano.Header.AddJavascriptFileForLater("https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.min.js")
    BANano.Header.AddJavascriptFileForLater("https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.js")
    BANano.Header.AddJavascriptFileForLater("https://cdn.jsdelivr.net/npm/vue-router@3.4.7/dist/vue-router.min.js")
    BANano.Header.AddJavascriptFileForLater("https://cdn.jsdelivr.net/npm/dayjs@1.9.4/dayjs.min.js")
    BANano.Header.AddJavascriptFileForLater("https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js")
    
    ' start the build
    #if release
        BANano.BuildAsB4Xlib(Version)
    #else
        BANano.Build(File.DirApp)
    #end if
    ExitApplication
End Sub

In BANano_Ready

B4X:
Sub BANano_Ready
    Dim pathsNotFound() As String
    If BANano.AssetsIsDefined("Loader") = False Then
        'define the resources to be loaded
        Dim resources As List
        resources.Initialize
        resources.add("https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900")
        resources.add("https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css")
        resources.add("https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css")
        resources.add("https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.min.js")
        resources.add("https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.js")
        resources.add("https://cdn.jsdelivr.net/npm/vue-router@3.4.7/dist/vue-router.min.js")
        resources.add("https://cdn.jsdelivr.net/npm/dayjs@1.9.4/dayjs.min.js")
        resources.add("https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js")
        'load the assets
        pathsNotFound = BANano.AssetsLoadWait("Loader", resources)
        If BANano.IsNull(pathsNotFound) = False Then
            Log("Doh! Loader has not been loaded completely!")
            For Each path As String In pathsNotFound
                Log(path)
            Next
        Else
            Log("Loader has been loaded!")
        End If
    End If
End Sub

Thanks
 
Top