MainActivity: Use NavigationRail on large screen devices
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -55,7 +55,4 @@ object Constants {
|
||||
const val PAGE_TYPE = "PAGE_TYPE"
|
||||
const val TOP_CHART_TYPE = "TOP_CHART_TYPE"
|
||||
const val TOP_CHART_CATEGORY = "TOP_CHART_CATEGORY"
|
||||
|
||||
//NAVIGATION
|
||||
const val NAVIGATION_UPDATES = "NAVIGATION_UPDATES"
|
||||
}
|
||||
|
||||
@@ -31,16 +31,15 @@ import androidx.navigation.FloatingWindow
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.accentColor
|
||||
import com.aurora.extensions.applyThemeAccent
|
||||
import com.aurora.store.data.model.NetworkStatus
|
||||
import com.aurora.store.data.providers.NetworkProvider
|
||||
import com.aurora.store.databinding.ActivityMainBinding
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB
|
||||
import com.aurora.store.view.ui.sheets.NetworkDialogSheet
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -94,7 +93,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
B.navView.apply {
|
||||
(B.navView as NavigationBarView).apply {
|
||||
val alphaColor = ColorUtils.setAlphaComponent(this@MainActivity.accentColor(), 100)
|
||||
setupWithNavController(navController)
|
||||
itemActiveIndicatorColor = ColorStateList.valueOf(alphaColor)
|
||||
@@ -121,12 +120,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle intents
|
||||
when (intent?.action) {
|
||||
Constants.NAVIGATION_UPDATES -> B.navView.selectedItemId = R.id.updatesFragment
|
||||
else -> Log.i("Unhandled intent action: ${intent.action}")
|
||||
}
|
||||
|
||||
// Handle views on fragments
|
||||
navController.addOnDestinationChangedListener { _, navDestination, _ ->
|
||||
if (navDestination !is FloatingWindow) {
|
||||
|
||||
@@ -213,14 +213,11 @@ object NotificationUtil {
|
||||
}
|
||||
|
||||
fun getUpdateNotification(context: Context, updatesList: List<App>): Notification {
|
||||
val contentIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
Intent(context, MainActivity::class.java).apply {
|
||||
action = Constants.NAVIGATION_UPDATES
|
||||
},
|
||||
PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val contentIntent = NavDeepLinkBuilder(context)
|
||||
.setGraph(R.navigation.mobile_navigation)
|
||||
.setDestination(R.id.updatesFragment)
|
||||
.setComponentName(MainActivity::class.java)
|
||||
.createPendingIntent()
|
||||
|
||||
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPDATES)
|
||||
.setSmallIcon(R.drawable.ic_updates)
|
||||
|
||||
30
app/src/main/res/layout-sw600dp/activity_main.xml
Normal file
30
app/src/main/res/layout-sw600dp/activity_main.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/nav_view"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:navGraph="@navigation/mobile_navigation" />
|
||||
|
||||
<com.google.android.material.navigationrail.NavigationRailView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
app:headerLayout="@layout/layout_nav_header"
|
||||
app:labelVisibilityMode="labeled"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:menu="@menu/menu_bottom_nav"
|
||||
app:menuGravity="center" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
33
app/src/main/res/layout/layout_nav_header.xml
Normal file
33
app/src/main/res/layout/layout_nav_header.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Aurora Store
|
||||
~ Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
~
|
||||
~ Aurora Store 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 2 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ Aurora Store 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 Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
~
|
||||
-->
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/nav_header_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/img"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
android:layout_width="@dimen/icon_size_small"
|
||||
android:layout_height="@dimen/icon_size_small"
|
||||
app:srcCompat="@drawable/bg_placeholder" />
|
||||
</RelativeLayout>
|
||||
Reference in New Issue
Block a user