From 3475ea545ed6e5469493402749e7a422f8261a7a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 6 Oct 2022 11:40:18 +0200 Subject: [PATCH] 573 include free disk space in the contact support information (#607) * [#174]added warning screen + StorageChecker.kt * [#174]added warning screen + StorageChecker.kt * added manual test * added manual test * [#573] Include free disk space in the Contact Support information * resolved merge conflicts * code review fixes * [#573] Include free disk space in the Contact Support information * added vector drawable * fixed merge issues * fixed support info test * code review fixes * SupportInfoTest fix * Remove trailing comma Co-authored-by: Carter Jernigan --- .../zcash/ui/screen/support/model/EnvironmentInfo.kt | 10 ++++++++-- .../ui/screen/support/viewmodel/SupportViewModel.kt | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/model/EnvironmentInfo.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/model/EnvironmentInfo.kt index 9077e768..4a662698 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/model/EnvironmentInfo.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/model/EnvironmentInfo.kt @@ -3,19 +3,25 @@ package co.electriccoin.zcash.ui.screen.support.model import android.annotation.SuppressLint import android.content.Context import cash.z.ecc.sdk.ext.ui.model.MonetarySeparators +import co.electriccoin.zcash.global.StorageChecker import co.electriccoin.zcash.spackle.AndroidApiVersion import java.util.Locale -class EnvironmentInfo(val locale: Locale, val monetarySeparators: MonetarySeparators) { +class EnvironmentInfo(val locale: Locale, val monetarySeparators: MonetarySeparators, val usableStorageMegabytes: Int) { fun toSupportString() = buildString { appendLine("Locale: ${locale.androidResName()}") appendLine("Currency grouping separator: ${monetarySeparators.grouping}") appendLine("Currency decimal separator: ${monetarySeparators.decimal}") + appendLine("Usable storage: $usableStorageMegabytes MB") } companion object { - fun new(context: Context) = EnvironmentInfo(currentLocale(context), MonetarySeparators.current()) + suspend fun new(context: Context): EnvironmentInfo { + val usableStorage = StorageChecker.checkAvailableStorageMegabytes() + + return EnvironmentInfo(currentLocale(context), MonetarySeparators.current(), usableStorage) + } private fun currentLocale(context: Context) = if (AndroidApiVersion.isAtLeastN) { currentLocaleNPlus(context) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/viewmodel/SupportViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/viewmodel/SupportViewModel.kt index 78de627a..527a7525 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/viewmodel/SupportViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/support/viewmodel/SupportViewModel.kt @@ -16,6 +16,8 @@ class SupportViewModel(application: Application) : AndroidViewModel(application) // Technically, some of the support info could be invalidated after a configuration change, // such as the user's current locale. However it really doesn't matter here since all we // care about is capturing a snapshot of the app, OS, and device state. - val supportInfo: StateFlow = flow { emit(SupportInfo.new(application)) } + val supportInfo: StateFlow = flow { + emit(SupportInfo.new(application)) + } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT, Duration.ZERO), null) }