From 61ea4191dc616ef5ec2baaee37947d84cd3967b3 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 12 Feb 2020 16:48:11 +0100 Subject: [PATCH] Update json viewer lib --- build.gradle | 1 + vector/build.gradle | 5 +- .../src/main/assets/open_source_licenses.html | 5 +- .../im/vector/riotx/core/utils/UserColor.kt | 13 +++++ .../home/room/detail/RoomDetailFragment.kt | 37 +++++------- .../settings/devtools/AccountDataFragment.kt | 13 ++++- .../devtools/JsonViewerBottomSheetDialog.kt | 57 ------------------- .../main/res/layout/fragment_jsonviewer.xml | 16 ------ 8 files changed, 43 insertions(+), 104 deletions(-) delete mode 100644 vector/src/main/java/im/vector/riotx/features/settings/devtools/JsonViewerBottomSheetDialog.kt delete mode 100644 vector/src/main/res/layout/fragment_jsonviewer.xml diff --git a/build.gradle b/build.gradle index a2fac55175..1ee6fa49bb 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,7 @@ allprojects { includeGroupByRegex "com\\.github\\.jaiselrahman" // And monarchy includeGroupByRegex "com\\.github\\.Zhuinden" + includeGroupByRegex 'com\\.github\\.BillCarsonFr' } } maven { diff --git a/vector/build.gradle b/vector/build.gradle index dac6a5a4c9..a59f3340d5 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -354,9 +354,6 @@ dependencies { compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.5.0' kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.5.0' - // Json viewer - implementation "com.yuyh.json:jsonviewer:1.0.6" - // gplay flavor only // Warning: due to the exclude, Android Studio does not propose to upgrade. Uncomment next line to be proposed to upgrade // implementation 'com.google.firebase:firebase-messaging:20.0.0' @@ -371,6 +368,8 @@ dependencies { implementation "androidx.emoji:emoji-appcompat:1.0.0" + implementation 'com.github.BillCarsonFr:JsonViewer:0.4' + // QR-code // Stick to 3.3.3 because of https://github.com/zxing/zxing/issues/1170 implementation 'com.google.zxing:core:3.3.3' diff --git a/vector/src/main/assets/open_source_licenses.html b/vector/src/main/assets/open_source_licenses.html index 55ec775e58..02ef5aba18 100755 --- a/vector/src/main/assets/open_source_licenses.html +++ b/vector/src/main/assets/open_source_licenses.html @@ -22,6 +22,7 @@ padding: 4px; } + @@ -375,9 +376,7 @@ SOFTWARE. Copyright (c) 2014 Dushyanth Maguluru
  • - JsonViewer -
    - Copyright 2017 smuyyh, All right reserved. + BillCarsonFr/JsonViewer
  • 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 1f8308cd5c..15c4ce8a15 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,6 +18,8 @@ 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
    @@ -37,3 +39,14 @@ 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 5cb3024712..79eb63bfb7 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
    @@ -27,12 +27,10 @@ import android.os.Bundle
     import android.os.Parcelable
     import android.text.Spannable
     import android.view.HapticFeedbackConstants
    -import android.view.LayoutInflater
     import android.view.Menu
     import android.view.MenuItem
     import android.view.View
     import android.view.Window
    -import android.widget.TextView
     import android.widget.Toast
     import androidx.annotation.DrawableRes
     import androidx.annotation.StringRes
    @@ -96,6 +94,7 @@ import im.vector.riotx.core.extensions.showKeyboard
     import im.vector.riotx.core.files.addEntryToDownloadManager
     import im.vector.riotx.core.glide.GlideApp
     import im.vector.riotx.core.platform.VectorBaseFragment
    +import im.vector.riotx.core.resources.ColorProvider
     import im.vector.riotx.core.ui.views.JumpToReadMarkerView
     import im.vector.riotx.core.ui.views.NotificationAreaView
     import im.vector.riotx.core.utils.Debouncer
    @@ -110,6 +109,7 @@ import im.vector.riotx.core.utils.checkPermissions
     import im.vector.riotx.core.utils.copyToClipboard
     import im.vector.riotx.core.utils.createUIHandler
     import im.vector.riotx.core.utils.getColorFromUserId
    +import im.vector.riotx.core.utils.jsonViewerStyler
     import im.vector.riotx.core.utils.openUrlInExternalBrowser
     import im.vector.riotx.core.utils.shareMedia
     import im.vector.riotx.core.utils.toast
    @@ -154,6 +154,7 @@ import kotlinx.android.parcel.Parcelize
     import kotlinx.android.synthetic.main.fragment_room_detail.*
     import kotlinx.android.synthetic.main.merge_composer_layout.view.*
     import kotlinx.android.synthetic.main.merge_overlay_waiting_view.*
    +import org.billcarsonfr.jsonviewer.JSonViewerDialog
     import org.commonmark.parser.Parser
     import timber.log.Timber
     import java.io.File
    @@ -178,8 +179,8 @@ class RoomDetailFragment @Inject constructor(
             private val notificationDrawerManager: NotificationDrawerManager,
             val roomDetailViewModelFactory: RoomDetailViewModel.Factory,
             private val eventHtmlRenderer: EventHtmlRenderer,
    -        private val vectorPreferences: VectorPreferences
    -) :
    +        private val vectorPreferences: VectorPreferences,
    +        private val colorProvider: ColorProvider) :
             VectorBaseFragment(),
             TimelineEventController.Callback,
             VectorInviteView.Callback,
    @@ -1155,26 +1156,18 @@ class RoomDetailFragment @Inject constructor(
                     onEditedDecorationClicked(action.messageInformationData)
                 }
                 is EventSharedAction.ViewSource                 -> {
    -                val view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_event_content, null)
    -                view.findViewById(R.id.event_content_text_view)?.let {
    -                    it.text = action.content
    -                }
    -
    -                AlertDialog.Builder(requireActivity())
    -                        .setView(view)
    -                        .setPositiveButton(R.string.ok, null)
    -                        .show()
    +                JSonViewerDialog.newInstance(
    +                        action.content,
    +                        -1,
    +                        jsonViewerStyler(colorProvider)
    +                ).show(childFragmentManager, "JSON_VIEWER")
                 }
                 is EventSharedAction.ViewDecryptedSource        -> {
    -                val view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_event_content, null)
    -                view.findViewById(R.id.event_content_text_view)?.let {
    -                    it.text = action.content
    -                }
    -
    -                AlertDialog.Builder(requireActivity())
    -                        .setView(view)
    -                        .setPositiveButton(R.string.ok, null)
    -                        .show()
    +                JSonViewerDialog.newInstance(
    +                        action.content,
    +                        -1,
    +                        jsonViewerStyler(colorProvider)
    +                ).show(childFragmentManager, "JSON_VIEWER")
                 }
                 is EventSharedAction.QuickReact                 -> {
                     // eventId,ClickedOn,Add
    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 a7d5d82fb1..0799ae270b 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
    @@ -27,12 +27,16 @@ import im.vector.riotx.R
     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 kotlinx.android.synthetic.main.fragment_generic_recycler.*
    +import org.billcarsonfr.jsonviewer.JSonViewerDialog
     import javax.inject.Inject
     
     class AccountDataFragment @Inject constructor(
             val viewModelFactory: AccountDataViewModel.Factory,
    -        private val epoxyController: AccountDataEpoxyController
    +        private val epoxyController: AccountDataEpoxyController,
    +        private val colorProvider: ColorProvider
     ) : VectorBaseFragment(), AccountDataEpoxyController.InteractionListener {
     
         override fun getLayoutResId() = R.layout.fragment_generic_recycler
    @@ -59,7 +63,10 @@ class AccountDataFragment @Inject constructor(
             val jsonString = MoshiProvider.providesMoshi()
                     .adapter(UserAccountDataEvent::class.java)
                     .toJson(fb)
    -        JsonViewerBottomSheetDialog.newInstance(jsonString)
    -                .show(childFragmentManager, "JSON_VIEWER")
    +        JSonViewerDialog.newInstance(
    +                jsonString,
    +                -1, // open All
    +                jsonViewerStyler(colorProvider)
    +        ).show(childFragmentManager, "JSON_VIEWER")
         }
     }
    diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/JsonViewerBottomSheetDialog.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/JsonViewerBottomSheetDialog.kt
    deleted file mode 100644
    index c638846f51..0000000000
    --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/JsonViewerBottomSheetDialog.kt
    +++ /dev/null
    @@ -1,57 +0,0 @@
    -/*
    - * 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.features.settings.devtools
    -
    -import android.os.Bundle
    -import android.view.View
    -import androidx.core.content.ContextCompat
    -import butterknife.BindView
    -import com.airbnb.mvrx.MvRx
    -import com.yuyh.jsonviewer.library.JsonRecyclerView
    -import im.vector.riotx.R
    -import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment
    -import im.vector.riotx.features.themes.ThemeUtils
    -
    -class JsonViewerBottomSheetDialog : VectorBaseBottomSheetDialogFragment() {
    -
    -    override fun getLayoutResId() = R.layout.fragment_jsonviewer
    -
    -    @BindView(R.id.rv_json)
    -    lateinit var jsonRecyclerView: JsonRecyclerView
    -
    -    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    -        super.onViewCreated(view, savedInstanceState)
    -
    -        jsonRecyclerView.setKeyColor(ThemeUtils.getColor(requireContext(), R.attr.colorAccent))
    -        jsonRecyclerView.setValueTextColor(ContextCompat.getColor(requireContext(), R.color.riotx_notice_secondary))
    -        jsonRecyclerView.setValueNumberColor(ContextCompat.getColor(requireContext(), R.color.riotx_notice_secondary))
    -        jsonRecyclerView.setValueUrlColor(ThemeUtils.getColor(requireContext(), android.R.attr.textColorLink))
    -        jsonRecyclerView.setValueNullColor(ContextCompat.getColor(requireContext(), R.color.riotx_notice_secondary))
    -        jsonRecyclerView.setBracesColor(ThemeUtils.getColor(requireContext(), R.attr.riotx_text_primary))
    -
    -        val jsonString = arguments?.getString(MvRx.KEY_ARG)
    -        jsonRecyclerView.bindJson(jsonString)
    -    }
    -
    -    companion object {
    -        fun newInstance(jsonString: String): JsonViewerBottomSheetDialog {
    -            return JsonViewerBottomSheetDialog().apply {
    -                setArguments(Bundle().apply { putString(MvRx.KEY_ARG, jsonString) })
    -            }
    -        }
    -    }
    -}
    diff --git a/vector/src/main/res/layout/fragment_jsonviewer.xml b/vector/src/main/res/layout/fragment_jsonviewer.xml
    deleted file mode 100644
    index 5a4aecc56c..0000000000
    --- a/vector/src/main/res/layout/fragment_jsonviewer.xml
    +++ /dev/null
    @@ -1,16 +0,0 @@
    -
    -
    -
    -    
    -
    \ No newline at end of file