Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9a9ff97 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

eDrive: Add layout to show advanced account settings

parent eee142d3
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -25,6 +25,12 @@
        android:icon="@mipmap/ic_eelo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_eelo_round">
        <activity
            android:exported="true"
            android:name=".activity.AccountsActivity"
            android:label="Account Activity"
            android:theme="@style/Theme.AppCompat.DayNight"/>

        <receiver
            android:name=".widgets.EDriveWidget"
            android:exported="true">
+119 −0
Original line number Diff line number Diff line
/*
 * 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<Object> 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));
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -11,6 +11,6 @@ package foundation.e.drive.widgets;
/**
 * @author TheScarastic
 */
public interface EDriveWidgetCallback {
public interface EDriveNetworkCallback {
    void onComplete();
}
+2 −2
Original line number Diff line number Diff line
@@ -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
    }

+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/plan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/alias1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/upgrade"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Upgrade"/>

</LinearLayout>
 No newline at end of file
Loading