1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-23 04:41:16 +00:00

Send an alternative intent on folder open (fixes #838)

This commit is contained in:
Catfriend1 2018-04-27 23:52:53 +02:00 committed by Audrius Butkevicius
parent 299b556923
commit f6f09515c5
2 changed files with 15 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -33,6 +34,8 @@ import static android.view.View.VISIBLE;
*/ */
public class FoldersAdapter extends ArrayAdapter<Folder> { public class FoldersAdapter extends ArrayAdapter<Folder> {
private static final String TAG = "FoldersAdapter";
private final HashMap<String, Model> mModels = new HashMap<>(); private final HashMap<String, Model> mModels = new HashMap<>();
public FoldersAdapter(Context context) { public FoldersAdapter(Context context) {
@ -53,12 +56,21 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
binding.openFolder.setOnClickListener(v -> { binding.openFolder.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(folder.path)), "resource/folder"); intent.setDataAndType(Uri.fromFile(new File(folder.path)), "resource/folder");
intent.putExtra("org.openintents.extra.ABSOLUTE_PATH", folder.path);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
if (intent.resolveActivity(getContext().getPackageManager()) != null) { if (intent.resolveActivity(getContext().getPackageManager()) != null) {
getContext().startActivity(intent); getContext().startActivity(intent);
} else {
// Try a second way to find a compatible file explorer app.
Log.v(TAG, "openFolder: Fallback to application chooser to open folder.");
intent.setDataAndType(Uri.parse(folder.path), "application/*");
Intent chooserIntent = Intent.createChooser(intent, getContext().getString(R.string.open_file_manager));
if (chooserIntent != null) {
getContext().startActivity(chooserIntent);
} else { } else {
Toast.makeText(getContext(), R.string.toast_no_file_manager, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.toast_no_file_manager, Toast.LENGTH_SHORT).show();
} }
}
}); });
if (model != null) { if (model != null) {

View file

@ -79,6 +79,8 @@ Please report any problems you encounter via Github.</string>
<item quantity="other">%1$d / %2$d Files</item> <item quantity="other">%1$d / %2$d Files</item>
</plurals> </plurals>
<string name="open_file_manager">Open file manager</string>
<string name="toast_no_file_manager">No compatible file manager found</string> <string name="toast_no_file_manager">No compatible file manager found</string>
<!-- DevicesFragment --> <!-- DevicesFragment -->