use of com.nextcloud.client.account.User in project android by nextcloud.
the class DrawerActivity method onNavigationItemClicked.
private void onNavigationItemClicked(final MenuItem menuItem) {
setDrawerMenuItemChecked(menuItem.getItemId());
int itemId = menuItem.getItemId();
if (itemId == R.id.nav_all_files) {
if (this instanceof FileDisplayActivity && !(((FileDisplayActivity) this).getLeftFragment() instanceof GalleryFragment) && !(((FileDisplayActivity) this).getLeftFragment() instanceof PreviewTextStringFragment)) {
showFiles(false);
((FileDisplayActivity) this).browseToRoot();
EventBus.getDefault().post(new ChangeMenuEvent());
} else {
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(FileDisplayActivity.ALL_FILES);
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
startActivity(intent);
}
} else if (itemId == R.id.nav_favorites) {
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH), menuItem.getItemId());
} else if (itemId == R.id.nav_gallery) {
startPhotoSearch(menuItem);
} else if (itemId == R.id.nav_on_device) {
EventBus.getDefault().post(new ChangeMenuEvent());
showFiles(true);
} else if (itemId == R.id.nav_uploads) {
startActivity(UploadListActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else if (itemId == R.id.nav_trashbin) {
startActivity(TrashbinActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else if (itemId == R.id.nav_activity) {
startActivity(ActivitiesActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else if (itemId == R.id.nav_notifications) {
startActivity(NotificationsActivity.class);
} else if (itemId == R.id.nav_settings) {
startActivity(SettingsActivity.class);
} else if (itemId == R.id.nav_community) {
startActivity(CommunityActivity.class);
} else if (itemId == R.id.nav_logout) {
mCheckedMenuItem = -1;
menuItem.setChecked(false);
final Optional<User> optionalUser = getUser();
if (optionalUser.isPresent()) {
UserInfoActivity.openAccountRemovalConfirmationDialog(optionalUser.get(), getSupportFragmentManager());
}
} else if (itemId == R.id.nav_shared) {
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER), menuItem.getItemId());
} else if (itemId == R.id.nav_recently_modified) {
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH), menuItem.getItemId());
} else {
if (menuItem.getItemId() >= MENU_ITEM_EXTERNAL_LINK && menuItem.getItemId() <= MENU_ITEM_EXTERNAL_LINK + 100) {
// external link clicked
externalLinkClicked(menuItem);
} else {
Log_OC.w(TAG, "Unknown drawer menu item clicked: " + menuItem.getTitle());
}
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class DrawerActivity method fetchExternalLinks.
/**
* Retrieves external links via api from 'external' app
*/
public void fetchExternalLinks(final boolean force) {
if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
Thread t = new Thread(() -> {
// fetch capabilities as early as possible
if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) {
GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
getCapabilities.execute(getBaseContext());
}
User user = accountManager.getUser();
String name = user.getAccountName();
if (getStorageManager() != null && getStorageManager().getCapability(name).getExternalLinks().isTrue()) {
int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT);
if (count > 10 || count == -1 || force) {
if (force) {
Log_OC.d("ExternalLinks", "force update");
}
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0");
Log_OC.d("ExternalLinks", "update via api");
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(user.toPlatformAccount(), this);
if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();
ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();
for (ExternalLink link : externalLinks) {
externalLinksProvider.storeExternalLink(link);
}
}
} else {
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
}
} else {
externalLinksProvider.deleteAllExternalLinks();
Log_OC.d("ExternalLinks", "links disabled");
}
runOnUiThread(this::updateExternalLinksInDrawer);
});
t.start();
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class DrawerActivity method setupDrawerMenu.
/**
* setup drawer content, basically setting the item selected listener.
*
* @param navigationView the drawers navigation view
*/
private void setupDrawerMenu(NavigationView navigationView) {
navigationView.setItemIconTintList(null);
// setup actions for drawer menu items
navigationView.setNavigationItemSelectedListener(menuItem -> {
mDrawerLayout.closeDrawers();
// pending runnable will be executed after the drawer has been closed
pendingRunnable = () -> onNavigationItemClicked(menuItem);
return true;
});
User account = accountManager.getUser();
filterDrawerMenu(navigationView.getMenu(), account);
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class DrawerActivity method getAndDisplayUserQuota.
/**
* Retrieves and shows the user quota if available
*/
private void getAndDisplayUserQuota() {
// set user space information
Thread t = new Thread(() -> {
final User user = accountManager.getUser();
if (user.isAnonymous()) {
return;
}
final Context context = MainApp.getAppContext();
NextcloudClient nextcloudClient = null;
try {
nextcloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().getNextcloudClientFor(user.toOwnCloudAccount(), context);
} catch (OperationCanceledException | AuthenticatorException | IOException e) {
Log_OC.e(this, "Error retrieving user quota", e);
}
if (nextcloudClient == null) {
return;
}
RemoteOperationResult<UserInfo> result = new GetUserInfoRemoteOperation().execute(nextcloudClient);
if (result.isSuccess() && result.getResultData() != null) {
final UserInfo userInfo = result.getResultData();
final Quota quota = userInfo.getQuota();
if (quota != null) {
final long used = quota.getUsed();
final long total = quota.getTotal();
final int relative = (int) Math.ceil(quota.getRelative());
final long quotaValue = quota.getQuota();
runOnUiThread(() -> {
if (quotaValue > 0 || quotaValue == GetUserInfoRemoteOperation.SPACE_UNLIMITED || quotaValue == GetUserInfoRemoteOperation.QUOTA_LIMIT_INFO_NOT_AVAILABLE) {
/*
* show quota in case
* it is available and calculated (> 0) or
* in case of legacy servers (==QUOTA_LIMIT_INFO_NOT_AVAILABLE)
*/
setQuotaInformation(used, total, relative, quotaValue);
} else {
/*
* quotaValue < 0 means special cases like
* {@link RemoteGetUserQuotaOperation.SPACE_NOT_COMPUTED},
* {@link RemoteGetUserQuotaOperation.SPACE_UNKNOWN} or
* {@link RemoteGetUserQuotaOperation.SPACE_UNLIMITED}
* thus don't display any quota information.
*/
showQuota(false);
}
});
}
}
});
t.start();
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method onTransferStateChanged.
/**
* {@inheritDoc}
*/
@Override
public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
updateListOfFilesFragment(false);
Fragment leftFragment = getLeftFragment();
Optional<User> optionalUser = getUser();
if (leftFragment instanceof FileDetailFragment && file.equals(((FileDetailFragment) leftFragment).getFile()) && optionalUser.isPresent()) {
final User currentUser = optionalUser.get();
if (downloading || uploading) {
((FileDetailFragment) leftFragment).updateFileDetails(file, currentUser);
} else {
if (!file.fileExists()) {
cleanSecondFragment();
} else {
((FileDetailFragment) leftFragment).updateFileDetails(false, true);
}
}
}
}
Aggregations