Skip to content

Commit

Permalink
add support for non-document.ui import
Browse files Browse the repository at this point in the history
When an import is started, search all folders in of
getExternalFilesDirs() for a rclone.conf and prompt the user to import
it. The path is generally available as
<device>/Android/ca.pkay.rcloneexplorer/files/rclone.conf

Signed-off-by: x0b <x0b@users.noreply.github.com>
  • Loading branch information
x0b committed Aug 19, 2019
1 parent 6bd7f7a commit e7bea29
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
Expand Up @@ -5,6 +5,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -112,8 +113,15 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
view.findViewById(R.id.empty_state_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (getActivity() != null) {
((MainActivity) getActivity()).importConfigFile();
Uri externalConfig;
if(null != (externalConfig = rclone.searchExternalConfig())){
if (getActivity() != null) {
((MainActivity) getActivity()).askUseExternalConfig(externalConfig);
}
} else {
if (getActivity() != null) {
((MainActivity) getActivity()).importConfigFile();
}
}
}
});
Expand Down
33 changes: 32 additions & 1 deletion app/src/main/java/ca/pkay/rcloneexplorer/MainActivity.java
Expand Up @@ -380,7 +380,12 @@ private void warnUserAboutOverwritingConfiguration() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
importConfigFile();
Uri configUri;
if(null != (configUri = rclone.searchExternalConfig())){
askUseExternalConfig(configUri);
} else {
importConfigFile();
}
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
Expand All @@ -392,6 +397,32 @@ public void onClick(DialogInterface dialogInterface, int i) {
builder.show();
}

public void askUseExternalConfig(final Uri uri) {
AlertDialog.Builder builder;
if (isDarkTheme) {
builder = new AlertDialog.Builder(this, R.style.DarkDialogTheme);
} else {
builder = new AlertDialog.Builder(this);
}
builder.setTitle(R.string.config_use_external_question);
builder.setMessage(context.getString(R.string.config_import_external_explain, uri.toString()));
builder.setPositiveButton(R.string.continue_statement, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
new CopyConfigFile().execute(uri);
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
importConfigFile();
}
});
builder.show();
}

private void askForConfigPassword() {
findViewById(R.id.locked_config).setVisibility(View.VISIBLE);
new InputDialog()
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/ca/pkay/rcloneexplorer/Rclone.java
Expand Up @@ -808,6 +808,18 @@ public boolean isConfigFileCreated() {
return file.exists();
}

// on all devices, look under ./Android/ca.pkay.rcloneexplorer/files/rclone.config
public Uri searchExternalConfig(){
File[] extDir = context.getExternalFilesDirs(null);
for(File dir : extDir){
File file = new File(dir + "/rclone.conf");
if(file.exists()){
return Uri.fromFile(file);
}
}
return null;
}

public void copyConfigFile(Uri uri) throws IOException {
String appsFileDir = context.getFilesDir().getPath();
InputStream inputStream = context.getContentResolver().openInputStream(uri);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -365,4 +365,6 @@
<string name="authentication">Authentication</string>
<string name="optional">Optional</string>
<string name="serve_dialog_title">Serve a remote</string>
<string name="config_use_external_question">Import found configuration?</string>
<string name="config_import_external_explain">Automatically import from %1$s</string>
</resources>

0 comments on commit e7bea29

Please sign in to comment.