Finish splitting ViewThemeUtils

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-08-30 15:23:14 +02:00
parent 892cc82ade
commit 05c60ff4b7
No known key found for this signature in database
GPG Key ID: 2585783189A62105
24 changed files with 179 additions and 150 deletions

View File

@ -117,7 +117,7 @@ open class BaseActivity : AppCompatActivity() {
)
val dialogBuilder = MaterialAlertDialogBuilder(this)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_security_white_24dp))
.setIcon(viewThemeUtils.dialog.colorMaterialAlertDialogIcon(context, R.drawable.ic_security_white_24dp))
.setTitle(R.string.nc_certificate_dialog_title)
.setMessage(dialogText)
.setPositiveButton(R.string.nc_yes) { _, _ ->
@ -128,7 +128,7 @@ open class BaseActivity : AppCompatActivity() {
sslErrorHandler?.cancel()
}
viewThemeUtils.material.colorMaterialAlertDialogBackground(context, dialogBuilder)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(context, dialogBuilder)
val dialog = dialogBuilder.show()

View File

@ -143,7 +143,7 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
null));
if (adapter.hasFilter()) {
viewThemeUtils.highlightText(holder.binding.dialogName,
viewThemeUtils.platform.highlightText(holder.binding.dialogName,
conversation.getDisplayName(),
String.valueOf(adapter.getFilter(String.class)));
} else {

View File

@ -22,7 +22,6 @@
package com.nextcloud.talk.adapters.items
import android.content.Context
import android.text.SpannableString
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.talk.R
@ -77,12 +76,11 @@ data class MessageResultItem constructor(
}
private fun bindMessageExcerpt(holder: ViewHolder) {
val highlightedSpan = viewThemeUtils.createHighlightedSpan(
holder.binding.messageExcerpt.context,
SpannableString(messageEntry.messageExcerpt),
viewThemeUtils.platform.highlightText(
holder.binding.messageExcerpt,
messageEntry.messageExcerpt,
messageEntry.searchTerm
)
holder.binding.messageExcerpt.text = highlightedSpan
}
private fun loadImage(holder: ViewHolder) {

View File

@ -1433,7 +1433,7 @@ class ChatController(args: Bundle) :
// unused atm
}
viewThemeUtils.material.colorMaterialAlertDialogBackground(
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
binding.messageInputView.context,
materialAlertDialogBuilder
)

View File

@ -334,7 +334,7 @@ class ContactsController(args: Bundle) :
val searchManager: SearchManager? = activity?.getSystemService(Context.SEARCH_SERVICE) as SearchManager?
if (searchItem != null) {
searchView = MenuItemCompat.getActionView(searchItem) as SearchView
viewThemeUtils.appcompat.themeSearchView(searchView!!)
viewThemeUtils.androidx.themeSearchView(searchView!!)
searchView!!.maxWidth = Int.MAX_VALUE
searchView!!.inputType = InputType.TYPE_TEXT_VARIATION_FILTER
var imeOptions: Int = EditorInfo.IME_ACTION_DONE or EditorInfo.IME_FLAG_NO_FULLSCREEN
@ -629,7 +629,7 @@ class ContactsController(args: Bundle) :
binding.controllerGenericRv.recyclerView.adapter = adapter
binding.controllerGenericRv.swipeRefreshLayout.setOnRefreshListener { fetchData() }
viewThemeUtils.themeSwipeRefreshLayout(binding.controllerGenericRv.swipeRefreshLayout)
viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.controllerGenericRv.swipeRefreshLayout)
binding.joinConversationViaLink.joinConversationViaLinkImageView
.background

View File

@ -191,7 +191,7 @@ class ConversationInfoController(args: Bundle) :
binding.webinarInfoView.conversationInfoLobby,
binding.notificationSettingsView.callNotifications,
binding.notificationSettingsView.conversationInfoPriorityConversation
).forEach(viewThemeUtils::colorSwitchPreference)
).forEach(viewThemeUtils.talk::colorSwitchPreference)
}
}
@ -207,7 +207,7 @@ class ConversationInfoController(args: Bundle) :
categoryConversationSettings,
binding.webinarInfoView.conversationInfoWebinar,
binding.notificationSettingsView.notificationSettingsCategory
).forEach(viewThemeUtils::colorPreferenceCategory)
).forEach(viewThemeUtils.talk::colorPreferenceCategory)
}
}
@ -365,7 +365,7 @@ class ConversationInfoController(args: Bundle) :
private fun showDeleteConversationDialog() {
if (activity != null) {
val dialogBuilder = MaterialAlertDialogBuilder(binding.conversationInfoName.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setIcon(viewThemeUtils.dialog.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setTitle(R.string.nc_delete_call)
.setMessage(R.string.nc_delete_conversation_more)
.setPositiveButton(R.string.nc_delete) { _, _ ->
@ -374,7 +374,7 @@ class ConversationInfoController(args: Bundle) :
.setNegativeButton(R.string.nc_cancel) { _, _ ->
// unused atm
}
viewThemeUtils.material
viewThemeUtils.dialog
.colorMaterialAlertDialogBackground(binding.conversationInfoName.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
@ -537,7 +537,7 @@ class ConversationInfoController(args: Bundle) :
private fun showClearHistoryDialog() {
if (activity != null) {
val dialogBuilder = MaterialAlertDialogBuilder(binding.conversationInfoName.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setIcon(viewThemeUtils.dialog.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setTitle(R.string.nc_clear_history)
.setMessage(R.string.nc_clear_history_warning)
.setPositiveButton(R.string.nc_delete_all) { _, _ ->
@ -546,7 +546,7 @@ class ConversationInfoController(args: Bundle) :
.setNegativeButton(R.string.nc_cancel) { _, _ ->
// unused atm
}
viewThemeUtils.material
viewThemeUtils.dialog
.colorMaterialAlertDialogBackground(binding.conversationInfoName.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(

View File

@ -296,7 +296,7 @@ class ConversationsListController(bundle: Bundle) :
val searchManager = activity!!.getSystemService(Context.SEARCH_SERVICE) as SearchManager?
if (searchItem != null) {
searchView = MenuItemCompat.getActionView(searchItem) as SearchView
viewThemeUtils.appcompat.themeSearchView(searchView!!)
viewThemeUtils.androidx.themeSearchView(searchView!!)
searchView!!.maxWidth = Int.MAX_VALUE
searchView!!.inputType = InputType.TYPE_TEXT_VARIATION_FILTER
var imeOptions = EditorInfo.IME_ACTION_DONE or EditorInfo.IME_FLAG_NO_FULLSCREEN
@ -666,7 +666,7 @@ class ConversationsListController(bundle: Bundle) :
false
}
binding.swipeRefreshLayoutView.setOnRefreshListener { fetchData() }
viewThemeUtils.themeSwipeRefreshLayout(binding.swipeRefreshLayoutView)
viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeRefreshLayoutView)
binding.emptyLayout.setOnClickListener { showNewConversationsScreen() }
binding.floatingActionButton.setOnClickListener {
run(context)
@ -939,7 +939,7 @@ class ConversationsListController(bundle: Bundle) :
)
}
val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.upload))
.setIcon(viewThemeUtils.dialog.colorMaterialAlertDialogIcon(context, R.drawable.upload))
.setTitle(confirmationQuestion)
.setMessage(fileNamesWithLineBreaks.toString())
.setPositiveButton(R.string.nc_yes) { _, _ ->
@ -950,7 +950,7 @@ class ConversationsListController(bundle: Bundle) :
Log.d(TAG, "sharing files aborted, going back to share-to screen")
showShareToScreen = true
}
viewThemeUtils.material
viewThemeUtils.dialog
.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
@ -1131,7 +1131,10 @@ class ConversationsListController(bundle: Bundle) :
val conversation = Parcels.unwrap<Conversation>(conversationMenuBundle!!.getParcelable(KEY_ROOM))
if (conversation != null) {
val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setIcon(
viewThemeUtils.dialog
.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp)
)
.setTitle(R.string.nc_delete_call)
.setMessage(R.string.nc_delete_conversation_more)
.setPositiveButton(R.string.nc_delete) { _, _ ->
@ -1147,7 +1150,7 @@ class ConversationsListController(bundle: Bundle) :
.setNegativeButton(R.string.nc_cancel) { _, _ ->
conversationMenuBundle = null
}
viewThemeUtils.material
viewThemeUtils.dialog
.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
@ -1161,7 +1164,7 @@ class ConversationsListController(bundle: Bundle) :
private fun showUnauthorizedDialog() {
if (activity != null) {
val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setIcon(viewThemeUtils.dialog.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setTitle(R.string.nc_dialog_invalid_password)
.setMessage(R.string.nc_dialog_reauth_or_delete)
.setCancelable(false)
@ -1191,7 +1194,7 @@ class ConversationsListController(bundle: Bundle) :
.popChangeHandler(VerticalChangeHandler())
)
}
viewThemeUtils.material
viewThemeUtils.dialog
.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
@ -1203,7 +1206,7 @@ class ConversationsListController(bundle: Bundle) :
private fun showServerEOLDialog() {
val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_warning_white))
.setIcon(viewThemeUtils.dialog.colorMaterialAlertDialogIcon(context, R.drawable.ic_warning_white))
.setTitle(R.string.nc_settings_server_eol_title)
.setMessage(R.string.nc_settings_server_eol)
.setCancelable(false)
@ -1234,7 +1237,7 @@ class ConversationsListController(bundle: Bundle) :
activity!!.finish()
}
}
viewThemeUtils.material.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),

View File

@ -385,7 +385,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
// unused atm
}
viewThemeUtils.material.colorMaterialAlertDialogBackground(
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
binding.messageText.context,
materialAlertDialogBuilder
)
@ -508,7 +508,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
settingsPhoneBookIntegration,
settingsReadPrivacy,
settingsProxyUseCredentials
).forEach(viewThemeUtils::colorSwitchPreference)
).forEach(viewThemeUtils.talk::colorSwitchPreference)
}
}
@ -520,7 +520,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
settingsAdvancedCategory,
settingsAppearanceCategory,
settingsPrivacyCategory
).forEach(viewThemeUtils::colorPreferenceCategory)
).forEach(viewThemeUtils.talk::colorPreferenceCategory)
}
}
@ -952,7 +952,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
.setPositiveButton(context!!.resources.getString(R.string.nc_common_set), null)
.setNegativeButton(context!!.resources.getString(R.string.nc_common_skip), null)
viewThemeUtils.material.colorMaterialAlertDialogBackground(phoneNumberInputLayout.context, dialogBuilder)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(phoneNumberInputLayout.context, dialogBuilder)
val dialog = dialogBuilder.create()
dialog.setOnShowListener(object : OnShowListener {

View File

@ -41,8 +41,8 @@ class PollResultHeaderViewHolder(
binding.pollOptionText.text = item.name
binding.pollOptionPercentText.text = "${item.percent}%"
viewThemeUtils.colorDialogSupportingText(binding.pollOptionText)
viewThemeUtils.colorDialogSupportingText(binding.pollOptionPercentText)
viewThemeUtils.dialog.colorDialogSupportingText(binding.pollOptionText)
viewThemeUtils.dialog.colorDialogSupportingText(binding.pollOptionPercentText)
if (item.selfVoted) {
binding.pollOptionText.setTypeface(null, Typeface.BOLD)

View File

@ -47,7 +47,7 @@ class PollResultVoterViewHolder(
binding.pollVoterName.text = item.details.actorDisplayName
binding.pollVoterAvatar.controller = getAvatarDraweeController(item.details)
viewThemeUtils.colorDialogSupportingText(binding.pollVoterName)
viewThemeUtils.dialog.colorDialogSupportingText(binding.pollVoterName)
}
private fun getAvatarDraweeController(pollDetail: PollDetails): DraweeController? {

View File

@ -75,7 +75,7 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
val dialogBuilder = MaterialAlertDialogBuilder(binding.root.context)
.setView(binding.root)
viewThemeUtils.material.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)
return dialogBuilder.create()
}

View File

@ -72,13 +72,13 @@ class PollMainDialogFragment : DialogFragment() {
val dialogBuilder = MaterialAlertDialogBuilder(binding.root.context).setView(binding.root)
viewThemeUtils.material.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)
val dialog = dialogBuilder.create()
binding.messagePollTitle.text = viewModel.pollTitle
viewThemeUtils.colorDialogHeadline(binding.messagePollTitle)
viewThemeUtils.colorDialogIcon(binding.messagePollIcon)
viewThemeUtils.dialog.colorDialogHeadline(binding.messagePollTitle)
viewThemeUtils.dialog.colorDialogIcon(binding.messagePollIcon)
return dialog
}
@ -143,7 +143,7 @@ class PollMainDialogFragment : DialogFragment() {
private fun initVotersAmount(showVotersAmount: Boolean, numVoters: Int, showResultSubtitle: Boolean) {
if (showVotersAmount) {
viewThemeUtils.colorDialogSupportingText(binding.pollVotesAmount)
viewThemeUtils.dialog.colorDialogSupportingText(binding.pollVotesAmount)
binding.pollVotesAmount.visibility = View.VISIBLE
binding.pollVotesAmount.text = resources.getQuantityString(
R.plurals.polls_amount_voters,
@ -155,7 +155,7 @@ class PollMainDialogFragment : DialogFragment() {
}
if (showResultSubtitle) {
viewThemeUtils.colorDialogSupportingText(binding.pollResultsSubtitle)
viewThemeUtils.dialog.colorDialogSupportingText(binding.pollResultsSubtitle)
binding.pollResultsSubtitle.visibility = View.VISIBLE
binding.pollResultsSubtitleSeperator.visibility = View.VISIBLE
} else {

View File

@ -132,7 +132,7 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener {
}
.setNegativeButton(R.string.nc_cancel, null)
viewThemeUtils.material.colorMaterialAlertDialogBackground(
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
binding.pollResultsEndPollButton.context,
dialogBuilder
)

View File

@ -215,7 +215,7 @@ class PollVoteFragment : Fragment() {
}
.setNegativeButton(R.string.nc_cancel, null)
viewThemeUtils.material.colorMaterialAlertDialogBackground(
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
binding.pollVoteEndPollButton.context,
dialogBuilder
)

View File

@ -100,7 +100,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
initViewModel(mimeTypeSelectionFilter)
binding.swipeRefreshList.setOnRefreshListener(this)
viewThemeUtils.themeSwipeRefreshLayout(binding.swipeRefreshList)
viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeRefreshList)
binding.pathNavigationBackButton.setOnClickListener { viewModel.navigateUp() }
binding.sortButton.setOnClickListener { changeSorting() }

View File

@ -217,11 +217,11 @@ public class ChooseAccountDialogFragment extends DialogFragment {
viewThemeUtils.platform.themeDialogDivider(binding.divider);
viewThemeUtils.material.colorMaterialTextButton(binding.setStatus);
viewThemeUtils.colorDialogMenuText(binding.setStatus);
viewThemeUtils.dialog.colorDialogMenuText(binding.setStatus);
viewThemeUtils.material.colorMaterialTextButton(binding.addAccount);
viewThemeUtils.colorDialogMenuText(binding.addAccount);
viewThemeUtils.dialog.colorDialogMenuText(binding.addAccount);
viewThemeUtils.material.colorMaterialTextButton(binding.manageSettings);
viewThemeUtils.colorDialogMenuText(binding.manageSettings);
viewThemeUtils.dialog.colorDialogMenuText(binding.manageSettings);
}
private void loadCurrentStatus(User user) {

View File

@ -167,7 +167,7 @@ class SetStatusDialogFragment :
binding = DialogSetStatusBinding.inflate(LayoutInflater.from(context))
val dialogBuilder = MaterialAlertDialogBuilder(binding.root.context).setView(binding.root)
viewThemeUtils.material.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)
return dialogBuilder.create()
}

View File

@ -21,26 +21,13 @@
package com.nextcloud.talk.ui.theme
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.text.Spannable
import android.text.SpannableString
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.DrawableCompat
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.button.MaterialButton
import com.nextcloud.android.common.ui.theme.MaterialSchemes
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
import com.nextcloud.talk.R
import com.nextcloud.talk.ui.theme.viewthemeutils.AndroidViewThemeUtils
import com.nextcloud.talk.ui.theme.viewthemeutils.AppCompatViewThemeUtils
import com.nextcloud.talk.ui.theme.viewthemeutils.AndroidXViewThemeUtils
import com.nextcloud.talk.ui.theme.viewthemeutils.DialogViewThemeUtils
import com.nextcloud.talk.ui.theme.viewthemeutils.MaterialViewThemeUtils
import com.nextcloud.talk.ui.theme.viewthemeutils.TalkSpecificViewThemeUtils
import com.nextcloud.talk.utils.DisplayUtils
import eu.davidea.flexibleadapter.utils.FlexibleUtils
import javax.inject.Inject
@Suppress("TooManyFunctions")
@ -51,62 +38,9 @@ class ViewThemeUtils @Inject constructor(
@JvmField
val material: MaterialViewThemeUtils,
@JvmField
val appcompat: AppCompatViewThemeUtils,
val androidx: AndroidXViewThemeUtils,
@JvmField
val talk: TalkSpecificViewThemeUtils
) : ViewThemeUtilsBase(schemes) {
fun themeSwipeRefreshLayout(swipeRefreshLayout: SwipeRefreshLayout) {
withScheme(swipeRefreshLayout) { scheme ->
swipeRefreshLayout.setColorSchemeColors(scheme.primary)
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.refresh_spinner_background)
}
}
fun colorDialogMenuText(button: MaterialButton) {
withScheme(button) { scheme ->
button.setTextColor(scheme.onSurface)
button.iconTint = ColorStateList.valueOf(scheme.onSurface)
}
}
fun colorDialogHeadline(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurface)
}
}
fun colorDialogSupportingText(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurfaceVariant)
}
}
fun colorDialogIcon(icon: ImageView) {
withScheme(icon) { scheme ->
icon.setColorFilter(scheme.secondary)
}
}
fun highlightText(textView: TextView, originalText: String, constraint: String) {
withScheme(textView) { scheme ->
FlexibleUtils.highlightText(textView, originalText, constraint, scheme.primary)
}
}
fun createHighlightedSpan(context: Context, messageSpannable: SpannableString, searchTerm: String): Spannable {
var spannable: Spannable = messageSpannable
withScheme(context) { scheme ->
spannable = DisplayUtils.searchAndColor(messageSpannable, searchTerm, scheme.primary)
}
return spannable
}
fun colorMaterialAlertDialogIcon(context: Context, drawableId: Int): Drawable {
val drawable = AppCompatResources.getDrawable(context, drawableId)!!
withScheme(context) { scheme ->
DrawableCompat.setTint(drawable, scheme.secondary)
}
return drawable
}
}
val talk: TalkSpecificViewThemeUtils,
@JvmField
val dialog: DialogViewThemeUtils
) : ViewThemeUtilsBase(schemes)

