Update json viewer lib

This commit is contained in:
Valere 2020-02-12 16:48:11 +01:00 committed by Valere
parent 108ebea84e
commit 61ea4191dc
8 changed files with 43 additions and 104 deletions

View file

@ -34,6 +34,7 @@ allprojects {
includeGroupByRegex "com\\.github\\.jaiselrahman" includeGroupByRegex "com\\.github\\.jaiselrahman"
// And monarchy // And monarchy
includeGroupByRegex "com\\.github\\.Zhuinden" includeGroupByRegex "com\\.github\\.Zhuinden"
includeGroupByRegex 'com\\.github\\.BillCarsonFr'
} }
} }
maven { maven {

View file

@ -354,9 +354,6 @@ dependencies {
compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.5.0' compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.5.0'
kapt 'com.squareup.inject:assisted-inject-processor-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 // gplay flavor only
// Warning: due to the exclude, Android Studio does not propose to upgrade. Uncomment next line to be proposed to upgrade // 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' // implementation 'com.google.firebase:firebase-messaging:20.0.0'
@ -371,6 +368,8 @@ dependencies {
implementation "androidx.emoji:emoji-appcompat:1.0.0" implementation "androidx.emoji:emoji-appcompat:1.0.0"
implementation 'com.github.BillCarsonFr:JsonViewer:0.4'
// QR-code // QR-code
// Stick to 3.3.3 because of https://github.com/zxing/zxing/issues/1170 // Stick to 3.3.3 because of https://github.com/zxing/zxing/issues/1170
implementation 'com.google.zxing:core:3.3.3' implementation 'com.google.zxing:core:3.3.3'

View file

@ -22,6 +22,7 @@
padding: 4px; padding: 4px;
} }
</style> </style>
</head> </head>
<body> <body>
@ -375,9 +376,7 @@ SOFTWARE.
Copyright (c) 2014 Dushyanth Maguluru Copyright (c) 2014 Dushyanth Maguluru
</li> </li>
<li> <li>
<b>JsonViewer</b> <b>BillCarsonFr/JsonViewer</b>
<br/>
Copyright 2017 smuyyh, All right reserved.
</li> </li>
</ul> </ul>
<pre> <pre>

View file

@ -18,6 +18,8 @@ package im.vector.riotx.core.utils
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.resources.ColorProvider
import org.billcarsonfr.jsonviewer.JSonViewerStyleProvider
import kotlin.math.abs import kotlin.math.abs
@ColorRes @ColorRes
@ -37,3 +39,14 @@ fun getColorFromUserId(userId: String?): Int {
else -> R.color.riotx_username_1 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)
)
}

View file

