Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Add Tag Color #14339

Merged
merged 15 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.shares.ShareeUser
import com.owncloud.android.lib.resources.tags.Tag
import com.owncloud.android.utils.MimeType
import com.owncloud.android.utils.ScreenshotTest
import org.junit.Assert
Expand Down Expand Up @@ -50,7 +51,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
fileLength = 3072000
modificationTimestamp = 746443755000
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
tags = listOf("Top secret")
tags = listOf(Tag("", "Top secret", null))
sut.storageManager.saveFile(this)
}

Expand All @@ -72,7 +73,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
fileLength = 12092000
modificationTimestamp = 746143952000
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
tags = listOf("Confidential", "+5")
tags = listOf(Tag("", "Confidential", null), Tag("", "+5", null))
sut.storageManager.saveFile(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
import com.owncloud.android.lib.resources.status.E2EVersion;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.tags.Tag;
import com.owncloud.android.operations.RemoteOperationFailedException;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeType;
Expand Down Expand Up @@ -1283,7 +1284,7 @@ private OCFile createFileInstance(FileEntity fileEntity) {
ocFile.setTags(new ArrayList<>());
} else {
try {
String[] tagsArray = gson.fromJson(tags, String[].class);
Tag[] tagsArray = gson.fromJson(tags, Tag[].class);
ocFile.setTags(new ArrayList<>(Arrays.asList(tagsArray)));
} catch (JsonSyntaxException e) {
// ignore saved value due to api change
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.owncloud.android.lib.resources.files.model.ImageDimension;
import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
import com.owncloud.android.lib.resources.shares.ShareeUser;
import com.owncloud.android.lib.resources.tags.Tag;
import com.owncloud.android.utils.MimeType;

import java.io.File;
Expand Down Expand Up @@ -117,7 +118,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
private long e2eCounter = -1;
@Nullable
private GeoLocation geolocation;
private List<String> tags = new ArrayList<>();
private List<Tag> tags = new ArrayList<>();
private Long internalFolderSyncTimestamp = -1L;
private String internalFolderSyncResult = "";

Expand Down Expand Up @@ -1047,11 +1048,11 @@ public GeoLocation getGeoLocation() {
return geolocation;
}

public List<String> getTags() {
public List<Tag> getTags() {
return tags;
}

public void setTags(List<String> tags) {
public void setTags(List<Tag> tags) {
this.tags = tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
Expand All @@ -30,6 +31,7 @@
import android.widget.LinearLayout;

import com.elyeproj.loaderviewlibrary.LoaderImageView;
import com.google.android.material.chip.Chip;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.client.account.User;
import com.nextcloud.client.database.entity.OfflineOperationEntity;
Expand Down Expand Up @@ -62,6 +64,7 @@
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.shares.ShareeUser;
import com.owncloud.android.lib.resources.tags.Tag;
import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.operations.RemoteOperationFailedException;
import com.owncloud.android.ui.activity.ComponentsGetter;
Expand Down Expand Up @@ -580,12 +583,11 @@ private void bindListItemViewHolder(ListItemViewHolder holder, OCFile file) {
holder.getSecondTag().setVisibility(View.GONE);
holder.getTagMore().setVisibility(View.GONE);

holder.getFirstTag().setText(file.getTags().get(0));
applyChipVisuals(holder.getFirstTag(), file.getTags().get(0));

if (file.getTags().size() > 1) {
viewThemeUtils.material.themeChipSuggestion(holder.getSecondTag());
holder.getSecondTag().setVisibility(View.VISIBLE);
holder.getSecondTag().setText(file.getTags().get(1));
applyChipVisuals(holder.getSecondTag(), file.getTags().get(1));
}

if (file.getTags().size() > 2) {
Expand Down Expand Up @@ -649,6 +651,23 @@ private void bindListItemViewHolder(ListItemViewHolder holder, OCFile file) {
configureThumbnail(holder, file);
}

private void applyChipVisuals(Chip chip, Tag tag) {
viewThemeUtils.material.themeChipSuggestion(chip);
chip.setText(tag.getName());
String tagColor = tag.getColor();
if (TextUtils.isEmpty(tagColor)) {
return;
}

try {
int color = Color.parseColor(tagColor);
chip.setChipStrokeColor(ColorStateList.valueOf(color));
chip.setTextColor(color);
} catch (IllegalArgumentException e) {
Log_OC.d(TAG, "Exception applyChipVisuals: " + e);
}
}

private void prepareFileSize(ListItemViewHolder holder, OCFile file, long size) {
holder.getFileSize().setVisibility(View.VISIBLE);
String fileSizeText = getFileSizeText(file, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -50,6 +51,7 @@
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.tags.Tag;
import com.owncloud.android.ui.activity.DrawerActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.ToolbarActivity;
Expand Down Expand Up @@ -241,16 +243,23 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
if (getFile().getTags().isEmpty()) {
binding.tagsGroup.setVisibility(View.GONE);
} else {
for (String tag : getFile().getTags()) {
for (Tag tag : getFile().getTags()) {
Chip chip = new Chip(context);
chip.setText(tag);
chip.setText(tag.getName());
chip.setChipBackgroundColor(ColorStateList.valueOf(getResources().getColor(R.color.bg_default,
context.getTheme())));
chip.setShapeAppearanceModel(chip.getShapeAppearanceModel().toBuilder().setAllCornerSizes((100.0f))
.build());
chip.setEnsureMinTouchTargetSize(false);
chip.setClickable(false);
viewThemeUtils.material.themeChipSuggestion(chip);

if (tag.getColor() != null) {
int color = Color.parseColor(tag.getColor());
chip.setChipStrokeColor(ColorStateList.valueOf(color));
chip.setTextColor(color);
}

binding.tagsGroup.addView(chip);
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
buildscript {
ext {
androidLibraryVersion ="4c07e6a69e8a8bab43ca9406ea546613e90d934b"
androidLibraryVersion ="40fea7dfa5"
androidPluginVersion = '8.8.0'
androidxMediaVersion = '1.5.1'
androidxTestVersion = "1.6.1"
Expand Down
32 changes: 32 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9082,6 +9082,14 @@
<sha256 value="fc987eaf53cefe50c60453d32727bb23bb1818eb4898ef89abce4d001c0f87c5" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="0b31cc65be">
<artifact name="android-library-0b31cc65be.aar">
<sha256 value="518b4b9db77888510cbb03f5a3156ff989e91841677e9c71f9cc7a30f3b42749" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-0b31cc65be.module">
<sha256 value="ecc59e0fe6d4d6683f467011e430f7c256017348cebfc8ac7287ea23f8b1e14a" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="0c886d61f6">
<artifact name="android-library-0c886d61f6.aar">
<sha256 value="9c3a87487717acd878305a00f0d6f2337b9f5512d541f7ac46b9bdb5a53020b9" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand All @@ -9098,6 +9106,22 @@
<sha256 value="66fc4c12f83ef0d2ae5536ebc4d808e2225129ba4668af77f03f27bd95b93934" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="1b59a97bdbbf2160236880e6cb02933e3bd441a1">
<artifact name="android-library-1b59a97bdbbf2160236880e6cb02933e3bd441a1.aar">
<sha256 value="8093484cb07ee1d96376c5b6ec0390c381a364aad2c7465ce306691075433d58" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-1b59a97bdbbf2160236880e6cb02933e3bd441a1.module">
<sha256 value="4d022bff5a48c368ad91f681268429e1b4efae92080ee11d21cf743cbac358dc" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="24744f9235fa9446fa314f66e753fab5f9554313">
<artifact name="android-library-24744f9235fa9446fa314f66e753fab5f9554313.aar">
<sha256 value="f7bbb063eace028f28fb1d3e8215a29f2d5a8c3964cfa29b559d18cb87abbb85" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-24744f9235fa9446fa314f66e753fab5f9554313.module">
<sha256 value="b54a67922d5a797da641e1a5f7bc7ad1e409f6cfc20b001792fbdab5a5424e57" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="26dc8477962f12356db840bb1a774f0186b38e4d">
<artifact name="android-library-26dc8477962f12356db840bb1a774f0186b38e4d.aar">
<sha256 value="57ab4fd7c922875a7e0b5feac20aa27ab5df0fd3b4e042f92ed727c0b6316e81" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down Expand Up @@ -9170,6 +9194,14 @@
<sha256 value="cd34092733bea9249fbe600b31e018c7c4c344f4201df45a1c16035338a505ca" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="40fea7dfa5">
<artifact name="android-library-40fea7dfa5.aar">
<sha256 value="95de953bff85130ed94528089dc850fa99969ad50fff3259d94988578eab3dc2" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-40fea7dfa5.module">
<sha256 value="d972b7569884e8e8a1754d2009b870744e0a1a7a3e51c7dcaccbdc381dcd34d5" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="451cddeba122ff4d17dc8f88feb2fd7589f77567">
<artifact name="android-library-451cddeba122ff4d17dc8f88feb2fd7589f77567.aar">
<sha256 value="c253a126ca3c32dd5b373ab1c64668e4603305b3113b052fc0fc5e3c833a913c" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down
Loading