Kontrol - a Kotlin Multiplatform library for creating a debugging menu.
Add a dependency to your build.gradle
val commonMain by getting {
dependencies {
implementation("io.github.chopyourbrain:kontrol:$kontrol_version")
}
}
Android setup:
class App : Application() {
override fun onCreate() {
super.onCreate()
kontrolAndroidInstall(applicationContext)
}
}
iOS setup (inside iosMain):
fun initIOS(navigationController: UINavigationController) {
kontrolIOSInstall(navigationController)
}
Ktor network inspection setup:
val httpClient = HttpClient(okhttp) {
install(KontrolKtorInterceptor) {
databaseDriverFactory = DatabaseDriverFactory(applicationContext)
}
}
Add dependency to your build.gradle
implementation("io.github.chopyourbrain:kontrol-android:$kontrol_version")
Add setup to your application:
class App : Application() {
override fun onCreate() {
super.onCreate()
kontrolAndroidInstall(applicationContext)
}
}
Okhttp inspection setup:
val client = OkHttpClient.Builder()
.addInterceptor(KontrolOkhttpInterceptor(DatabaseDriverFactory(applicationContext)))
.build()
Inside common code
Create your properties by DSL:
val properties = properties {
group("Network") {
switcher("Enable log", true) {
//Check listener
}
dropDown("Server", listOf("google.com", "amazon.com", "reddit.com"), "google.com") {
//Change listener
}
text("Default error", "Main Exception")
button("Send request") {
//Click listener
}
}
group("App") {
switcher("darkTheme", "Enable dark theme")
dropDown("version", "Version", listOf("1.0", "2.0", "3.0"))
text("Version code", "1.0")
button("Kill application") {
//Click listener
}
}
button("Clear cache") {
//Click listener
}
}
Implement key-value storage for saving switcher and dropDown state (if nessesary):
val kvStorage = object : KVStorage {
override fun getBoolean(key: String): Boolean? {
return settings.getBooleanOrNull(key)
}
override fun getString(key: String): String? {
return settings.getStringOrNull(key)
}
override fun setBoolean(key: String, value: Boolean) {
settings[key] = value
}
override fun setString(key: String, value: String) {
settings[key] = value
}
}
If you want to use KVStorage, create switchers and dropDowns by this:
switcher("KEY", "Description")
dropDown("KEY", "Description", listOf("First value", "Second value", "Third value"))
Then create DebugScreen object and use show()
for open screen:
val debugScreen = createDebugScreen(properties, kvStorage)
debugScreen.show()