Skip to content

Commit

Permalink
Customized theming related changes for grid and list views.
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed Jul 16, 2024
1 parent 5716e23 commit 1736545
Show file tree
Hide file tree
Showing 30 changed files with 448 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
binding.thumbnailLayout.thumbnailShimmer,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
syncedFolderProvider,
false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ private static String getWebLoginUserAgent() {
@SuppressFBWarnings("ANDROID_WEB_VIEW_JAVASCRIPT")
@SuppressLint("SetJavaScriptEnabled")
private void initWebViewLogin(String baseURL, boolean useGenericUserAgent) {
viewThemeUtils.platform.colorCircularProgressBar(accountSetupWebviewBinding.loginWebviewProgressBar, ColorRole.ON_PRIMARY_CONTAINER);
accountSetupWebviewBinding.loginWebview.setVisibility(View.GONE);
new WebViewUtil(this).setProxyKKPlus(accountSetupWebviewBinding.loginWebview);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class GalleryAdapter(
transferServiceGetter,
showMetadata = false,
showShareAvatar = false,
viewThemeUtils
viewThemeUtils,
true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
if (isCheckedFile(file)) {
gridViewHolder.itemLayout.setBackgroundColor(ContextCompat.getColor(mContext, R.color.selected_item_background));

gridViewHolder.checkbox.setImageDrawable(
viewThemeUtils.platform.tintDrawable(mContext, R.drawable.ic_checkbox_marked, ColorRole.PRIMARY));
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_marked);
} else {
gridViewHolder.itemLayout.setBackgroundColor(mContext.getResources().getColor(R.color.bg_default));
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public OCFileListAdapter(
.getVersion()
.isShareesOnDavSupported(),
viewThemeUtils,
false,
syncedFolderProvider);

setHasStableIds(true);
Expand Down Expand Up @@ -367,6 +368,8 @@ public boolean isEmpty() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
// change required for NMC
// default case will be used for VIEWTYPE_IMAGE & VIEWTYPE_ITEM also
default -> {
if (gridView) {
return new OCFileListGridItemViewHolder(
Expand All @@ -378,17 +381,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
);
}
}
case VIEWTYPE_IMAGE -> {
if (gridView) {
return new OCFileListGridImageViewHolder(
GridImageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
);
} else {
return new OCFileListItemViewHolder(
ListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
);
}
}
case VIEWTYPE_FOOTER -> {
return new OCFileListFooterViewHolder(
ListFooterBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
Expand All @@ -412,7 +404,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof OCFileListFooterViewHolder footerViewHolder) {
footerViewHolder.getFooterText().setText(getFooterText());
viewThemeUtils.platform.colorCircularProgressBar(footerViewHolder.getLoadingProgressBar(), ColorRole.ON_SURFACE_VARIANT);
footerViewHolder.getLoadingProgressBar().setVisibility(
ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
} else if (holder instanceof OCFileListHeaderViewHolder headerViewHolder) {
Expand Down Expand Up @@ -519,15 +510,10 @@ private void updateLivePhotoIndicators(ListGridImageViewHolder holder, OCFile fi
private void bindListGridItemViewHolder(ListGridItemViewHolder holder, OCFile file) {
holder.getFileName().setText(file.getDecryptedFileName());

boolean gridImage = MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file);
if (gridView && gridImage) {
if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
holder.getFileName().setVisibility(View.GONE);
} else {
if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
holder.getFileName().setVisibility(View.GONE);
} else {
holder.getFileName().setVisibility(View.VISIBLE);
}
holder.getFileName().setVisibility(View.VISIBLE);
}
}

Expand Down Expand Up @@ -697,7 +683,7 @@ public boolean shouldShowHeader() {
return false;
}

if (MainApp.isOnlyOnDevice()) {
if (MainApp.isOnlyOnDevice() || ocFileListFragmentInterface.isSearchFragment()) {
return false;
}

Expand Down Expand Up @@ -1087,6 +1073,7 @@ public void cancelAllPendingTasks() {

public void setGridView(boolean bool) {
gridView = bool;
ocFileListDelegate.setGridView(bool);
}

public void setShowMetadata(boolean bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ class OCFileListDelegate(
private val storageManager: FileDataStorageManager,
private val hideItemOptions: Boolean,
private val preferences: AppPreferences,
private val gridView: Boolean,
private var gridView: Boolean,
private val transferServiceGetter: ComponentsGetter,
private val showMetadata: Boolean,
private var showShareAvatar: Boolean,
private var viewThemeUtils: ViewThemeUtils,
private val isMediaGallery: Boolean,
private val syncFolderProvider: SyncedFolderProvider? = null
) {
private val checkedFiles: MutableSet<OCFile> = HashSet()
Expand Down Expand Up @@ -214,7 +215,8 @@ class OCFileListDelegate(
gridViewHolder.shimmerThumbnail,
preferences,
viewThemeUtils,
syncFolderProvider
syncFolderProvider,
isMediaGallery
)

// item layout + click listeners
Expand All @@ -238,7 +240,8 @@ class OCFileListDelegate(

// shares
val shouldHideShare = (
hideItemOptions ||
gridView || // NMC: don't show share icon in grid mode
hideItemOptions ||
!file.isFolder &&
file.isEncrypted ||
file.isEncrypted &&
Expand Down Expand Up @@ -315,9 +318,8 @@ class OCFileListDelegate(

private fun setCheckBoxImage(file: OCFile, gridViewHolder: ListGridImageViewHolder) {
if (isCheckedFile(file)) {
gridViewHolder.checkbox.setImageDrawable(
viewThemeUtils.platform.tintDrawable(context, R.drawable.ic_checkbox_marked, ColorRole.PRIMARY)
)
// NMC Customization
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_marked)
} else {
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline)
}
Expand Down Expand Up @@ -405,6 +407,10 @@ class OCFileListDelegate(
showShareAvatar = bool
}

fun setGridView(bool: Boolean){
gridView = bool
}

companion object {
private val TAG = OCFileListDelegate::class.java.simpleName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ internal class OCFileListGridItemViewHolder(var binding: GridItemBinding) :
get() = null
override val livePhotoIndicatorSeparator: TextView?
get() = null
override val fileFeaturesLayout: LinearLayout
get() = binding.fileFeaturesLayout
override val fileFeaturesLayout: LinearLayout?
get() = null
override val more: ImageButton
get() = binding.more

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public void onBindHeaderViewHolder(SectionedViewHolder holder, int section, bool
headerViewHolder.binding.uploadListTitle.setText(
String.format(parentActivity.getString(R.string.uploads_view_group_header),
group.getGroupName(), group.getGroupItemCount()));
viewThemeUtils.platform.colorPrimaryTextViewElement(headerViewHolder.binding.uploadListTitle);
//NMC Customization
headerViewHolder.binding.uploadListTitle.setTextColor(parentActivity.getResources().getColor(R.color.primary, null));

headerViewHolder.binding.uploadListTitle.setOnClickListener(v -> {
toggleSectionExpanded(section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class ConflictsResolveDialog : DialogFragment(), Injectable {
null,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
syncedFolderProvider,
false
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public interface OCFileListFragmentInterface {
boolean isLoading();

void onHeaderClicked();

boolean isSearchFragment();
}
72 changes: 58 additions & 14 deletions app/src/main/java/com/owncloud/android/utils/DisplayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,13 @@ public static void setThumbnail(OCFile file,
LoaderImageView shimmerThumbnail,
AppPreferences preferences,
ViewThemeUtils viewThemeUtils,
SyncedFolderProvider syncedFolderProvider) {
SyncedFolderProvider syncedFolderProvider,
boolean isMediaGallery) {
if (file.isFolder()) {
stopShimmer(shimmerThumbnail, thumbnailView);
updateThumbnailViewSize(thumbnailView, gridView, context, isMediaGallery, R.dimen.standard_folders_grid_item_size);
//reset the padding as this will change for files and we don't this for folders
thumbnailView.setPadding(0, 0, 0, 0);

boolean isAutoUploadFolder = SyncedFolderProvider.isAutoUploadFolder(syncedFolderProvider, file, user);
boolean isDarkModeActive = preferences.isDarkModeEnabled();
Expand All @@ -871,36 +875,39 @@ public static void setThumbnail(OCFile file,
LayerDrawable fileIcon = MimeTypeUtil.getFileIcon(isDarkModeActive, overlayIconId, context, viewThemeUtils);
thumbnailView.setImageDrawable(fileIcon);
} else {
updateThumbnailViewSize(thumbnailView, gridView, context, isMediaGallery, R.dimen.standard_files_grid_item_size);
if (file.getRemoteId() != null && file.isPreviewAvailable()) {
// Thumbnail in cache?
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());

if (thumbnail != null && !file.isUpdateThumbnailNeeded()) {
setThumbnailViewPadding(thumbnailView, gridView, context, isMediaGallery, R.dimen.alternate_padding);
stopShimmer(shimmerThumbnail, thumbnailView);

if (MimeTypeUtil.isVideo(file)) {
Bitmap withOverlay = ThumbnailsCacheManager.addVideoOverlay(thumbnail, context);
thumbnailView.setImageBitmap(withOverlay);
thumbnail = ThumbnailsCacheManager.addVideoOverlay(thumbnail, context);
}

// set the corner for both video and image thumbnail
if (gridView) {
BitmapUtils.setRoundedBitmapForGridMode(thumbnail, thumbnailView);
} else {
if (gridView) {
BitmapUtils.setRoundedBitmapForGridMode(thumbnail, thumbnailView);
} else {
BitmapUtils.setRoundedBitmap(thumbnail, thumbnailView);
}
BitmapUtils.setRoundedBitmap(thumbnail, thumbnailView);
}
} else {
generateNewThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, shimmerThumbnail, preferences, viewThemeUtils);
generateNewThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, shimmerThumbnail, preferences, viewThemeUtils, isMediaGallery);
}

if ("image/png".equalsIgnoreCase(file.getMimeType())) {
thumbnailView.setBackgroundColor(context.getResources().getColor(R.color.bg_default));
}
} else {
if (file.getRemoteId() != null) {
generateNewThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, shimmerThumbnail, preferences, viewThemeUtils);
generateNewThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, shimmerThumbnail, preferences, viewThemeUtils, isMediaGallery);
} else {
stopShimmer(shimmerThumbnail, thumbnailView);
setThumbnailViewPadding(thumbnailView, gridView, context, isMediaGallery, R.dimen.standard_quarter_padding);
thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
file.getFileName(),
context,
Expand All @@ -919,7 +926,8 @@ private static void generateNewThumbnail(OCFile file,
Context context,
LoaderImageView shimmerThumbnail,
AppPreferences preferences,
ViewThemeUtils viewThemeUtils) {
ViewThemeUtils viewThemeUtils,
boolean isMediaGallery) {
if (!ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
return;
}
Expand Down Expand Up @@ -957,15 +965,14 @@ private static void generateNewThumbnail(OCFile file,

int px = ThumbnailsCacheManager.getThumbnailDimension();
thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
//set thumbnailView padding for no thumbnail
setThumbnailViewPadding(thumbnailView, gridView, context, isMediaGallery, R.dimen.standard_quarter_padding);
}
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
thumbnail, task);

if (shimmerThumbnail != null && shimmerThumbnail.getVisibility() == View.GONE) {
if (gridView) {
configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
}
startShimmer(shimmerThumbnail, thumbnailView);
}

Expand Down Expand Up @@ -1035,4 +1042,41 @@ private static Point getScreenSize(Context context) throws Exception {
throw new Exception("WindowManager not found");
}
}

/**
* method to set the padding to thumbnail view this is required for files so that there will be space between file
* and file name
*
* @param thumbnailView
* @param gridView
* @param context
* @param isMediaGallery
* @param dimensPadding
*/
private static void setThumbnailViewPadding(ImageView thumbnailView, boolean gridView, Context context,
boolean isMediaGallery, int dimensPadding) {
if (gridView && !isMediaGallery) {
int padding = context.getResources().getDimensionPixelSize(dimensPadding);
thumbnailView.setPadding(0, 0, 0, padding);
}
}

/**
* method to set manual thumbnail view height and width for folders and files because we are using different size
* for both files and folders
*
* @param thumbnailView
* @param gridView
* @param context
* @param isMediaGallery
* @param size
*/
private static void updateThumbnailViewSize(ImageView thumbnailView, boolean gridView, Context context,
boolean isMediaGallery, int size) {
if (gridView && !isMediaGallery) {
thumbnailView.getLayoutParams().width =
context.getResources().getDimensionPixelSize(size);
thumbnailView.getLayoutParams().height = context.getResources().getDimensionPixelSize(size);
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/cursor_drawable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/text_color" />
<size android:width="1.5dp" />
</shape>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/file_details_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

<ImageView
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="@dimen/zero"
android:layout_marginEnd="@dimen/standard_eighth_margin"
android:contentDescription="@null"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/file_thumbnail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:layout_width="@dimen/file_icon_size"
android:layout_height="@dimen/file_icon_size"
android:contentDescription="@null"
android:src="@drawable/folder" />
tools:src="@drawable/folder" />

<ImageView
android:id="@+id/videoOverlay"
Expand Down
13 changes: 3 additions & 10 deletions app/src/main/res/layout/files_folder_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@
android:layout_height="0dp"
android:layout_weight="1" />

<LinearLayout
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/list_divider_background" />

</LinearLayout>
android:layout_height="0.5dp"
android:background="@color/divider_color" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
Loading

0 comments on commit 1736545

Please sign in to comment.