use of androidx.annotation.NonNull in project android by nextcloud.
the class OCFileListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof OCFileListFooterViewHolder) {
OCFileListFooterViewHolder footerViewHolder = (OCFileListFooterViewHolder) holder;
footerViewHolder.binding.footerText.setText(getFooterText());
footerViewHolder.binding.loadingProgressBar.getIndeterminateDrawable().setColorFilter(ThemeColorUtils.primaryColor(activity), PorterDuff.Mode.SRC_IN);
footerViewHolder.binding.loadingProgressBar.setVisibility(ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
} else if (holder instanceof OCFileListHeaderViewHolder) {
OCFileListHeaderViewHolder headerViewHolder = (OCFileListHeaderViewHolder) holder;
String text = currentDirectory.getRichWorkspace();
PreviewTextFragment.setText(headerViewHolder.binding.headerText, text, null, activity, true, true);
headerViewHolder.binding.headerView.setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());
} else {
ListGridImageViewHolder gridViewHolder = (ListGridImageViewHolder) holder;
OCFile file = getItem(position);
boolean gridImage = MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file);
gridViewHolder.getThumbnail().setTag(file.getFileId());
setThumbnail(file, gridViewHolder.getThumbnail(), user, mStorageManager, asyncTasks, gridView, activity, gridViewHolder.getShimmerThumbnail(), preferences);
if (highlightedItem != null && file.getFileId() == highlightedItem.getFileId()) {
gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.selected_item_background));
} else if (isCheckedFile(file)) {
gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.selected_item_background));
gridViewHolder.getCheckbox().setImageDrawable(ThemeDrawableUtils.tintDrawable(R.drawable.ic_checkbox_marked, ThemeColorUtils.primaryColor(activity)));
} else {
gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.bg_default));
gridViewHolder.getCheckbox().setImageResource(R.drawable.ic_checkbox_blank_outline);
}
gridViewHolder.getItemLayout().setOnClickListener(v -> ocFileListFragmentInterface.onItemClicked(file));
if (!hideItemOptions) {
gridViewHolder.getItemLayout().setLongClickable(true);
gridViewHolder.getItemLayout().setOnLongClickListener(v -> ocFileListFragmentInterface.onLongItemClicked(file));
}
// unread comments
if (file.getUnreadCommentsCount() > 0) {
gridViewHolder.getUnreadComments().setVisibility(View.VISIBLE);
gridViewHolder.getUnreadComments().setOnClickListener(view -> ocFileListFragmentInterface.showActivityDetailView(file));
} else {
gridViewHolder.getUnreadComments().setVisibility(View.GONE);
}
if (holder instanceof ListItemViewHolder) {
ListItemViewHolder itemViewHolder = (ListItemViewHolder) holder;
if ((file.isSharedWithMe() || file.isSharedWithSharee()) && !multiSelect && !gridView && !hideItemOptions) {
itemViewHolder.getSharedAvatars().setVisibility(View.VISIBLE);
itemViewHolder.getSharedAvatars().removeAllViews();
String fileOwner = file.getOwnerId();
List<ShareeUser> sharees = file.getSharees();
// use fileOwner if not oneself, then add at first
ShareeUser fileOwnerSharee = new ShareeUser(fileOwner, file.getOwnerDisplayName(), ShareType.USER);
if (!TextUtils.isEmpty(fileOwner) && !fileOwner.equals(userId) && !sharees.contains(fileOwnerSharee)) {
sharees.add(fileOwnerSharee);
}
Collections.reverse(sharees);
Log_OC.d(this, "sharees of " + file.getFileName() + ": " + sharees);
itemViewHolder.getSharedAvatars().setAvatars(user, sharees);
itemViewHolder.getSharedAvatars().setOnClickListener(view -> ocFileListFragmentInterface.onShareIconClick(file));
} else {
itemViewHolder.getSharedAvatars().setVisibility(View.GONE);
itemViewHolder.getSharedAvatars().removeAllViews();
}
// npe fix: looks like file without local storage path somehow get here
final String storagePath = file.getStoragePath();
if (onlyOnDevice && storagePath != null) {
File localFile = new File(storagePath);
long localSize;
if (localFile.isDirectory()) {
localSize = FileStorageUtils.getFolderSize(localFile);
} else {
localSize = localFile.length();
}
itemViewHolder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(localSize));
} else {
itemViewHolder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
}
itemViewHolder.getLastModification().setText(DisplayUtils.getRelativeTimestamp(activity, file.getModificationTimestamp()));
if (multiSelect || gridView || hideItemOptions) {
itemViewHolder.getOverflowMenu().setVisibility(View.GONE);
} else {
itemViewHolder.getOverflowMenu().setVisibility(View.VISIBLE);
itemViewHolder.getOverflowMenu().setOnClickListener(view -> ocFileListFragmentInterface.onOverflowIconClicked(file, view));
}
}
// default first
gridViewHolder.getLocalFileIndicator().setVisibility(View.INVISIBLE);
if (showMetadata) {
OperationsService.OperationsServiceBinder operationsServiceBinder = transferServiceGetter.getOperationsServiceBinder();
FileDownloader.FileDownloaderBinder fileDownloaderBinder = transferServiceGetter.getFileDownloaderBinder();
FileUploader.FileUploaderBinder fileUploaderBinder = transferServiceGetter.getFileUploaderBinder();
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user, file)) {
// synchronizing
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user, file)) {
// downloading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user, file)) {
// uploading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (file.getEtagInConflict() != null) {
// conflict
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing_error);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (file.isDown()) {
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synced);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
}
gridViewHolder.getFavorite().setVisibility(file.isFavorite() ? View.VISIBLE : View.GONE);
}
if (multiSelect) {
gridViewHolder.getCheckbox().setVisibility(View.VISIBLE);
} else {
gridViewHolder.getCheckbox().setVisibility(View.GONE);
}
if (holder instanceof ListGridItemViewHolder) {
ListGridItemViewHolder gridItemViewHolder = (ListGridItemViewHolder) holder;
gridItemViewHolder.getFileName().setText(file.getDecryptedFileName());
if (gridView && gridImage) {
gridItemViewHolder.getFileName().setVisibility(View.GONE);
} else {
if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
gridItemViewHolder.getFileName().setVisibility(View.GONE);
} else {
gridItemViewHolder.getFileName().setVisibility(View.VISIBLE);
}
}
}
if (gridView || hideItemOptions || (file.isFolder() && !file.canReshare())) {
gridViewHolder.getShared().setVisibility(View.GONE);
} else {
showShareIcon(gridViewHolder, file);
}
}
}
use of androidx.annotation.NonNull in project android by nextcloud.
the class ShareLinkToDialog method onCreateDialog.
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
mIntent = getArguments().getParcelable(ARG_INTENT);
String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
List<String> packagesToExcludeList = Arrays.asList(packagesToExclude != null ? packagesToExclude : new String[0]);
PackageManager pm = getActivity().getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
Iterator<ResolveInfo> it = activities.iterator();
ResolveInfo resolveInfo;
while (it.hasNext()) {
resolveInfo = it.next();
if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase(Locale.ROOT))) {
it.remove();
}
}
boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false);
if (!sendAction) {
// add activity for copy to clipboard
Intent copyToClipboardIntent = new Intent(getActivity(), CopyToClipboardActivity.class);
List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
if (!copyToClipboard.isEmpty()) {
activities.add(copyToClipboard.get(0));
}
}
Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm));
mAdapter = new ActivityAdapter(getActivity(), pm, activities);
return createSelector(sendAction);
}
use of androidx.annotation.NonNull in project android by nextcloud.
the class SyncedFoldersActivity method createSyncedFolderWithoutMediaFolder.
@NonNull
private SyncedFolderDisplayItem createSyncedFolderWithoutMediaFolder(@NonNull SyncedFolder syncedFolder) {
File localFolder = new File(syncedFolder.getLocalPath());
File[] files = SyncedFolderUtils.getFileList(localFolder);
List<String> filePaths = getDisplayFilePathList(files);
return new SyncedFolderDisplayItem(syncedFolder.getId(), syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder.isWifiOnly(), syncedFolder.isChargingOnly(), syncedFolder.isExisting(), syncedFolder.isSubfolderByDate(), syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.getNameCollisionPolicyInt(), syncedFolder.isEnabled(), clock.getCurrentTime(), filePaths, localFolder.getName(), files.length, syncedFolder.getType(), syncedFolder.isHidden());
}
use of androidx.annotation.NonNull in project android by nextcloud.
the class StringUtils method searchAndColor.
@NonNull
public static String searchAndColor(@Nullable String text, @Nullable String searchText, @ColorInt int color) {
if (text != null) {
if (text.isEmpty() || searchText == null || searchText.isEmpty()) {
return text;
}
Matcher matcher = Pattern.compile(searchText, Pattern.CASE_INSENSITIVE | Pattern.LITERAL).matcher(text);
StringBuffer stringBuffer = new StringBuffer();
while (matcher.find()) {
String replacement = matcher.group().replace(matcher.group(), String.format(Locale.getDefault(), "<font color='%d'><b>%s</b></font>", color, matcher.group()));
matcher.appendReplacement(stringBuffer, Matcher.quoteReplacement(replacement));
}
matcher.appendTail(stringBuffer);
return stringBuffer.toString();
} else {
return "";
}
}
use of androidx.annotation.NonNull in project butterknife by JakeWharton.
the class ButterKnife method bind.
/**
* BindView annotated fields and methods in the specified {@code target} using the {@code source}
* {@link View} as the view root.
*
* @param target Target class for view binding.
* @param source View root on which IDs will be looked up.
*/
@NonNull
@UiThread
public static Unbinder bind(@NonNull Object target, @NonNull View source) {
List<Unbinder> unbinders = new ArrayList<>();
Class<?> targetClass = target.getClass();
if ((targetClass.getModifiers() & PRIVATE) != 0) {
throw new IllegalArgumentException(targetClass.getName() + " must not be private.");
}
while (true) {
String clsName = targetClass.getName();
if (clsName.startsWith("android.") || clsName.startsWith("java.") || clsName.startsWith("androidx.")) {
break;
}
for (Field field : targetClass.getDeclaredFields()) {
int unbinderStartingSize = unbinders.size();
Unbinder unbinder;
unbinder = parseBindView(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindViews(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindAnim(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindArray(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindBitmap(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindBool(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindColor(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindDimen(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindDrawable(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindFloat(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindFont(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindInt(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseBindString(target, field, source);
if (unbinder != null)
unbinders.add(unbinder);
if (unbinders.size() - unbinderStartingSize > 1) {
throw new IllegalStateException("More than one bind annotation on " + targetClass.getName() + "." + field.getName());
}
}
for (Method method : targetClass.getDeclaredMethods()) {
Unbinder unbinder;
unbinder = parseOnCheckedChanged(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnClick(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnEditorAction(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnFocusChange(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnItemClick(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnItemLongClick(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnLongClick(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnPageChange(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnTextChanged(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
unbinder = parseOnTouch(target, method, source);
if (unbinder != null)
unbinders.add(unbinder);
}
targetClass = targetClass.getSuperclass();
}
if (unbinders.isEmpty()) {
if (debug)
Log.d(TAG, "MISS: Reached framework class. Abandoning search.");
return Unbinder.EMPTY;
}
if (debug)
Log.d(TAG, "HIT: Reflectively found " + unbinders.size() + " bindings.");
return new CompositeUnbinder(unbinders);
}
Aggregations