From 3fea2173f47bc9b220988cf427574c1b63766a25 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 29 May 2020 11:57:20 +0200 Subject: [PATCH] Move fun to a dedicated file. --- .../riotx/core/utils/JsonViewerStyler.kt | 32 +++++++++++++++++++ .../im/vector/riotx/core/utils/UserColor.kt | 13 -------- .../home/room/detail/RoomDetailFragment.kt | 6 ++-- .../settings/devtools/AccountDataFragment.kt | 4 +-- .../GossipingEventsPaperTrailFragment.kt | 4 +-- 5 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/core/utils/JsonViewerStyler.kt diff --git a/vector/src/main/java/im/vector/riotx/core/utils/JsonViewerStyler.kt b/vector/src/main/java/im/vector/riotx/core/utils/JsonViewerStyler.kt new file mode 100644 index 0000000000..94b08b22d6 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/core/utils/JsonViewerStyler.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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.riotx.core.utils + +import im.vector.riotx.R +import im.vector.riotx.core.resources.ColorProvider +import org.billcarsonfr.jsonviewer.JSonViewerStyleProvider + +fun createJSonViewerStyleProvider(colorProvider: ColorProvider): JSonViewerStyleProvider { + return JSonViewerStyleProvider( + keyColor = colorProvider.getColor(R.color.riotx_accent), + secondaryColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary), + stringColor = colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color), + baseColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_primary), + booleanColor = colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color), + numberColor = colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color) + ) +} diff --git a/vector/src/main/java/im/vector/riotx/core/utils/UserColor.kt b/vector/src/main/java/im/vector/riotx/core/utils/UserColor.kt index 15c4ce8a15..1f8308cd5c 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/UserColor.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/UserColor.kt @@ -18,8 +18,6 @@ package im.vector.riotx.core.utils import androidx.annotation.ColorRes import im.vector.riotx.R -import im.vector.riotx.core.resources.ColorProvider -import org.billcarsonfr.jsonviewer.JSonViewerStyleProvider import kotlin.math.abs @ColorRes @@ -39,14 +37,3 @@ fun getColorFromUserId(userId: String?): Int { else -> R.color.riotx_username_1 } } - -fun jsonViewerStyler(colorProvider: ColorProvider): JSonViewerStyleProvider { - return JSonViewerStyleProvider( - keyColor = colorProvider.getColor(R.color.riotx_accent), - secondaryColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary), - stringColor = colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color), - baseColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_primary), - booleanColor = colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color), - numberColor = colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color) - ) -} diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 296f15fa92..3f959746c0 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -110,10 +110,10 @@ import im.vector.riotx.core.utils.allGranted import im.vector.riotx.core.utils.checkPermissions import im.vector.riotx.core.utils.colorizeMatchingText import im.vector.riotx.core.utils.copyToClipboard +import im.vector.riotx.core.utils.createJSonViewerStyleProvider import im.vector.riotx.core.utils.createUIHandler import im.vector.riotx.core.utils.getColorFromUserId import im.vector.riotx.core.utils.isValidUrl -import im.vector.riotx.core.utils.jsonViewerStyler import im.vector.riotx.core.utils.openUrlInExternalBrowser import im.vector.riotx.core.utils.saveMedia import im.vector.riotx.core.utils.shareMedia @@ -1207,14 +1207,14 @@ class RoomDetailFragment @Inject constructor( JSonViewerDialog.newInstance( action.content, -1, - jsonViewerStyler(colorProvider) + createJSonViewerStyleProvider(colorProvider) ).show(childFragmentManager, "JSON_VIEWER") } is EventSharedAction.ViewDecryptedSource -> { JSonViewerDialog.newInstance( action.content, -1, - jsonViewerStyler(colorProvider) + createJSonViewerStyleProvider(colorProvider) ).show(childFragmentManager, "JSON_VIEWER") } is EventSharedAction.QuickReact -> { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt index 7a57a03deb..ad8831124a 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt @@ -29,7 +29,7 @@ import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.resources.ColorProvider -import im.vector.riotx.core.utils.jsonViewerStyler +import im.vector.riotx.core.utils.createJSonViewerStyleProvider import kotlinx.android.synthetic.main.fragment_generic_recycler.* import org.billcarsonfr.jsonviewer.JSonViewerDialog import javax.inject.Inject @@ -73,7 +73,7 @@ class AccountDataFragment @Inject constructor( JSonViewerDialog.newInstance( jsonString, -1, // open All - jsonViewerStyler(colorProvider) + createJSonViewerStyleProvider(colorProvider) ).show(childFragmentManager, "JSON_VIEWER") } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt index d7ffd8adfa..9489fb8506 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt @@ -26,7 +26,7 @@ import im.vector.riotx.core.extensions.cleanup import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.resources.ColorProvider -import im.vector.riotx.core.utils.jsonViewerStyler +import im.vector.riotx.core.utils.createJSonViewerStyleProvider import kotlinx.android.synthetic.main.fragment_generic_recycler.* import org.billcarsonfr.jsonviewer.JSonViewerDialog import javax.inject.Inject @@ -66,7 +66,7 @@ class GossipingEventsPaperTrailFragment @Inject constructor( JSonViewerDialog.newInstance( it, -1, - jsonViewerStyler(colorProvider) + createJSonViewerStyleProvider(colorProvider) ).show(childFragmentManager, "JSON_VIEWER") } }