Code Monkey home page Code Monkey logo

kontrol's Introduction

Kontrol

Maven Central badge badge

A Kotlin Multiplatform library for creating debug menu.

Setup

Add 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)
    }
}

Using the Library

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
    }

}

Important:

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()

SAMPLE

Click here

ENJOY!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.