feat: Navigation Drawer(햄버거 메뉴) 구현

This commit is contained in:
2026-01-05 01:35:25 +09:00
parent 0b7e72c9b1
commit 3225ed3b36
5 changed files with 143 additions and 42 deletions

View File

@@ -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
@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)
}
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<StorageVolume> 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;
});
}).start();
}
}
}
}
// ... (rest of the file remains the same)
@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)
}

View File

@@ -1,10 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:fitsSystemWindows="true"
tools:openDrawer="start">
<!-- Main Content -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
@@ -28,4 +35,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appBarLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- Navigation Drawer -->
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="176dp"
android:background="?attr/colorPrimaryVariant"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</LinearLayout>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/group_storage">
<!-- Storage volumes will be added here dynamically -->
</group>
<item android:title="Remote">
<menu>
<item
android:id="@+id/nav_remote_storage"
android:icon="@drawable/ic_storage"
android:title="Remote Storages" />
</menu>
</item>
</menu>

View File

@@ -1,3 +1,5 @@
<resources>
<string name="app_name">Gyub_s File Explorer</string>
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
</resources>