Skip to content

Commit

Permalink
feat add drawer menu functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
root14 committed May 18, 2023
1 parent 471196f commit de62a59
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies {
kapt "androidx.room:room-compiler:2.5.1"
implementation 'androidx.room:room-ktx:2.5.1'

//Glider
//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
kapt 'com.github.bumptech.glide:compiler:4.12.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import androidx.activity.viewModels
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.viewModelScope
import androidx.navigation.Navigation
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import com.google.android.material.navigation.NavigationView
import com.root14.flashlightappsmarket.databinding.ActivityMainBinding
import com.root14.flashlightappsmarket.model.CategoryType
import com.root14.flashlightappsmarket.view.ui.mainFragment.MainFragmentDirections
import com.root14.flashlightappsmarket.viewmodel.ApplicationFragmentViewModel
import com.root14.flashlightappsmarket.viewmodel.MainFragmentViewModel
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -29,7 +35,6 @@ class MainActivity : AppCompatActivity() {
val view = binding.root
setContentView(view)


//drawer layout
drawerLayout = binding.myDrawerLayout
actionBarDrawerToggle =
Expand All @@ -40,6 +45,44 @@ class MainActivity : AppCompatActivity() {

//action bar
supportActionBar?.setDisplayHomeAsUpEnabled(true)

val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as NavHostFragment
val navController = navHostFragment.navController

//drawer menu
binding.navigationView.setNavigationItemSelectedListener { item ->
val action = MainFragmentDirections.actionMainFragmentToApplicationFragment()
when (item.itemId) {
R.id.menu_flashlights -> {

action.categoryType = CategoryType.FLASHLIGHTS
navController.navigate(action)
drawerLayout.closeDrawers()
true
}

R.id.menu_colored_lights -> {
action.categoryType = CategoryType.COLOREDLIGHTS
navController.navigate(action)
drawerLayout.closeDrawers()
true
}

R.id.menu_sos_alerts -> {
action.categoryType = CategoryType.SOSALERTS
navController.navigate(action)
drawerLayout.closeDrawers()
true
}

else -> {
//TODO: not implemented yet
true
}
}

}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:src="@drawable/baseline_refresh_24"
app:layout_anchor="@id/fragmentContainerView"
app:layout_anchorGravity="bottom|end"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"/>
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior" />


<androidx.fragment.app.FragmentContainerView
Expand All @@ -32,6 +32,7 @@
<!-- Navigation Drawer'ı çizip gösteren NavigationView -->
<!-- menu kısmında oluşturulan menüyü içerir -->
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
Expand Down

0 comments on commit de62a59

Please sign in to comment.