KMULE is a comprehensive, open-source library designed to enhance the Kotlin Multiplatform development experience. It provides a wide range of tools and utilities that simplify common programming tasks, fostering cross-platform consistency and code reusability.
To configure your Kotlin Multiplatform project to use the KMULE library, follow these steps:
- Create a new Kotlin Multiplatform project or open an existing one.
- Ensure that your project is set up to use Gradle.
To add Kmule
to your project, follow:
- Open the
build.gradle.kts
file (orbuild.gradle
if you are using groovy) of your project. - Add the Sonatype repository on your project:
repositories { mavenCentral() maven { url = "https://s01.oss.sonatype.org/content/repositories/releases/" } }
- Add the dependency on the commonMain dependecies of your project:
sourceSets {
commonMain.dependencies {
implementation("digital.thon:kmule:<KMULE_VERSION>")
}
}
Currently, the KMULE library offers several useful functions that can be used directly in
the commonMain
module. These functions include:
openSpotify(showId: String?)
: Opens Spotify and directs to the specific show. If the showId is null, the Spotify app will open on the home screen.openYoutube(youtubeChannel: String?)
: Opens YouTube and directs to the specified channel. If the channel is null, the YouTube app will open on the home screen.openInstagram(instagramProfile: String?)
: Opens Instagram and directs to the specified profile. If the profile is null, the Instagram app will open on the home screen.openCallApp(phoneNumber: String?)
: Opens Twitter and directs to the specified profile. If the profile is null, the Twitter app will open with empty prompt.openWebPage(url: String)
: Opens a web page in the default browser.openEmailApp(email: String?)
: Opens the email app with the specified email address. If the email is null, the email app will open with an empty prompt.openWhatsApp(phoneNumber: String?)
: Opens WhatsApp and directs to the specified phone number. If the phone number is null, the WhatsApp app will open on the home screen.openMaps(latitude: Double?, longitude: Double?,label: String?)
: Opens the maps app and directs to the specified latitude and longitude. If the latitude and longitude are null, the maps app will open on the home screen. label can be used to specify the label of the location and is optional.openSettings()
: Opens the settings app.
Each implementation of these functions is optimized to work natively on different platforms. For
example, on Android, these functions use Intent
to open the corresponding apps, while on iOS, they
will try to open the apps directly.
This approach ensures a consistent and integrated user experience across all platforms supported by the KMULE library (Android,IOS).
Here is a basic example of how to use the KMULE library in your project:
import Kmule.openInstagramProfile
import Kmule.openSpotify
import Kmule.openYouTubeChannel
object NavigationHelper {
fun getNavigationItems(): List<ClickableMenuItem> =
listOf(
ClickableMenuItem(
screen =
ExternalScreen {
openSpotify(SPOTIFY_SHOW_ID)
},
resourceId = "podcast.png",
name = "Podcast"
),
ClickableMenuItem(
screen =
ExternalScreen {
openYouTubeChannel(YOUTUBE_CHANNEL_ID)
},
resourceId = "youtube.png",
name = "Youtube"
),
ClickableMenuItem(
screen =
ExternalScreen {
openInstagramProfile(INSTAGRAM_PROFILE_ID)
},
resourceId = "instagram.png",
name = "Instagram"
),
)
}
These are currently the features supported by KMULE, new ones coming soon.
To ensure that the KMULE library works correctly in an Android app, you need to initialize it in
the onCreate
method
of the Application
class. Add the following code to your Application
class:
class App : Application() {
companion object {
lateinit var appContext: Context
}
override fun onCreate() {
super.onCreate()
// Application context configuration and KMULE initialization
appContext = applicationContext
startKmule { appContext }
}
}
This configuration ensures that the KMULE library has access to the application context when necessary.
Don't forget to add the following lines to your Info.plist
file to ensure that the KMULE library
works correctly on iOS:
<key>LSApplicationQueriesSchemes</key><array>
<string>youtube</string>
<string>spotify</string>
<string>instagram</string>
<string>whatsapp</string>
</array>