Begin splitting ViewThemeUtils. Part 1: AndroidViewThemeUtils, for platform views

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-08-29 17:02:33 +02:00
parent b90afdc5c7
commit a2caf425a6
No known key found for this signature in database
GPG Key ID: 2585783189A62105
41 changed files with 382 additions and 376 deletions

View File

@ -66,9 +66,6 @@
<MarkdownNavigatorCodeStyleSettings>
<option name="RIGHT_MARGIN" value="120" />
</MarkdownNavigatorCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="JAVA">
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_METHOD_BRACKETS" value="true" />

View File

@ -132,7 +132,7 @@ open class BaseActivity : AppCompatActivity() {
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)

View File

@ -104,7 +104,7 @@ class FullScreenTextViewerActivity : AppCompatActivity() {
supportActionBar?.title = fileName
supportActionBar?.setDisplayHomeAsUpEnabled(true)
viewThemeUtils.themeStatusBar(this, binding.textviewToolbar)
viewThemeUtils.androidViewThemeUtils.themeStatusBar(this, binding.textviewToolbar)
if (resources != null) {
DisplayUtils.applyColorToNavigationBar(

View File

@ -113,7 +113,7 @@ public class ContactItem extends AbstractFlexibleItem<ContactItem.ContactItemVie
holder.binding.avatarDraweeView.setController(null);
if (participant.getSelected()) {
viewThemeUtils.colorImageView(holder.binding.checkedImageView);
viewThemeUtils.androidViewThemeUtils.colorImageView(holder.binding.checkedImageView);
holder.binding.checkedImageView.setVisibility(View.VISIBLE);
} else {
holder.binding.checkedImageView.setVisibility(View.GONE);

View File

@ -74,7 +74,7 @@ public class GenericTextHeaderItem extends AbstractHeaderItem<GenericTextHeaderI
Log.d(TAG, "We have payloads, so ignoring!");
} else {
holder.binding.titleTextView.setText(title);
viewThemeUtils.colorPrimaryTextViewElement(holder.binding.titleTextView);
viewThemeUtils.androidViewThemeUtils.colorPrimaryTextViewElement(holder.binding.titleTextView);
}
}

View File

@ -187,7 +187,7 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) : Mess
.setTextColor(context!!.resources.getColor(R.color.textColorMaxContrast))
if (parentChatMessage.actorId?.equals(message.activeUser!!.userId) == true) {
viewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
viewThemeUtils.androidViewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
} else {
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.textColorMaxContrast)
}

View File

@ -217,7 +217,7 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
.setTextColor(ContextCompat.getColor(context, R.color.textColorMaxContrast))
if (parentChatMessage.actorId?.equals(message.activeUser!!.userId) == true) {
viewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
viewThemeUtils.androidViewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
} else {
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.textColorMaxContrast)
}

View File

@ -95,8 +95,8 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : Message
updateDownloadState(message)
binding.seekbar.max = message.voiceMessageDuration
viewThemeUtils.themeHorizontalSeekBar(binding.seekbar)
viewThemeUtils.colorCircularProgressBarOnSurfaceVariant(binding.progressBar)
viewThemeUtils.androidViewThemeUtils.themeHorizontalSeekBar(binding.seekbar)
viewThemeUtils.androidViewThemeUtils.colorCircularProgressBarOnSurfaceVariant(binding.progressBar)
if (message.isPlayingVoiceMessage) {
showPlayButton()
@ -292,7 +292,7 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : Message
.setTextColor(ContextCompat.getColor(context!!, R.color.textColorMaxContrast))
if (parentChatMessage.actorId?.equals(message.activeUser!!.userId) == true) {
viewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
viewThemeUtils.androidViewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
} else {
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.textColorMaxContrast)
}

View File

