mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
use MDMConfig
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
8bdfbb49ab
commit
f4b49b5da5
7 changed files with 39 additions and 34 deletions
|
@ -25,7 +25,7 @@ import com.nextcloud.client.account.UserAccountManager
|
|||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.client.network.ClientFactory
|
||||
import com.nextcloud.utils.extensions.getParcelableArgument
|
||||
import com.nextcloud.utils.extensions.getRestriction
|
||||
import com.nextcloud.utils.mdm.MDMConfig
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.databinding.DialogChooseAccountBinding
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
|
@ -37,7 +37,6 @@ import com.owncloud.android.ui.adapter.UserListAdapter
|
|||
import com.owncloud.android.ui.adapter.UserListItem
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener
|
||||
import com.owncloud.android.utils.appConfig.AppConfigKeys
|
||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
@ -122,13 +121,7 @@ class ChooseAccountDialogFragment :
|
|||
viewThemeUtils
|
||||
)
|
||||
|
||||
val disableMultiAccountViaMDM = requireContext().getRestriction(
|
||||
AppConfigKeys.DisableMultiAccount,
|
||||
context?.resources?.getBoolean(R.bool.disable_multiaccount) ?: false
|
||||
)
|
||||
|
||||
// hide "add account" when no multi account
|
||||
if (!resources.getBoolean(R.bool.multiaccount_support) || disableMultiAccountViaMDM) {
|
||||
if (!MDMConfig.multiAccountSupport(requireContext())) {
|
||||
binding.addAccount.visibility = View.GONE
|
||||
}
|
||||
|
||||
|
|
26
app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt
Normal file
26
app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.utils.mdm
|
||||
|
||||
import android.content.Context
|
||||
import com.nextcloud.utils.extensions.getRestriction
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.utils.appConfig.AppConfigKeys
|
||||
|
||||
object MDMConfig {
|
||||
fun multiAccountSupport(context: Context): Boolean {
|
||||
val multiAccountSupport = context.resources.getBoolean(R.bool.multiaccount_support)
|
||||
val disableMultiAccountViaMDM = context.getRestriction(
|
||||
AppConfigKeys.DisableMultiAccount,
|
||||
MainApp.getAppContext().resources.getBoolean(R.bool.disable_multiaccount)
|
||||
)
|
||||
|
||||
return multiAccountSupport && !disableMultiAccountViaMDM
|
||||
}
|
||||
}
|
|
@ -21,12 +21,11 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nextcloud.utils.extensions.ContextExtensionsKt;
|
||||
import com.nextcloud.utils.mdm.MDMConfig;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.utils.appConfig.AppConfigKeys;
|
||||
|
||||
/**
|
||||
* Authenticator for ownCloud accounts.
|
||||
|
@ -72,8 +71,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|||
|
||||
final Bundle bundle = new Bundle();
|
||||
|
||||
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(mContext, AppConfigKeys.DisableMultiAccount, mContext.getResources().getBoolean(R.bool.disable_multiaccount));
|
||||
if (!disableMultiAccountViaMDM && mContext.getResources().getBoolean(R.bool.multiaccount_support) && accounts.length > 1) {
|
||||
if (MDMConfig.INSTANCE.multiAccountSupport(mContext) && accounts.length > 1) {
|
||||
try {
|
||||
validateAccountType(accountType);
|
||||
} catch (AuthenticatorException e) {
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.app.Activity;
|
|||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.RestrictionsManager;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
|
@ -72,6 +71,7 @@ import com.nextcloud.common.PlainClient;
|
|||
import com.nextcloud.operations.PostMethod;
|
||||
import com.nextcloud.utils.extensions.BundleExtensionsKt;
|
||||
import com.nextcloud.utils.extensions.ContextExtensionsKt;
|
||||
import com.nextcloud.utils.mdm.MDMConfig;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.databinding.AccountSetupBinding;
|
||||
|
@ -811,10 +811,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
passCodeManager.onActivityResumed(this);
|
||||
|
||||
Uri data = intent.getData();
|
||||
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount));
|
||||
if (data != null && data.toString().startsWith(getString(R.string.login_data_own_scheme))) {
|
||||
if (disableMultiAccountViaMDM ||
|
||||
!getResources().getBoolean(R.bool.multiaccount_support) ||
|
||||
if (!MDMConfig.INSTANCE.multiAccountSupport(this) ||
|
||||
accountManager.getAccounts().length == 1) {
|
||||
Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
|
@ -1535,9 +1533,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
return;
|
||||
}
|
||||
|
||||
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount));
|
||||
if (disableMultiAccountViaMDM ||
|
||||
!getResources().getBoolean(R.bool.multiaccount_support) ||
|
||||
if (!MDMConfig.INSTANCE.multiAccountSupport(this) ||
|
||||
accountManager.getAccounts().length == 1) {
|
||||
Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
|
|
|
@ -11,19 +11,14 @@ import android.os.Bundle
|
|||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.utils.extensions.getRestriction
|
||||
import com.nextcloud.utils.mdm.MDMConfig
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.utils.appConfig.AppConfigKeys
|
||||
|
||||
class DeepLinkLoginActivity : AuthenticatorActivity(), Injectable {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val disableMultiAccountViaMDM = getRestriction(AppConfigKeys.DisableMultiAccount, resources.getBoolean(R.bool.disable_multiaccount))
|
||||
if (disableMultiAccountViaMDM ||
|
||||
!resources.getBoolean(R.bool.multiaccount_support) ||
|
||||
accountManager.accounts.size == 1
|
||||
) {
|
||||
if (!MDMConfig.multiAccountSupport(this) || accountManager.accounts.size == 1) {
|
||||
Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import com.nextcloud.client.onboarding.FirstRunActivity;
|
|||
import com.nextcloud.model.WorkerState;
|
||||
import com.nextcloud.model.WorkerStateLiveData;
|
||||
import com.nextcloud.utils.extensions.BundleExtensionsKt;
|
||||
import com.nextcloud.utils.extensions.ContextExtensionsKt;
|
||||
import com.nextcloud.utils.mdm.MDMConfig;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
|
@ -47,7 +47,6 @@ import com.owncloud.android.ui.adapter.UserListItem;
|
|||
import com.owncloud.android.ui.dialog.AccountRemovalDialog;
|
||||
import com.owncloud.android.ui.events.AccountRemovedEvent;
|
||||
import com.owncloud.android.ui.helpers.FileOperationsHelper;
|
||||
import com.owncloud.android.utils.appConfig.AppConfigKeys;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
@ -133,8 +132,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|||
}
|
||||
|
||||
arbitraryDataProvider = new ArbitraryDataProviderImpl(this);
|
||||
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount));
|
||||
multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM;
|
||||
multipleAccountsSupported = MDMConfig.INSTANCE.multiAccountSupport(this);
|
||||
|
||||
userListAdapter = new UserListAdapter(this,
|
||||
accountManager,
|
||||
|
@ -232,8 +230,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|||
userListItems.add(new UserListItem(user, !pendingForRemoval));
|
||||
}
|
||||
|
||||
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount));
|
||||
if (getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM) {
|
||||
if (MDMConfig.INSTANCE.multiAccountSupport(this)) {
|
||||
userListItems.add(new UserListItem());
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class MultipleAccountsDialog : DialogFragment(), Injectable, UserListAdapter.Cli
|
|||
private val accountListItems: List<UserListItem>
|
||||
/**
|
||||
* creates the account list items list including the add-account action in case
|
||||
* multiaccount_support is enabled.
|
||||
* multi account support is enabled.
|
||||
*
|
||||
* @return list of account list items
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue