public DownloadViewModel(
     Application app,
     ILogger logger,
     IResourceProvider resProvider,
     IApplicationControlFileProvider appControlFileProvider,
     IFileSystemHelper fileSystemHelper,
     IByteConverter byteConverter,
     IEpisodeFinder podcastEpisodeFinder,
     ISyncItemToEpisodeDownloaderTaskConverter converter,
     ITaskPool taskPool,
     ICrashReporter crashReporter,
     IAnalyticsEngine analyticsEngine,
     IStatusAndProgressMessageStore messageStore,
     INetworkHelper networkHelper,
     IUserSettings userSettings) : base(app)
 {
     ApplicationContext = app;
     Logger             = logger;
     Logger.Debug(() => $"DownloadViewModel:ctor");
     ResourceProvider = resProvider;
     ApplicationControlFileProvider = appControlFileProvider;
     FileSystemHelper     = fileSystemHelper;
     ByteConverter        = byteConverter;
     PodcastEpisodeFinder = podcastEpisodeFinder;
     Converter            = converter;
     TaskPool             = taskPool;
     CrashReporter        = crashReporter;
     AnalyticsEngine      = analyticsEngine;
     MessageStore         = messageStore;
     NetworkHelper        = networkHelper;
     UserSettings         = userSettings;
 }
        public void Setup()
        {
            ResetObservedResults();

            MockApplication = A.Fake <Application>();
            A.CallTo(() => MockApplication.PackageName).Returns("com.andrewandderek.podcastutilities");
            MockLogger           = A.Fake <ILogger>();
            MockResourceProvider = A.Fake <IResourceProvider>();
            MockFileSystemHelper = A.Fake <IFileSystemHelper>();
            // there is 10MB free in the filesystem
            A.CallTo(() => MockFileSystemHelper.GetAvailableFileSystemSizeInBytes(A <string> .Ignored)).Returns(1024 * 1024 * FREE_DISK_SPACE_MB);
            MockApplicationControlFileProvider = A.Fake <IApplicationControlFileProvider>();
            MockCrashReporter   = A.Fake <ICrashReporter>();
            MockAnalyticsEngine = A.Fake <IAnalyticsEngine>();
            MockApplicationControlFileFactory            = A.Fake <IApplicationControlFileFactory>();
            MockPodcastEpisodeFinder                     = A.Fake <IEpisodeFinder>();
            MockSyncItemToEpisodeDownloaderTaskConverter = A.Fake <ISyncItemToEpisodeDownloaderTaskConverter>();
            MockTaskPool = A.Fake <ITaskPool>();
            MockStatusAndProgressMessageStore = A.Fake <IStatusAndProgressMessageStore>();
            MockNetworkHelper = A.Fake <INetworkHelper>();
            A.CallTo(() => MockNetworkHelper.ActiveNetworkType).Returns(INetworkHelper.NetworkType.Wifi);
            MockUserSettings = A.Fake <IUserSettings>();

            ByteConverter = new ByteConverter();

            SetupResources();

            ViewModel = new DownloadViewModel(
                MockApplication,
                MockLogger,
                MockResourceProvider,
                MockApplicationControlFileProvider,
                MockFileSystemHelper,
                ByteConverter,
                MockPodcastEpisodeFinder,
                MockSyncItemToEpisodeDownloaderTaskConverter,
                MockTaskPool,
                MockCrashReporter,
                MockAnalyticsEngine,
                MockStatusAndProgressMessageStore,
                MockNetworkHelper,
                MockUserSettings
                );
            ViewModel.Observables.Title              += SetTitle;
            ViewModel.Observables.SetEmptyText       += SetEmptyText;
            ViewModel.Observables.StartProgress      += StartProgress;
            ViewModel.Observables.UpdateProgress     += UpdateProgress;
            ViewModel.Observables.EndProgress        += EndProgress;
            ViewModel.Observables.SetSyncItems       += SetSyncItems;
            ViewModel.Observables.DisplayMessage     += DisplayMessage;
            ViewModel.Observables.CellularPrompt     += CellularPrompt;
            ViewModel.Observables.StartDownloading   += StartDownloading;
            ViewModel.Observables.EndDownloading     += EndDownloading;
            ViewModel.Observables.UpdateItemProgress += UpdateItemProgress;
            ViewModel.Observables.UpdateItemStatus   += UpdateItemStatus;
            ViewModel.Observables.ExitPrompt         += ExitPrompt;
            ViewModel.Observables.Exit += Exit;
        }
        private void FindEpisodesToDownload()
        {
            AndroidApplication.Logger.Debug(() => $"MainActivity:FindEpisodesToDownload");
            OutputBuffer.Clear();
            AddLineToOutput("Started");
            DisplayOutput();
            if (AndroidApplication.ControlFile == null)
            {
                AndroidApplication.Logger.Warning(() => $"MainActivity:FindEpisodesToDownload - no control file");
                AddLineToOutput("No control file");
                DisplayOutput();
                return;
            }

            StartProgress();
            ToastMessage("Started");
            IEpisodeFinder podcastEpisodeFinder = null;

            podcastEpisodeFinder = AndroidApplication.IocContainer.Resolve <IEpisodeFinder>();

            // find the episodes to download
            AllEpisodes.Clear();
            int count = 0;

            foreach (var podcastInfo in AndroidApplication.ControlFile.GetPodcasts())
            {
                var episodesInThisFeed = podcastEpisodeFinder.FindEpisodesToDownload(
                    // works on all OS's with just WRITE_EXTERNAL
                    //"/sdcard/Android/data/com.andrewandderek.podcastutilitiespoc.debug/files/PodcastEpisodes",
                    // works on OS4 with just WRITE_EXTERNAL, hangs on OS10 and fails with exception on OS11
                    // OS10 hangs unless <application android:requestLegacyExternalStorage="true" is in the manifest
                    //"/sdcard/PodcastUtilities/PodcastEpisodes",
                    // ApplicationContext.GetExternalFilesDirs(null); last folder in the array
                    //"/storage/82E7-140A/Android/data/com.andrewandderek.podcastutilitiespoc.debug/files"
                    //OverrideRoot,
                    AndroidApplication.ControlFile.GetSourceRoot(),
                    AndroidApplication.ControlFile.GetRetryWaitInSeconds(),
                    podcastInfo,
                    AndroidApplication.ControlFile.GetDiagnosticRetainTemporaryFiles());
                AllEpisodes.AddRange(episodesInThisFeed);
                foreach (var episode in episodesInThisFeed)
                {
                    AndroidApplication.Logger.Debug(() => $"MainActivity:FindEpisodesToDownload {episode.Id}, {episode.EpisodeTitle}");
                    AddLineToOutput(episode.EpisodeTitle);
                }
                count++;
                UpdateProgress(count);
            }
            AddLineToOutput("Done.");
            ToastMessage("Done");
            EndProgress();
            DisplayOutput();
        }