@ -163,7 +163,7 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
binding.messageQuote.quotedMessage.text = parentChatMessage.text
if (parentChatMessage.actorId?.equals(message.activeUser!!.userId) == true) {
viewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
viewThemeUtils.androidViewThemeUtils.colorPrimaryView(binding.messageQuote.quoteColoredView)
} else {
binding.messageQuote.quoteColoredView.setBackgroundColor(
ContextCompat.getColor(binding.messageQuote.quoteColoredView.context, R.color.high_emphasis_text)

View File

@ -150,7 +150,7 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
}
progressBar = getProgressBar();
viewThemeUtils.colorCircularProgressBar(getProgressBar());
viewThemeUtils.androidViewThemeUtils.colorCircularProgressBar(getProgressBar());
image = getImage();
clickView = getImage();
getMessageText().setVisibility(View.VISIBLE);
@ -169,7 +169,7 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
clickView = getPreviewContactContainer();
viewThemeUtils.colorContactChatItemBackground(getPreviewContactContainer());
viewThemeUtils.colorContactChatItemName(getPreviewContactName());
viewThemeUtils.colorCircularProgressBarOnPrimaryContainer(getPreviewContactProgressBar());
viewThemeUtils.androidViewThemeUtils.colorCircularProgressBarOnPrimaryContainer(getPreviewContactProgressBar());
} else {
getPreviewContainer().setVisibility(View.VISIBLE);
getPreviewContactContainer().setVisibility(View.GONE);

View File

@ -90,8 +90,8 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
updateDownloadState(message)
binding.seekbar.max = message.voiceMessageDuration
viewThemeUtils.themeHorizontalSeekBar(binding.seekbar)
viewThemeUtils.colorCircularProgressBarOnSurfaceVariant(binding.progressBar)
viewThemeUtils.androidViewThemeUtils.themeHorizontalSeekBar(binding.seekbar)
viewThemeUtils.androidViewThemeUtils.colorCircularProgressBarOnSurfaceVariant(binding.progressBar)
handleIsPlayingVoiceMessageState(message)

View File

@ -877,7 +877,7 @@ class ChatController(args: Bundle) :
.nc_description_send_message_button
)
viewThemeUtils.colorImageView(binding.messageInputView.button)
viewThemeUtils.androidViewThemeUtils.colorImageView(binding.messageInputView.button)
if (currentConversation != null && currentConversation?.roomId != null) {
loadAvatarForStatusBar()
@ -1440,7 +1440,7 @@ class ChatController(args: Bundle) :
val dialog = materialAlertDialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
@ -1772,7 +1772,8 @@ class ChatController(args: Bundle) :
cancelReply()
}
viewThemeUtils.themeImageButton(binding.messageInputView.findViewById<ImageButton>(R.id.cancelReplyButton))
viewThemeUtils.androidViewThemeUtils
.themeImageButton(binding.messageInputView.findViewById<ImageButton>(R.id.cancelReplyButton))
cancelNotificationsForCurrentConversation()
@ -2523,12 +2524,12 @@ class ChatController(args: Bundle) :
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.menu_conversation, menu)
viewThemeUtils.colorToolbarMenuIcon(
viewThemeUtils.androidViewThemeUtils.colorToolbarMenuIcon(
binding.messageInputView.context,
menu.findItem(R.id.conversation_voice_call)
)
viewThemeUtils.colorToolbarMenuIcon(
viewThemeUtils.androidViewThemeUtils.colorToolbarMenuIcon(
binding.messageInputView.context,
menu.findItem(R.id.conversation_video_call)
)

View File

@ -380,7 +380,7 @@ class ContactsController(args: Bundle) :
super.onPrepareOptionsMenu(menu)
if (searchItem != null) {
viewThemeUtils.colorToolbarMenuIcon(
viewThemeUtils.androidViewThemeUtils.colorToolbarMenuIcon(
binding.titleTextView.context,
searchItem!!
)
@ -638,7 +638,7 @@ class ContactsController(args: Bundle) :
PorterDuff.Mode.SRC_IN
)
viewThemeUtils.colorImageViewButton(binding.conversationPrivacyToggle.publicCallLink)
viewThemeUtils.androidViewThemeUtils.colorImageViewButton(binding.conversationPrivacyToggle.publicCallLink)
disengageProgressBar()
}

View File

@ -227,7 +227,7 @@ class ConversationInfoController(args: Bundle) :
binding.addParticipantsAction.visibility = View.GONE
viewThemeUtils.colorCircularProgressBar(binding.progressBar)
viewThemeUtils.androidViewThemeUtils.colorCircularProgressBar(binding.progressBar)
}
private fun setupWebinaryView() {
@ -376,7 +376,7 @@ class ConversationInfoController(args: Bundle) :
}
viewThemeUtils.colorMaterialAlertDialogBackground(binding.conversationInfoName.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
@ -547,7 +547,7 @@ class ConversationInfoController(args: Bundle) :
}
viewThemeUtils.colorMaterialAlertDialogBackground(binding.conversationInfoName.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)

View File

@ -353,14 +353,14 @@ class ConversationsListController(bundle: Bundle) :
}
activity.binding.searchText.setOnClickListener {
showSearchView(activity, searchView, searchItem)
viewThemeUtils.themeStatusBar(activity, searchView!!)
viewThemeUtils.androidViewThemeUtils.themeStatusBar(activity, searchView!!)
}
}
searchView!!.setOnCloseListener {
if (TextUtils.isEmpty(searchView!!.query.toString())) {
searchView!!.onActionViewCollapsed()
if (activity != null) {
viewThemeUtils.resetStatusBar(activity, searchView!!)
viewThemeUtils.androidViewThemeUtils.resetStatusBar(activity, searchView!!)
}
} else {
searchView!!.post { searchView!!.setQuery(TAG, true) }
@ -400,7 +400,8 @@ class ConversationsListController(bundle: Bundle) :
mainActivity.binding.toolbar.visibility = View.GONE
mainActivity.binding.searchToolbar.visibility = View.VISIBLE
if (resources != null) {
viewThemeUtils.resetStatusBar(mainActivity, mainActivity.binding.searchToolbar)
viewThemeUtils.androidViewThemeUtils
.resetStatusBar(mainActivity, mainActivity.binding.searchToolbar)
}
}
val layoutManager = binding.recyclerView.layoutManager as SmoothScrollLinearLayoutManager?
@ -950,7 +951,7 @@ class ConversationsListController(bundle: Bundle) :
}
viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
@ -1146,7 +1147,7 @@ class ConversationsListController(bundle: Bundle) :
}
viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
@ -1189,7 +1190,7 @@ class ConversationsListController(bundle: Bundle) :
}
viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
@ -1231,7 +1232,7 @@ class ConversationsListController(bundle: Bundle) :
}
viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)

