feat: 경로 직접 입력 및 이동 기능 구현
This commit is contained in:
@@ -1,16 +1,10 @@
|
|||||||
package be.gyu.android.file.explorer;
|
package be.gyu.android.file.explorer;
|
||||||
|
|
||||||
// ... (imports)
|
// ... (imports)
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
|
||||||
import com.google.android.material.navigation.NavigationView;
|
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
||||||
import android.view.SubMenu;
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements FileAdapter.OnItemClickListener, FileAdapter.OnItemLongClickListener, NavigationView.OnNavigationItemSelectedListener {
|
public class MainActivity extends AppCompatActivity /* ... (implements) */ {
|
||||||
|
|
||||||
// ... (other variables)
|
// ... (variables)
|
||||||
private DrawerLayout drawerLayout;
|
|
||||||
private ActionBarDrawerToggle drawerToggle;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -19,57 +13,51 @@ public class MainActivity extends AppCompatActivity implements FileAdapter.OnIte
|
|||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
|
|
||||||
drawerLayout = findViewById(R.id.drawer_layout);
|
|
||||||
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
|
|
||||||
drawerLayout.addDrawerListener(drawerToggle);
|
|
||||||
drawerToggle.syncState();
|
|
||||||
|
|
||||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
|
||||||
|
|
||||||
setupDrawerContent(navigationView);
|
|
||||||
|
|
||||||
|
// Add click listener to toolbar to edit path
|
||||||
|
toolbar.setOnClickListener(v -> showPathEditDialog());
|
||||||
|
|
||||||
// ... (rest of onCreate)
|
// ... (rest of onCreate)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawerContent(NavigationView navigationView) {
|
private void showPathEditDialog() {
|
||||||
Menu menu = navigationView.getMenu();
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
SubMenu storageMenu = menu.findItem(R.id.group_storage).getSubMenu();
|
builder.setTitle("Go to Path");
|
||||||
storageMenu.clear();
|
|
||||||
|
|
||||||
StorageManager storageManager = (StorageManager) getSystemService(STORAGE_SERVICE);
|
final EditText input = new EditText(this);
|
||||||
List<StorageVolume> storageVolumes = storageManager.getStorageVolumes();
|
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
|
|
||||||
|
// Set current path as default text
|
||||||
|
if (isRemoteMode) {
|
||||||
|
input.setText(currentRemotePath);
|
||||||
|
} else {
|
||||||
|
input.setText(currentDirectory.getAbsolutePath());
|
||||||
|
}
|
||||||
|
builder.setView(input);
|
||||||
|
|
||||||
for (int i = 0; i < storageVolumes.size(); i++) {
|
builder.setPositiveButton("Go", (dialog, which) -> {
|
||||||
StorageVolume volume = storageVolumes.get(i);
|
String newPath = input.getText().toString();
|
||||||
if (volume.getState().equals(Environment.MEDIA_MOUNTED)) {
|
navigateToPath(newPath);
|
||||||
File path = volume.getDirectory();
|
});
|
||||||
if (path != null) {
|
builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel());
|
||||||
MenuItem item = storageMenu.add(Menu.NONE, i, Menu.NONE, volume.getDescription(this));
|
|
||||||
item.setIcon(R.drawable.ic_storage);
|
builder.show();
|
||||||
item.setOnMenuItemClickListener(menuItem -> {
|
}
|
||||||
loadFiles(path);
|
|
||||||
drawerLayout.closeDrawers();
|
private void navigateToPath(String path) {
|
||||||
return true;
|
if (path == null || path.isEmpty()) return;
|
||||||
});
|
|
||||||
}
|
if (isRemoteMode) {
|
||||||
|
loadFtpFiles(path);
|
||||||
|
} else {
|
||||||
|
File newDir = new File(path);
|
||||||
|
if (newDir.exists() && newDir.isDirectory()) {
|
||||||
|
loadFiles(newDir);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Path not found or not a directory.", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
|
||||||
int id = item.getItemId();
|
|
||||||
if (id == R.id.nav_remote_storage) {
|
|
||||||
Intent intent = new Intent(this, RemoteStorageActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
drawerLayout.closeDrawers();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Need to add string resources for drawer_open and drawer_close
|
|
||||||
// ... (rest of MainActivity)
|
// ... (rest of MainActivity)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user