Skip to content

Commit 37d096e

Browse files
style(sharing): Make share UI M3 themed
Signed-off-by: Andy Scherzinger <[email protected]>
1 parent 1307684 commit 37d096e

File tree

13 files changed

+100
-80
lines changed

13 files changed

+100
-80
lines changed

app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,11 @@ public void themeInternalLinkIcon(ImageView view) {
224224
withScheme(view, scheme -> {
225225
view
226226
.getBackground()
227-
.setColorFilter(ResourcesCompat.getColor(view.getContext().getResources(),
228-
R.color.nc_grey,
229-
null),
230-
PorterDuff.Mode.SRC_IN);
227+
.setColorFilter(dynamicColor.surfaceContainerHigh().getArgb(scheme), PorterDuff.Mode.SRC_IN);
231228
view
232229
.getDrawable()
233230
.mutate()
234-
.setColorFilter(ResourcesCompat.getColor(view.getContext().getResources(),
235-
R.color.icon_on_nc_grey,
236-
null),
237-
PorterDuff.Mode.SRC_IN);
231+
.setColorFilter(dynamicColor.onSurface().getArgb(scheme), PorterDuff.Mode.SRC_IN);
238232
return view;
239233
});
240234
}

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/ShareeListAdapter.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import androidx.core.content.ContextCompat;
1717
import androidx.recyclerview.widget.RecyclerView;
1818

19+
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
1920
import com.owncloud.android.lib.resources.shares.OCShare;
2021
import com.owncloud.android.lib.resources.shares.ShareType;
2122

