protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // ActionBar Hintergrund Farbe setzen
            var backgroundPaint = ContextCompat.GetDrawable(this, Resource.Color.Application_ActionBar_Background);

            backgroundPaint.SetBounds(0, 0, 10, 10);
            ActionBar.SetBackgroundDrawable(backgroundPaint);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetIcon(Resource.Drawable.baseline_folder_white_24);

            this.Title         = Intent.GetStringExtra("Text");
            this.path          = Intent.GetStringExtra("Path");
            this.searchPattern = Intent.GetStringExtra("SearchPattern");

            // Soll noch umgestellt werden
            SetContentView(Resource.Layout.SelectFile);

            var pathView = FindViewById <TextView>(Resource.Id.SelectFile_Path);

            pathView.Text = this.path;

            var selectFileButton = FindViewById <Button>(Resource.Id.SelectFile_Button);

            selectFileButton.Click += SelectFileButton_Click;

            var listView = FindViewById <ListView>(Resource.Id.SelectFile);

            listView.ItemClick += ListView_ItemClick;

            bool isGranted = new SdCardAccess().Grand(this);

            if (isGranted)
            {
                this.ShowFileList();
            }
        }
        private void ButtonBackup_Click(object sender, EventArgs eventArgs)
        {
            bool isGranted = new SdCardAccess().Grand(this);

            if (!isGranted)
            {
                return;
            }

            // Vor dem Backup ggf. die User-Kategorien ggf. speichern,
            // damit es auch im Backup ist.
            this.SaveUserDefinedCategories();

            var databaseFilePath = Android_Database.Instance.GetProductiveDatabasePath();

            var downloadFolder = Android.OS.Environment.GetExternalStoragePublicDirectory(
                Android.OS.Environment.DirectoryDownloads).AbsolutePath;

            string backupFileName;
            string databaseFileName = Path.GetFileNameWithoutExtension(databaseFilePath);

            if (databaseFileName == "Vorraete")
            {
                backupFileName = string.Format("Vue_{0}.VueBak",
                                               DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss"));
            }
            else
            {
                backupFileName = string.Format(databaseFileName + "_{0}.VueBak",
                                               DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss"));
            }

            var backupFilePath = Path.Combine(downloadFolder, backupFileName);

            Android_Database.Instance.CloseConnection();

            var progressDialog = this.CreateProgressBar(Resource.Id.ProgressBar_BackupAndRestore);

            new Thread(new ThreadStart(delegate
            {
                string message;
                try
                {
                    File.Copy(databaseFilePath, backupFilePath);
                    message = string.Format(
                        "Datenbank im Download Verzeichnis gesichert als:\n\n {0}" +
                        "\n\nSichern Sie diese Datei auf Google Drive oder auf Ihren PC.",
                        backupFilePath);
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }

                this.HideProgressBar(progressDialog);

                RunOnUiThread(() =>
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetMessage(message);
                    builder.SetPositiveButton("Ok", (s, e) => { });
                    builder.Create().Show();
                });
            })).Start();

            return;
        }
Esempio n. 3
0
        private void CreateBackup()
        {
            bool isGranted = new SdCardAccess().Grand(this);

            if (!isGranted)
            {
                return;
            }

            // Vor dem Backup ggf. die User-Kategorien ggf. speichern,
            // damit es auch im Backup ist.
            this.SaveUserDefinedCategories();

            DateTime?lastBackupDay = Database.GetSettingsDate("LAST_BACKUP");

            // Datum vom Backup in der Datenbank speichern.
            Database.SetSettingsDate("LAST_BACKUP", DateTime.Today);

            this.ShowLastBackupDay();

            var databaseFilePath = Android_Database.Instance.GetProductiveDatabasePath();

            string backupFilePath = this.GetBackupFileName(databaseFilePath);

            Android_Database.Instance.CloseConnection();

            var progressDialog = this.CreateProgressBar(Resource.Id.ProgressBar_BackupAndRestore);

            new Thread(new ThreadStart(delegate
            {
                string message;
                try
                {
                    File.Copy(databaseFilePath, backupFilePath);

                    message = string.Format(
                        "Datenbank im Download Verzeichnis gesichert als:\n\n {0}" +
                        "\n\nSichern Sie diese Datei auf Google Drive oder auf Ihren PC.",
                        backupFilePath);
                }
                catch (Exception ex)
                {
                    TRACE(ex);

                    message = ex.Message;

                    if (lastBackupDay != null)
                    {
                        // Datum vom wieder zurückspielen.
                        Database.SetSettingsDate("LAST_BACKUP", lastBackupDay.Value);
                    }
                }

                this.HideProgressBar(progressDialog);

                RunOnUiThread(() =>
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetMessage(message);
                    builder.SetPositiveButton("Ok", (s, e) => { });
                    builder.Create().Show();
                });
            })).Start();

            return;
        }