Skip to content

Commit ba7bb94

Browse files
committed
fix(accesskey): add background only to exported photo
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 0145b98 commit ba7bb94

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

app/src/main/java/com/getcode/view/login/BaseAccessKeyViewModel.kt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ data class AccessKeyUiModel(
5252
val accessKeyCroppedBitmap: Bitmap? = null,
5353
)
5454

55-
abstract class BaseAccessKeyViewModel(private val resources: ResourceHelper) : BaseViewModel(resources) {
55+
abstract class BaseAccessKeyViewModel(private val resources: ResourceHelper) :
56+
BaseViewModel(resources) {
5657
val uiFlow = MutableStateFlow(AccessKeyUiModel())
5758

58-
@OptIn(InternalCoroutinesApi::class)
5959
fun init() {
6060
viewModelScope.launch {
6161
SessionManager.authState
62-
.distinctUntilChangedBy { it?.entropyB64 }
63-
.collect(
64-
FlowCollector { it?.entropyB64?.let { e -> initWithEntropy(e) } }
65-
)
62+
.distinctUntilChangedBy { it.entropyB64 }
63+
.collect { it.entropyB64?.let { e -> initWithEntropy(e) } }
6664
}
6765
}
6866

@@ -79,8 +77,9 @@ abstract class BaseAccessKeyViewModel(private val resources: ResourceHelper) : B
7977
)
8078

8179
CoroutineScope(Dispatchers.IO).launch {
82-
val accessKeyBitmap = createBitmapForExport(words, entropyB64)
83-
val accessKeyCroppedBitmap = Bitmap.createBitmap(accessKeyBitmap, 0, 300, 1200, 1450)
80+
val accessKeyBitmap = createBitmapForExport(words = words, entropyB64 = entropyB64)
81+
val accessKeyBitmapDisplay = createBitmapForExport(drawBackground = false, words, entropyB64)
82+
val accessKeyCroppedBitmap = Bitmap.createBitmap(accessKeyBitmapDisplay, 0, 300, 1200, 1450)
8483

8584
uiFlow.value = uiFlow.value.copy(
8685
accessKeyBitmap = accessKeyBitmap,
@@ -132,11 +131,15 @@ abstract class BaseAccessKeyViewModel(private val resources: ResourceHelper) : B
132131
return true
133132
}
134133

135-
private fun createBitmapForExport(words: List<String>, entropyB64: String): Bitmap {
134+
private fun createBitmapForExport(
135+
drawBackground: Boolean = true,
136+
words: List<String>,
137+
entropyB64: String
138+
): Bitmap {
136139
val accessKeyText = getAccessKeyText(words)
137140

138141
val accessKeyBg = resources.getDrawable(R.drawable.ic_access_key_bg)
139-
?.toBitmap(812, 1353)!!
142+
?.toBitmap(812, 1353)!!
140143

141144
val imageLogo =
142145
resources.getDrawable(R.drawable.ic_code_logo_white)
@@ -148,6 +151,14 @@ abstract class BaseAccessKeyViewModel(private val resources: ResourceHelper) : B
148151
).applyCanvas {
149152
val accessBgActualWidth =
150153
accessKeyBg.getScaledWidth(resources.displayMetrics)
154+
155+
if (drawBackground) {
156+
val paintBackground = Paint()
157+
paintBackground.color = Brand.toAGColor()
158+
paintBackground.style = Paint.Style.FILL
159+
drawPaint(paintBackground)
160+
}
161+
151162
drawBitmap(
152163
accessKeyBg,
153164
(((targetWidth - accessBgActualWidth) / 2)).toFloat(),

0 commit comments

Comments
 (0)