From 3225ed3b36cf5d45c5c9785ec6cacd6e07119c18 Mon Sep 17 00:00:00 2001 From: Gyubin Han Date: Mon, 5 Jan 2026 01:35:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Navigation=20Drawer(=ED=96=84=EB=B2=84?= =?UTF-8?q?=EA=B1=B0=20=EB=A9=94=EB=89=B4)=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/file/explorer/MainActivity.java | 89 ++++++++++++++----- app/src/main/res/layout/activity_main.xml | 56 ++++++++---- app/src/main/res/layout/nav_header.xml | 23 +++++ app/src/main/res/menu/drawer_menu.xml | 15 ++++ app/src/main/res/values/strings.xml | 2 + 5 files changed, 143 insertions(+), 42 deletions(-) create mode 100644 app/src/main/res/layout/nav_header.xml create mode 100644 app/src/main/res/menu/drawer_menu.xml diff --git a/app/src/main/java/be/gyu/android/file/explorer/MainActivity.java b/app/src/main/java/be/gyu/android/file/explorer/MainActivity.java index df2cf8c..1c4a5eb 100644 --- a/app/src/main/java/be/gyu/android/file/explorer/MainActivity.java +++ b/app/src/main/java/be/gyu/android/file/explorer/MainActivity.java @@ -1,32 +1,75 @@ package be.gyu.android.file.explorer; // ... (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 { +public class MainActivity extends AppCompatActivity implements FileAdapter.OnItemClickListener, FileAdapter.OnItemLongClickListener, NavigationView.OnNavigationItemSelectedListener { - // ... (variables) + // ... (other variables) + private DrawerLayout drawerLayout; + private ActionBarDrawerToggle drawerToggle; - // --- FTP Methods --- - private void connectAndLoadFtpFiles() { - setTitle("Connecting to " + remoteServer.getHost()); - new Thread(() -> { - boolean success = ftpHelper.connect(remoteServer.getHost(), remoteServer.getPort(), remoteServer.getUsername(), remoteServer.getPassword()); - runOnUiThread(() -> { - if (success) { - Toast.makeText(MainActivity.this, "Connected", Toast.LENGTH_SHORT).show(); - String initialPath = remoteServer.getInitialPath(); - if (initialPath != null && !initialPath.isEmpty()) { - loadFtpFiles(initialPath); - } else { - loadFtpFiles("/"); - } - } else { - Toast.makeText(MainActivity.this, "Connection Failed", Toast.LENGTH_LONG).show(); - finish(); // Close activity if connection fails - } - }); - }).start(); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Toolbar toolbar = findViewById(R.id.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); + + // ... (rest of onCreate) } - // ... (rest of the file remains the same) + private void setupDrawerContent(NavigationView navigationView) { + Menu menu = navigationView.getMenu(); + SubMenu storageMenu = menu.findItem(R.id.group_storage).getSubMenu(); + storageMenu.clear(); + + StorageManager storageManager = (StorageManager) getSystemService(STORAGE_SERVICE); + List storageVolumes = storageManager.getStorageVolumes(); + + for (int i = 0; i < storageVolumes.size(); i++) { + StorageVolume volume = storageVolumes.get(i); + if (volume.getState().equals(Environment.MEDIA_MOUNTED)) { + File path = volume.getDirectory(); + if (path != null) { + MenuItem item = storageMenu.add(Menu.NONE, i, Menu.NONE, volume.getDescription(this)); + item.setIcon(R.drawable.ic_storage); + item.setOnMenuItemClickListener(menuItem -> { + loadFiles(path); + drawerLayout.closeDrawers(); + return true; + }); + } + } + } + } + + @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) } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6b38c8f..91b0b4c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,31 +1,49 @@ - + android:fitsSystemWindows="true" + tools:openDrawer="start"> - + + android:layout_height="match_parent"> - + android:layout_height="wrap_content" + app:layout_constraintTop_toTopOf="parent"> - + - + - \ No newline at end of file + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/nav_header.xml b/app/src/main/res/layout/nav_header.xml new file mode 100644 index 0000000..aa9423b --- /dev/null +++ b/app/src/main/res/layout/nav_header.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/drawer_menu.xml b/app/src/main/res/menu/drawer_menu.xml new file mode 100644 index 0000000..d6de599 --- /dev/null +++ b/app/src/main/res/menu/drawer_menu.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d753e7a..f4714c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ Gyub_s File Explorer + Open navigation drawer + Close navigation drawer \ No newline at end of file