View File

@ -44,6 +44,7 @@ import com.nextcloud.android.common.ui.theme.MaterialSchemes
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
import com.nextcloud.talk.R
import com.nextcloud.talk.utils.DisplayUtils
import eu.davidea.flexibleadapter.utils.FlexibleUtils
import javax.inject.Inject
/**
@ -67,15 +68,18 @@ class AndroidViewThemeUtils @Inject constructor(schemes: MaterialSchemes, privat
fun themeStatusBar(activity: Activity, view: View) {
withScheme(view) { scheme ->
// TODO extract from displayutils to common
DisplayUtils.applyColorToStatusBar(activity, scheme.surface)
}
}
fun resetStatusBar(activity: Activity, view: View) {
// TODO extract from displayutils to common
DisplayUtils.applyColorToStatusBar(
activity,
ResourcesCompat.getColor(
activity.resources,
// TODO do not use talk.R
R.color.bg_default,
activity.theme
)
@ -250,6 +254,13 @@ class AndroidViewThemeUtils @Inject constructor(schemes: MaterialSchemes, privat
}
}
fun highlightText(textView: TextView, originalText: String, constraint: String) {
withScheme(textView) { scheme ->
// TODO do not use FlexibleUtils for this
FlexibleUtils.highlightText(textView, originalText, constraint, scheme.primary)
}
}
companion object {
private const val ON_SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.38f
}

View File

@ -27,16 +27,16 @@ import android.widget.LinearLayout
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.res.ResourcesCompat
import com.nextcloud.android.common.ui.color.ColorUtil
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.nextcloud.android.common.ui.theme.MaterialSchemes
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
import com.nextcloud.talk.R
import javax.inject.Inject
/**
* View theme utils for AppCompat views (androidx.appcompat.*)
* View theme utils for Android extension views (androidx.*)
*/
class AppCompatViewThemeUtils @Inject constructor(schemes: MaterialSchemes, private val colorUtil: ColorUtil) :
class AndroidXViewThemeUtils @Inject constructor(schemes: MaterialSchemes) :
ViewThemeUtilsBase(schemes) {
fun themeSearchView(searchView: SearchView) {
withScheme(searchView) { scheme ->
@ -58,11 +58,13 @@ class AppCompatViewThemeUtils @Inject constructor(schemes: MaterialSchemes, priv
val thumbUncheckedColor = ResourcesCompat.getColor(
context.resources,
// TODO extract to common
R.color.switch_thumb_color_unchecked,
context.theme
)
val trackUncheckedColor = ResourcesCompat.getColor(
context.resources,
// TODO extract to common
R.color.switch_track_color_unchecked,
context.theme
)
@ -86,6 +88,13 @@ class AppCompatViewThemeUtils @Inject constructor(schemes: MaterialSchemes, priv
}
}
fun themeSwipeRefreshLayout(swipeRefreshLayout: SwipeRefreshLayout) {
withScheme(swipeRefreshLayout) { scheme ->
swipeRefreshLayout.setColorSchemeColors(scheme.primary)
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.refresh_spinner_background)
}
}
companion object {
private const val SWITCH_COMPAT_TRACK_ALPHA: Int = 77
private const val SEARCH_TEXT_SIZE: Float = 16f

View File

@ -0,0 +1,99 @@
/*
* Nextcloud Talk application
*
* @author Álvaro Brey
* Copyright (C) 2022 Álvaro Brey
* Copyright (C) 2022 Nextcloud GmbH
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.ui.theme.viewthemeutils
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.os.Build
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.DrawableCompat
import com.google.android.material.R
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.shape.MaterialShapeDrawable
import com.nextcloud.android.common.ui.theme.MaterialSchemes
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
import javax.inject.Inject
/**
* View theme utils for dialogs
*/
class DialogViewThemeUtils @Inject constructor(schemes: MaterialSchemes) :
ViewThemeUtilsBase(schemes) {
fun colorMaterialAlertDialogBackground(context: Context, dialogBuilder: MaterialAlertDialogBuilder) {
withScheme(dialogBuilder.context) { scheme ->
val materialShapeDrawable = MaterialShapeDrawable(
context,
null,
R.attr.alertDialogStyle,
R.style.MaterialAlertDialog_MaterialComponents
)
materialShapeDrawable.initializeElevationOverlay(context)
materialShapeDrawable.fillColor = ColorStateList.valueOf(scheme.surface)
// dialogCornerRadius first appeared in Android Pie
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val radius = context.resources.getDimension(com.nextcloud.talk.R.dimen.dialogBorderRadius)
materialShapeDrawable.setCornerSize(radius)
}
dialogBuilder.background = materialShapeDrawable
}
}
fun colorDialogMenuText(button: MaterialButton) {
withScheme(button) { scheme ->
button.setTextColor(scheme.onSurface)
button.iconTint = ColorStateList.valueOf(scheme.onSurface)
}
}
fun colorDialogHeadline(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurface)
}
}
fun colorDialogSupportingText(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurfaceVariant)
}
}
fun colorDialogIcon(icon: ImageView) {
withScheme(icon) { scheme ->
icon.setColorFilter(scheme.secondary)
}
}
fun colorMaterialAlertDialogIcon(context: Context, drawableId: Int): Drawable {
val drawable = AppCompatResources.getDrawable(context, drawableId)!!
withScheme(context) { scheme ->
DrawableCompat.setTint(drawable, scheme.secondary)
}
return drawable
}
}

