Esempio n. 1
0
 // use the message specified in the layout XML and use a stepped progress
 public static void StartProgress(ProgressSpinnerView progressBar, Window window, int max)
 {
     progressBar.Max = max;
     StartProgress(progressBar, window, false);
 }
Esempio n. 2
0
 // specify a dynamic message to display in the progress view and use a stepped progress
 public static void StartProgress(ProgressSpinnerView progressBar, Window window, int messageId, Context context, int max)
 {
     progressBar.Message = context.GetString(messageId);
     progressBar.Max     = max;
     StartProgress(progressBar, window, false);
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            AndroidApplication = Application as AndroidApplication;
            AndroidApplication.Logger.Debug(() => "MainActivity:OnCreate");
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            DriveInfoProvider   = AndroidApplication.IocContainer.Resolve <IDriveInfoProvider>();
            FileSystemHelper    = AndroidApplication.IocContainer.Resolve <IFileSystemHelper>();
            PreferencesProvider = AndroidApplication.IocContainer.Resolve <IPreferencesProvider>();
            ControlFileUri      = PreferencesProvider.GetPreferenceString(ApplicationContext.GetString(Resource.String.prefs_control_uri_key), "");
            AndroidApplication.Logger.Debug(() => $"MainActivity:OnCreate Conrol Uri = {ControlFileUri}");

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            // Get our UI controls from the loaded layout
            List <string> envirnment = WindowsEnvironmentInformationProvider.GetEnvironmentRuntimeDisplayInformation();
            StringBuilder builder    = new StringBuilder();

            builder.AppendLine(AndroidApplication.DisplayVersion);
            foreach (string line in envirnment)
            {
                builder.AppendLine(line);
            }
            SetTextViewText(Resource.Id.txtVersions, builder.ToString());

            builder.Clear();

            builder.AppendLine($"Personal Folder = {System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)}");
            builder.AppendLine($"AppData Folder = {System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)}");
            builder.AppendLine($"CommonAppData Folder = {System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData)}");
            Java.IO.File[] files = ApplicationContext.GetExternalFilesDirs(null);
            foreach (Java.IO.File file in files)
            {
                builder.AppendLine($"ExternalFile = {file.AbsolutePath}");
                OverrideRoot = file.AbsolutePath;
            }
            builder.AppendLine($"Podcasts Folder = {Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPodcasts).AbsolutePath}");
            SetTextViewText(Resource.Id.txtAppStorage, builder.ToString());

            ProgressSpinner = FindViewById <ProgressSpinnerView>(Resource.Id.progressBar);

            Button btnLoad = FindViewById <Button>(Resource.Id.btnLoadConfig);

            btnLoad.Click += (sender, e) => LoadConfig();

            Button btnFind = FindViewById <Button>(Resource.Id.btnFindPodcasts);

            // works
            btnFind.Click += (sender, e) => Task.Run(() => FindEpisodesToDownload());
            // crash - java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
            //btnFind.Click += async (sender, e) => await Task.Run(() => FindEpisodesToDownload());
            // blocks UI thread
            //btnFind.Click += async (sender, e) => FindEpisodesToDownload();

            Button btnSetRoot = FindViewById <Button>(Resource.Id.btnSetRoot);

            btnSetRoot.Click += (sender, e) => SetRoot();

            Button btnDownload = FindViewById <Button>(Resource.Id.btnDownload);

            btnDownload.Click += (sender, e) => Task.Run(() => Download());

            bool isReadonly  = Android.OS.Environment.MediaMountedReadOnly.Equals(Android.OS.Environment.ExternalStorageState);
            bool isWriteable = Android.OS.Environment.MediaMounted.Equals(Android.OS.Environment.ExternalStorageState);

            if (!string.IsNullOrEmpty(ControlFileUri))
            {
                try
                {
                    // TODO - we need to ask permission if the file has been edited by another app
                    Android.Net.Uri uri = Android.Net.Uri.Parse(ControlFileUri);
                    AndroidApplication.ControlFile = OpenControlFile(uri);
                }
                catch (Exception ex)
                {
                    AndroidApplication.Logger.LogException(() => $"MainActivity: OnCreate", ex);
                    SetTextViewText(Resource.Id.txtConfigFilePath, $"Error {ex.Message}");
                }
            }
        }