Toggle drawer from Assistant screen via menu button

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-15 14:55:00 +02:00 committed by Alper Öztürk
parent afeb87ff78
commit 0200e51eb7
4 changed files with 70 additions and 5 deletions

View file

@ -53,11 +53,14 @@ class ComposeActivity : DrawerActivity() {
val titleId = intent.getIntExtra(TITLE, R.string.empty)
menuItemId = intent.getIntExtra(MENU_ITEM, -1)
setupToolbar()
updateActionBarTitleAndHomeButtonByString(getString(titleId))
if (menuItemId != -1) {
setupDrawer(menuItemId!!)
} else {
setupDrawer()
}
setupToolbarShowOnlyMenuButtonAndTitle(getString(titleId)) {
toggleDrawer()
}
binding.composeView.setContent {
@ -80,7 +83,7 @@ class ComposeActivity : DrawerActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
if (isDrawerOpen) closeDrawer() else openDrawer()
toggleDrawer()
true
}
else -> super.onOptionsItemSelected(item)

View file

@ -506,6 +506,8 @@ public abstract class DrawerActivity extends ToolbarActivity
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
startActivity(intent);
}
closeDrawer();
} else if (itemId == R.id.nav_favorites) {
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH),
menuItem.getItemId());
@ -681,6 +683,14 @@ public abstract class DrawerActivity extends ToolbarActivity
return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START);
}
public void toggleDrawer() {
if (isDrawerOpen()) {
closeDrawer();
} else {
openDrawer();
}
}
/**
* closes the drawer.
*/

View file

@ -104,6 +104,22 @@ public abstract class ToolbarActivity extends BaseActivity implements Injectable
viewThemeUtils.material.colorMaterialTextButton(mSwitchAccountButton);
}
public void setupToolbarShowOnlyMenuButtonAndTitle(String title, View.OnClickListener toggleDrawer) {
setupToolbar(false, false);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
}
LinearLayout toolbar = findViewById(R.id.toolbar_linear_layout);
MaterialButton menuButton = findViewById(R.id.toolbar_menu_button);
MaterialTextView titleTextView = findViewById(R.id.toolbar_title);
titleTextView.setText(title);
toolbar.setVisibility(View.VISIBLE);
menuButton.setOnClickListener(toggleDrawer);
}
public void setupToolbar() {
setupToolbar(false, false);
}

View file

@ -114,6 +114,42 @@
</RelativeLayout>
<LinearLayout
android:id="@+id/toolbar_linear_layout"
android:visibility="gone"
tools:visibility="visible"
android:orientation="horizontal"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="@+id/toolbar_menu_button"
style="@style/Widget.AppTheme.Button.IconButton"
android:layout_width="48dp"
android:layout_height="48dp"
app:cornerRadius="@dimen/button_corner_radius"
app:icon="@drawable/ic_menu"
app:iconTint="@color/black" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/toolbar_title"
android:gravity="center"
android:textColor="@color/black"
android:lines="1"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="48dp"/>
</LinearLayout>
<!-- home/search toolbar -->
<com.google.android.material.card.MaterialCardView
android:id="@+id/home_toolbar"