1
1
package com.x8bit.bitwarden.ui.platform.feature.settings.about
2
2
3
- import android.os.Build
4
3
import android.os.Parcelable
5
4
import androidx.lifecycle.SavedStateHandle
6
5
import androidx.lifecycle.viewModelScope
7
- import com.x8bit.bitwarden.BuildConfig
8
6
import com.x8bit.bitwarden.R
9
7
import com.x8bit.bitwarden.data.platform.manager.LogsManager
10
8
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
11
9
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
12
10
import com.x8bit.bitwarden.data.platform.repository.util.baseWebVaultUrlOrDefault
11
+ import com.x8bit.bitwarden.data.platform.util.ciBuildInfo
12
+ import com.x8bit.bitwarden.data.platform.util.deviceData
13
13
import com.x8bit.bitwarden.data.platform.util.isFdroid
14
+ import com.x8bit.bitwarden.data.platform.util.versionData
14
15
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
15
16
import com.x8bit.bitwarden.ui.platform.base.util.Text
16
17
import com.x8bit.bitwarden.ui.platform.base.util.asText
@@ -37,10 +38,15 @@ class AboutViewModel @Inject constructor(
37
38
private val logsManager : LogsManager ,
38
39
private val environmentRepository : EnvironmentRepository ,
39
40
) : BaseViewModel<AboutState, AboutEvent, AboutAction>(
40
- initialState = savedStateHandle[KEY_STATE ] ? : createInitialState(
41
- clock = clock,
42
- isCrashLoggingEnabled = logsManager.isEnabled,
43
- ),
41
+ initialState = savedStateHandle[KEY_STATE ]
42
+ ? : AboutState (
43
+ version = R .string.version.asText().concat(": $versionData".asText()),
44
+ deviceData = deviceData.asText(),
45
+ ciData = ciBuildInfo?.let { "\n$it" }.orEmpty().asText(),
46
+ isSubmitCrashLogsEnabled = logsManager.isEnabled,
47
+ shouldShowCrashLogsButton = !isFdroid,
48
+ copyrightInfo = "© Bitwarden Inc . 2015-${Year .now(clock).value}".asText(),
49
+ ),
44
50
) {
45
51
init {
46
52
stateFlow
@@ -92,34 +98,13 @@ class AboutViewModel @Inject constructor(
92
98
}
93
99
94
100
private fun handleVersionClick () {
95
- val buildFlavour = when (BuildConfig .FLAVOR ) {
96
- " standard" -> " "
97
- else -> " -${BuildConfig .FLAVOR } "
98
- }
99
-
100
- val buildVariant = when (BuildConfig .BUILD_TYPE ) {
101
- " debug" -> " dev"
102
- " release" -> " prod"
103
- else -> BuildConfig .BUILD_TYPE
104
- }
105
-
106
- val deviceBrandModel = " \uD83D\uDCF1 ${Build .BRAND } ${Build .MODEL } "
107
- val osInfo = " \uD83E\uDD16 ${Build .VERSION .RELEASE } @${Build .VERSION .SDK_INT } "
108
- val buildInfo = " \uD83D\uDCE6 $buildVariant$buildFlavour "
109
- val ciBuildInfoString = BuildConfig .CI_INFO
110
-
111
101
clipboardManager.setText(
112
102
text = state.copyrightInfo
113
103
.concat(" \n\n " .asText())
114
104
.concat(state.version)
115
105
.concat(" \n " .asText())
116
- .concat(" $deviceBrandModel $osInfo $buildInfo " .asText())
117
- .concat(
118
- " \n $ciBuildInfoString "
119
- .takeUnless { ciBuildInfoString.isEmpty() }
120
- .orEmpty()
121
- .asText(),
122
- ),
106
+ .concat(state.deviceData)
107
+ .concat(state.ciData),
123
108
)
124
109
}
125
110
@@ -130,26 +115,6 @@ class AboutViewModel @Inject constructor(
130
115
),
131
116
)
132
117
}
133
-
134
- @Suppress(" UndocumentedPublicClass" )
135
- companion object {
136
- /* *
137
- * Create initial state for the About View model.
138
- */
139
- fun createInitialState (clock : Clock , isCrashLoggingEnabled : Boolean ): AboutState {
140
- val currentYear = Year .now(clock).value
141
- val copyrightInfo = " © Bitwarden Inc. 2015-$currentYear " .asText()
142
-
143
- return AboutState (
144
- version = R .string.version
145
- .asText()
146
- .concat(" : ${BuildConfig .VERSION_NAME } (${BuildConfig .VERSION_CODE } )" .asText()),
147
- isSubmitCrashLogsEnabled = isCrashLoggingEnabled,
148
- shouldShowCrashLogsButton = ! isFdroid,
149
- copyrightInfo = copyrightInfo,
150
- )
151
- }
152
- }
153
118
}
154
119
155
120
/* *
@@ -158,6 +123,8 @@ class AboutViewModel @Inject constructor(
158
123
@Parcelize
159
124
data class AboutState (
160
125
val version : Text ,
126
+ val deviceData : Text ,
127
+ val ciData : Text ,
161
128
val isSubmitCrashLogsEnabled : Boolean ,
162
129
val shouldShowCrashLogsButton : Boolean ,
163
130
val copyrightInfo : Text ,
0 commit comments