View File

@ -755,7 +755,7 @@ class ProfileController : BaseController(R.layout.controller_profile) {
initUserInfoEditText(holder, item)
holder.binding.icon.contentDescription = item.hint
viewThemeUtils.colorImageView(holder.binding.icon)
viewThemeUtils.androidViewThemeUtils.colorImageView(holder.binding.icon)
if (!TextUtils.isEmpty(item.text) || controller.edit) {
holder.binding.userInfoDetailContainer.visibility = View.VISIBLE
controller.viewThemeUtils.colorTextInputLayout(holder.binding.userInfoInputLayout)

View File

@ -392,7 +392,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
val dialog = materialAlertDialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
@ -968,7 +968,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
dialog.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)

View File

@ -217,9 +217,9 @@ abstract class BaseController(@LayoutRes var layoutRes: Int, args: Bundle? = nul
private fun colorizeStatusBar(showSearchBar: Boolean, activity: Activity?, resources: Resources?) {
if (activity != null && resources != null) {
if (showSearchBar) {
view?.let { viewThemeUtils.resetStatusBar(activity, it) }
view?.let { viewThemeUtils.androidViewThemeUtils.resetStatusBar(activity, it) }
} else {
view?.let { viewThemeUtils.themeStatusBar(activity, it) }
view?.let { viewThemeUtils.androidViewThemeUtils.themeStatusBar(activity, it) }
}
}
}

View File

@ -126,7 +126,7 @@ class EntryMenuController(args: Bundle) :
rootView = view,
editText = binding.textEdit,
onEmojiPopupShownListener = {
viewThemeUtils.colorImageView(binding.smileyButton)
viewThemeUtils.androidViewThemeUtils.colorImageView(binding.smileyButton)
},
onEmojiPopupDismissListener = {
binding.smileyButton.imageTintList = ColorStateList.valueOf(

View File

@ -117,7 +117,7 @@ class OperationsMenuController(args: Bundle) : BaseController(
sharedApplication!!.componentApplication.inject(this)
currentUser = userManager.currentUser.blockingGet()
viewThemeUtils.colorCircularProgressBar(binding.progressBar)
viewThemeUtils.androidViewThemeUtils.colorCircularProgressBar(binding.progressBar)
if (!TextUtils.isEmpty(callUrl) && callUrl.contains("/call")) {
conversationToken = callUrl.substring(callUrl.lastIndexOf("/") + 1)

View File

@ -101,9 +101,9 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
}
private fun themeDialog() {
viewThemeUtils.colorPrimaryTextViewElement(binding.pollQuestion)
viewThemeUtils.colorPrimaryTextViewElement(binding.pollOptions)
viewThemeUtils.colorPrimaryTextViewElement(binding.pollSettings)
viewThemeUtils.androidViewThemeUtils.colorPrimaryTextViewElement(binding.pollQuestion)
viewThemeUtils.androidViewThemeUtils.colorPrimaryTextViewElement(binding.pollOptions)
viewThemeUtils.androidViewThemeUtils.colorPrimaryTextViewElement(binding.pollSettings)
viewThemeUtils.colorTextInputLayout(binding.pollCreateQuestionTextInputLayout)
@ -111,8 +111,8 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
viewThemeUtils.colorMaterialButtonText(binding.pollDismiss)
viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.pollCreateButton)
viewThemeUtils.themeCheckbox(binding.pollPrivatePollCheckbox)
viewThemeUtils.themeCheckbox(binding.pollMultipleAnswersCheckbox)
viewThemeUtils.androidViewThemeUtils.themeCheckbox(binding.pollPrivatePollCheckbox)
viewThemeUtils.androidViewThemeUtils.themeCheckbox(binding.pollMultipleAnswersCheckbox)
}
private fun setupListeners() {

View File

@ -55,7 +55,7 @@ class PollLoadingFragment : Fragment() {
): View {
binding = DialogPollLoadingBinding.inflate(inflater, container, false)
binding.root.layoutParams.height = fragmentHeight
viewThemeUtils.colorCircularProgressBar(binding.pollLoadingProgressbar)
viewThemeUtils.androidViewThemeUtils.colorCircularProgressBar(binding.pollLoadingProgressbar)
return binding.root
}

View File

@ -139,7 +139,7 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener {
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)

View File

@ -149,7 +149,7 @@ class PollVoteFragment : Fragment() {
RadioButton(context).apply { text = option }
}?.forEachIndexed { index, radioButton ->
radioButton.id = index
viewThemeUtils.themeRadioButton(radioButton)
viewThemeUtils.androidViewThemeUtils.themeRadioButton(radioButton)
makeOptionBoldIfSelfVoted(radioButton, poll, index)
binding.pollVoteRadioGroup.addView(radioButton)
@ -170,7 +170,7 @@ class PollVoteFragment : Fragment() {
setLayoutParams(layoutParams)
}
}?.forEachIndexed { index, checkBox ->
viewThemeUtils.themeCheckbox(checkBox)
viewThemeUtils.androidViewThemeUtils.themeCheckbox(checkBox)
checkBox.id = index
makeOptionBoldIfSelfVoted(checkBox, poll, index)
binding.voteOptionsCheckboxesWrapper.addView(checkBox)
@ -222,7 +222,7 @@ class PollVoteFragment : Fragment() {
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
viewThemeUtils.androidViewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)

View File

@ -84,7 +84,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
binding.pathNavigationBackButton.iconTint = ColorStateList.valueOf(scheme.onSurface)
binding.pathNavigationBackButton.setTextColor(scheme.onSurface)
viewThemeUtils.colorMaterialTextButton(binding.pathNavigationBackButton)
viewThemeUtils.themeStatusBar(this, binding.remoteFileBrowserItemsToolbar)
viewThemeUtils.androidViewThemeUtils.themeStatusBar(this, binding.remoteFileBrowserItemsToolbar)
setContentView(binding.root)
DisplayUtils.applyColorToNavigationBar(

View File

@ -129,7 +129,7 @@ class RemoteFileBrowserItemsListViewHolder(
private fun setSelectability() {
if (selectable) {
binding.selectFileCheckbox.visibility = View.VISIBLE
viewThemeUtils.themeCheckbox(binding.selectFileCheckbox)
viewThemeUtils.androidViewThemeUtils.themeCheckbox(binding.selectFileCheckbox)
} else {
binding.selectFileCheckbox.visibility = View.GONE
}

View File

@ -73,7 +73,7 @@ class SharedItemsActivity : AppCompatActivity() {
setSupportActionBar(binding.sharedItemsToolbar)
setContentView(binding.root)
viewThemeUtils.themeStatusBar(this, binding.sharedItemsToolbar)
viewThemeUtils.androidViewThemeUtils.themeStatusBar(this, binding.sharedItemsToolbar)
viewThemeUtils.themeToolbar(binding.sharedItemsToolbar)
viewThemeUtils.themeTabLayoutOnSurface(binding.sharedItemsTabs)

View File

@ -53,7 +53,7 @@ class AttachmentDialog(val activity: Activity, var chatController: ChatControlle
setContentView(dialogAttachmentBinding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.themeDialog(dialogAttachmentBinding.root)
viewThemeUtils.androidViewThemeUtils.themeDialog(dialogAttachmentBinding.root)
initItemsStrings()
initItemsVisibility()
initItemsClickListeners()

View File

@ -51,7 +51,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
setContentView(dialogAudioOutputBinding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.themeDialogDark(dialogAudioOutputBinding.root)
viewThemeUtils.androidViewThemeUtils.themeDialogDark(dialogAudioOutputBinding.root)
updateOutputDeviceList()
initClickListeners()
}
@ -92,23 +92,28 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
private fun highlightActiveOutputChannel() {
when (callActivity.audioManager?.currentAudioDevice) {
WebRtcAudioManager.AudioDevice.BLUETOOTH -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputBluetoothIcon)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputBluetoothText)
viewThemeUtils.androidViewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputBluetoothIcon)
viewThemeUtils.androidViewThemeUtils
.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputBluetoothText)
}
WebRtcAudioManager.AudioDevice.SPEAKER_PHONE -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputSpeakerIcon)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputSpeakerText)
viewThemeUtils.androidViewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputSpeakerIcon)
viewThemeUtils.androidViewThemeUtils
.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputSpeakerText)
}
WebRtcAudioManager.AudioDevice.EARPIECE -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputEarspeakerIcon)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputEarspeakerText)
viewThemeUtils.androidViewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputEarspeakerIcon)
viewThemeUtils.androidViewThemeUtils
.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputEarspeakerText)
}
WebRtcAudioManager.AudioDevice.WIRED_HEADSET -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputWiredHeadsetIcon)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputWiredHeadsetText)
viewThemeUtils.androidViewThemeUtils
.colorImageView(dialogAudioOutputBinding.audioOutputWiredHeadsetIcon)
viewThemeUtils.androidViewThemeUtils
.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputWiredHeadsetText)
}
else -> Log.d(TAG, "AudioOutputDialog doesn't know this AudioDevice")

