public void OnDownloadProgress(SKToolsDownloadItem currentDownloadItem)
            {
                ListItem         affectedListItem;
                DownloadResource resource;
                bool             stateChanged = false;
                long             bytesDownloadedSinceLastUpdate = 0;

                if (_activity.codesMap.TryGetValue(currentDownloadItem.ItemCode, out affectedListItem))
                {
                    stateChanged = currentDownloadItem.DownloadState != affectedListItem.DownloadResource.DownloadState;
                    bytesDownloadedSinceLastUpdate = currentDownloadItem.NoDownloadedBytes - affectedListItem.DownloadResource.NoDownloadedBytes;
                    affectedListItem.DownloadResource.NoDownloadedBytes = (currentDownloadItem.NoDownloadedBytes);
                    affectedListItem.DownloadResource.DownloadState     = (currentDownloadItem.DownloadState);
                    resource = affectedListItem.DownloadResource;
                    _activity.RunOnUiThread((() => NotifyDataSetChanged()));
                }
                else
                {
                    resource = allMapResources[currentDownloadItem.ItemCode];
                    bytesDownloadedSinceLastUpdate = currentDownloadItem.NoDownloadedBytes - resource.NoDownloadedBytes;
                    stateChanged = currentDownloadItem.DownloadState != resource.DownloadState;
                    resource.NoDownloadedBytes = currentDownloadItem.NoDownloadedBytes;
                    resource.DownloadState     = currentDownloadItem.DownloadState;
                }
                if (resource.DownloadState == SKToolsDownloadItem.Downloaded)
                {
                    activeDownloads.Remove(resource);
                    _activity.appContext.AppPrefs.SaveDownloadQueuePreference(activeDownloads);
                }
                else if (resource.DownloadState == SKToolsDownloadItem.Downloading)
                {
                    _activity.downloadChunksMap.Add(DemoUtils.CurrentTimeMillis(), bytesDownloadedSinceLastUpdate);
                    if (stateChanged)
                    {
                        _activity.StartPeriodicUpdates();
                    }
                }
                if (resource.DownloadState != SKToolsDownloadItem.Downloading)
                {
                    _activity.StopPeriodicUpdates();
                }
                if (stateChanged)
                {
                    mapsDAO.updateMapResource((MapDownloadResource)resource);
                }

                _activity.appContext.AppPrefs.SaveDownloadStepPreference(currentDownloadItem.CurrentStepIndex);
            }
            public void OnInstallStarted(SKToolsDownloadItem currentInstallingItem)
            {
                ListItem affectedListItem;

                if (_activity.codesMap.TryGetValue(currentInstallingItem.ItemCode, out affectedListItem))
                {
                    affectedListItem.DownloadResource.DownloadState = SKToolsDownloadItem.Installing;
                    mapsDAO.updateMapResource((MapDownloadResource)affectedListItem.DownloadResource);
                    _activity.RunOnUiThread(() => _activity.adapter.NotifyDataSetChanged());
                }
                else
                {
                    DownloadResource downloadResource = allMapResources[currentInstallingItem.ItemCode];
                    downloadResource.DownloadState = (SKToolsDownloadItem.Installing);
                    mapsDAO.updateMapResource((MapDownloadResource)downloadResource);
                }
            }
        private List <SKToolsDownloadItem> createDownloadItemsFromDownloadResources(List <DownloadResource> downloadResources)
        {
            List <SKToolsDownloadItem> downloadItems = new List <SKToolsDownloadItem>();

            foreach (DownloadResource currentDownloadResource in downloadResources)
            {
                SKToolsDownloadItem currentItem = currentDownloadResource.ToDownloadItem();
                if (currentDownloadResource.DownloadState == SKToolsDownloadItem.Queued)
                {
                    currentItem.CurrentStepIndex = ((sbyte)0);
                }
                else if ((currentDownloadResource.DownloadState == SKToolsDownloadItem.Paused) || (currentDownloadResource.DownloadState == SKToolsDownloadItem.Downloading))
                {
                    int downloadStepIndex = appContext.AppPrefs.GetIntPreference(ApplicationPreferences.DOWNLOAD_STEP_INDEX_PREF_KEY);
                    currentItem.CurrentStepIndex = ((sbyte)downloadStepIndex);
                }
                downloadItems.Add(currentItem);
            }
            return(downloadItems);
        }
            public void OnInstallFinished(SKToolsDownloadItem currentInstallingItem)
            {
                DownloadResource resource;
                ListItem         affectedListItem;

                if (_activity.codesMap.TryGetValue(currentInstallingItem.ItemCode, out affectedListItem))
                {
                    affectedListItem.DownloadResource.DownloadState = SKToolsDownloadItem.Installed;
                    resource = affectedListItem.DownloadResource;
                    mapsDAO.updateMapResource((MapDownloadResource)affectedListItem.DownloadResource);
                    _activity.RunOnUiThread(() => _activity.adapter.NotifyDataSetChanged());
                }
                else
                {
                    resource = allMapResources[currentInstallingItem.ItemCode];
                    resource.DownloadState = SKToolsDownloadItem.Installed;
                    mapsDAO.updateMapResource((MapDownloadResource)resource);
                }

                _activity.RunOnUiThread(() => Toast.MakeText(_activity.appContext, ((MapDownloadResource)resource).getName() + " was installed", ToastLength.Short).Show());
            }
            public void OnDownloadPaused(SKToolsDownloadItem currentDownloadItem)
            {
                _activity.StopPeriodicUpdates();
                ListItem affectedListItem;

                if (_activity.codesMap.TryGetValue(currentDownloadItem.ItemCode, out affectedListItem))
                {
                    affectedListItem.DownloadResource.DownloadState     = (currentDownloadItem.DownloadState);
                    affectedListItem.DownloadResource.NoDownloadedBytes = (currentDownloadItem.NoDownloadedBytes);
                    mapsDAO.updateMapResource((MapDownloadResource)affectedListItem.DownloadResource);
                    _activity.RunOnUiThread(() => _activity.adapter.NotifyDataSetChanged());
                }
                else
                {
                    DownloadResource downloadResource = allMapResources[currentDownloadItem.ItemCode];
                    downloadResource.DownloadState     = currentDownloadItem.DownloadState;
                    downloadResource.NoDownloadedBytes = currentDownloadItem.NoDownloadedBytes;
                    mapsDAO.updateMapResource((MapDownloadResource)downloadResource);
                }

                _activity.appContext.AppPrefs.SaveDownloadStepPreference(currentDownloadItem.CurrentStepIndex);
            }
        public override SKToolsDownloadItem ToDownloadItem()
        {
            SKPackageURLInfo info = SKPackageManager.Instance.GetURLInfoForPackageWithCode(Code, null, skmFilePath.StartsWith("custom-packages"));
            List <SKToolsFileDownloadStep> downloadSteps = new List <SKToolsFileDownloadStep>();

            downloadSteps.Add(new SKToolsFileDownloadStep(info.MapURL, new StringBuilder(DownloadPath).Append(Code)
                                                          .Append(SKToolsDownloadManager.SkmFileExtension).ToString(), skmFileSize));
            if (txgFileSize != 0)
            {
                downloadSteps.Add(new SKToolsFileDownloadStep(info.TexturesURL, new StringBuilder(DownloadPath).Append(Code)
                                                              .Append(SKToolsDownloadManager.TxgFileExtension).ToString(), txgFileSize));
            }
            if (unzippedFileSize != 0)
            {
                downloadSteps.Add(new SKToolsFileDownloadStep(info.NameBrowserFilesURL, new StringBuilder(DownloadPath).Append(Code)
                                                              .Append(SKToolsDownloadManager.ZipFileExtension).ToString(), (skmAndZipFilesSize - skmFileSize)));
            }
            SKToolsDownloadItem currentItem = new SKToolsDownloadItem(Code, downloadSteps, DownloadState, (unzippedFileSize != 0), true);

            currentItem.NoDownloadedBytes = (NoDownloadedBytes);
            return(currentItem);
        }
 public void OnNotEnoughMemoryOnCurrentStorage(SKToolsDownloadItem currentDownloadItem)
 {
     _activity.RunOnUiThread(() => Toast.MakeText(_activity.ApplicationContext, "Not enough memory on the storage", ToastLength.Short).Show());
 }
 public void OnInternetConnectionFailed(SKToolsDownloadItem currentDownloadItem, bool responseReceivedFromServer)
 {
     _activity.StopPeriodicUpdates();
     _activity.appContext.AppPrefs.SaveDownloadStepPreference(currentDownloadItem.CurrentStepIndex);
 }