I have a xamarin app that reads photos without extracting them into a zip file.
When I click very quickly on the page where the photos should be displayed. Sometimes half doesn't show because the app hasn't been able to read them all yet.
Navigating after that page goes like this
public async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
{
Content tappedStep = (Content)MyListView.SelectedItem;
int stepIndex = tappedStep.contentid;
string nextTitle = _protocol.name;
using (UserDialogs.Instance.Loading("Loading", null, null, true, MaskType.Black))
{
loading = true;
if (loading)
{
Title = nextTitle;
}
await Navigation.PushAsync(new StepView(_protocol, Title, tappedStep.chaptertitle, stepIndex));
}
((ListView)sender).SelectedItem = null;
}
So if I want to navigate too quickly after the stepview, the photos are often not all there.
This is the code I use to read the photos in the zip file.
private string PathToZip()
{
string folderName = $"protocol-{_protocol.id}-{_protocol.versionnr}.zip";
string extractPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string zipPath = $"{$"{extractPath}"}/{$"{folderName}"}";
return zipPath;
}
private async Task GetImage()
{
try
{
PathToZip();
int currentIndex = GetCurrentIndex();
Content content = _protocol.contents[currentIndex];
string imageName = $"{content.contentid}.jpg";
using (ZipArchive archive = ZipFile.OpenRead(PathToZip()))
{
for (int i = 0; i < archive.Entries.Count; i++)
{
ZipArchiveEntry pictureEntry = archive.Entries[i];
if (pictureEntry.Name == imageName)
{
//for reading the image
byte[] buffer;
long length = pictureEntry.Length;
buffer = new byte[length];
pictureEntry.Open().Read(buffer, 0, (int)length);
myImage.Source = ImageSource.FromStream(() => new MemoryStream(buffer));
}
}
}
}
catch (Exception)
{
}
}
How can I make this more efficient so that if the app hasn't loaded everything yet, when I want to navigate to the next page, the app then waits for each page to be read?
Thanks in advance