mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
update user name with correct id found by user ocs call
This commit is contained in:
parent
75d6de9b7c
commit
08875fe1e5
2 changed files with 43 additions and 13 deletions
|
@ -30,13 +30,18 @@ import android.preference.PreferenceManager;
|
|||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.UserInfo;
|
||||
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.ui.activity.ManageAccountsActivity;
|
||||
import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
|
||||
import com.owncloud.android.operations.GetCapabilitiesOperarion;
|
||||
import com.owncloud.android.ui.activity.ManageAccountsActivity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -51,6 +56,7 @@ public class AccountUtils {
|
|||
public static final String STATUS_PATH = "/status.php";
|
||||
|
||||
public static final int ACCOUNT_VERSION = 1;
|
||||
public static final int ACCOUNT_VERSION_WITH_PROPER_ID = 2;
|
||||
|
||||
/**
|
||||
* Can be used to get the currently selected ownCloud {@link Account} in the
|
||||
|
@ -238,8 +244,8 @@ public class AccountUtils {
|
|||
if ( currentAccount != null ) {
|
||||
String currentAccountVersion = accountMgr.getUserData(currentAccount, Constants.KEY_OC_ACCOUNT_VERSION);
|
||||
|
||||
if (currentAccountVersion == null) {
|
||||
Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION);
|
||||
if (!String.valueOf(ACCOUNT_VERSION_WITH_PROPER_ID).equalsIgnoreCase(currentAccountVersion)) {
|
||||
Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION_WITH_PROPER_ID);
|
||||
Account[] ocAccounts = accountMgr.getAccountsByType(MainApp.getAccountType());
|
||||
String serverUrl;
|
||||
String username;
|
||||
|
@ -249,8 +255,29 @@ public class AccountUtils {
|
|||
for (Account account : ocAccounts) {
|
||||
// build new account name
|
||||
serverUrl = accountMgr.getUserData(account, Constants.KEY_OC_BASE_URL);
|
||||
username = com.owncloud.android.lib.common.accounts.AccountUtils.
|
||||
getUsernameForAccount(account);
|
||||
|
||||
// update user name
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
|
||||
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton()
|
||||
.getClientFor(ocAccount, context);
|
||||
|
||||
GetRemoteUserInfoOperation remoteUserNameOperation = new GetRemoteUserInfoOperation();
|
||||
RemoteOperationResult result = remoteUserNameOperation.execute(client);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
UserInfo userInfo = (UserInfo) result.getData().get(0);
|
||||
username = userInfo.id;
|
||||
} else {
|
||||
// skip account, try it next time
|
||||
Log_OC.e(TAG, "Error while getting username for account: " + account.name);
|
||||
continue;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error while getting username: " + e.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
newAccountName = com.owncloud.android.lib.common.accounts.AccountUtils.
|
||||
buildAccountName(Uri.parse(serverUrl), username);
|
||||
|
||||
|
@ -312,11 +339,9 @@ public class AccountUtils {
|
|||
}
|
||||
|
||||
// at least, upgrade account version
|
||||
Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION + " to " + newAccountName);
|
||||
accountMgr.setUserData(
|
||||
newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION)
|
||||
);
|
||||
|
||||
Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION_WITH_PROPER_ID + " to " + newAccountName);
|
||||
accountMgr.setUserData(newAccount,
|
||||
Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION_WITH_PROPER_ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import com.owncloud.android.MainApp;
|
|||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
|
@ -157,8 +156,14 @@ public abstract class FileActivity extends DrawerActivity
|
|||
false);
|
||||
}
|
||||
|
||||
AccountUtils.updateAccountVersion(this); // best place, before any access to AccountManager
|
||||
// or database
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// best place, before any access to AccountManager or database
|
||||
AccountUtils.updateAccountVersion(getApplicationContext());
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
setAccount(account, savedInstanceState != null);
|
||||
|
||||
|
|
Loading…
Reference in a new issue