View File

@ -129,7 +129,7 @@ public class ChooseAccountDialogFragment extends DialogFragment {
binding.currentAccount.ticker.setVisibility(View.GONE);
binding.currentAccount.account.setText((Uri.parse(user.getBaseUrl()).getHost()));
viewThemeUtils.colorImageView(binding.currentAccount.accountMenu);
viewThemeUtils.androidViewThemeUtils.colorImageView(binding.currentAccount.accountMenu);
if (user.getBaseUrl() != null &&
@ -213,8 +213,8 @@ public class ChooseAccountDialogFragment extends DialogFragment {
}
private void themeViews() {
viewThemeUtils.themeDialog(binding.getRoot());
viewThemeUtils.themeDialogDivider(binding.divider);
viewThemeUtils.androidViewThemeUtils.themeDialog(binding.getRoot());
viewThemeUtils.androidViewThemeUtils.themeDialogDivider(binding.divider);
viewThemeUtils.colorMaterialTextButton(binding.setStatus);
viewThemeUtils.colorDialogMenuText(binding.setStatus);

View File

@ -59,7 +59,7 @@ class ContactsBottomDialog(
setContentView(binding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.themeDialog(binding.root)
viewThemeUtils.androidViewThemeUtils.themeDialog(binding.root)
executeEntryMenuController(bundle)
}

View File

@ -97,7 +97,7 @@ class ConversationsListBottomDialog(
setContentView(binding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.themeDialog(binding.root)
viewThemeUtils.androidViewThemeUtils.themeDialog(binding.root)
initHeaderDescription()
initItemsVisibility()
initClickListeners()

View File

@ -83,7 +83,7 @@ class MessageActionsDialog(
setContentView(dialogMessageActionsBinding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.themeDialog(dialogMessageActionsBinding.root)
viewThemeUtils.androidViewThemeUtils.themeDialog(dialogMessageActionsBinding.root)
initEmojiBar(hasChatPermission)
initMenuItemCopy(!message.isDeleted)
initMenuReplyToMessage(message.replyable && hasChatPermission)

View File

@ -59,7 +59,7 @@ class ScopeDialog(
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.themeDialog(dialogScopeBinding.root)
viewThemeUtils.androidViewThemeUtils.themeDialog(dialogScopeBinding.root)
if (field == ProfileController.Field.DISPLAYNAME || field == ProfileController.Field.EMAIL) {
dialogScopeBinding.scopePrivate.visibility = View.GONE

View File

@ -242,7 +242,7 @@ class SetStatusDialogFragment :
}
}
viewThemeUtils.themeDialog(binding.root)
viewThemeUtils.androidViewThemeUtils.themeDialog(binding.root)
viewThemeUtils.colorMaterialButtonText(binding.clearStatus)
viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.setStatus)
@ -419,7 +419,7 @@ class SetStatusDialogFragment :
}
}
viewThemeUtils.colorCardViewBackground(views.first)
viewThemeUtils.colorPrimaryTextViewElement(views.second)
viewThemeUtils.androidViewThemeUtils.colorPrimaryTextViewElement(views.second)
}
private fun clearTopStatus() {

View File

@ -86,7 +86,7 @@ class ShowReactionsDialog(
binding = DialogMessageReactionsBinding.inflate(layoutInflater)
setContentView(binding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.themeDialog(binding.root)
viewThemeUtils.androidViewThemeUtils.themeDialog(binding.root)
adapter = ReactionsAdapter(this, user)
binding.reactionsList.adapter = adapter
binding.reactionsList.layoutManager = LinearLayoutManager(context)

View File

@ -120,7 +120,7 @@ public class SortingOrderDialogFragment extends DialogFragment implements View.O
* find all relevant UI elements and set their values.
*/
private void setupDialogElements() {
viewThemeUtils.themeDialog(binding.root);
viewThemeUtils.androidViewThemeUtils.themeDialog(binding.root);
viewThemeUtils.colorMaterialButtonPrimaryBorderless(binding.cancel);
taggedViews = new View[12];
@ -166,7 +166,7 @@ public class SortingOrderDialogFragment extends DialogFragment implements View.O
viewThemeUtils.colorMaterialButtonText((MaterialButton) view);
}
if (view instanceof TextView) {
viewThemeUtils.colorPrimaryTextViewElement((TextView) view);
viewThemeUtils.androidViewThemeUtils.colorPrimaryTextViewElement((TextView) view);
((TextView) view).setTypeface(Typeface.DEFAULT_BOLD);
}
}

View File

@ -22,7 +22,6 @@
package com.nextcloud.talk.ui.theme
import android.annotation.TargetApi
import android.app.Activity
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
@ -32,24 +31,15 @@ import android.graphics.drawable.LayerDrawable
import android.os.Build
import android.text.Spannable
import android.text.SpannableString
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.RadioButton
import android.widget.SeekBar
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.SearchView.SearchAutoComplete
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
@ -70,12 +60,13 @@ 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
import com.nextcloud.android.common.ui.color.ColorUtil
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.utils.DisplayUtils
import com.nextcloud.talk.utils.DrawableUtils
import com.nextcloud.android.common.ui.color.ColorUtil
import com.nextcloud.talk.utils.ui.PlatformThemeUtil.isDarkMode
import com.vanniktech.emoji.EmojiTextView
import com.yarolegovich.mp.MaterialPreferenceCategory
import com.yarolegovich.mp.MaterialSwitchPreference
@ -85,49 +76,13 @@ import javax.inject.Inject
import kotlin.math.roundToInt
@Suppress("TooManyFunctions")
class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, private val colorUtil: ColorUtil) {
/**
* Scheme for painting elements
*/
fun getScheme(context: Context): Scheme = when {
isDarkMode(context) -> schemes.darkScheme
else -> schemes.lightScheme
}
private fun getSchemeDark(): Scheme = schemes.darkScheme
private fun withScheme(view: View, block: (Scheme) -> Unit) {
block(getScheme(view.context))
}
private fun withScheme(context: Context, block: (Scheme) -> Unit) {
block(getScheme(context))
}
private fun withSchemeDark(block: (Scheme) -> Unit) {
block(getSchemeDark())
}
fun themeToolbar(toolbar: MaterialToolbar) {
withScheme(toolbar) { scheme ->
toolbar.setBackgroundColor(scheme.surface)
toolbar.setNavigationIconTint(scheme.onSurface)
toolbar.setTitleTextColor(scheme.onSurface)
}
}
fun colorViewBackground(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.surface)
}
}
fun colorToolbarMenuIcon(context: Context, item: MenuItem) {
withScheme(context) { scheme ->
item.icon.setColorFilter(scheme.onSurface, PorterDuff.Mode.SRC_ATOP)
}
}
class ViewThemeUtils @Inject constructor(
schemes: MaterialSchemes,
private val colorUtil: ColorUtil,
@JvmField
val androidViewThemeUtils: AndroidViewThemeUtils
) :
ViewThemeUtilsBase(schemes) {
fun colorToolbarOverflowIcon(toolbar: MaterialToolbar) {
withScheme(toolbar) { scheme ->
@ -138,7 +93,7 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
fun themeSearchView(searchView: SearchView) {
withScheme(searchView) { scheme ->
// hacky as no default way is provided
val editText = searchView.findViewById<SearchAutoComplete>(R.id.search_src_text)
val editText = searchView.findViewById<SearchView.SearchAutoComplete>(R.id.search_src_text)
val searchPlate = searchView.findViewById<LinearLayout>(R.id.search_plate)
editText.textSize = SEARCH_TEXT_SIZE
editText.setHintTextColor(scheme.onSurfaceVariant)
@ -154,41 +109,6 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
}
}
fun themeStatusBar(activity: Activity, view: View) {
withScheme(view) { scheme ->
DisplayUtils.applyColorToStatusBar(activity, scheme.surface)
}
}
fun resetStatusBar(activity: Activity, view: View) {
DisplayUtils.applyColorToStatusBar(
activity,
ResourcesCompat.getColor(
activity.resources,
R.color.bg_default,
activity.theme
)
)
}
fun themeDialog(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.surface)
}
}
fun themeDialogDark(view: View) {
withSchemeDark { scheme ->
view.setBackgroundColor(scheme.surface)
}
}
fun themeDialogDivider(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.surfaceVariant)
}
}
fun themeFAB(fab: FloatingActionButton) {
withScheme(fab) { scheme ->
fab.backgroundTintList = ColorStateList.valueOf(scheme.primaryContainer)
@ -202,94 +122,6 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
}
}
fun themeHorizontalSeekBar(seekBar: SeekBar) {
withScheme(seekBar) { scheme ->
themeHorizontalProgressBar(seekBar, scheme.primary)
seekBar.thumb.setColorFilter(scheme.primary, PorterDuff.Mode.SRC_IN)
}
}
fun themeHorizontalProgressBar(progressBar: ProgressBar?, @ColorInt color: Int) {
if (progressBar != null) {
progressBar.indeterminateDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
progressBar.progressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
}
}
fun colorPrimaryTextViewElement(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.primary)
}
}
fun colorPrimaryTextViewElementDarkMode(textView: TextView) {
withSchemeDark { scheme ->
textView.setTextColor(scheme.primary)
}
}
fun colorPrimaryView(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.primary)
}
}
/**
* Colors the background as element color and the foreground as text color.
*/
fun colorImageViewButton(imageView: ImageView) {
withScheme(imageView) { scheme ->
imageView.imageTintList = ColorStateList.valueOf(scheme.onPrimaryContainer)
imageView.backgroundTintList = ColorStateList.valueOf(scheme.primaryContainer)
}
}
fun themeImageButton(imageButton: ImageButton) {
withScheme(imageButton) { scheme ->
imageButton.imageTintList = ColorStateList(
arrayOf(
intArrayOf(android.R.attr.state_selected),
intArrayOf(-android.R.attr.state_selected),
intArrayOf(android.R.attr.state_enabled),
intArrayOf(-android.R.attr.state_enabled)
),
intArrayOf(
scheme.primary,
scheme.onSurfaceVariant,
scheme.onSurfaceVariant,
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
)
)
}
}
/**
* Tints the image with element color
*/
fun colorImageView(imageView: ImageView) {
withScheme(imageView) { scheme ->
imageView.imageTintList = ColorStateList.valueOf(scheme.primary)
}
}
fun colorOutgoingQuoteText(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurfaceVariant)
}
}
fun colorOutgoingQuoteAuthorText(textView: TextView) {
withScheme(textView) { scheme ->
ColorUtils.setAlphaComponent(scheme.onSurfaceVariant, ALPHA_80_INT)
}
}
fun colorOutgoingQuoteBackground(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.onSurfaceVariant)
}
}
fun colorMaterialTextButton(button: MaterialButton) {
withScheme(button) { scheme ->
button.rippleColor = ColorStateList(
@ -318,25 +150,6 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
}
}
fun colorTextButtons(vararg buttons: Button) {
withScheme(buttons[0]) { scheme ->
for (button in buttons) {
button.setTextColor(
ColorStateList(
arrayOf(
intArrayOf(android.R.attr.state_enabled),
intArrayOf(-android.R.attr.state_enabled)
),
intArrayOf(
scheme.primary,
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
)
)
)
}
}
}
fun colorMaterialButtonPrimaryFilled(button: MaterialButton) {
withScheme(button) { scheme ->
button.backgroundTintList =
@ -449,11 +262,20 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
val bubbleDrawable = DisplayUtils.getMessageSelector(
bgBubbleColor,
resources.getColor(R.color.transparent),
bgBubbleColor, bubbleResource
bgBubbleColor,
bubbleResource
)
ViewCompat.setBackground(bubble, bubbleDrawable)
}
fun themeToolbar(toolbar: MaterialToolbar) {
withScheme(toolbar) { scheme ->
toolbar.setBackgroundColor(scheme.surface)
toolbar.setNavigationIconTint(scheme.onSurface)
toolbar.setTitleTextColor(scheme.onSurface)
}
}
fun themeOutgoingMessageBubble(bubble: ViewGroup, grouped: Boolean, deleted: Boolean) {
withScheme(bubble) { scheme ->
val bgBubbleColor = if (deleted) {
@ -477,6 +299,24 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
}
}
fun colorOutgoingQuoteText(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurfaceVariant)
}
}
fun colorOutgoingQuoteAuthorText(textView: TextView) {
withScheme(textView) { scheme ->
ColorUtils.setAlphaComponent(scheme.onSurfaceVariant, ALPHA_80_INT)
}
}
fun colorOutgoingQuoteBackground(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.onSurfaceVariant)
}
}
fun colorCardViewBackground(card: MaterialCardView) {
withScheme(card) { scheme ->
card.setCardBackgroundColor(scheme.surfaceVariant)
@ -495,24 +335,6 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
}
}
fun colorCircularProgressBarOnPrimaryContainer(progressBar: ProgressBar) {
withScheme(progressBar) { scheme ->
progressBar.indeterminateDrawable.setColorFilter(scheme.onPrimaryContainer, PorterDuff.Mode.SRC_ATOP)
}
}
fun colorCircularProgressBar(progressBar: ProgressBar) {
withScheme(progressBar) { scheme ->
progressBar.indeterminateDrawable.setColorFilter(scheme.primary, PorterDuff.Mode.SRC_ATOP)
}
}
fun colorCircularProgressBarOnSurfaceVariant(progressBar: ProgressBar) {
withScheme(progressBar) { scheme ->
progressBar.indeterminateDrawable.setColorFilter(scheme.onSurfaceVariant, PorterDuff.Mode.SRC_ATOP)
}
}
// TODO split this util into classes depending on framework views vs library views
fun colorPreferenceCategory(category: MaterialPreferenceCategory) {
withScheme(category) { scheme ->
@ -564,35 +386,6 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
}
}
fun colorDrawable(context: Context, drawable: Drawable) {
val scheme = getScheme(context)
drawable.setTint(scheme.primary)
}
fun themeCheckbox(checkbox: CheckBox) {
withScheme(checkbox) { scheme ->
checkbox.buttonTintList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
),
intArrayOf(Color.GRAY, scheme.primary)
)
}
}
fun themeRadioButton(radioButton: RadioButton) {
withScheme(radioButton) { scheme ->
radioButton.buttonTintList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
),
intArrayOf(Color.GRAY, scheme.primary)
)
}
}
fun themeSwipeRefreshLayout(swipeRefreshLayout: SwipeRefreshLayout) {
withScheme(swipeRefreshLayout) { scheme ->
swipeRefreshLayout.setColorSchemeColors(scheme.primary)
@ -606,25 +399,6 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
}
}
fun colorEditText(editText: EditText) {
withScheme(editText) { scheme ->
// TODO check API-level compatibility
// editText.background.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
editText.backgroundTintList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_focused),
intArrayOf(android.R.attr.state_focused)
),
intArrayOf(
scheme.outline,
scheme.primary
)
)
editText.setHintTextColor(scheme.onSurfaceVariant)
editText.setTextColor(scheme.onSurface)
}
}
fun colorTextInputLayout(textInputLayout: TextInputLayout) {
withScheme(textInputLayout) { scheme ->
val errorColor = scheme.onSurfaceVariant
@ -696,6 +470,11 @@ class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, p
return drawable
}
private fun colorDrawable(context: Context, drawable: Drawable) {
val scheme = getScheme(context)
drawable.setTint(scheme.primary)
}
fun colorChipBackground(chip: Chip) {
withScheme(chip) { scheme ->
chip.chipBackgroundColor = ColorStateList.valueOf(scheme.primary)

View File

@ -0,0 +1,256 @@
/*
* 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.app.Activity
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.PorterDuff
import android.view.MenuItem
import android.view.View
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.RadioButton
import android.widget.SeekBar
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.content.res.ResourcesCompat
import com.nextcloud.android.common.ui.color.ColorUtil
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 javax.inject.Inject
/**
* View theme utils for platform views (android.widget.*, android.view.*)
*/
@Suppress("TooManyFunctions")
class AndroidViewThemeUtils @Inject constructor(schemes: MaterialSchemes, private val colorUtil: ColorUtil) :
ViewThemeUtilsBase(schemes) {
fun colorViewBackground(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.surface)
}
}
fun colorToolbarMenuIcon(context: Context, item: MenuItem) {
withScheme(context) { scheme ->
item.icon.setColorFilter(scheme.onSurface, PorterDuff.Mode.SRC_ATOP)
}
}
fun themeStatusBar(activity: Activity, view: View) {
withScheme(view) { scheme ->
DisplayUtils.applyColorToStatusBar(activity, scheme.surface)
}
}
fun resetStatusBar(activity: Activity, view: View) {
DisplayUtils.applyColorToStatusBar(
activity,
ResourcesCompat.getColor(
activity.resources,
R.color.bg_default,
activity.theme
)
)
}
fun themeDialog(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.surface)
}
}
fun themeDialogDark(view: View) {
withSchemeDark { scheme ->
view.setBackgroundColor(scheme.surface)
}
}
fun themeDialogDivider(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.surfaceVariant)
}
}
fun themeHorizontalSeekBar(seekBar: SeekBar) {
withScheme(seekBar) { scheme ->
themeHorizontalProgressBar(seekBar, scheme.primary)
seekBar.thumb.setColorFilter(scheme.primary, PorterDuff.Mode.SRC_IN)
}
}
fun themeHorizontalProgressBar(progressBar: ProgressBar?, @ColorInt color: Int) {
if (progressBar != null) {
progressBar.indeterminateDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
progressBar.progressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
}
}
fun colorPrimaryTextViewElement(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.primary)
}
}
fun colorPrimaryTextViewElementDarkMode(textView: TextView) {
withSchemeDark { scheme ->
textView.setTextColor(scheme.primary)
}
}
fun colorPrimaryView(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.primary)
}
}
/**
* Colors the background as element color and the foreground as text color.
*/
fun colorImageViewButton(imageView: ImageView) {
withScheme(imageView) { scheme ->
imageView.imageTintList = ColorStateList.valueOf(scheme.onPrimaryContainer)
imageView.backgroundTintList = ColorStateList.valueOf(scheme.primaryContainer)
}
}
fun themeImageButton(imageButton: ImageButton) {
withScheme(imageButton) { scheme ->
imageButton.imageTintList = ColorStateList(
arrayOf(
intArrayOf(android.R.attr.state_selected),
intArrayOf(-android.R.attr.state_selected),
intArrayOf(android.R.attr.state_enabled),
intArrayOf(-android.R.attr.state_enabled)
),
intArrayOf(
scheme.primary,
scheme.onSurfaceVariant,
scheme.onSurfaceVariant,
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
)
)
}
}
/**
* Tints the image with element color
*/
fun colorImageView(imageView: ImageView) {
withScheme(imageView) { scheme ->
imageView.imageTintList = ColorStateList.valueOf(scheme.primary)
}
}
fun colorTextButtons(vararg buttons: Button) {
withScheme(buttons[0]) { scheme ->
for (button in buttons) {
button.setTextColor(
ColorStateList(
arrayOf(
intArrayOf(android.R.attr.state_enabled),
intArrayOf(-android.R.attr.state_enabled)
),
intArrayOf(
scheme.primary,
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
)
)
)
}
}
}
fun colorCircularProgressBarOnPrimaryContainer(progressBar: ProgressBar) {
withScheme(progressBar) { scheme ->
progressBar.indeterminateDrawable.setColorFilter(scheme.onPrimaryContainer, PorterDuff.Mode.SRC_ATOP)
}
}
fun colorCircularProgressBar(progressBar: ProgressBar) {
withScheme(progressBar) { scheme ->
progressBar.indeterminateDrawable.setColorFilter(scheme.primary, PorterDuff.Mode.SRC_ATOP)
}
}
fun colorCircularProgressBarOnSurfaceVariant(progressBar: ProgressBar) {
withScheme(progressBar) { scheme ->
progressBar.indeterminateDrawable.setColorFilter(scheme.onSurfaceVariant, PorterDuff.Mode.SRC_ATOP)
}
}
fun themeCheckbox(checkbox: CheckBox) {
withScheme(checkbox) { scheme ->
checkbox.buttonTintList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
),
intArrayOf(Color.GRAY, scheme.primary)
)
}
}
fun themeRadioButton(radioButton: RadioButton) {
withScheme(radioButton) { scheme ->
radioButton.buttonTintList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
),
intArrayOf(Color.GRAY, scheme.primary)
)
}
}
fun colorEditText(editText: EditText) {
withScheme(editText) { scheme ->
// TODO check API-level compatibility
// editText.background.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
editText.backgroundTintList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_focused),
intArrayOf(android.R.attr.state_focused)
),
intArrayOf(
scheme.outline,
scheme.primary
)
)
editText.setHintTextColor(scheme.onSurfaceVariant)
editText.setTextColor(scheme.onSurface)
}
}
companion object {
private const val ON_SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.38f
}
}

View File

@ -73,7 +73,7 @@ public class MagicUserInputModule extends StandardUserInputModule {
final Listener<String> listener) {
final View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null);
final EditText inputField = view.findViewById(R.id.mp_text_input);
viewThemeUtils.colorEditText(inputField);
viewThemeUtils.androidViewThemeUtils.colorEditText(inputField);
int paddingStartEnd = Math.round(view.getResources().getDimension(R.dimen.standard_padding));
int paddingTopBottom = Math.round(view.getResources().getDimension(R.dimen.dialog_padding_top_bottom));
@ -101,7 +101,7 @@ public class MagicUserInputModule extends StandardUserInputModule {
final Dialog dialog = dialogBuilder.show();
TextView button = view.findViewById(R.id.mp_btn_confirm);
viewThemeUtils.colorPrimaryTextViewElement(button);
viewThemeUtils.androidViewThemeUtils.colorPrimaryTextViewElement(button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View File

@ -1,33 +0,0 @@
/*
* 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.utils.ui
import android.content.Context
import android.content.res.Configuration
object PlatformThemeUtil {
fun isDarkMode(context: Context): Boolean =
when (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> true
else -> false
}
}