diff --git a/lib/services/billing_service.dart b/lib/services/billing_service.dart index e78ecde7f..7416c8882 100644 --- a/lib/services/billing_service.dart +++ b/lib/services/billing_service.dart @@ -113,6 +113,28 @@ class BillingService { } } + Future getUsageInGBs() async { + try { + final response = await _dio.get( + _config.getHttpEndpoint() + "/billing/usage", + queryParameters: { + "startTime": 0, + "endTime": DateTime.now().microsecondsSinceEpoch, + }, + options: Options( + headers: { + "X-Auth-Token": _config.getToken(), + }, + ), + ); + final usageInBytes = response.data["usage"]; + return double.parse( + (usageInBytes / (1024 * 1024 * 1024)).toStringAsFixed(2)); + } catch (e) { + throw e; + } + } + Subscription getSubscription() { final jsonValue = _prefs.getString(subscriptionKey); if (jsonValue == null) { diff --git a/lib/ui/settings_page.dart b/lib/ui/settings_page.dart index a4c65eb9a..e899fd3ef 100644 --- a/lib/ui/settings_page.dart +++ b/lib/ui/settings_page.dart @@ -2,17 +2,15 @@ import 'dart:io'; import 'package:archive/archive_io.dart'; import 'package:crisp/crisp.dart'; -import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_email_sender/flutter_email_sender.dart'; import 'package:flutter_sodium/flutter_sodium.dart'; -import 'package:logging/logging.dart'; import 'package:path_provider/path_provider.dart'; import 'package:photos/core/configuration.dart'; -import 'package:photos/core/network.dart'; import 'package:photos/db/files_db.dart'; +import 'package:photos/services/billing_service.dart'; import 'package:photos/ui/loading_widget.dart'; import 'package:photos/ui/subscription_page.dart'; import 'package:photos/ui/web_page.dart'; @@ -159,29 +157,11 @@ class BackupSettingsWidgetState extends State { } void _getUsage() { - Network.instance - .getDio() - .get( - Configuration.instance.getHttpEndpoint() + "/billing/usage", - queryParameters: { - "startTime": 0, - "endTime": DateTime.now().microsecondsSinceEpoch, - }, - options: Options( - headers: {"X-Auth-Token": Configuration.instance.getToken()}, - ), - ) - .catchError((e) async { - Logger("Settings").severe(e); - }).then((response) async { - if (response != null && response.statusCode == 200) { - final usageInBytes = response.data["usage"]; - if (mounted) { - setState(() { - _usageInGBs = double.parse( - (usageInBytes / (1024 * 1024 * 1024)).toStringAsFixed(2)); - }); - } + BillingService.instance.getUsageInGBs().then((usage) async { + if (mounted) { + setState(() { + _usageInGBs = usage; + }); } }); }