View File

@ -21,20 +21,16 @@
package com.nextcloud.talk.ui.theme.viewthemeutils
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Build
import androidx.core.content.ContextCompat
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import com.google.android.material.chip.Chip
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textfield.TextInputLayout
import com.google.android.material.textview.MaterialTextView
@ -296,27 +292,6 @@ class MaterialViewThemeUtils @Inject constructor(schemes: MaterialSchemes, priva
}
}
fun colorMaterialAlertDialogBackground(context: Context, dialogBuilder: MaterialAlertDialogBuilder) {
withScheme(dialogBuilder.context) { scheme ->
val materialShapeDrawable = MaterialShapeDrawable(
context,
null,
com.google.android.material.R.attr.alertDialogStyle,
com.google.android.material.R.style.MaterialAlertDialog_MaterialComponents
)
materialShapeDrawable.initializeElevationOverlay(context)
materialShapeDrawable.fillColor = ColorStateList.valueOf(scheme.surface)
// dialogCornerRadius first appeared in Android Pie
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val radius = context.resources.getDimension(com.nextcloud.talk.R.dimen.dialogBorderRadius)
materialShapeDrawable.setCornerSize(radius)
}
dialogBuilder.background = materialShapeDrawable
}
}
companion object {
private const val SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.12f
private const val ON_SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.38f

View File

@ -62,7 +62,7 @@ import kotlin.math.roundToInt
@Suppress("TooManyFunctions")
class TalkSpecificViewThemeUtils @Inject constructor(
schemes: MaterialSchemes,
private val appcompat: AppCompatViewThemeUtils
private val appcompat: AndroidXViewThemeUtils
) :
ViewThemeUtilsBase(schemes) {
fun themeIncomingMessageBubble(bubble: ViewGroup, grouped: Boolean, deleted: Boolean) {

View File

@ -96,7 +96,7 @@ public class MagicUserInputModule extends StandardUserInputModule {
.setTitle(title)
.setView(view);
viewThemeUtils.material.colorMaterialAlertDialogBackground(view.getContext(), dialogBuilder);
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(view.getContext(), dialogBuilder);
final Dialog dialog = dialogBuilder.show();