Skip to content

Commit

Permalink
Fix backup command does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftrot committed Jan 26, 2024
1 parent b33760e commit 530f2f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
33 changes: 0 additions & 33 deletions term/src/main/java/jackpal/androidterm/ASFUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
Expand All @@ -26,37 +24,6 @@ public class ASFUtils {
static AlertDialog mProcessingDialog = null;
static private boolean mCANCEL = false;

static public void directoryPicker(final AppCompatActivity activity, final int request, String mes, final ChooserDialog.Result r, int flags) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setIcon(android.R.drawable.ic_dialog_info);
bld.setTitle(activity.getString(R.string.select_directory_message));
bld.setMessage(mes);
bld.setPositiveButton(android.R.string.ok, (dialog, id) -> {
dialog.dismiss();
documentTreePicker(activity, request, flags);
});
bld.setNegativeButton(activity.getString(android.R.string.cancel), (dialog, id) -> dialog.dismiss());
bld.setNeutralButton(activity.getString(R.string.reset_directory), (dialog, id) -> {
dialog.dismiss();
r.onChoosePath(null, null);
});
bld.create().show();
}

static public void documentTreePicker(final AppCompatActivity activity, int requestCode, int flags) {
mCANCEL = false;
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(flags);
doStartActivityForResult(activity, intent, requestCode);
}

static private void doStartActivityForResult(AppCompatActivity activity, Intent intent, int requestCode) {
PackageManager pm = activity.getApplicationContext().getPackageManager();
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (intent.resolveActivity(pm) != null)
activity.startActivityForResult(intent, requestCode);
}

static public void backupToTreeUri(final AppCompatActivity activity, final Uri rootUri, final String path) {
if (rootUri == null) return;
if (isHomeDirectory(activity, rootUri)) return;
Expand Down
16 changes: 14 additions & 2 deletions term/src/main/java/jackpal/androidterm/Term.java
Original file line number Diff line number Diff line change
Expand Up @@ -1216,11 +1216,23 @@ private void editVimrc() {
}

private void backupFromHome() {
ASFUtils.documentTreePicker(this, REQUEST_COPY_DOCUMENT_TREE_BACKUP_HOME, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent = getDocumentsuiIntent(getApplicationContext(), intent);
if (checkImplicitIntent(this, intent))
doStartActivityForResult(intent, REQUEST_COPY_DOCUMENT_TREE_BACKUP_HOME);
}

private void restoreToHome() {
ASFUtils.documentTreePicker(this, REQUEST_COPY_DOCUMENT_TREE_RESTORE_TO_HOME, Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent = getDocumentsuiIntent(getApplicationContext(), intent);
if (checkImplicitIntent(this, intent))
doStartActivityForResult(intent, REQUEST_COPY_DOCUMENT_TREE_RESTORE_TO_HOME);
}

private void backupAndRestoreHome() {
Expand Down

0 comments on commit 530f2f0

Please sign in to comment.