feat: Navigation Drawer(햄버거 메뉴) 구현
This commit is contained in:
@@ -1,32 +1,75 @@
|
|||||||
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 {
|
public class MainActivity extends AppCompatActivity implements FileAdapter.OnItemClickListener, FileAdapter.OnItemLongClickListener, NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
// ... (variables)
|
// ... (other variables)
|
||||||
|
private DrawerLayout drawerLayout;
|
||||||
|
private ActionBarDrawerToggle drawerToggle;
|
||||||
|
|
||||||
// --- FTP Methods ---
|
@Override
|
||||||
private void connectAndLoadFtpFiles() {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
setTitle("Connecting to " + remoteServer.getHost());
|
super.onCreate(savedInstanceState);
|
||||||
new Thread(() -> {
|
setContentView(R.layout.activity_main);
|
||||||
boolean success = ftpHelper.connect(remoteServer.getHost(), remoteServer.getPort(), remoteServer.getUsername(), remoteServer.getPassword());
|
|
||||||
runOnUiThread(() -> {
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
if (success) {
|
setSupportActionBar(toolbar);
|
||||||
Toast.makeText(MainActivity.this, "Connected", Toast.LENGTH_SHORT).show();
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
String initialPath = remoteServer.getInitialPath();
|
|
||||||
if (initialPath != null && !initialPath.isEmpty()) {
|
drawerLayout = findViewById(R.id.drawer_layout);
|
||||||
loadFtpFiles(initialPath);
|
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
|
||||||
} else {
|
drawerLayout.addDrawerListener(drawerToggle);
|
||||||
loadFtpFiles("/");
|
drawerToggle.syncState();
|
||||||
}
|
|
||||||
} else {
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
Toast.makeText(MainActivity.this, "Connection Failed", Toast.LENGTH_LONG).show();
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
finish(); // Close activity if connection fails
|
|
||||||
}
|
setupDrawerContent(navigationView);
|
||||||
});
|
|
||||||
}).start();
|
// ... (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<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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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)
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,49 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/drawer_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
android:fitsSystemWindows="true"
|
||||||
|
tools:openDrawer="start">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<!-- Main Content -->
|
||||||
android:id="@+id/appBarLayout"
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent">
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/appBarLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize" />
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
android:id="@+id/recyclerView"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/appBarLayout" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerView"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/appBarLayout" />
|
||||||
|
|
||||||
|
</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>
|
||||||
23
app/src/main/res/layout/nav_header.xml
Normal file
23
app/src/main/res/layout/nav_header.xml
Normal 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>
|
||||||
15
app/src/main/res/menu/drawer_menu.xml
Normal file
15
app/src/main/res/menu/drawer_menu.xml
Normal 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>
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Gyub_s File Explorer</string>
|
<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>
|
</resources>
|
||||||
Reference in New Issue
Block a user