From 930d014520f9aee4c7943f3de96cf5fbcb3e47c9 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Mon, 30 May 2022 17:56:36 +0530 Subject: [PATCH 1/2] eDrive: handle Invalid totalBytes for link parsing --- .../e/drive/activity/AccountsActivity.java | 2 +- .../foundation/e/drive/widgets/EDriveWidget.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java index dc911d45..f40413ca 100644 --- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -143,7 +143,7 @@ public class AccountsActivity extends AppCompatActivity { binding.upgrade.setOnClickListener(v -> { final Intent upgradeIntent = buildIntent(Intent.ACTION_VIEW, String.format(EDriveWidget.WEBPAGE, email, - dataForWeb(Long.parseLong(totalQuota)))); + dataForWeb(totalQuota))); startActivity(upgradeIntent); }); diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index 0041f9ab..fd77681a 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -68,8 +68,14 @@ public class EDriveWidget extends AppWidgetProvider { private RemoteViews views; private Account account = null; - public static String dataForWeb(Long bytes) { - final String space = CommonUtils.humanReadableByteCountBin(bytes); + public static String dataForWeb(String bytes) { + long convertedBytes = 0; + try { + convertedBytes = Long.parseLong(bytes); + } catch (NumberFormatException e ) { + Log.i(TAG, "Invalid bytes " + bytes); + } + final String space = CommonUtils.humanReadableByteCountBin(convertedBytes); final String[] split = space.split(" "); return Math.round(Double.parseDouble(split[0])) + split[1]; } @@ -284,8 +290,7 @@ public class EDriveWidget extends AppWidgetProvider { final PendingIntent pendingIntentUpgrade = PendingIntent.getActivity(context, 0, buildIntent(Intent.ACTION_VIEW, String.format(WEBPAGE, email, - dataForWeb(Long.parseLong(totalQuota)))), - PendingIntent.FLAG_IMMUTABLE); + dataForWeb(totalQuota))), PendingIntent.FLAG_IMMUTABLE); views.setOnClickPendingIntent(R.id.upgrade, pendingIntentUpgrade); } -- GitLab From e4c3177da17d903bd16013bc7c5a5b19b363c9db Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 30 May 2022 12:56:24 +0000 Subject: [PATCH 2/2] Apply 1 suggestion(s) to 1 file(s) --- app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index fd77681a..25d870f7 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -72,7 +72,7 @@ public class EDriveWidget extends AppWidgetProvider { long convertedBytes = 0; try { convertedBytes = Long.parseLong(bytes); - } catch (NumberFormatException e ) { + } catch (NumberFormatException e) { Log.i(TAG, "Invalid bytes " + bytes); } final String space = CommonUtils.humanReadableByteCountBin(convertedBytes); -- GitLab