use of com.nextcloud.client.account.User in project android by nextcloud.
the class SyncedFoldersActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = SyncedFoldersLayoutBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getIntent() != null && getIntent().getExtras() != null) {
final String accountName = getIntent().getExtras().getString(NotificationWork.KEY_NOTIFICATION_ACCOUNT);
Optional<User> optionalUser = getUser();
if (optionalUser.isPresent() && accountName != null) {
User user = optionalUser.get();
if (!accountName.equalsIgnoreCase(user.getAccountName())) {
accountManager.setCurrentOwnCloudAccount(accountName);
setUser(getUserAccountManager().getUser());
}
}
path = getIntent().getStringExtra(MediaFoldersDetectionWork.KEY_MEDIA_FOLDER_PATH);
type = getIntent().getIntExtra(MediaFoldersDetectionWork.KEY_MEDIA_FOLDER_TYPE, -1);
// Cancel notification
int notificationId = getIntent().getIntExtra(MediaFoldersDetectionWork.NOTIFICATION_ID, 0);
NotificationManager notificationManager = (NotificationManager) getSystemService(Activity.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationId);
}
// setup toolbar
setupToolbar();
updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_synced_folders));
setupDrawer();
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
if (mDrawerToggle != null) {
mDrawerToggle.setDrawerIndicatorEnabled(false);
}
// TODO: The content loading should be done asynchronously
setupContent();
if (ThemeUtils.themingEnabled(this)) {
setTheme(R.style.FallbackThemingTheme);
}
binding.emptyList.emptyListViewAction.setOnClickListener(v -> showHiddenItems());
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class SyncedFoldersActivity method load.
/**
* loads all media/synced folders, adds them to the recycler view adapter and shows the list.
*
* @param perFolderMediaItemLimit the amount of media items to be loaded/shown per media folder
*/
private void load(final int perFolderMediaItemLimit, boolean force) {
if (adapter.getItemCount() > 0 && !force) {
return;
}
showLoadingContent();
final List<MediaFolder> mediaFolders = MediaProvider.getImageFolders(getContentResolver(), perFolderMediaItemLimit, this, false);
mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit, this, false));
List<SyncedFolder> syncedFolderArrayList = syncedFolderProvider.getSyncedFolders();
List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
User user = getUserAccountManager().getUser();
for (SyncedFolder syncedFolder : syncedFolderArrayList) {
if (syncedFolder.getAccount().equals(user.getAccountName())) {
// delete non-existing & disabled synced folders
if (!new File(syncedFolder.getLocalPath()).exists() && !syncedFolder.isEnabled()) {
syncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
} else {
currentAccountSyncedFoldersList.add(syncedFolder);
}
}
}
List<SyncedFolderDisplayItem> syncFolderItems = sortSyncedFolderItems(mergeFolderData(currentAccountSyncedFoldersList, mediaFolders));
adapter.setSyncFolderItems(syncFolderItems);
adapter.notifyDataSetChanged();
showList();
if (!TextUtils.isEmpty(path)) {
int section = adapter.getSectionByLocalPathAndType(path, type);
if (section >= 0) {
onSyncFolderSettingsClick(section, adapter.get(section));
}
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class RichDocumentsEditorWebView method handleRemoteFile.
private void handleRemoteFile(Intent data) {
OCFile file = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILES);
new Thread(() -> {
User user = currentAccountProvider.getUser();
RichDocumentsCreateAssetOperation operation = new RichDocumentsCreateAssetOperation(file.getRemotePath());
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), this);
if (result.isSuccess()) {
String asset = (String) result.getSingleData();
runOnUiThread(() -> getWebView().evaluateJavascript("OCA.RichDocuments.documentsMain.postAsset('" + file.getFileName() + "', '" + asset + "');", null));
} else {
runOnUiThread(() -> DisplayUtils.showSnackMessage(this, "Inserting image failed!"));
}
}).start();
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class ShareActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ShareActivityBinding binding = ShareActivityBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
OCFile file = getFile();
Optional<User> optionalUser = getUser();
if (!optionalUser.isPresent()) {
finish();
return;
}
// Icon
if (file.isFolder()) {
binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType(), this));
} else {
binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(), optionalUser.get(), this));
if (MimeTypeUtil.isImage(file)) {
String remoteId = String.valueOf(file.getRemoteId());
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId);
if (thumbnail != null) {
binding.shareFileIcon.setImageBitmap(thumbnail);
}
}
}
// Name
binding.shareFileName.setText(getResources().getString(R.string.share_file, file.getFileName()));
binding.shareHeaderDivider.getBackground().setColorFilter(ThemeColorUtils.primaryAccentColor(this), PorterDuff.Mode.SRC_ATOP);
// Size
binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
Activity activity = this;
new Thread(() -> {
RemoteOperationResult result = new ReadFileRemoteOperation(getFile().getRemotePath()).execute(optionalUser.get().toPlatformAccount(), activity);
if (result.isSuccess()) {
RemoteFile remoteFile = (RemoteFile) result.getData().get(0);
long length = remoteFile.getLength();
getFile().setFileLength(length);
runOnUiThread(() -> binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(length)));
}
}).start();
if (savedInstanceState == null) {
// Add Share fragment on first creation
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment fragment = FileDetailSharingFragment.newInstance(getFile(), optionalUser.get());
ft.replace(R.id.share_fragment_container, fragment, TAG_SHARE_FRAGMENT);
ft.commit();
}
}
Aggregations