Searching in documents folder at Android

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Searching in documents folder at Android

Post by UrosDobricic » Tue Oct 01, 2019 7:24 pm

Hi, i wrote a code for a searchfield in my app.

It should search in my earlier created documents folder in my app.
There are some files stored, and i want the User to find them with this search option.

Here is my code:

Code: Select all

on openField
   if the text of me is "Nach Profilen suchen" then
      set the textColor of me to "black"
      put empty into me
   end if
end openField

on closeField
   if the text of me is empty then
      set the textColor of me to 127,127,127
      put "Nach Profilen suchen" into me
   end if
end closeField

on exitField
   closeField
end exitField


on textChanged
   put the text of me into tsearch
   set the defaultFolder to specialFolderPath("documents")
   put the files into zwischenSpeicher
   filter zwischenSpeicher with "*(&tsearch)"
   put zwischenSpeicher into field "ergebnisse"
end textChanged
The last part is interesting "on textChanged".
There i specify the search function.
Is there a mistake? Because it wont work like that.

Thanks for your help,

Urosch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3465
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Searching in documents folder at Android

Post by bn » Tue Oct 01, 2019 8:50 pm

Hi Urosch,

Code: Select all

filter zwischenSpeicher with "*" & tsearch & "*"
works. Your solution did not work because you put your filter into quotes. Everything in quotes is treated as literal. In your case the variable tSearch. It is not a variable anymore but just the word.

Code: Select all

filter zwischenSpeicher with "*(&tsearch)"
Kind regards
Bernd

UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Re: Searching in documents folder at Android

Post by UrosDobricic » Tue Oct 01, 2019 9:31 pm

Hi,

that was my problem. Thanks a lot!!!

Regards,

Urosch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3465
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Searching in documents folder at Android

Post by bn » Tue Oct 01, 2019 9:49 pm

Hi Urosch,

one thing I noticed is that you get the content of the document folder everytime when "textchanged"

You could reduce this step to a one time step in the openField handler.

It uses a script local variable. That is a variable that is accessible by all handler in the same script. It is declared outside of any script, typically at the top of a script (to be more precise a script local variable is accessible to all handlers of a script that are below the declaration of the script local variable)

I always prepend my script local variables with an "s" to indicate that it is a script local variable.

In your case I modified the scripts a bit:

Code: Select all

local sSearchAll -- declare script local variable
on openField
   if the text of me is "Nach Profilen suchen" then
      set the textColor of me to "black"
      put empty into me
      set the defaultFolder to specialFolderPath("documents") -- do your filling of the script local variable
      put the files into sSearchAll -- filling of sSearchAll
   end if
end openField

-- unchanged handlers left out

on textChanged
   put the text of me into tsearch
   put sSearchAll into zwischenSpeicher -- use script local variable to fill zwischenspeicher
   filter zwischenSpeicher with "*" & tsearch & "*"
   put zwischenSpeicher into field "ergebnisse"
end textChanged
It might save you some time. Acessing the filesystem can be costly.

Just an idea how to use script local variables and save time

Kind regards
Bernd

UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Re: Searching in documents folder at Android

Post by UrosDobricic » Tue Oct 01, 2019 10:08 pm

Hi Bernd,

i did that because with this i have a real time filtering.
So every change in this text field is filtering and giving possible profiles in the list.
Do I get the same with your solution?

Regards,

Urosch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3465
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Searching in documents folder at Android

Post by bn » Tue Oct 01, 2019 11:01 pm

Hi Urosch,

the idea is to fill the script local variable when you start your search, i.e on openField

Code: Select all

on openField
   if the text of me is "Nach Profilen suchen" then
      set the textColor of me to "black"
      put empty into me
      set the defaultFolder to specialFolderPath("documents") -- do your filling of the script local variable
      put the files into sSearchAll -- filling of sSearchAll
that to me seems when the user will be searching.
And I assume that as long as the user searches folder "documents" will not change.

If that is not the case, because for example the user leaves a search and does something that affects the content of folder "directory" and continues the search later then leave it as it is.

Anyway it is not a big deal and you have to decide from how your app is working.

Kind regards
Bernd

UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Re: Searching in documents folder at Android

Post by UrosDobricic » Wed Oct 02, 2019 8:01 am

Aa, ok now i got you.
When i set the special folder path at open field, it will do the same but read it just once. Makes sense to me.
I'll give it a try.
For me it is just important to read the folder path once and to filter then in it. So it is the better way like you said.

Thanks a lot Bernd.

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Searching in documents folder at Android

Post by Klaus » Wed Oct 02, 2019 10:18 am

We do not need to set the DEFAULTFOLDER to get the files/folders anymore!

Code: Select all

...
put files(specialfolderpath("documents")) into sSearchall
## Done!
...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3465
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Searching in documents folder at Android

Post by bn » Wed Oct 02, 2019 10:34 am

I missed that

Thanks Klaus

Post Reply

Return to “Android Deployment”