Here my AddFavorite sub to write the current page number into favorite file.
The idea is: If this page isn't in favorite yet => write into file.
If it's already in favorite => delete it from file.
I'm sure the pager.CurrentPage is correct. "favorite.dat" file is correct too. But it keep writing the same page number instead of delete it. I think the problem is fav.IndexOf(pager.CurrentPage) It's always = -1 !!!
I used this sub before with my old app and it worked correctly until now :BangHead:
The idea is: If this page isn't in favorite yet => write into file.
If it's already in favorite => delete it from file.
I'm sure the pager.CurrentPage is correct. "favorite.dat" file is correct too. But it keep writing the same page number instead of delete it. I think the problem is fav.IndexOf(pager.CurrentPage) It's always = -1 !!!
I used this sub before with my old app and it worked correctly until now :BangHead:
B4X:
' pager.CurrentPage is Int
Sub AddFavorite
If File.Exists(File.DirInternal, "favorite.dat") = False Then ' if no favorite file then create it
Dim fav As List
fav.Initialize
fav.Add(pager.CurrentPage)
File.WriteList(File.DirInternal, "favorite.dat", fav)
ToastMessageShow("Added page #" & pager.CurrentPage & " into Favorite", False)
Else ' if there's favorite file then read it
Dim fav As List
fav.Initialize
fav = File.ReadList(File.DirInternal, "favorite.dat")
If fav.IndexOf(pager.CurrentPage) = - 1 Then ' find this current page, if not found then write it
fav.Add(pager.CurrentPage)
File.WriteList(File.DirInternal, "favorite.dat", fav)
ToastMessageShow("Added page #" & pager.CurrentPage & " into Favorite", False)
Else ' found this current page then delete it
fav.RemoveAt(fav.IndexOf(pager.CurrentPage))
File.WriteList(File.DirInternal, "favorite.dat", fav)
ToastMessageShow("Removed page #" & pager.CurrentPage & " from Favorite", False)
End If
End If
End Sub