Colored dialog button is now handled by the theme

This commit is contained in:
Benoit Marty 2021-06-23 13:27:55 +02:00
parent 67bdb75d80
commit 11b16ea065
13 changed files with 33 additions and 85 deletions

View file

@ -50,11 +50,15 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() {
}
views.debugShowDialog.setOnClickListener {
showTestDialog(false)
showTestDialog(0)
}
views.debugShowDialogDestructive.setOnClickListener {
showTestDialog(true)
showTestDialog(R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
}
views.debugShowDialogNegativeDestructive.setOnClickListener {
showTestDialog(R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
}
views.debugShowBottomSheet.setOnClickListener {
@ -62,8 +66,8 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() {
}
}
private fun showTestDialog(destructive: Boolean) {
MaterialAlertDialogBuilder(this, if (destructive) R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive else 0)
private fun showTestDialog(theme: Int) {
MaterialAlertDialogBuilder(this, theme)
.setTitle("Dialog title")
.setMessage("Dialog content")
.setIcon(R.drawable.ic_debug_icon)

View file

@ -459,6 +459,13 @@
android:layout_gravity="center_horizontal"
android:text="Show Dialog Destructive" />
<Button
android:id="@+id/debugShowDialogNegativeDestructive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Show Dialog Neg Destructive" />
<Button
android:id="@+id/debugShowBottomSheet"
android:layout_width="wrap_content"

View file

@ -7,6 +7,10 @@
<item name="buttonBarPositiveButtonStyle">@style/Widget.Vector.Button.TextButton.Dialog.Destructive</item>
</style>
<style name="ThemeOverlay.Vector.MaterialAlertDialog.NegativeDestructive">
<item name="buttonBarNegativeButtonStyle">@style/Widget.Vector.Button.TextButton.Dialog.Destructive</item>
</style>
<style name="Widget.Vector.Button.TextButton.Dialog" parent="Widget.MaterialComponents.Button.TextButton.Dialog" />
<style name="Widget.Vector.Button.TextButton.Dialog.Destructive">

View file

@ -1,27 +0,0 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.core.dialogs
import androidx.annotation.AttrRes
import androidx.appcompat.app.AlertDialog
import im.vector.app.R
import im.vector.app.features.themes.ThemeUtils
fun AlertDialog.withColoredButton(whichButton: Int, @AttrRes color: Int = R.attr.colorError): AlertDialog {
getButton(whichButton)?.setTextColor(ThemeUtils.getColor(context, color))
return this
}

View file

@ -18,7 +18,6 @@ package im.vector.app.features.home.room.detail
import android.annotation.SuppressLint
import android.app.Activity
import android.content.DialogInterface
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
@ -75,7 +74,6 @@ import com.vanniktech.emoji.EmojiPopup
import im.vector.app.R
import im.vector.app.core.dialogs.ConfirmationDialogBuilder
import im.vector.app.core.dialogs.GalleryOrCameraDialogHelper
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.epoxy.LayoutManagerStateRestorer
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.exhaustive
@ -1410,7 +1408,7 @@ class RoomDetailFragment @Inject constructor(
is RoomDetailAction.ReportContent -> {
when {
data.spam -> {
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
.setTitle(R.string.content_reported_as_spam_title)
.setMessage(R.string.content_reported_as_spam_content)
.setPositiveButton(R.string.ok, null)
@ -1418,10 +1416,9 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(data.senderId))
}
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
}
data.inappropriate -> {
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
.setTitle(R.string.content_reported_as_inappropriate_title)
.setMessage(R.string.content_reported_as_inappropriate_content)
.setPositiveButton(R.string.ok, null)
@ -1429,10 +1426,9 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(data.senderId))
}
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
}
else -> {
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
.setTitle(R.string.content_reported_title)
.setMessage(R.string.content_reported_content)
.setPositiveButton(R.string.ok, null)
@ -1440,7 +1436,6 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(data.senderId))
}
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
}
}
}
@ -1502,7 +1497,7 @@ class RoomDetailFragment @Inject constructor(
.subscribe { managed ->
if (!managed) {
if (title.isValidUrl() && url.isValidUrl() && URL(title).host != URL(url).host) {
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
.setTitle(R.string.external_link_confirmation_title)
.setMessage(
getString(R.string.external_link_confirmation_message, title, url)
@ -1515,7 +1510,6 @@ class RoomDetailFragment @Inject constructor(
}
.setNegativeButton(R.string.cancel, null)
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
} else {
// Open in external browser, in a new Tab
openUrlInExternalBrowser(requireContext(), url)
@ -1868,7 +1862,7 @@ class RoomDetailFragment @Inject constructor(
}
private fun askConfirmationToIgnoreUser(senderId: String) {
MaterialAlertDialogBuilder(requireContext())
MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.room_participants_action_ignore_title)
.setMessage(R.string.room_participants_action_ignore_prompt_msg)
.setNegativeButton(R.string.cancel, null)
@ -1876,7 +1870,6 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(senderId))
}
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
/**

View file

@ -16,7 +16,6 @@
package im.vector.app.features.home.room.list
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -34,7 +33,6 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.epoxy.LayoutManagerStateRestorer
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.exhaustive
@ -386,7 +384,7 @@ class RoomListFragment @Inject constructor(
append(getString(R.string.room_participants_leave_private_warning))
}
}
MaterialAlertDialogBuilder(requireContext())
MaterialAlertDialogBuilder(requireContext(), if (isPublicRoom) 0 else R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(message)
.setPositiveButton(R.string.leave) { _, _ ->
@ -394,11 +392,6 @@ class RoomListFragment @Inject constructor(
}
.setNegativeButton(R.string.cancel, null)
.show()
.apply {
if (!isPublicRoom) {
withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}
}
override fun invalidate() = withState(roomListViewModel) { state ->

View file

@ -17,7 +17,6 @@
package im.vector.app.features.roomprofile
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -33,7 +32,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.animations.AppBarStateChangeListener
import im.vector.app.core.animations.MatrixItemAppBarStateChangeListener
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.copyOnLongClick
@ -268,7 +266,7 @@ class RoomProfileFragment @Inject constructor(
append(getString(R.string.room_participants_leave_private_warning))
}
}
MaterialAlertDialogBuilder(requireContext())
MaterialAlertDialogBuilder(requireContext(), if (isPublicRoom) 0 else R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(message)
.setPositiveButton(R.string.leave) { _, _ ->
@ -276,11 +274,6 @@ class RoomProfileFragment @Inject constructor(
}
.setNegativeButton(R.string.cancel, null)
.show()
.apply {
if (!isPublicRoom) {
withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}
}
override fun onRoomAliasesClicked() {

View file

@ -16,7 +16,6 @@
package im.vector.app.features.roomprofile.alias
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -27,7 +26,6 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.exhaustive
@ -133,7 +131,7 @@ class RoomAliasFragment @Inject constructor(
}
private fun unpublishAlias(alias: String) {
MaterialAlertDialogBuilder(requireContext())
MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.dialog_title_confirmation)
.setMessage(getString(R.string.room_alias_unpublish_confirmation, alias))
.setNegativeButton(R.string.cancel, null)
@ -141,7 +139,6 @@ class RoomAliasFragment @Inject constructor(
viewModel.handle(RoomAliasAction.UnpublishAlias(alias))
}
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
override fun toggleManualPublishForm() {
@ -185,7 +182,7 @@ class RoomAliasFragment @Inject constructor(
}
private fun removeLocalAlias(alias: String) {
MaterialAlertDialogBuilder(requireContext())
MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.dialog_title_confirmation)
.setMessage(getString(R.string.room_alias_delete_confirmation, alias))
.setNegativeButton(R.string.cancel, null)
@ -193,6 +190,5 @@ class RoomAliasFragment @Inject constructor(
viewModel.handle(RoomAliasAction.RemoveLocalAlias(alias))
}
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}

View file

@ -16,7 +16,6 @@
package im.vector.app.features.settings.devtools
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -26,7 +25,6 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
@ -85,7 +83,7 @@ class AccountDataFragment @Inject constructor(
}
override fun didLongTap(data: UserAccountDataEvent) {
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.delete)
.setMessage(getString(R.string.delete_account_data_warning, data.type))
.setNegativeButton(R.string.cancel, null)
@ -93,6 +91,5 @@ class AccountDataFragment @Inject constructor(
viewModel.handle(AccountDataAction.DeleteAccountData(data.type))
}
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}

View file

@ -17,7 +17,6 @@
package im.vector.app.features.settings.threepids
import android.app.Activity
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -27,7 +26,6 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.exhaustive
@ -192,14 +190,13 @@ class ThreePidsSettingsFragment @Inject constructor(
}
override fun deleteThreePid(threePid: ThreePid) {
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setMessage(getString(R.string.settings_remove_three_pid_confirmation_content, threePid.getFormattedValue()))
.setPositiveButton(R.string.remove) { _, _ ->
viewModel.handle(ThreePidsSettingsAction.DeleteThreePid(threePid))
}
.setNegativeButton(R.string.cancel, null)
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
override fun onBackPressed(toolbarButton: Boolean): Boolean {

View file

@ -16,7 +16,6 @@
package im.vector.app.features.signout.soft
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -25,7 +24,6 @@ import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.hideKeyboard
@ -127,7 +125,7 @@ class SoftLogoutFragment @Inject constructor(
R.string.soft_logout_clear_data_dialog_content
}
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.soft_logout_clear_data_dialog_title)
.setMessage(messageResId)
.setNegativeButton(R.string.cancel, null)
@ -135,7 +133,6 @@ class SoftLogoutFragment @Inject constructor(
softLogoutViewModel.handle(SoftLogoutAction.ClearData)
}
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}

View file

@ -16,7 +16,6 @@
package im.vector.app.features.spaces
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -28,7 +27,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.resources.ColorProvider
@ -174,7 +172,7 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
null
}
MaterialAlertDialogBuilder(requireContext())
MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setMessage(warningMessage)
.setTitle(getString(R.string.space_leave_prompt_msg))
.setPositiveButton(R.string.leave) { _, _ ->
@ -189,7 +187,6 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
}
.setNegativeButton(R.string.cancel, null)
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}

View file

@ -16,7 +16,6 @@
package im.vector.app.features.spaces.explore
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -30,7 +29,6 @@ import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.registerStartForActivityResult
@ -180,7 +178,7 @@ class SpaceDirectoryFragment @Inject constructor(
.subscribe { managed ->
if (!managed) {
if (title.isValidUrl() && url.isValidUrl() && URL(title).host != URL(url).host) {
MaterialAlertDialogBuilder(requireActivity())
MaterialAlertDialogBuilder(requireActivity(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.external_link_confirmation_title)
.setMessage(
getString(R.string.external_link_confirmation_message, title, url)
@ -193,7 +191,6 @@ class SpaceDirectoryFragment @Inject constructor(
}
.setNegativeButton(R.string.cancel, null)
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
} else {
// Open in external browser, in a new Tab
openUrlInExternalBrowser(requireContext(), url)