mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Analytics: add actions in debug screen to manually test the optin screen
This commit is contained in:
parent
d804d1b6c5
commit
3689a62aae
@ -5,6 +5,7 @@
|
||||
<application>
|
||||
<activity android:name=".features.debug.TestLinkifyActivity" />
|
||||
<activity android:name=".features.debug.DebugPermissionActivity" />
|
||||
<activity android:name=".features.debug.analytics.DebugAnalyticsActivity" />
|
||||
<activity android:name=".features.debug.settings.DebugPrivateSettingsActivity" />
|
||||
<activity android:name=".features.debug.sas.DebugSasEmojiActivity" />
|
||||
</application>
|
||||
|
@ -34,6 +34,7 @@ import im.vector.app.core.utils.checkPermissions
|
||||
import im.vector.app.core.utils.registerForPermissionsResult
|
||||
import im.vector.app.core.utils.toast
|
||||
import im.vector.app.databinding.ActivityDebugMenuBinding
|
||||
import im.vector.app.features.debug.analytics.DebugAnalyticsActivity
|
||||
import im.vector.app.features.debug.sas.DebugSasEmojiActivity
|
||||
import im.vector.app.features.debug.settings.DebugPrivateSettingsActivity
|
||||
import im.vector.app.features.qrcode.QrCodeScannerActivity
|
||||
@ -77,6 +78,9 @@ class DebugMenuActivity : VectorBaseActivity<ActivityDebugMenuBinding>() {
|
||||
|
||||
private fun setupViews() {
|
||||
views.debugPrivateSetting.setOnClickListener { openPrivateSettings() }
|
||||
views.debugAnalytics.setOnClickListener {
|
||||
startActivity(Intent(this, DebugAnalyticsActivity::class.java))
|
||||
}
|
||||
views.debugTestTextViewLink.setOnClickListener { testTextViewLink() }
|
||||
views.debugOpenButtonStylesLight.setOnClickListener {
|
||||
startActivity(Intent(this, DebugVectorButtonStylesLightActivity::class.java))
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.app.features.debug.analytics
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.addFragment
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.databinding.ActivitySimpleBinding
|
||||
|
||||
@AndroidEntryPoint
|
||||
class DebugAnalyticsActivity : VectorBaseActivity<ActivitySimpleBinding>() {
|
||||
|
||||
override fun getBinding() = ActivitySimpleBinding.inflate(layoutInflater)
|
||||
|
||||
override fun initUiAndData() {
|
||||
if (isFirstCreation()) {
|
||||
addFragment(
|
||||
R.id.simpleFragmentContainer,
|
||||
DebugAnalyticsFragment::class.java
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.app.features.debug.analytics
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.app.core.epoxy.onClick
|
||||
import im.vector.app.core.extensions.toOnOff
|
||||
import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.databinding.FragmentDebugAnalyticsBinding
|
||||
import me.gujun.android.span.span
|
||||
|
||||
class DebugAnalyticsFragment : VectorBaseFragment<FragmentDebugAnalyticsBinding>() {
|
||||
|
||||
private val viewModel: DebugAnalyticsViewModel by fragmentViewModel()
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentDebugAnalyticsBinding {
|
||||
return FragmentDebugAnalyticsBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setViewListeners()
|
||||
}
|
||||
|
||||
private fun setViewListeners() {
|
||||
views.showAnalyticsOptIn.onClick {
|
||||
navigator.openAnalyticsOptIn(requireContext())
|
||||
}
|
||||
views.resetAnalyticsOptInDisplayed.onClick {
|
||||
viewModel.handle(DebugAnalyticsViewActions.ResetAnalyticsOptInDisplayed)
|
||||
}
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(viewModel) { state ->
|
||||
views.analyticsStoreContent.text = span {
|
||||
+"AnalyticsId: "
|
||||
span {
|
||||
textStyle = "bold"
|
||||
text = state.analyticsId.orEmpty()
|
||||
}
|
||||
+"\nOptIn: "
|
||||
span {
|
||||
textStyle = "bold"
|
||||
text = state.userConsent.toOnOff()
|
||||
}
|
||||
+"\nDidAsk: "
|
||||
span {
|
||||
textStyle = "bold"
|
||||
text = state.didAskUserConsent.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.app.features.debug.analytics
|
||||
|
||||
import im.vector.app.core.platform.VectorViewModelAction
|
||||
|
||||
sealed interface DebugAnalyticsViewActions : VectorViewModelAction {
|
||||
object ResetAnalyticsOptInDisplayed : DebugAnalyticsViewActions
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.app.features.debug.analytics
|
||||
|
||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||
import im.vector.app.core.extensions.exhaustive
|
||||
import im.vector.app.core.platform.EmptyViewEvents
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.features.analytics.store.AnalyticsStore
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class DebugAnalyticsViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: DebugAnalyticsViewState,
|
||||
private val analyticsStore: AnalyticsStore
|
||||
) : VectorViewModel<DebugAnalyticsViewState, DebugAnalyticsViewActions, EmptyViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : MavericksAssistedViewModelFactory<DebugAnalyticsViewModel, DebugAnalyticsViewState> {
|
||||
override fun create(initialState: DebugAnalyticsViewState): DebugAnalyticsViewModel
|
||||
}
|
||||
|
||||
companion object : MavericksViewModelFactory<DebugAnalyticsViewModel, DebugAnalyticsViewState> by hiltMavericksViewModelFactory()
|
||||
|
||||
init {
|
||||
observerStore()
|
||||
}
|
||||
|
||||
private fun observerStore() {
|
||||
analyticsStore.analyticsIdFlow.setOnEach { copy(analyticsId = it) }
|
||||
analyticsStore.userConsentFlow.setOnEach { copy(userConsent = it) }
|
||||
analyticsStore.didAskUserConsentFlow.setOnEach { copy(didAskUserConsent = it) }
|
||||
}
|
||||
|
||||
override fun handle(action: DebugAnalyticsViewActions) {
|
||||
when (action) {
|
||||
DebugAnalyticsViewActions.ResetAnalyticsOptInDisplayed -> handleResetAnalyticsOptInDisplayed()
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
private fun handleResetAnalyticsOptInDisplayed() {
|
||||
viewModelScope.launch {
|
||||
analyticsStore.setDidAskUserConsent(false)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.app.features.debug.analytics
|
||||
|
||||
import com.airbnb.mvrx.MavericksState
|
||||
|
||||
data class DebugAnalyticsViewState(
|
||||
val analyticsId: String? = null,
|
||||
val userConsent: Boolean = false,
|
||||
val didAskUserConsent: Boolean = false
|
||||
) : MavericksState
|
@ -23,12 +23,18 @@ import dagger.multibindings.IntoMap
|
||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||
import im.vector.app.core.di.MavericksViewModelComponent
|
||||
import im.vector.app.core.di.MavericksViewModelKey
|
||||
import im.vector.app.features.debug.analytics.DebugAnalyticsViewModel
|
||||
import im.vector.app.features.debug.settings.DebugPrivateSettingsViewModel
|
||||
|
||||
@InstallIn(MavericksViewModelComponent::class)
|
||||
@Module
|
||||
interface MavericksViewModelDebugModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@MavericksViewModelKey(DebugAnalyticsViewModel::class)
|
||||
fun debugAnalyticsViewModelFactory(factory: DebugAnalyticsViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@MavericksViewModelKey(DebugPrivateSettingsViewModel::class)
|
||||
|
@ -26,6 +26,12 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Private settings" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/debug_analytics"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Analytics" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/debug_test_text_view_link"
|
||||
android:layout_width="wrap_content"
|
||||
|
43
vector/src/debug/res/layout/fragment_debug_analytics.xml
Normal file
43
vector/src/debug/res/layout/fragment_debug_analytics.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/coordinatorLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".features.debug.analytics.DebugAnalyticsActivity"
|
||||
tools:ignore="HardcodedText">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@drawable/linear_divider"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/layout_horizontal_margin"
|
||||
android:showDividers="middle">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/analytics_store_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Store content" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/show_analytics_opt_in"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Show Analytics Opt in" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/reset_analytics_opt_in_displayed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Reset Analytics Opt in Displayed" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -61,9 +61,9 @@ class AnalyticsStore @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setDidAskUserConsent() {
|
||||
suspend fun setDidAskUserConsent(newValue: Boolean = true) {
|
||||
context.dataStore.edit { settings ->
|
||||
settings[didAskUserConsent] = true
|
||||
settings[didAskUserConsent] = newValue
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user