ui clean up from template

This commit is contained in:
2025-07-24 16:32:10 +05:00
parent cf4e2307b5
commit e2d1e58b78
6 changed files with 38 additions and 50 deletions

View File

@@ -2,48 +2,60 @@ package sh.sar.gridflow
import android.os.Bundle
import android.view.Menu
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.navigation.NavigationView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.drawerlayout.widget.DrawerLayout
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import androidx.drawerlayout.widget.DrawerLayout
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.navigation.NavigationView
import sh.sar.gridflow.databinding.ActivityMainBinding
import sh.sar.gridflow.utils.SecureStorage
class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
private lateinit var secureStorage: SecureStorage
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
secureStorage = SecureStorage(this)
setSupportActionBar(binding.appBarMain.toolbar)
binding.appBarMain.fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null)
.setAnchorView(R.id.fab).show()
}
val drawerLayout: DrawerLayout = binding.drawerLayout
val navView: NavigationView = binding.navView
val navController = findNavController(R.id.nav_host_fragment_content_main)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
// Update navigation header with user info
updateNavHeader(navView)
// Only Home in the navigation
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow
), drawerLayout
setOf(R.id.nav_home), drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
private fun updateNavHeader(navView: NavigationView) {
val headerView = navView.getHeaderView(0)
val nameTextView = headerView.findViewById<TextView>(R.id.nav_header_name)
val mobileTextView = headerView.findViewById<TextView>(R.id.nav_header_mobile)
val emailTextView = headerView.findViewById<TextView>(R.id.nav_header_email)
// Load user info from secure storage
nameTextView.text = secureStorage.getUserName() ?: "User"
mobileTextView.text = secureStorage.getMobile() ?: ""
emailTextView.text = secureStorage.getUserEmail() ?: ""
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.

View File

@@ -22,13 +22,4 @@
<include layout="@layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="16dp"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@@ -21,15 +21,23 @@
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/nav_header_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/nav_header_title"
android:text="Shihaam Abdul Rahman"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:id="@+id/nav_header_mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nav_header_subtitle" />
android:text="9198026" />
<TextView
android:id="@+id/nav_header_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="shihaam_ab_r@outlook.com" />
</LinearLayout>

View File

@@ -8,13 +8,5 @@
android:id="@+id/nav_home"
android:icon="@drawable/ic_menu_camera"
android:title="@string/menu_home" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/ic_menu_gallery"
android:title="@string/menu_gallery" />
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/ic_menu_slideshow"
android:title="@string/menu_slideshow" />
</group>
</menu>

View File

@@ -1,9 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
<!-- Empty menu - no 3-dot menu items -->
</menu>

View File

@@ -11,15 +11,4 @@
android:label="@string/menu_home"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/nav_gallery"
android:name="sh.sar.gridflow.ui.gallery.GalleryFragment"
android:label="@string/menu_gallery"
tools:layout="@layout/fragment_gallery" />
<fragment
android:id="@+id/nav_slideshow"
android:name="sh.sar.gridflow.ui.slideshow.SlideshowFragment"
android:label="@string/menu_slideshow"
tools:layout="@layout/fragment_slideshow" />
</navigation>