Example #1
0
        protected override async void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent intent)
        {
            if (resultCode != Result.Ok)
            {
                return;
            }

            switch (requestCode)
            {
            case DeviceStorageCode:
                var file = $@"{intent.GetStringExtra("path")}/{intent.GetStringExtra("filename")}";
                _fileData = await File.ReadAllBytesAsync(file);

                break;

            case StorageAccessFrameworkCode:
                var stream       = ContentResolver.OpenInputStream(intent.Data);
                var memoryStream = new MemoryStream();

                await stream.CopyToAsync(memoryStream);

                _fileData = memoryStream.ToArray();
                break;

            default: return;
            }

            if (_fileData.Length == 0)
            {
                Toast.MakeText(this, Resource.String.invalidFileError, ToastLength.Short).Show();
                return;
            }

            // Open curly brace (file is not encrypted)
            if (_fileData[0] == 0x7b)
            {
                await Restore();

                return;
            }

            var transaction = SupportFragmentManager.BeginTransaction();
            var old         = SupportFragmentManager.FindFragmentByTag("password_dialog");

            if (old != null)
            {
                transaction.Remove(old);
            }

            transaction.AddToBackStack(null);
            _dialog = new BackupPasswordDialog(BackupPasswordDialog.Mode.Restore, OnDialogPositive, OnDialogNegative);
            _dialog.Show(transaction, "password_dialog");
        }
        private void ShowPasswordDialog(int requestCode, Intent intent)
        {
            var transaction = SupportFragmentManager.BeginTransaction();
            var old         = SupportFragmentManager.FindFragmentByTag("password_dialog");

            if (old != null)
            {
                transaction.Remove(old);
            }

            transaction.AddToBackStack(null);
            _passwordDialog = new BackupPasswordDialog(BackupPasswordDialog.Mode.Backup, () =>
            {
                Backup(requestCode, intent);
            }, null);

            _passwordDialog.Show(transaction, "password_dialog");
        }