mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-15 08:50:35 +03:00
Merge branch 'material190' into 'develop'
Upgrade material to 1.9.0 See merge request ultrasonic/ultrasonic!1009
This commit is contained in:
commit
f68eee5233
@ -12,7 +12,7 @@ preferences = "1.2.0"
|
||||
media3 = "1.0.2"
|
||||
|
||||
androidSupport = "1.6.0"
|
||||
materialDesign = "1.8.0"
|
||||
materialDesign = "1.9.0"
|
||||
constraintLayout = "2.1.4"
|
||||
multidex = "2.0.1"
|
||||
room = "2.5.1"
|
||||
|
@ -33,6 +33,7 @@
|
||||
android:supportsRtl="false"
|
||||
android:preserveLegacyExternalStorage="true"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<!-- Add for API 34 android:enableOnBackInvokedCallBack="true" -->
|
||||
|
||||
<meta-data android:name="com.google.android.gms.car.application"
|
||||
android:resource="@xml/automotive_app_desc"/>
|
||||
|
@ -21,6 +21,7 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -51,7 +52,6 @@ import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.app.UApp
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.data.ServerSettingDao
|
||||
import org.moire.ultrasonic.fragment.OnBackPressedHandler
|
||||
import org.moire.ultrasonic.model.ServerSettingsModel
|
||||
import org.moire.ultrasonic.provider.SearchSuggestionProvider
|
||||
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport
|
||||
@ -126,6 +126,8 @@ class NavigationActivity : AppCompatActivity() {
|
||||
navigationView = findViewById(R.id.nav_view)
|
||||
drawerLayout = findViewById(R.id.drawer_layout)
|
||||
|
||||
setupDrawerLayout(drawerLayout!!)
|
||||
|
||||
val toolbar = findViewById<Toolbar>(R.id.toolbar)
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
@ -212,6 +214,27 @@ class NavigationActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupDrawerLayout(drawerLayout: DrawerLayout) {
|
||||
onBackPressedDispatcher.addCallback(this, closeNavigationDrawerOnBack)
|
||||
drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener {
|
||||
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
override fun onDrawerOpened(drawerView: View) {
|
||||
closeNavigationDrawerOnBack.isEnabled = true
|
||||
}
|
||||
|
||||
override fun onDrawerClosed(drawerView: View) {
|
||||
closeNavigationDrawerOnBack.isEnabled = false
|
||||
}
|
||||
|
||||
override fun onDrawerStateChanged(newState: Int) {
|
||||
// Nothing
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
Timber.d("onResume called")
|
||||
super.onResume()
|
||||
@ -315,11 +338,18 @@ class NavigationActivity : AppCompatActivity() {
|
||||
|
||||
selectServerButton =
|
||||
navigationView?.getHeaderView(0)?.findViewById(R.id.header_select_server)
|
||||
selectServerButton?.setOnClickListener {
|
||||
val dropDownButton: ImageView? =
|
||||
navigationView?.getHeaderView(0)?.findViewById(R.id.edit_server_button)
|
||||
|
||||
val onClick: (View) -> Unit = {
|
||||
if (drawerLayout?.isDrawerVisible(GravityCompat.START) == true)
|
||||
this.drawerLayout?.closeDrawer(GravityCompat.START)
|
||||
navController.navigate(R.id.serverSelectorFragment)
|
||||
}
|
||||
|
||||
selectServerButton?.setOnClickListener(onClick)
|
||||
dropDownButton?.setOnClickListener(onClick)
|
||||
|
||||
headerBackgroundImage =
|
||||
navigationView?.getHeaderView(0)?.findViewById(R.id.img_header_bg)
|
||||
}
|
||||
@ -328,13 +358,9 @@ class NavigationActivity : AppCompatActivity() {
|
||||
setupActionBarWithNavController(navController, appBarConfig)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (drawerLayout?.isDrawerVisible(GravityCompat.START) == true) {
|
||||
this.drawerLayout?.closeDrawer(GravityCompat.START)
|
||||
} else {
|
||||
val currentFragment = host!!.childFragmentManager.fragments.last()
|
||||
if (currentFragment is OnBackPressedHandler) currentFragment.onBackPressed()
|
||||
else super.onBackPressed()
|
||||
private val closeNavigationDrawerOnBack = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
drawerLayout?.closeDrawer(GravityCompat.START)
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,17 +378,12 @@ class NavigationActivity : AppCompatActivity() {
|
||||
super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
// TODO: Why is this needed? Shouldn't it just work by default?
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
val currentFragment = host!!.childFragmentManager.fragments.last()
|
||||
return if (currentFragment is OnBackPressedHandler) {
|
||||
currentFragment.onBackPressed()
|
||||
true
|
||||
} else {
|
||||
findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration)
|
||||
}
|
||||
return findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration)
|
||||
}
|
||||
|
||||
// TODO Test if this works with external Intents
|
||||
// TODO: Test if this works with external Intents
|
||||
// android.intent.action.SEARCH and android.media.action.MEDIA_PLAY_FROM_SEARCH calls here
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
|
@ -7,12 +7,14 @@
|
||||
|
||||
package org.moire.ultrasonic.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -52,7 +54,7 @@ private const val DIALOG_PADDING = 12
|
||||
/**
|
||||
* Displays a form where server settings can be created / edited
|
||||
*/
|
||||
class EditServerFragment : Fragment(), OnBackPressedHandler {
|
||||
class EditServerFragment : Fragment() {
|
||||
|
||||
private val serverSettingsModel: ServerSettingsModel by viewModel()
|
||||
private val activeServerProvider: ActiveServerProvider by inject()
|
||||
@ -82,6 +84,13 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
requireActivity().onBackPressedDispatcher.addCallback(
|
||||
this, confirmCloseCallback
|
||||
)
|
||||
super.onAttach(context)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@ -189,11 +198,25 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private val confirmCloseCallback = object : OnBackPressedCallback(
|
||||
true // default to enabled
|
||||
) {
|
||||
override fun handleOnBackPressed() {
|
||||
finishActivity()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Util.hideKeyboard(activity)
|
||||
confirmCloseCallback.isEnabled = false
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
confirmCloseCallback.isEnabled = true
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
private fun correctServerAddress() {
|
||||
serverAddressEditText?.editText?.setText(
|
||||
serverAddressEditText?.editText?.text?.trim(' ', '/')
|
||||
@ -206,11 +229,6 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
||||
image?.setTint(currentColor)
|
||||
serverColorImageView?.background = image
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
finishActivity()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||
savedInstanceState.putString(
|
||||
::serverNameEditText.name, serverNameEditText!!.editText?.text.toString()
|
||||
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* OnBackPressedHandler.kt
|
||||
* Copyright (C) 2009-2022 Ultrasonic developers
|
||||
*
|
||||
* Distributed under terms of the GNU GPLv3 license.
|
||||
*/
|
||||
|
||||
package org.moire.ultrasonic.fragment
|
||||
|
||||
/**
|
||||
* Interface for fragments handling their own Back button
|
||||
*/
|
||||
interface OnBackPressedHandler {
|
||||
fun onBackPressed()
|
||||
}
|
5
ultrasonic/src/main/res/drawable/arrow_drop_down.xml
Normal file
5
ultrasonic/src/main/res/drawable/arrow_drop_down.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7,10l5,5 5,-5z"/>
|
||||
</vector>
|
@ -42,6 +42,7 @@
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
a:id="@+id/nav_view"
|
||||
a:layout_width="wrap_content"
|
||||
a:maxWidth="300dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_gravity="start"
|
||||
a:fitsSystemWindows="true"
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
a:id="@+id/view_container"
|
||||
@ -13,19 +12,18 @@
|
||||
a:id="@+id/img_header_bg"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"
|
||||
a:importantForAccessibility="no"
|
||||
a:scaleType="fitXY"
|
||||
a:src="@drawable/ic_header_bg"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
a:importantForAccessibility="no" />
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
a:id="@+id/header_select_server"
|
||||
style="@style/Widget.Material3.Button.TextButton.Icon"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_marginStart="3dp"
|
||||
a:layout_marginTop="24dp"
|
||||
a:layout_marginTop="48dp"
|
||||
a:background="@drawable/default_ripple"
|
||||
a:gravity="center_vertical"
|
||||
a:paddingHorizontal="22dp"
|
||||
@ -39,9 +37,27 @@
|
||||
app:iconPadding="12dp"
|
||||
app:iconSize="24dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/edit_server_button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:iconTint="@color/selected_menu_dark"
|
||||
tools:textColor="@color/selected_menu_dark" />
|
||||
|
||||
<ImageView
|
||||
a:id="@+id/edit_server_button"
|
||||
style="@style/Widget.Material3.Button.TextButton.Icon"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="0dp"
|
||||
a:layout_marginTop="6dp"
|
||||
a:layout_marginBottom="6dp"
|
||||
a:contentDescription="@string/server_menu.edit"
|
||||
a:maxHeight="32dp"
|
||||
a:src="@drawable/arrow_drop_down"
|
||||
a:text="@null"
|
||||
app:layout_constraintBottom_toBottomOf="@id/header_select_server"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/header_select_server"
|
||||
app:layout_constraintTop_toTopOf="@id/header_select_server"
|
||||
app:tint="@color/selected_menu_dark" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user