Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,20 @@ class PublishConventionPlugin : Plugin<Project> {
}
}
}
signAllPublications()

if (hasSigningKeys()) {
signAllPublications()
}
}
}

private fun hasSigningKeys(): Boolean {
val signingKeyId = System.getenv("ORG_GRADLE_PROJECT_signingInMemoryKeyId")
val signingKeyPassword = System.getenv("ORG_GRADLE_PROJECT_signingInMemoryKeyPassword")
val signingKey = System.getenv("ORG_GRADLE_PROJECT_signingInMemoryKey")

return !signingKeyId.isNullOrBlank() &&
!signingKeyPassword.isNullOrBlank() &&
!signingKey.isNullOrBlank()
}
}
2 changes: 1 addition & 1 deletion libraries/analytics-logger-no-op/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
}

group = "com.trendyol.android.devtools"
version = "0.6.0"
version = "0.7.0"

publishConfig {
defaultConfiguration(
Expand Down
2 changes: 1 addition & 1 deletion libraries/analytics-logger/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
}

group = "com.trendyol.android.devtools"
version = "0.6.0"
version = "0.7.0"

publishConfig {
defaultConfiguration(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.trendyol.android.devtools.analyticslogger.internal.data.repository

import android.content.SharedPreferences
import androidx.core.content.edit

internal class ExcludeKeysRepository(
private val sharedPreferences: SharedPreferences
) {

fun saveExcludedKeys(keys: String) {
sharedPreferences.edit {
putString(EXCLUDED_KEYS_KEY, keys)
}
}

fun getExcludedKeys(): String {
return sharedPreferences.getString(EXCLUDED_KEYS_KEY, "").orEmpty()
}

companion object {
private const val EXCLUDED_KEYS_KEY = "excluded_event_keys"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import com.trendyol.android.devtools.analyticslogger.internal.data.database.EventDatabase
import com.trendyol.android.devtools.analyticslogger.internal.data.repository.EventRepository
import com.trendyol.android.devtools.analyticslogger.internal.data.repository.EventRepositoryImpl
import com.trendyol.android.devtools.analyticslogger.internal.data.repository.ExcludeKeysRepository
import com.trendyol.android.devtools.analyticslogger.internal.domain.manager.EventManager
import com.trendyol.android.devtools.analyticslogger.internal.domain.manager.EventManagerImpl
import com.trendyol.android.devtools.analyticslogger.internal.domain.usecase.ExcludeKeysUseCase

internal class AnalyticsContainer(private val context: Context) {

Expand All @@ -25,4 +27,12 @@ internal class AnalyticsContainer(private val context: Context) {
val sharedPreferencesManager: SharedPreferences by lazy {
context.getSharedPreferences("analytics_logger", Context.MODE_PRIVATE)
}

private val excludeKeysRepository: ExcludeKeysRepository by lazy {
ExcludeKeysRepository(sharedPreferencesManager)
}

val excludeKeysUseCase: ExcludeKeysUseCase by lazy {
ExcludeKeysUseCase(excludeKeysRepository)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.trendyol.android.devtools.analyticslogger.internal.domain.usecase

import android.util.Log
import com.trendyol.android.devtools.analyticslogger.internal.data.repository.ExcludeKeysRepository
import org.json.JSONException
import org.json.JSONObject

internal class ExcludeKeysUseCase(
private val excludeKeysRepository: ExcludeKeysRepository
) {

fun saveExcludedKeys(keys: String) {
excludeKeysRepository.saveExcludedKeys(keys)
}

fun getExcludedKeys(): String {
return excludeKeysRepository.getExcludedKeys()
}

fun getExcludedKeysList(): List<String> {
return getExcludedKeys()
.split(" ")
.map { it.trim() }
.filter { it.isNotEmpty() }
}

fun filterJsonByExcludedKeys(jsonString: String, excludedKeys: List<String>): String {
if (excludedKeys.isEmpty() || jsonString.isEmpty()) {
return jsonString
}

return try {
val jsonObject = JSONObject(jsonString)
excludedKeys.forEach { key ->
removeKeyRecursively(jsonObject, key)
}
jsonObject.toString(4)
} catch (e: JSONException) {
Log.e("AnalyticsLogger", e.message.toString())
jsonString
}
}

private fun removeKeyRecursively(jsonObject: JSONObject, keyToRemove: String) {
jsonObject.remove(keyToRemove)

val keys = jsonObject.keys()
while (keys.hasNext()) {
val key = keys.next()
val value = jsonObject.opt(key)
if (value is JSONObject) {
removeKeyRecursively(value, keyToRemove)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.text.SpannableString
import android.text.style.BackgroundColorSpan
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
Expand Down Expand Up @@ -33,7 +36,12 @@ internal class DetailFragment : Fragment() {
ContextContainer.mainContainer.MainViewModelFactory()
}

private val excludeKeysUseCase by lazy {
ContextContainer.analyticsContainer.excludeKeysUseCase
}

private var _binding: AnalyticsLoggerFragmentDetailBinding? = null
private var originalJsonText: String = ""

private val binding get() = _binding!!

Expand Down Expand Up @@ -62,6 +70,15 @@ internal class DetailFragment : Fragment() {
checkboxShowJSTransformFunction.setOnCheckedChangeListener { _, isChecked ->
editTextjsTransformFunction.visibility = if (isChecked) View.VISIBLE else View.GONE
}

editTextExcludeEventKeys.setText(excludeKeysUseCase.getExcludedKeys())
editTextExcludeEventKeys.doAfterTextChanged { editable ->
excludeKeysUseCase.saveExcludedKeys(editable.toString())
}

editTextHighlightEventText.doAfterTextChanged { editable ->
highlightTextInJsonView(editable.toString())
}
}

private fun observeData() {
Expand All @@ -76,7 +93,8 @@ internal class DetailFragment : Fragment() {
if (state is DetailState.Selected) {
textViewKey.text = state.event.key
textViewSource.text = state.event.source
textViewValue.text = state.event.json
originalJsonText = state.event.json.orEmpty()
highlightTextInJsonView(editTextHighlightEventText.text.toString())
textViewDate.text = state.event.date
textViewPlatform.text = state.event.platform
textViewPlatform.background = createPlatformBackground(state.event.platform)
Expand Down Expand Up @@ -104,10 +122,44 @@ internal class DetailFragment : Fragment() {
}
}

private fun highlightTextInJsonView(searchText: String) {
if (originalJsonText.isEmpty()) {
return
}

if (searchText.isEmpty()) {
binding.textViewValue.text = originalJsonText
return
}

val spannableString = SpannableString(originalJsonText)
val searchTextLower = searchText.lowercase()
val originalTextLower = originalJsonText.lowercase()
val highlightColor = Color.YELLOW

var startIndex = 0
while (true) {
val index = originalTextLower.indexOf(searchTextLower, startIndex)
if (index == -1) break

spannableString.setSpan(
BackgroundColorSpan(highlightColor),
index,
index + searchText.length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
startIndex = index + 1
}

binding.textViewValue.text = spannableString
}

private fun copyToClipboard() {
val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val data = (viewModel.detailState.value as? DetailState.Selected)?.event?.json.orEmpty()
clipboard.setPrimaryClip(ClipData.newPlainText(CLIPBOARD_LABEL, data))
val originalData = (viewModel.detailState.value as? DetailState.Selected)?.event?.json.orEmpty()
val excludedKeys = excludeKeysUseCase.getExcludedKeysList()
val filteredData = excludeKeysUseCase.filterJsonByExcludedKeys(originalData, excludedKeys)
clipboard.setPrimaryClip(ClipData.newPlainText(CLIPBOARD_LABEL, filteredData))
Toast.makeText(context, R.string.analytics_logger_toast_copied, Toast.LENGTH_SHORT).show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,24 @@
app:layout_constraintEnd_toStartOf="@id/textViewPlatform"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textViewKey"
tools:text="12.00PM"/>
tools:text="12.00PM" />

<TextView
android:id="@+id/textViewSource"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginEnd="12dp"
android:textColor="@color/textColorPrimary"
android:ellipsize="end"
android:lines="2"
android:textColor="@color/textColorPrimary"
android:textSize="12sp"
android:textStyle="italic"
app:layout_constraintEnd_toStartOf="@id/textViewPlatform"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textViewDate"
tools:text="com.trendyol.product.ProductClickEvent" />

<TextView
android:id="@+id/textViewPlatform"
android:layout_width="wrap_content"
Expand All @@ -63,13 +64,60 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayoutExcludedEventKeys"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/analytics_logger_event_key_exclusion_hint"
app:boxStrokeColor="?android:attr/textColorPrimary"
app:hintTextColor="?android:attr/textColorSecondary"
app:layout_constraintTop_toBottomOf="@id/textViewSource">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextExcludeEventKeys"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="3"
android:scrollHorizontally="false"
android:textColor="?android:attr/textColorPrimary"
android:textColorHint="?android:attr/textColorSecondary"
android:textCursorDrawable="@null"
android:textSize="12sp" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayoutHighlightEventText"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/analytics_logger_event_highlight_hint"
app:boxStrokeColor="?android:attr/textColorPrimary"
app:hintTextColor="?android:attr/textColorSecondary"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutExcludedEventKeys">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextHighlightEventText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:scrollHorizontally="false"
android:textColor="?android:attr/textColorPrimary"
android:textColorHint="?android:attr/textColorSecondary"
android:textCursorDrawable="@null"
android:textSize="12sp" />
</com.google.android.material.textfield.TextInputLayout>

<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/textViewSource"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutHighlightEventText"
app:layout_constraintVertical_bias="0"
tools:background="@drawable/analytics_logger_json_background">

Expand Down Expand Up @@ -102,9 +150,9 @@
android:id="@+id/editTextjsTransformFunction"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/checkboxShowJSTransformFunction" />
</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
3 changes: 3 additions & 0 deletions libraries/analytics-logger/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<string name="analytics_logger_action_copy_source">Source</string>

<string name="analytics_logger_toast_copied">Copied to the clipboard.</string>

<string name="analytics_logger_event_key_exclusion_hint">Event keys to exclude (space separated)</string>
<string name="analytics_logger_event_highlight_hint">Highlight event text</string>
</resources>
Loading