@ -27,12 +27,10 @@ import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.text.Spannable import android.text.Spannable
import android.view.HapticFeedbackConstants import android.view.HapticFeedbackConstants
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.Window import android.view.Window
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes 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.files.addEntryToDownloadManager
import im.vector.riotx.core.glide.GlideApp import im.vector.riotx.core.glide.GlideApp
import im.vector.riotx.core.platform.VectorBaseFragment 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.JumpToReadMarkerView
import im.vector.riotx.core.ui.views.NotificationAreaView import im.vector.riotx.core.ui.views.NotificationAreaView
import im.vector.riotx.core.utils.Debouncer 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.copyToClipboard
import im.vector.riotx.core.utils.createUIHandler import im.vector.riotx.core.utils.createUIHandler
import im.vector.riotx.core.utils.getColorFromUserId 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.openUrlInExternalBrowser
import im.vector.riotx.core.utils.shareMedia import im.vector.riotx.core.utils.shareMedia
import im.vector.riotx.core.utils.toast 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.fragment_room_detail.*
import kotlinx.android.synthetic.main.merge_composer_layout.view.* import kotlinx.android.synthetic.main.merge_composer_layout.view.*
import kotlinx.android.synthetic.main.merge_overlay_waiting_view.* import kotlinx.android.synthetic.main.merge_overlay_waiting_view.*
import org.billcarsonfr.jsonviewer.JSonViewerDialog
import org.commonmark.parser.Parser import org.commonmark.parser.Parser
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
@ -178,8 +179,8 @@ class RoomDetailFragment @Inject constructor(
private val notificationDrawerManager: NotificationDrawerManager, private val notificationDrawerManager: NotificationDrawerManager,
val roomDetailViewModelFactory: RoomDetailViewModel.Factory, val roomDetailViewModelFactory: RoomDetailViewModel.Factory,
private val eventHtmlRenderer: EventHtmlRenderer, private val eventHtmlRenderer: EventHtmlRenderer,
private val vectorPreferences: VectorPreferences private val vectorPreferences: VectorPreferences,
) : private val colorProvider: ColorProvider) :
VectorBaseFragment(), VectorBaseFragment(),
TimelineEventController.Callback, TimelineEventController.Callback,
VectorInviteView.Callback, VectorInviteView.Callback,
@ -1155,26 +1156,18 @@ class RoomDetailFragment @Inject constructor(
onEditedDecorationClicked(action.messageInformationData) onEditedDecorationClicked(action.messageInformationData)
} }
is EventSharedAction.ViewSource -> { is EventSharedAction.ViewSource -> {
val view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_event_content, null) JSonViewerDialog.newInstance(
view.findViewById<TextView>(R.id.event_content_text_view)?.let { action.content,
it.text = action.content -1,
} jsonViewerStyler(colorProvider)
).show(childFragmentManager, "JSON_VIEWER")
AlertDialog.Builder(requireActivity())
.setView(view)
.setPositiveButton(R.string.ok, null)
.show()
} }
is EventSharedAction.ViewDecryptedSource -> { is EventSharedAction.ViewDecryptedSource -> {
val view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_event_content, null) JSonViewerDialog.newInstance(
view.findViewById<TextView>(R.id.event_content_text_view)?.let { action.content,
it.text = action.content -1,
} jsonViewerStyler(colorProvider)
).show(childFragmentManager, "JSON_VIEWER")
AlertDialog.Builder(requireActivity())
.setView(view)
.setPositiveButton(R.string.ok, null)
.show()
} }
is EventSharedAction.QuickReact -> { is EventSharedAction.QuickReact -> {
// eventId,ClickedOn,Add // eventId,ClickedOn,Add

View file

@ -27,12 +27,16 @@ import im.vector.riotx.R
import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.extensions.configureWith
import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.platform.VectorBaseFragment 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 kotlinx.android.synthetic.main.fragment_generic_recycler.*
import org.billcarsonfr.jsonviewer.JSonViewerDialog
import javax.inject.Inject import javax.inject.Inject
class AccountDataFragment @Inject constructor( class AccountDataFragment @Inject constructor(
val viewModelFactory: AccountDataViewModel.Factory, val viewModelFactory: AccountDataViewModel.Factory,
private val epoxyController: AccountDataEpoxyController private val epoxyController: AccountDataEpoxyController,
private val colorProvider: ColorProvider
) : VectorBaseFragment(), AccountDataEpoxyController.InteractionListener { ) : VectorBaseFragment(), AccountDataEpoxyController.InteractionListener {
override fun getLayoutResId() = R.layout.fragment_generic_recycler override fun getLayoutResId() = R.layout.fragment_generic_recycler
@ -59,7 +63,10 @@ class AccountDataFragment @Inject constructor(
val jsonString = MoshiProvider.providesMoshi() val jsonString = MoshiProvider.providesMoshi()
.adapter(UserAccountDataEvent::class.java) .adapter(UserAccountDataEvent::class.java)
.toJson(fb) .toJson(fb)
JsonViewerBottomSheetDialog.newInstance(jsonString) JSonViewerDialog.newInstance(
.show(childFragmentManager, "JSON_VIEWER") jsonString,
-1, // open All
jsonViewerStyler(colorProvider)
).show(childFragmentManager, "JSON_VIEWER")
} }
} }

View file

@ -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) })
}
}
}
}

View file

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:fillViewport="true"
android:orientation="vertical">
<com.yuyh.jsonviewer.library.JsonRecyclerView
android:id="@+id/rv_json"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="ScrollViewSize" />
</HorizontalScrollView>