Page 1 of 1

Multi-Select app list?

Posted: 22 Nov 2019 22:54
by hockeyduck3
So I need someone who is smart, cause I don't know what I'm doing with this script. What I'm trying to make is something similar to what automagic has already which is just selecting apps from a multi-select list. Kinda like what you would see if you go into Init Package Info and select specific packages instead of all packages.

Right now the flow I have is simple. There's no trigger (yet), I kinda wanna get through this hurdle before I add a trigger. But the flow goes like this, Init Package Info (All packages) > Script > Input Dialog. The thing I'm having trouble with is the script. I'm trying to get the code to just filter out the app names and have that in a new list so I can have that list in the Input Dialog. Not like com.google or com.textra, etc. But more so like, AMC, Android Auto, Automagic Premium, stuff like that.

Here's the script code I have now:

keys=getMapKeys(package_info);
list=newList();

for (pn in keys)
{ label=package_info[pn]["application_info"]["label"];
if (startsWith(label, pn))
{
addElement(list, pn)
}
else
{
continue
}
}

As y'all can see, I don't know what I'm doing :lol:. I'm not entirely sure if it's possible to have it just filter out the app names and have them put in a list or not. But if anyone can help, I'd definitely appreciate it!

Re: Multi-Select app list?

Posted: 23 Nov 2019 06:13
by Desmanto
I remember someone have made the flow, but I can't find it. At mine, I do something similar

Code: Select all

app = newList();
for(i in getMapKeys(package_info))
  addElement(app, "{package_info[i]['application_info']['label']}\n[{i}]");
sort(app);
The package_info has all the package names, so we loop upon the key (as you have done too). Then we take out the app name and combined it back to the package name. Package name is unique, but app name can be the same. That's why I still use the package name, to differentiate same app name but different package name. Use {app} in your input dialog.

Re: Multi-Select app list?

Posted: 25 Nov 2019 06:53
by hockeyduck3
Thank you so much! That worked!

I have one more question though. Is there a way to filter out some of the apps from the list? For example, "2 button navigation", "3 button navigation", etc. I was thinking of using an if statement, but I can't figure out the code to get the if statement to work properly.

Re: Multi-Select app list?

Posted: 25 Nov 2019 17:46
by Desmanto
You can put all the blacklisted app into a newList() and then remove these from the exisiting list.

But because in previous script, we have concat them into string, we can't do exact element removal. We have to search by strings using contains(). Following from what we got above.

Code: Select all

app = newList();
for(i in getMapKeys(package_info))
  addElement(app, "{package_info[i]['application_info']['label']}\n[{i}]");
sort(app);

blacklisted = newList("2 button navigation", "3 button navigation");
temp = newList();
for(i in app)
{
  for(j in blacklisted)
    if(contains(i, j)) addElement(temp, i);
}
removeAllElementValues(app, temp);
Define your blacklisted app name in the newList(). Create a temporary temp list to store the element which contains the blacklisted keyword. Then loop upon app and the blacklisted. If it found the keyword, add it to the temp. So {temp} contains list of the element need to be removed. Use the removeAllElements() to remove it from the {app} list. {app} now is free from the blacklisted keyword.

Re: Multi-Select app list?

Posted: 26 Nov 2019 00:42
by hockeyduck3
Thank you Desmanto! You're a genius!

Re: Multi-Select app list?

Posted: 28 Nov 2019 11:21
by hockeyduck3
Hey Desmanto, one last question. Do you just use automagic to write code? Or do you have a program on your computer that you write the code with?

I only ask cause writing code on my phone doesn't seem as efficient. Like I'm glad I have the option but didn't know if there was another way?

Re: Multi-Select app list?

Posted: 28 Nov 2019 18:23
by Desmanto
Yes, I usually walk around while typing at my phone. It is usually my source of inspiration as well.
But at times I can type the code just in notepad or notepad++ and then transfer it to phone, either by QR code, wifi PC to phone (using eventghost), or just simply copy paste in scrcpy. I don't mind typing without syntax hightlghting, i can fix the wrong syntax after I copy it to the phone.

If you really need to edit at PC, just mirror your phone to PC using scrcpy. I have mentioned it here :
viewtopic.php?f=6&t=7313
viewtopic.php?f=4&t=8012
viewtopic.php?f=6&t=8117
Maybe I should combine all the consideration of using scrcpy into a single thread, as my post is scattered around those threads.

Re: Multi-Select app list?

Posted: 28 Nov 2019 18:36
by hockeyduck3
Awesome! Thanks again Desmanto!