Example #4
0
        private IList <ISyncItem> GetAllEpisodesInFeed(ReadOnlyControlFile controlFile, IPodcastInfo info)
        {
            List <ISyncItem>  allEpisodes          = new List <ISyncItem>(20);
            IEpisodeFinder    podcastEpisodeFinder = _iocContainer.Resolve <IEpisodeFinder>();
            IList <ISyncItem> episodesInThisFeed   = podcastEpisodeFinder.FindEpisodesToDownload(
                controlFile.GetSourceRoot(),
                controlFile.GetRetryWaitInSeconds(),
                info,
                controlFile.GetDiagnosticRetainTemporaryFiles()
                );

            allEpisodes.AddRange(episodesInThisFeed);
            return(allEpisodes);
        }
Example #5
0
        public DownloadViewModel(
            Application app,
            ILogger logger,
            IResourceProvider resProvider,
            IEpisodeFinder podcastEpisodeFinder,
            ISyncItemToEpisodeDownloaderTaskConverter converter,
            ITaskPool taskPool,
            IFileSystemHelper fileSystemHelper,
            IByteConverter byteConverter) : base(app)
        {
            Logger = logger;
            Logger.Debug(() => $"DownloadViewModel:ctor");

            ResourceProvider     = resProvider;
            PodcastEpisodeFinder = podcastEpisodeFinder;
            Converter            = converter;
            TaskPool             = taskPool;
            FileSystemHelper     = fileSystemHelper;
            ByteConverter        = byteConverter;
        }