improve using more external sdcards
Hi,
I am not sure if this is the right place for a patch. It improves using more than one external sdcard (or otg flash disk). In the list on home screen you can see the block id of the partition and SAF can be used to access multiple partition at once. My use case is simply to copy files from otg flash disk to sdcard or vice versa. Could you, please, implement something like this?
Thanks
Pavel
The patch is against the fdroid code for 1.56.4 version.
diff --git a/res/values-cs-rCZ/strings.xml b/res/values-cs-rCZ/strings.xml
index 69d08c0..3dbd51b 100644
--- a/res/values-cs-rCZ/strings.xml
+++ b/res/values-cs-rCZ/strings.xml
@@ -397,4 +397,5 @@ Pro vypsání namountovaných zařízení napište "mount://".<br/>
Klikněte na namountovaný záznam pro změnu práv pro zápis "rw" nebo zpět pro čtení "ro".
</p>
]]></string>
+<string name="enable_for">povolit pro</string>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index cf1a778..5308039 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -569,4 +569,5 @@ follows:
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p>
<p>You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/</p>
]]></string>
+<string name="enable_for">enable for</string>
</resources>
diff --git a/src/com/ghostsq/commander/adapters/HomeAdapter.java b/src/com/ghostsq/commander/adapters/HomeAdapter.java
index 78f746b..337f275 100644
--- a/src/com/ghostsq/commander/adapters/HomeAdapter.java
+++ b/src/com/ghostsq/commander/adapters/HomeAdapter.java
@@ -57,8 +57,12 @@ public class HomeAdapter extends CommanderAdapterBase {
private Item[] items = null;
private Item makeItem( int[] mode, String scheme ) {
- return makeItem(mode, scheme, "" );
- } +
- private Item makeItem( int[] mode, String scheme, String ext ) { Item item = new Item();
- item.name = s( mode[0] );
- item.name = s( mode[0] ) + " " + ext; item.attr = s( mode[1] ); item.icon_id = mode[2]; item.origin = scheme; @@ -133,7 +137,7 @@ public class HomeAdapter extends CommanderAdapterBase { for( int i = 0; i < dirs.length; i++ ) { if( !Utils.str( dirs[i] ) ) continue; if( fs.equals( dirs[i] ) ) continue;
- Item item = makeItem( EXTERNAL, dirs[i] );
Item item = makeItem( EXTERNAL, dirs[i], dirs[i] ); ia.add( item ); } }
@@ -144,7 +148,26 @@ public class HomeAdapter extends CommanderAdapterBase {
} if( android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {
Item item = makeItem( SAF, SAFAdapter.ORG_SCHEME );
String fs = Environment.getExternalStorageDirectory().getAbsolutePath();
fs = Utils.mbAddSl( fs );
String[] dirs = ForwardCompat.getStorageDirs( ctx );
if( dirs != null ) {
for( int i = 0; i < dirs.length; i++ ) {
if( !Utils.str( dirs[i] ) ) continue;
if( fs.equals( dirs[i] ) ) continue;
String scheme = SAFAdapter.ORG_SCHEME + ":" + dirs[i];
SharedPreferences saf_sp = ctx.getSharedPreferences( SAFAdapter.ORG_SCHEME, Activity.MODE_PRIVATE );
String uri_s = null;
if( saf_sp != null ){
uri_s = saf_sp.getString(scheme, null);
}
Item item = makeItem( SAF , scheme, (uri_s == null?(s(R.string.enable_for) + " "):"") + dirs[i]);
item.dir = true;
ia.add( item );
}
}
Item item = makeItem( SAF , SAFAdapter.ORG_SCHEME ); item.dir = true; ia.add( item ); }
@@ -288,10 +311,11 @@ public class HomeAdapter extends CommanderAdapterBase {
commander.dispatchCommand( R.id.exit );
return;
}if( "saf".equals( item.origin ) ) {
if(item.origin.toString().startsWith("saf")){ SharedPreferences saf_sp = ctx.getSharedPreferences( SAFAdapter.ORG_SCHEME, Activity.MODE_PRIVATE );
if( saf_sp != null )
uri_s = saf_sp.getString( "tree_root_uri", null );
if( saf_sp != null ){
uri_s = saf_sp.getString(item.origin.toString(), null);
} if( uri_s == null ) { commander.issue( Lollipop.getDocTreeIntent(), Commander.REQUEST_OPEN_DOCUMENT_TREE ); return;
diff --git a/src/com/ghostsq/commander/adapters/SAFAdapter.java b/src/com/ghostsq/commander/adapters/SAFAdapter.java
index e666593..f31445c 100644
--- a/src/com/ghostsq/commander/adapters/SAFAdapter.java
+++ b/src/com/ghostsq/commander/adapters/SAFAdapter.java
@@ -48,6 +48,8 @@ import android.util.SparseBooleanArray;
import android.view.ContextMenu;
import android.widget.AdapterView;
+import java.util.List;
+
@SuppressLint("NewApi")
public class SAFAdapter extends CommanderAdapterBase implements Engines.IReciever {
private final static String TAG = "SAFAdapter";
@@ -1396,7 +1398,9 @@ public class SAFAdapter extends CommanderAdapterBase implements Engines.IRecieve
public static void saveURI( Context ctx, Uri uri ) {
SharedPreferences safsp = ctx.getSharedPreferences( SAFAdapter.ORGSCHEME, Activity.MODEPRIVATE );
SharedPreferences.Editor editor = safsp.edit();
- editor.putString( "treerooturi", uri != null ? uri.toString() : null );
+ List<String> segments = uri.getPathSegments();
+ if(segments != null && segments.size() >=2 && "tree".equals(segments.get(0)))
+ editor.putString( "saf:/storage/"+segments.get(1).replace(":","/"), uri != null ? uri.toString() : null );
editor.commit();
}
}