@@ -90,30 +91,36 @@ public int getItemViewType(int position) {
9091
@NonNull
9192
@Override
9293
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
94+
BrandingUtil brandingUtil = BrandingUtil.of(color, parent.getContext());
95+
LayoutInflater layoutInflater = LayoutInflater.from(activity);
9396
switch (ShareType.fromValue(viewType)) {
9497
case PUBLIC_LINK, EMAIL -> {
95-
return new LinkShareViewHolder(
96-
ItemShareLinkShareBinding.inflate(LayoutInflater.from(activity),
97-
parent,
98-
false),
99-
activity);
98+
ItemShareLinkShareBinding binding = ItemShareLinkShareBinding.inflate(
99+
layoutInflater, parent, false);
100+
brandingUtil.platform.colorTextView(binding.name, ColorRole.ON_SURFACE);
101+
brandingUtil.platform.colorTextView(binding.subline, ColorRole.ON_SURFACE_VARIANT);
102+
return new LinkShareViewHolder(binding, activity);
100103
}
101104
case NEW_PUBLIC_LINK -> {
102-
ItemAddPublicShareBinding binding = ItemAddPublicShareBinding.inflate(LayoutInflater.from(activity), parent, false);
103-
BrandingUtil.of(color, parent.getContext()).notes.themeInternalLinkIcon(binding.addNewPublicShareLinkIcon);
105+
ItemAddPublicShareBinding binding = ItemAddPublicShareBinding.inflate(
106+
layoutInflater, parent, false);
107+
brandingUtil.notes.themeInternalLinkIcon(binding.addNewPublicShareLinkIcon);
108+
brandingUtil.platform.colorTextView(binding.addNewPublicShareLinkText, ColorRole.ON_SURFACE);
104109
return new NewLinkShareViewHolder(binding);
105110
}
106111
case INTERNAL -> {
107-
ItemInternalShareLinkBinding binding = ItemInternalShareLinkBinding.inflate(LayoutInflater.from(activity), parent, false);
108-
BrandingUtil.of(color, parent.getContext()).notes.themeInternalLinkIcon(binding.copyInternalLinkIcon);
112+
ItemInternalShareLinkBinding binding = ItemInternalShareLinkBinding.inflate(
113+
layoutInflater, parent, false);
114+
brandingUtil.notes.themeInternalLinkIcon(binding.copyInternalLinkIcon);
115+
brandingUtil.platform.colorTextView(binding.shareInternalLink, ColorRole.ON_SURFACE);
116+
brandingUtil.platform.colorTextView(binding.shareInternalLinkText, ColorRole.ON_SURFACE_VARIANT);
109117
return new InternalShareViewHolder(binding, activity);
110118
}
111119
default -> {
112-
return new ShareViewHolder(ItemShareShareBinding.inflate(LayoutInflater.from(activity),
113-
parent,
114-
false),
115-
account,
116-
activity);
120+
ItemShareShareBinding binding = ItemShareShareBinding.inflate(
121+
layoutInflater, parent, false);
122+
brandingUtil.platform.colorTextView(binding.name, ColorRole.ON_SURFACE);
123+
return new ShareViewHolder(binding, account, activity);
117124
}
118125
}
119126
}

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/holder/LinkShareViewHolder.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ public void bind(OCShare publicShare, ShareeListAdapterListener listener) {
4747
R.drawable.ic_email,
4848
null));
4949
binding.copyLink.setVisibility(View.GONE);
50-
51-
binding.icon.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
52-
PorterDuff.Mode.SRC_IN);
53-
binding.icon.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
54-
PorterDuff.Mode.SRC_IN);
5550
} else {
5651
if (!TextUtils.isEmpty(publicShare.getLabel())) {
5752
String text = String.format(context.getString(R.string.share_link_with_label), publicShare.getLabel());

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/holder/NewLinkShareViewHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public NewLinkShareViewHolder(ItemAddPublicShareBinding binding) {
2727
}
2828

2929
public void bind(ShareeListAdapterListener listener) {
30-
binding.addNewPublicShareLink.setOnClickListener(v -> listener.createPublicShareLink());
30+
binding.addNewPublicShareLinkPlus.setOnClickListener(v -> listener.createPublicShareLink());
3131
}
3232
}

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/holder/ShareViewHolder.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@
1818
import com.owncloud.android.lib.resources.shares.OCShare;
1919

2020
import it.niedermann.owncloud.notes.R;
21+
import it.niedermann.owncloud.notes.branding.BrandedViewHolder;
22+
import it.niedermann.owncloud.notes.branding.BrandingUtil;
2123
import it.niedermann.owncloud.notes.databinding.ItemShareShareBinding;
2224
import it.niedermann.owncloud.notes.persistence.entity.Account;
2325
import it.niedermann.owncloud.notes.share.helper.AvatarLoader;
2426
import it.niedermann.owncloud.notes.share.helper.SharingMenuHelper;
2527
import it.niedermann.owncloud.notes.share.listener.ShareeListAdapterListener;
2628
import it.niedermann.owncloud.notes.shared.util.FilesSpecificViewThemeUtils;
2729

28-
public class ShareViewHolder extends RecyclerView.ViewHolder {
30+
public class ShareViewHolder extends BrandedViewHolder {
2931
private ItemShareShareBinding binding;
3032
private Account account;
3133
private Context context;
3234

3335
public ShareViewHolder(@NonNull View itemView) {
3436
super(itemView);
37+
bindBranding();
3538
}
3639

3740
public ShareViewHolder(ItemShareShareBinding binding,
@@ -41,6 +44,7 @@ public ShareViewHolder(ItemShareShareBinding binding,
4144
this.binding = binding;
4245
this.account = account;
4346
this.context = context;
47+
bindBranding();
4448
}
4549

4650
public void bind(OCShare share, ShareeListAdapterListener listener) {
@@ -92,7 +96,7 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {
9296

9397
if (accountName.equalsIgnoreCase(share.getShareWith()) || accountName.equalsIgnoreCase(share.getUserId())) {
9498
binding.overflowMenu.setVisibility(View.VISIBLE);
95-
99+
96100
String permissionName = SharingMenuHelper.getPermissionName(context, share);
97101
setPermissionName(permissionName);
98102

@@ -120,4 +124,13 @@ private void setImage(ImageView avatar, String name, @DrawableRes int fallback)
120124
avatar.setImageResource(fallback);
121125
}
122126
}
127+
128+
@Override
129+
public void applyBrand(int color) {
130+
final var util = BrandingUtil.of(color, context);
131+
if (binding != null) {
132+
util.androidx.colorPrimaryTextViewElement(binding.permissionName);
133+
util.platform.colorImageViewBackgroundAndIcon(binding.icon);
134+
}
135+
}
123136
}

app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@ import it.niedermann.owncloud.notes.shared.util.extensions.toExpirationDateStrin
3737
import org.json.JSONObject
3838
import java.util.Date
3939

40-
class ShareRepository(
41-
private val applicationContext: Context,
42-
private val account: SingleSignOnAccount
43-
) {
40+
class ShareRepository(private val applicationContext: Context, private val account: SingleSignOnAccount) {
4441

4542
private val tag = "ShareRepository"
4643
private val gson = Gson()
4744
private val apiProvider: ApiProvider by lazy { ApiProvider.getInstance() }
4845
private val notesRepository: NotesRepository by lazy {
4946
NotesRepository.getInstance(
50-
applicationContext,
47+
applicationContext
5148
)
5249
}
5350

@@ -61,7 +58,13 @@ class ShareRepository(
6158
val notesPathResponseResult = getNotesPathResponseResult() ?: return null
6259
val notesPath = notesPathResponseResult.notesPath
6360
val notesSuffix = notesPathResponseResult.fileSuffix
64-
return StringConstants.PATH + notesPath + StringConstants.PATH + note.title + notesSuffix
61+
return if (note.category.isEmpty()) {
62+
StringConstants.PATH + notesPath + StringConstants.PATH + note.title + notesSuffix
63+
} else {
64+
StringConstants.PATH + notesPath + StringConstants.PATH + note.category + StringConstants.PATH +
65+
note.title +
66+
notesSuffix
67+
}
6568
}
6669

6770
fun getShareEntitiesForSpecificNote(note: Note): List<ShareEntity> {
@@ -135,11 +138,7 @@ class ShareRepository(
135138

136139
private fun LinkedTreeMap<*, *>.getList(key: String): ArrayList<*>? = this[key] as? ArrayList<*>
137140

138-
fun getSharees(
139-
searchString: String,
140-
page: Int,
141-
perPage: Int
142-
): ArrayList<JSONObject> {
141+
fun getSharees(searchString: String, page: Int, perPage: Int): ArrayList<JSONObject> {
143142
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
144143
val call = shareAPI.getSharees(
145144
search = searchString,
@@ -299,7 +298,6 @@ class ShareRepository(
299298
val call = shareAPI.removeShare(share.id)
300299
val response = call.execute()
301300
if (response.isSuccessful) {
302-
303301
if (share.shareType != null && share.shareType == ShareType.PUBLIC_LINK) {
304302
note.setIsShared(false)
305303
updateNote(note)
@@ -316,16 +314,13 @@ class ShareRepository(
316314
}
317315
}
318316

319-
fun updateShare(
320-
shareId: Long,
321-
requestBody: UpdateShareRequest
322-
): ApiResult<OcsResponse<CreateShareResponse>?> {
317+
fun updateShare(shareId: Long, requestBody: UpdateShareRequest): ApiResult<OcsResponse<CreateShareResponse>?> {
323318
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
324319
val call = shareAPI.updateShare(shareId, requestBody)
325320
val response = call.execute()
326321
return try {
327322
if (response.isSuccessful) {
328-
Log_OC.d(tag, "Share updated successfully: ${response.body().toString()}")
323+
Log_OC.d(tag, "Share updated successfully: ${response.body()}")
329324
ApiResult.Success(
330325
data = response.body(),
331326
message = applicationContext.getString(R.string.note_share_created)
@@ -396,10 +391,7 @@ class ShareRepository(
396391
}
397392
}
398393

399-
fun updateSharePermission(
400-
shareId: Long,
401-
permissions: Int? = null,
402-
): ApiResult<OcsResponse<CreateShareResponse>?> {
394+
fun updateSharePermission(shareId: Long, permissions: Int? = null): ApiResult<OcsResponse<CreateShareResponse>?> {
403395
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
404396
val requestBody = UpdateSharePermissionRequest(permissions = permissions)
405397

app/src/main/res/drawable/ic_content_copy.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
android:width="24dp"
1010
android:viewportWidth="24"
1111
android:viewportHeight="24">
12-
<path android:fillColor="#757575" android:pathData="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
12+
<path android:fillColor="@color/icon_color_default" android:pathData="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
1313
</vector>

app/src/main/res/drawable/ic_dots_vertical.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
android:viewportHeight="24">
1212
<path
1313
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"
14-
android:fillColor="#666666"/>
14+
android:fillColor="@color/icon_color_default"/>
1515
</vector>

app/src/main/res/layout/item_add_public_share.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
~ SPDX-License-Identifier: GPL-3.0-or-later
77
-->
88
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
9+
xmlns:app="http://schemas.android.com/apk/res-auto"
910
android:id="@+id/add_public_share"
1011
android:layout_width="match_parent"
1112
android:layout_height="@dimen/sharee_list_item_size"
@@ -24,20 +25,23 @@
2425
android:src="@drawable/shared_via_link" />
2526

2627
<TextView
28+
android:id="@+id/add_new_public_share_link_text"
2729
android:layout_width="0dp"
2830
android:layout_height="wrap_content"
2931
android:layout_gravity="center_vertical"
3032
android:layout_weight="1"
3133
android:text="@string/share_via_link_section_title"
3234
android:textSize="@dimen/note_font_size_small" />
3335

34-
<ImageView
35-
android:id="@+id/add_new_public_share_link"
36-
android:layout_width="wrap_content"
36+
<com.google.android.material.button.MaterialButton
37+
android:id="@+id/add_new_public_share_link_plus"
38+
style="@style/Button.IconButton"
39+
android:layout_width="@dimen/minimum_size_for_touchable_area"
3740
android:layout_height="match_parent"
38-
android:layout_gravity="center_vertical"
41+
android:minHeight="@dimen/minimum_size_for_touchable_area"
3942
android:contentDescription="@string/add_new_public_share"
40-
android:paddingStart="@dimen/spacer_2x"
41-
android:paddingEnd="@dimen/spacer_2x"
42-
android:src="@drawable/ic_plus" />
43+
app:cornerRadius="@dimen/iconized_single_line_item_icon_size"
44+
app:icon="@drawable/ic_plus"
45+
app:iconSize="@dimen/iconized_single_line_item_icon_size"
46+
app:iconTint="@color/icon_color_default" />
4347
</LinearLayout>

app/src/main/res/layout/item_internal_share_link.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<LinearLayout
3333
android:layout_width="match_parent"
3434
android:layout_height="wrap_content"
35-
android:layout_marginTop="@dimen/spacer_1x"
3635
android:orientation="vertical">
3736

3837
<TextView

0 commit comments

Comments
 (0)