folder navigation fixed

This commit is contained in:
Page Asgardius 2022-09-03 18:32:01 -07:00
parent 73f1cf5eb3
commit a30480e8a5

View file

@ -39,7 +39,7 @@ public class ObjectSelect extends AppCompatActivity {
RecyclerView recyclerView; RecyclerView recyclerView;
String username, password, endpoint, bucket, prefix; String username, password, endpoint, bucket, prefix;
int treelevel; int treelevel;
String[] filename; String[] filename, path;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -92,7 +92,12 @@ public class ObjectSelect extends AppCompatActivity {
} }
for (S3ObjectSummary os : objects) { for (S3ObjectSummary os : objects) {
filename = os.getKey().split("/"); filename = os.getKey().split("/");
if (filename.length == treelevel+1) {
object.add(filename[treelevel]); object.add(filename[treelevel]);
}
else {
object.add(filename[treelevel]+"/");
}
//i++; //i++;
} }
@ -105,7 +110,7 @@ public class ObjectSelect extends AppCompatActivity {
int i = 0; int i = 0;
while(i<Name.size()) { while(i<Name.size()) {
//Img.add(R.drawable.unknownfile); //Img.add(R.drawable.unknownfile);
if (!Name.get(i).toString().contains((CharSequence) ".")) { if (Name.get(i).toString().endsWith("/")) {
Img.add(R.drawable.folder); Img.add(R.drawable.folder);
} }
else if (Name.get(i).toString().endsWith(".opus") || Name.get(i).toString().endsWith(".ogg") else if (Name.get(i).toString().endsWith(".opus") || Name.get(i).toString().endsWith(".ogg")
@ -146,7 +151,8 @@ public class ObjectSelect extends AppCompatActivity {
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
} }
}); });
System.out.println("tree "+treelevel); //System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -176,7 +182,7 @@ public class ObjectSelect extends AppCompatActivity {
@Override @Override
public void onLongClick(View view, int position) { public void onLongClick(View view, int position) {
//System.out.println("Long click on "+Name.get(position).toString()); //System.out.println("Long click on "+Name.get(position).toString());
explorer(bucket); explorer(Name.get(position).toString());
} }
})); }));
} }
@ -189,7 +195,7 @@ public class ObjectSelect extends AppCompatActivity {
} }
private void explorer(String bucket) { private void explorer(String object) {
Intent intent = new Intent(this, ObjectSelect.class); Intent intent = new Intent(this, ObjectSelect.class);
treelevel ++; treelevel ++;
@ -197,15 +203,31 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("username", username); intent.putExtra("username", username);
intent.putExtra("password", password); intent.putExtra("password", password);
intent.putExtra("bucket", bucket); intent.putExtra("bucket", bucket);
intent.putExtra("prefix", prefix); intent.putExtra("prefix", prefix + object);
intent.putExtra("treelevel", treelevel); intent.putExtra("treelevel", treelevel);
startActivity(intent); startActivity(intent);
} }
public void onBackPressed() { public void onBackPressed() {
if (treelevel >= 2) {
path = prefix.split("/");
prefix = "";
int i = 0;
//System.out.println("path "+i);
while(i <= path.length-2) {
prefix = prefix.concat(path[i]);
prefix = prefix.concat("/");
//System.out.println("position "+i);
i++;
}
}
else if (treelevel == 1) {
prefix = "";
}
treelevel --; treelevel --;
System.out.println("tree "+treelevel); //System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix);
finish(); finish();
} }
} }