diff --git a/app/src/main/java/com/itsaky/androidide/fragments/sidebar/BulidVariantsFragment.kt b/app/src/main/java/com/itsaky/androidide/fragments/sidebar/BulidVariantsFragment.kt new file mode 100644 index 000000000..a46b7cd64 --- /dev/null +++ b/app/src/main/java/com/itsaky/androidide/fragments/sidebar/BulidVariantsFragment.kt @@ -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 . + */ + +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 { +} \ No newline at end of file diff --git a/app/src/main/java/com/itsaky/androidide/utils/EditorSidebarActions.kt b/app/src/main/java/com/itsaky/androidide/utils/EditorSidebarActions.kt index aa8aaaf1d..ca44da911 100644 --- a/app/src/main/java/com/itsaky/androidide/utils/EditorSidebarActions.kt +++ b/app/src/main/java/com/itsaky/androidide/utils/EditorSidebarActions.kt @@ -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 { diff --git a/app/src/main/res/layout/fragment_editor_sidebar.xml b/app/src/main/res/layout/fragment_editor_sidebar.xml index 8027d2b29..3e787d3de 100644 --- a/app/src/main/res/layout/fragment_editor_sidebar.xml +++ b/app/src/main/res/layout/fragment_editor_sidebar.xml @@ -17,6 +17,7 @@ @@ -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" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_editor_file_tree.xml b/app/src/main/res/layout/layout_editor_file_tree.xml index 1e441523e..348394ce7 100755 --- a/app/src/main/res/layout/layout_editor_file_tree.xml +++ b/app/src/main/res/layout/layout_editor_file_tree.xml @@ -1,9 +1,10 @@ - + android:paddingBottom="16dp" + android:paddingStart="16dp" + android:paddingEnd="16dp">