Netdex / android-usb-script

An Android app that allows you to script USB gadgets (work-in-progress).
MIT License
34 stars 12 forks source link

Adding a selection dialog #21

Open C-512L opened 3 weeks ago

C-512L commented 3 weeks ago

I am writting a Multi-ISO boot script and one thing I found missing is the ability to call from lua to open a selection dialog with options passed by lua. The code i conceptualize in lua could look something like this:

...
-- a, b and c would be an integer representing the selected option in the array or nil
local a,b,c = select {
  message = "Please select an option",
    -- maybe throw an error if it is empty?
  select_opts = { 
     [1] = "A Text",
     [2] = "B Text",
     [3] = "C Text".
  },
  multiple = true -- false by default
}
...
-- Possible code used later on
luausb.create({
  type = "storage"
  file = boot_entries[a].path
})

I have dived into the Java/Kotlin side of the code a little so If I have spare time, I might even try to make a PR implementing it.

Netdex commented 3 weeks ago

That looks like a reasonable addition to me, if you're interested in implementing this feel free to submit a PR. Otherwise, I could implement it myself.

C-512L commented 3 weeks ago

That looks like a reasonable addition to me, if you're interested in implementing this feel free to submit a PR. Otherwise, I could implement it myself.

I see the project uses both Kotlin and Java in a lot of places. Are there any contributing guidelines for the project on whether certain functionality should be written on Java or Kotlin?

Netdex commented 3 weeks ago

The Kotlin is a fairly recent addition, in general I have been writing new code in Kotlin and slowly rewriting the Java into Kotlin. The exception is classes which are directly exposed to the lua interface using CoerceJavaToLua, because LuaJ doesn't support Kotlin. These classes are contained under org.netdex.androidusbscript.lua and have a special Proguard rule to avoid scrambling names.