Search in sources :

Example 11 with NonNull

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);
        }
    }
}
Also used : User(com.nextcloud.client.account.User) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) OCFile(com.owncloud.android.datamodel.OCFile) Drawable(android.graphics.drawable.Drawable) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Vector(java.util.Vector) OCShare(com.owncloud.android.lib.resources.shares.OCShare) AvatarGroupLayout(com.owncloud.android.ui.AvatarGroupLayout) Locale(java.util.Locale) Handler(android.os.Handler) Looper(android.os.Looper) View(android.view.View) FileSortOrder(com.owncloud.android.utils.FileSortOrder) RecyclerView(androidx.recyclerview.widget.RecyclerView) DisplayUtils(com.owncloud.android.utils.DisplayUtils) ThemeDrawableUtils(com.owncloud.android.utils.theme.ThemeDrawableUtils) AccountManager(android.accounts.AccountManager) ListHeaderBinding(com.owncloud.android.databinding.ListHeaderBinding) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) SearchType(com.owncloud.android.ui.fragment.SearchType) Set(java.util.Set) AppPreferences(com.nextcloud.client.preferences.AppPreferences) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) GridItemBinding(com.owncloud.android.databinding.GridItemBinding) Log_OC(com.owncloud.android.lib.common.utils.Log_OC) List(java.util.List) TextView(android.widget.TextView) GridImageBinding(com.owncloud.android.databinding.GridImageBinding) ShareType(com.owncloud.android.lib.resources.shares.ShareType) BitmapUtils(com.owncloud.android.utils.BitmapUtils) ThemeColorUtils(com.owncloud.android.utils.theme.ThemeColorUtils) Nullable(androidx.annotation.Nullable) MainApp(com.owncloud.android.MainApp) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType) FileUploader(com.owncloud.android.files.services.FileUploader) MimeTypeUtil(com.owncloud.android.utils.MimeTypeUtil) ContentValues(android.content.ContentValues) R(com.owncloud.android.R) Context(android.content.Context) ResourcesCompat(androidx.core.content.res.ResourcesCompat) Filter(android.widget.Filter) ComponentsGetter(com.owncloud.android.ui.activity.ComponentsGetter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FileDownloader(com.owncloud.android.files.services.FileDownloader) LoaderImageView(com.elyeproj.loaderviewlibrary.LoaderImageView) OCFileListFragmentInterface(com.owncloud.android.ui.interfaces.OCFileListFragmentInterface) LayoutInflater(android.view.LayoutInflater) RemoteOperationFailedException(com.owncloud.android.operations.RemoteOperationFailedException) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) Point(android.graphics.Point) TextUtils(android.text.TextUtils) ListItemBinding(com.owncloud.android.databinding.ListItemBinding) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) File(java.io.File) ListFooterBinding(com.owncloud.android.databinding.ListFooterBinding) OperationsService(com.owncloud.android.services.OperationsService) FileStorageUtils(com.owncloud.android.utils.FileStorageUtils) Bitmap(android.graphics.Bitmap) ShareeUser(com.owncloud.android.lib.resources.shares.ShareeUser) ProviderMeta(com.owncloud.android.db.ProviderMeta) Activity(android.app.Activity) Collections(java.util.Collections) VisibleForTesting(androidx.annotation.VisibleForTesting) Resources(android.content.res.Resources) OCFile(com.owncloud.android.datamodel.OCFile) ShareeUser(com.owncloud.android.lib.resources.shares.ShareeUser) List(java.util.List) ArrayList(java.util.ArrayList) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Example 12 with NonNull

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);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) NonNull(androidx.annotation.NonNull)

Example 13 with NonNull

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());
}
Also used : SyncedFolderDisplayItem(com.owncloud.android.datamodel.SyncedFolderDisplayItem) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) NonNull(androidx.annotation.NonNull)

Example 14 with NonNull

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 "";
    }
}
Also used : Matcher(java.util.regex.Matcher) NonNull(androidx.annotation.NonNull)

Example 15 with NonNull

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);
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) UiThread(androidx.annotation.UiThread) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1200 View (android.view.View)192 ArrayList (java.util.ArrayList)154 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)118 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)77 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62