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

Commit d88cf7b1 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

5793-Fix_NPE_on_retrieving_account_group_data

parent 57b88301
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ package foundation.e.drive.activity;

import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_ALIAS_KEY;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_EMAIL;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_GROUPS;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_NAME;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_TOTAL_QUOTA_KEY;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_USED_QUOTA_KEY;
@@ -34,6 +33,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;

import foundation.e.drive.R;
import foundation.e.drive.databinding.ActivityAccountsBinding;
import foundation.e.drive.utils.AccountUtils;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.DavClientProvider;
import foundation.e.drive.widgets.EDriveWidget;
@@ -112,14 +112,9 @@ public class AccountsActivity extends AppCompatActivity {

        binding.plan.setText(getString(R.string.free_plan, totalShownQuota));

        String[] groups = accountManager.getUserData(account, ACCOUNT_DATA_GROUPS).split(",");
        for (String group : groups) {
            if (group.contains("premium-")) {
                binding.plan.setText(getString(R.string.premium_plan,
                        group.split("-")[1]));
                break;
            }
        }
        AccountUtils.getPremiumGroup(accountManager, account)
                .ifPresent(group -> binding.plan.setText(getString(R.string.premium_plan,
                        group.split("-")[1])));

        binding.myPlan.setVisibility(View.VISIBLE);
        binding.plan.setVisibility(View.VISIBLE);
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2022
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.drive.utils;

import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_GROUPS;

import android.accounts.Account;
import android.accounts.AccountManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Arrays;
import java.util.Optional;

public class AccountUtils {


    public static Optional<String> getPremiumGroup(@NonNull AccountManager accountManager, @Nullable Account account) {
        if (account == null) {
            return Optional.empty();
        }

        final String groupData = accountManager.getUserData(account, ACCOUNT_DATA_GROUPS);

        if (groupData == null || groupData.isEmpty()) {
            return Optional.empty();
        }

        final String[] groups = groupData.split(",");

        return Arrays.stream(groups)
                .filter(group -> group.contains("premium-"))
                .findFirst();
    }
}
+5 −9
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ package foundation.e.drive.widgets;

import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_ALIAS_KEY;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_EMAIL;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_GROUPS;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_NAME;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_TOTAL_QUOTA_KEY;
import static foundation.e.drive.utils.AppConstants.ACCOUNT_DATA_USED_QUOTA_KEY;
@@ -36,6 +35,7 @@ import java.util.Calendar;
import java.util.Locale;

import foundation.e.drive.R;
import foundation.e.drive.utils.AccountUtils;
import foundation.e.drive.utils.CommonUtils;
import timber.log.Timber;

@@ -240,14 +240,10 @@ public class EDriveWidget extends AppWidgetProvider {

        views.setTextViewText(R.id.planName, context.getString(R.string.free_plan, totalShownQuota));

        final String[] groups = accountManager.getUserData(account, ACCOUNT_DATA_GROUPS).split(",");
        for (String group : groups) {
            if (group.contains("premium-")) {
                views.setTextViewText(R.id.planName, context.getString(R.string.premium_plan,
                        group.split("-")[1]));
                break;
            }
        }
        AccountUtils.getPremiumGroup(accountManager, account)
                .ifPresent(group -> views.setTextViewText(R.id.planName,
                        context.getString(R.string.premium_plan,
                        group.split("-")[1])));

        views.setTextViewText(R.id.status, context.getString(R.string.progress_status,
                usedShownQuota, totalShownQuota));