mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(sidebar): add title for sidebar fragments
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.fragments.sidebar
|
||||
|
||||
import com.itsaky.androidide.fragments.EmptyStateFragment
|
||||
import com.itsaky.androidide.fragments.RecyclerViewFragment
|
||||
|
||||
/**
|
||||
* A fragment to show the list of modules and the selected build variants in the
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
class BulidVariantsFragment {
|
||||
}
|
||||
@@ -18,6 +18,10 @@
|
||||
package com.itsaky.androidide.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.core.view.forEach
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavDestination
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
@@ -27,7 +31,6 @@ import androidx.navigation.fragment.FragmentNavigatorDestinationBuilder
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.get
|
||||
import androidx.navigation.navOptions
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.google.android.material.shape.CornerFamily
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.google.android.material.shape.ShapeAppearanceModel
|
||||
@@ -42,6 +45,7 @@ import com.itsaky.androidide.actions.sidebar.FileTreeSidebarAction
|
||||
import com.itsaky.androidide.actions.sidebar.PreferencesSidebarAction
|
||||
import com.itsaky.androidide.actions.sidebar.TerminalSidebarAction
|
||||
import com.itsaky.androidide.fragments.sidebar.EditorSidebarFragment
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
|
||||
/**
|
||||
@@ -144,10 +148,35 @@ internal object EditorSidebarActions {
|
||||
}
|
||||
}
|
||||
|
||||
rail.setupWithNavController(controller)
|
||||
val railRef = WeakReference(rail)
|
||||
val titleRef = WeakReference(binding.title)
|
||||
controller.addOnDestinationChangedListener(
|
||||
object : NavController.OnDestinationChangedListener {
|
||||
override fun onDestinationChanged(
|
||||
controller: NavController,
|
||||
destination: NavDestination,
|
||||
arguments: Bundle?
|
||||
) {
|
||||
val railView = railRef.get()
|
||||
if (railView == null) {
|
||||
controller.removeOnDestinationChangedListener(this)
|
||||
return
|
||||
}
|
||||
|
||||
// make sure the 'Home' item is checked by default
|
||||
rail.menu.findItem(FileTreeSidebarAction.ID.hashCode())?.isChecked = true
|
||||
railView.menu.forEach { item ->
|
||||
if (destination.matchDestination(item.itemId)) {
|
||||
item.isChecked = true
|
||||
titleRef.get()?.text = item.title
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// make sure the 'File tree' item is checked by default
|
||||
rail.menu.findItem(FileTreeSidebarAction.ID.hashCode())?.also {
|
||||
it.isChecked = true
|
||||
binding.title.text = it.title
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,6 +188,15 @@ internal object EditorSidebarActions {
|
||||
internal fun NavDestination.matchDestination(route: String): Boolean =
|
||||
hierarchy.any { it.route == route }
|
||||
|
||||
/**
|
||||
* Determines whether the given `destId` matches the NavDestination. This handles
|
||||
* both the default case (the destination's id matches the given id) and the nested case where
|
||||
* the given id is a parent/grandparent/etc of the destination.
|
||||
*/
|
||||
@JvmStatic
|
||||
internal fun NavDestination.matchDestination(@IdRes destId: Int): Boolean =
|
||||
hierarchy.any { it.id == destId }
|
||||
|
||||
@JvmStatic
|
||||
internal fun ShapeAppearanceModel.roundedOnRight(cornerSize: Float = 28f): ShapeAppearanceModel {
|
||||
return toBuilder().run {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorSurfaceContainer">
|
||||
@@ -30,7 +31,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/navigation"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
|
||||
<com.google.android.material.navigationrail.NavigationRailView
|
||||
android:id="@+id/navigation"
|
||||
@@ -43,4 +44,21 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:menuGravity="bottom" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||
app:layout_constraintBottom_toTopOf="@id/fragment_container"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/navigation"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="File tree" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/horizontal_croll"
|
||||
|
||||
Reference in New Issue
Block a user