use of com.nextcloud.client.account.User in project android by nextcloud.
the class ConflictsResolveActivity method startDialog.
private void startDialog() {
Optional<User> userOptional = getUser();
if (!userOptional.isPresent()) {
Log_OC.e(TAG, "User not present");
showErrorAndFinish();
}
// Check whether the file is contained in the current Account
Fragment prev = getSupportFragmentManager().findFragmentByTag("conflictDialog");
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
if (prev != null) {
fragmentTransaction.remove(prev);
}
if (existingFile != null && getStorageManager().fileExists(newFile.getRemotePath())) {
ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile, newFile, userOptional.get());
dialog.show(fragmentTransaction, "conflictDialog");
} else {
// Account was changed to a different one - just finish
Log_OC.e(TAG, "Account was changed, finishing");
showErrorAndFinish();
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class ManageAccountsActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == KEY_DELETE_CODE && data != null) {
Bundle bundle = data.getExtras();
if (bundle != null && bundle.containsKey(UserInfoActivity.KEY_ACCOUNT)) {
final Account account = bundle.getParcelable(UserInfoActivity.KEY_ACCOUNT);
if (account != null) {
User user = accountManager.getUser(account.name).orElseThrow(RuntimeException::new);
accountName = account.name;
performAccountRemoval(user);
}
}
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class ManageAccountsActivity method run.
@Override
public void run(AccountManagerFuture<Boolean> future) {
if (future.isDone()) {
// after remove account
Account account = new Account(accountName, MainApp.getAccountType(this));
if (!accountManager.exists(account)) {
// Cancel transfers of the removed account
if (mUploaderBinder != null) {
mUploaderBinder.cancel(account);
}
if (mDownloaderBinder != null) {
mDownloaderBinder.cancel(account);
}
}
User user = getUserAccountManager().getUser();
if (user.isAnonymous()) {
String accountName = "";
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
if (accounts.length != 0) {
accountName = accounts[0].name;
}
accountManager.setCurrentOwnCloudAccount(accountName);
}
List<UserListItem> userListItemArray = getUserListItems();
if (userListItemArray.size() > SINGLE_ACCOUNT) {
userListAdapter = new UserListAdapter(this, accountManager, userListItemArray, this, multipleAccountsSupported, false);
recyclerView.setAdapter(userListAdapter);
} else {
onBackPressed();
}
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class ManageAccountsActivity method performAccountRemoval.
private void performAccountRemoval(User user) {
// disable account in recycler view
for (int i = 0; i < userListAdapter.getItemCount(); i++) {
UserListItem item = userListAdapter.getItem(i);
if (item != null && item.getUser().getAccountName().equalsIgnoreCase(user.getAccountName())) {
item.setEnabled(false);
break;
}
userListAdapter.notifyDataSetChanged();
}
// store pending account removal
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PENDING_FOR_REMOVAL, String.valueOf(true));
// Cancel transfers
if (mUploaderBinder != null) {
mUploaderBinder.cancel(user.toPlatformAccount());
}
if (mDownloaderBinder != null) {
mDownloaderBinder.cancel(user.toPlatformAccount());
}
backgroundJobManager.startAccountRemovalJob(user.getAccountName(), false);
// immediately select a new account
List<User> users = accountManager.getAllUsers();
String newAccountName = "";
for (User u : users) {
if (!u.getAccountName().equalsIgnoreCase(u.getAccountName())) {
newAccountName = u.getAccountName();
break;
}
}
if (newAccountName.isEmpty()) {
Log_OC.d(TAG, "new account set to null");
accountManager.resetOwnCloudAccount();
} else {
Log_OC.d(TAG, "new account set to: " + newAccountName);
accountManager.setCurrentOwnCloudAccount(newAccountName);
}
// only one to be (deleted) account remaining
if (users.size() < MIN_MULTI_ACCOUNT_SIZE) {
Intent resultIntent = new Intent();
resultIntent.putExtra(KEY_ACCOUNT_LIST_CHANGED, true);
resultIntent.putExtra(KEY_CURRENT_ACCOUNT_CHANGED, true);
setResult(RESULT_OK, resultIntent);
super.onBackPressed();
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class ContactsPreferenceActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_preference);
// setup toolbar
setupToolbar();
// setup drawer
// setupDrawer(R.id.nav_contacts); // TODO needed?
// show sidebar?
boolean showSidebar = getIntent().getBooleanExtra(EXTRA_SHOW_SIDEBAR, true);
if (!showSidebar) {
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
if (mDrawerToggle != null) {
mDrawerToggle.setDrawerIndicatorEnabled(false);
}
}
Intent intent = getIntent();
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (intent == null || intent.getParcelableExtra(EXTRA_FILE) == null || intent.getParcelableExtra(EXTRA_USER) == null) {
BackupFragment fragment = BackupFragment.create(showSidebar);
transaction.add(R.id.frame_container, fragment);
} else {
OCFile file = intent.getParcelableExtra(EXTRA_FILE);
User user = intent.getParcelableExtra(EXTRA_USER);
BackupListFragment contactListFragment = BackupListFragment.newInstance(file, user);
transaction.add(R.id.frame_container, contactListFragment);
}
transaction.commit();
}
}
Aggregations