diff --git a/lib/ui/settings/storage_card_widget.dart b/lib/ui/settings/storage_card_widget.dart index ba832bdbb..c936b9eca 100644 --- a/lib/ui/settings/storage_card_widget.dart +++ b/lib/ui/settings/storage_card_widget.dart @@ -118,17 +118,27 @@ class _StorageCardWidgetState extends State { Widget userDetails(UserDetails userDetails) { const hundredMBinBytes = 107374182; + const oneTBinBytes = 1073741824000; - final isMobileScreenSmall = MediaQuery.of(context).size.width <= 365; - final freeSpaceInBytes = userDetails.getFreeStorage(); - final shouldShowFreeSpaceInMBs = freeSpaceInBytes < hundredMBinBytes; + final usedStorageInBytes = + userDetails.getFamilyOrPersonalUsage() - userDetails.getFreeStorage(); + final totalStorageInBytes = userDetails.getTotalStorage(); + final freeStorageInBytes = totalStorageInBytes - usedStorageInBytes; - final usedSpaceInGB = roundBytesUsedToGBs( - userDetails.getFamilyOrPersonalUsage(), - userDetails.getFreeStorage(), + final isMobileScreenSmall = MediaQuery.of(context).size.width <= 360; + final shouldShowFreeSpaceInMBs = freeStorageInBytes <= hundredMBinBytes; + final shouldShowFreeSpaceInTBs = freeStorageInBytes >= oneTBinBytes; + final shouldShowUsedSpaceInTBs = usedStorageInBytes >= oneTBinBytes; + final shouldShowTotalSpaceInTBs = totalStorageInBytes >= oneTBinBytes; + + final usedStorageInGB = roundBytesUsedToGBs( + usedStorageInBytes, + freeStorageInBytes, ); - final totalStorageInGB = - convertBytesToGBs(userDetails.getTotalStorage()).truncate(); + final totalStorageInGB = convertBytesToGBs(totalStorageInBytes).truncate(); + + final usedStorageInTB = roundGBsToTBs(usedStorageInGB); + final totalStorageInTB = roundGBsToTBs(totalStorageInGB); return Padding( padding: EdgeInsets.fromLTRB( @@ -159,12 +169,15 @@ class _StorageCardWidgetState extends State { style: getEnteTextTheme(context) .h3Bold .copyWith(color: textBaseDark), - children: [ - TextSpan(text: usedSpaceInGB.toString()), - TextSpan(text: isMobileScreenSmall ? "/" : " GB of "), - TextSpan(text: totalStorageInGB.toString() + " GB"), - TextSpan(text: isMobileScreenSmall ? "" : " used"), - ], + children: storageDetails( + isMobileScreenSmall: isMobileScreenSmall, + shouldShowTotalSpaceInTBs: shouldShowTotalSpaceInTBs, + shouldShowUsedSpaceInTBs: shouldShowUsedSpaceInTBs, + usedStorageInGB: usedStorageInGB, + totalStorageInTB: totalStorageInTB, + usedStorageInTB: usedStorageInTB, + totalStorageInGB: totalStorageInGB, + ), ), ), ], @@ -246,12 +259,14 @@ class _StorageCardWidgetState extends State { children: [ TextSpan( text: - "${shouldShowFreeSpaceInMBs ? convertBytesToMBs(freeSpaceInBytes) : _roundedFreeSpace(totalStorageInGB, usedSpaceInGB)}", + "${shouldShowFreeSpaceInMBs ? convertBytesToMBs(freeStorageInBytes) : _roundedFreeSpace(totalStorageInGB, usedStorageInGB)}", ), TextSpan( - text: shouldShowFreeSpaceInMBs - ? " MB free" - : " GB free", + text: shouldShowFreeSpaceInTBs + ? " TB free" + : shouldShowFreeSpaceInMBs + ? " MB free" + : " GB free", ) ], ), @@ -265,20 +280,54 @@ class _StorageCardWidgetState extends State { ); } - num _roundedFreeSpace(num totalStorageInGB, num usedSpaceInGB) { + num _roundedFreeSpace(num totalStorageInGB, num usedStorageInGB) { int fractionDigits; //subtracting usedSpace from totalStorage in GB instead of converting from bytes so that free space and used space adds up in the UI - final freeSpace = totalStorageInGB - usedSpaceInGB; + final freeStorage = totalStorageInGB - usedStorageInGB; + + if (freeStorage >= 1000) { + return roundGBsToTBs(freeStorage); + } //show one decimal place if free space is less than 10GB - if (freeSpace < 10) { + if (freeStorage < 10) { fractionDigits = 1; } else { fractionDigits = 0; } //omit decimal if decimal is 0 - if (fractionDigits == 1 && freeSpace.remainder(1) == 0) { + if (fractionDigits == 1 && freeStorage.remainder(1) == 0) { fractionDigits = 0; } - return num.parse(freeSpace.toStringAsFixed(fractionDigits)); + return num.parse(freeStorage.toStringAsFixed(fractionDigits)); + } + + List storageDetails({ + @required isMobileScreenSmall, + @required shouldShowUsedSpaceInTBs, + @required shouldShowTotalSpaceInTBs, + @required usedStorageInGB, + @required totalStorageInGB, + @required usedStorageInTB, + @required totalStorageInTB, + }) { + if (isMobileScreenSmall) { + return [ + TextSpan(text: usedStorageInGB.toString() + "/"), + TextSpan(text: totalStorageInGB.toString() + " GB"), + ]; + } + + return [ + TextSpan( + text: shouldShowUsedSpaceInTBs + ? usedStorageInTB.toString() + " TB of " + : usedStorageInGB.toString() + " GB of ", + ), + TextSpan( + text: shouldShowTotalSpaceInTBs + ? totalStorageInTB.toString() + " TB used" + : totalStorageInGB.toString() + " GB used", + ), + ]; } } diff --git a/lib/utils/data_util.dart b/lib/utils/data_util.dart index a21bc4557..c217d6e3f 100644 --- a/lib/utils/data_util.dart +++ b/lib/utils/data_util.dart @@ -38,3 +38,12 @@ num convertBytesToGBs(int bytes) { int convertBytesToMBs(int bytes) { return (bytes / pow(1024, 2)).round(); } + +roundGBsToTBs(sizeInGBs) { + final num sizeInTBs = num.parse((sizeInGBs / 1000).toStringAsFixed(1)); + if (sizeInTBs % 1 == 0) { + return sizeInTBs.truncate(); + } else { + return sizeInTBs; + } +}