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"
// And monarchy
includeGroupByRegex "com\\.github\\.Zhuinden"
includeGroupByRegex 'com\\.github\\.BillCarsonFr'
}
}
maven {

View File

@ -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'

View File

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

View File

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

View File

@ -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<TextView>(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<TextView>(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

View File

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

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>