From c9a9ff97885bdbecd193ce29f4d0067544ddde33 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Tue, 5 Apr 2022 19:41:40 +0530 Subject: [PATCH] eDrive: Add layout to show advanced account settings --- app/src/main/AndroidManifest.xml | 6 + .../e/drive/activity/AccountsActivity.java | 119 ++++++++++++++++++ ...llback.java => EDriveNetworkCallback.java} | 2 +- .../e/drive/widgets/EDriveWidget.java | 4 +- app/src/main/res/layout/activity_accounts.xml | 39 ++++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/foundation/e/drive/activity/AccountsActivity.java rename app/src/main/java/foundation/e/drive/widgets/{EDriveWidgetCallback.java => EDriveNetworkCallback.java} (90%) create mode 100644 app/src/main/res/layout/activity_accounts.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1578dbf9..1bd5c534 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,12 @@ android:icon="@mipmap/ic_eelo" android:label="@string/app_name" android:roundIcon="@mipmap/ic_eelo_round"> + + diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java new file mode 100644 index 00000000..cc6bd5f2 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -0,0 +1,119 @@ +/* + * Copyright © ECORP SAS 2022. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ + +package foundation.e.drive.activity; + +import static foundation.e.drive.widgets.EDriveWidget.convertIntoMB; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.os.Bundle; +import android.os.Handler; +import android.os.HandlerThread; +import android.support.v7.app.AppCompatActivity; + +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.UserInfo; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation; + +import java.util.ArrayList; + +import foundation.e.drive.R; +import foundation.e.drive.databinding.ActivityAccountsBinding; +import foundation.e.drive.operations.GetAliasOperation; +import foundation.e.drive.utils.CommonUtils; +import foundation.e.drive.widgets.EDriveNetworkCallback; + +public class AccountsActivity extends AppCompatActivity { + + private final GetRemoteUserInfoOperation getRemoteUserInfoOperation = new GetRemoteUserInfoOperation(); + private final GetAliasOperation getAliasOperation = new GetAliasOperation(); + private UserInfo userInfo = null; + private ArrayList aliases; + + private ActivityAccountsBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = ActivityAccountsBinding.inflate(getLayoutInflater()); + + setContentView(binding.getRoot()); + + final AccountManager accountManager = AccountManager.get(this); + final Account account = CommonUtils.getAccount(getString(R.string.eelo_account_type), + accountManager); + final OwnCloudClient client = CommonUtils.getOwnCloudClient(account, this); + + final HandlerThread handlerThread = new HandlerThread("Network Request"); + handlerThread.start(); + final Handler mHandler = new Handler(handlerThread.getLooper()); + + final EDriveNetworkCallback callback = new EDriveNetworkCallback() { + @Override + public void onComplete() { + runOnUiThread(new Runnable() { + @Override + public void run() { + onNetworkRequestCompleted(); + } + }); + } + }; + + mHandler.post(new Runnable() { + @Override + public void run() { + if (client != null) { + RemoteOperationResult ocsResult = getRemoteUserInfoOperation.execute(client); + if (ocsResult.isSuccess() && ocsResult.getData() != null) { + userInfo = (UserInfo) ocsResult.getData().get(0); + } + RemoteOperationResult aliasResult = getAliasOperation.execute(client); + if (aliasResult.isSuccess() && aliasResult.getData() != null) { + aliases = aliasResult.getData(); + } + callback.onComplete(); + } + } + }); + } + + private void onNetworkRequestCompleted() { + if (userInfo.displayName == null) { + binding.name.setText(userInfo.alternateDisplayName); + } else { + binding.name.setText(userInfo.displayName); + } + binding.email.setText(userInfo.id); + + final int usedMB = convertIntoMB(userInfo.quota.used); + final int totalMB = convertIntoMB(userInfo.quota.total); + + binding.plan.setText(getString(R.string.free_plan, + CommonUtils.humanReadableByteCountBin(userInfo.quota.total))); + + for (String group : userInfo.groups) { + if (group.contains("premium-")) { + binding.plan.setText(getString(R.string.premium_plan, group.split("-")[1])); + break; + } + } + + binding.status.setText(getString(R.string.progress_status, + CommonUtils.humanReadableByteCountBin(userInfo.quota.used), + CommonUtils.humanReadableByteCountBin(userInfo.quota.total))); + + if (aliases != null && !aliases.isEmpty()) { + binding.alias1.setText(getString(R.string.alias_dot) + aliases.get(0)); + } else { + binding.alias1.setText(getString(R.string.no_alias)); + } + } +} diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidgetCallback.java b/app/src/main/java/foundation/e/drive/widgets/EDriveNetworkCallback.java similarity index 90% rename from app/src/main/java/foundation/e/drive/widgets/EDriveWidgetCallback.java rename to app/src/main/java/foundation/e/drive/widgets/EDriveNetworkCallback.java index 1cab2e23..3e0706e5 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidgetCallback.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveNetworkCallback.java @@ -11,6 +11,6 @@ package foundation.e.drive.widgets; /** * @author TheScarastic */ -public interface EDriveWidgetCallback { +public interface EDriveNetworkCallback { void onComplete(); } 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 846b70f8..fc684345 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -89,7 +89,7 @@ public class EDriveWidget extends AppWidgetProvider { handlerThread.start(); final Handler mHandler = new Handler(handlerThread.getLooper()); - final EDriveWidgetCallback callback = new EDriveWidgetCallback() { + final EDriveNetworkCallback callback = new EDriveNetworkCallback() { @Override public void onComplete() { onNetworkRequestCompleted(context, appWidgetManager, appWidgetId, client, account); @@ -274,7 +274,7 @@ public class EDriveWidget extends AppWidgetProvider { clipboard.setPrimaryClip(clip); } - private int convertIntoMB(Long quota) { + public static int convertIntoMB(Long quota) { return (int) (quota / 1048576); // 1024.0 * 1024.0 = 1048576.0 } diff --git a/app/src/main/res/layout/activity_accounts.xml b/app/src/main/res/layout/activity_accounts.xml new file mode 100644 index 00000000..c12bcf3a --- /dev/null +++ b/app/src/main/res/layout/activity_accounts.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + +