Skip to content
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 @@ -224,17 +224,11 @@ public void themeInternalLinkIcon(ImageView view) {
withScheme(view, scheme -> {
view
.getBackground()
.setColorFilter(ResourcesCompat.getColor(view.getContext().getResources(),
R.color.nc_grey,
null),
PorterDuff.Mode.SRC_IN);
.setColorFilter(dynamicColor.surfaceContainerHigh().getArgb(scheme), PorterDuff.Mode.SRC_IN);
view
.getDrawable()
.mutate()
.setColorFilter(ResourcesCompat.getColor(view.getContext().getResources(),
R.color.icon_on_nc_grey,
null),
PorterDuff.Mode.SRC_IN);
.setColorFilter(dynamicColor.onSurface().getArgb(scheme), PorterDuff.Mode.SRC_IN);
return view;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
executorService = Executors.newSingleThreadScheduledExecutor();
binding = ActivityNoteShareBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
binding.toolbar.setNavigationOnClickListener(v -> backPressed());
registerResultLauncher();
initializeArguments();
initializeOnBackPressedDispatcher();
Expand All @@ -127,14 +129,18 @@ private void initializeOnBackPressedDispatcher() {
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
Intent intent = new Intent(NoteShareActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
backPressed();
}
});
}

private void backPressed() {
Intent intent = new Intent(NoteShareActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
}

private void initializeArguments() {
Bundle bundler = getIntent().getExtras();
note = BundleExtensionsKt.getSerializableArgument(bundler, ARG_NOTE, Note.class);
Expand All @@ -156,6 +162,8 @@ private void initializeArguments() {
repository.getSharesForNotesAndSaveShareEntities();

runOnUiThread(() -> {
binding.title.setText(R.string.activity_sharing_title);
binding.fileName.setText(note.getTitle());
binding.searchContainer.setVisibility(View.VISIBLE);
binding.sharesList.setVisibility(View.VISIBLE);
binding.sharesList.setAdapter(new ShareeListAdapter(this, new ArrayList<>(), this, account));
Expand Down Expand Up @@ -798,6 +806,7 @@ private void updateShare(OCShare share) {
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.platform.themeStatusBar(this);
util.material.themeToolbar(binding.toolbar);
util.androidx.themeToolbarSearchView(binding.searchView);
util.platform.colorCircularProgressBar(binding.loadingLayoutIndicator, ColorRole.PRIMARY);
util.platform.themeHorizontalProgressBar(binding.progressBar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;

Expand Down Expand Up @@ -90,30 +91,36 @@ public int getItemViewType(int position) {
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
BrandingUtil brandingUtil = BrandingUtil.of(color, parent.getContext());
LayoutInflater layoutInflater = LayoutInflater.from(activity);
switch (ShareType.fromValue(viewType)) {
case PUBLIC_LINK, EMAIL -> {
return new LinkShareViewHolder(
ItemShareLinkShareBinding.inflate(LayoutInflater.from(activity),
parent,
false),
activity);
ItemShareLinkShareBinding binding = ItemShareLinkShareBinding.inflate(
layoutInflater, parent, false);
brandingUtil.platform.colorTextView(binding.name, ColorRole.ON_SURFACE);
brandingUtil.platform.colorTextView(binding.subline, ColorRole.ON_SURFACE_VARIANT);
return new LinkShareViewHolder(binding, activity);
}
case NEW_PUBLIC_LINK -> {
ItemAddPublicShareBinding binding = ItemAddPublicShareBinding.inflate(LayoutInflater.from(activity), parent, false);
BrandingUtil.of(color, parent.getContext()).notes.themeInternalLinkIcon(binding.addNewPublicShareLinkIcon);
ItemAddPublicShareBinding binding = ItemAddPublicShareBinding.inflate(
layoutInflater, parent, false);
brandingUtil.notes.themeInternalLinkIcon(binding.addNewPublicShareLinkIcon);
brandingUtil.platform.colorTextView(binding.addNewPublicShareLinkText, ColorRole.ON_SURFACE);
return new NewLinkShareViewHolder(binding);
}
case INTERNAL -> {
ItemInternalShareLinkBinding binding = ItemInternalShareLinkBinding.inflate(LayoutInflater.from(activity), parent, false);
BrandingUtil.of(color, parent.getContext()).notes.themeInternalLinkIcon(binding.copyInternalLinkIcon);
ItemInternalShareLinkBinding binding = ItemInternalShareLinkBinding.inflate(
layoutInflater, parent, false);
brandingUtil.notes.themeInternalLinkIcon(binding.copyInternalLinkIcon);
brandingUtil.platform.colorTextView(binding.shareInternalLink, ColorRole.ON_SURFACE);
brandingUtil.platform.colorTextView(binding.shareInternalLinkText, ColorRole.ON_SURFACE_VARIANT);
return new InternalShareViewHolder(binding, activity);
}
default -> {
return new ShareViewHolder(ItemShareShareBinding.inflate(LayoutInflater.from(activity),
parent,
false),
account,
activity);
ItemShareShareBinding binding = ItemShareShareBinding.inflate(
layoutInflater, parent, false);
brandingUtil.platform.colorTextView(binding.name, ColorRole.ON_SURFACE);
return new ShareViewHolder(binding, account, activity);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.core.content.res.ResourcesCompat;

import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;

Expand All @@ -28,6 +30,8 @@ public class LinkShareViewHolder extends BrandedViewHolder {
private ItemShareLinkShareBinding binding;
private Context context;

private BrandingUtil brandingUtil;

public LinkShareViewHolder(@NonNull View itemView) {
super(itemView);
bindBranding();
Expand All @@ -46,13 +50,17 @@ public void bind(OCShare publicShare, ShareeListAdapterListener listener) {
binding.icon.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(),
R.drawable.ic_email,
null));
if (publicShare.getLabel() != null && !publicShare.getLabel().isEmpty()) {
brandingUtil.platform.colorTextView(binding.name, ColorRole.ON_SURFACE_VARIANT);
binding.label.setText(publicShare.getLabel());
binding.label.setVisibility(View.VISIBLE);
} else {
brandingUtil.platform.colorTextView(binding.name, ColorRole.ON_SURFACE);
binding.label.setVisibility(View.GONE);
}
binding.copyLink.setVisibility(View.GONE);

binding.icon.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
PorterDuff.Mode.SRC_IN);
binding.icon.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
PorterDuff.Mode.SRC_IN);
} else {
brandingUtil.platform.colorTextView(binding.name, ColorRole.ON_SURFACE);
if (!TextUtils.isEmpty(publicShare.getLabel())) {
String text = String.format(context.getString(R.string.share_link_with_label), publicShare.getLabel());
binding.name.setText(text);
Expand Down Expand Up @@ -89,10 +97,11 @@ private void setPermissionName(OCShare publicShare, String permissionName) {

@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, context);
brandingUtil = BrandingUtil.of(color, context);
if (binding != null) {
util.androidx.colorPrimaryTextViewElement(binding.permissionName);
util.platform.colorImageViewBackgroundAndIcon(binding.icon);
brandingUtil.androidx.colorPrimaryTextViewElement(binding.permissionName);
brandingUtil.platform.colorTextView(binding.label, ColorRole.ON_SURFACE);
brandingUtil.platform.colorImageViewBackgroundAndIcon(binding.icon);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public NewLinkShareViewHolder(ItemAddPublicShareBinding binding) {
}

public void bind(ShareeListAdapterListener listener) {
binding.addNewPublicShareLink.setOnClickListener(v -> listener.createPublicShareLink());
binding.addNewPublicShareLinkPlus.setOnClickListener(v -> listener.createPublicShareLink());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
import com.owncloud.android.lib.resources.shares.OCShare;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedViewHolder;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.databinding.ItemShareShareBinding;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.share.helper.AvatarLoader;
import it.niedermann.owncloud.notes.share.helper.SharingMenuHelper;
import it.niedermann.owncloud.notes.share.listener.ShareeListAdapterListener;
import it.niedermann.owncloud.notes.shared.util.FilesSpecificViewThemeUtils;

public class ShareViewHolder extends RecyclerView.ViewHolder {
public class ShareViewHolder extends BrandedViewHolder {
private ItemShareShareBinding binding;
private Account account;
private Context context;

public ShareViewHolder(@NonNull View itemView) {
super(itemView);
bindBranding();
}

public ShareViewHolder(ItemShareShareBinding binding,
Expand All @@ -41,10 +44,11 @@ public ShareViewHolder(ItemShareShareBinding binding,
this.binding = binding;
this.account = account;
this.context = context;
bindBranding();
}

public void bind(OCShare share, ShareeListAdapterListener listener) {
String accountName = account.getDisplayName();
String accountUserName = account.getUserName();
String name = share.getSharedWithDisplayName();
binding.icon.setTag(null);
final var shareType = share.getShareType();
Expand Down Expand Up @@ -85,12 +89,8 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {

binding.name.setText(name);

if (accountName == null) {
binding.overflowMenu.setVisibility(View.GONE);
return;
}

if (accountName.equalsIgnoreCase(share.getShareWith()) || accountName.equalsIgnoreCase(share.getUserId())) {
if (accountUserName.equalsIgnoreCase(share.getShareWith()) ||
accountUserName.equalsIgnoreCase(share.getUserId())) {
binding.overflowMenu.setVisibility(View.VISIBLE);

String permissionName = SharingMenuHelper.getPermissionName(context, share);
Expand Down Expand Up @@ -120,4 +120,13 @@ private void setImage(ImageView avatar, String name, @DrawableRes int fallback)
avatar.setImageResource(fallback);
}
}

@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, context);
if (binding != null) {
util.androidx.colorPrimaryTextViewElement(binding.permissionName);
util.platform.colorImageViewBackgroundAndIcon(binding.icon);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,14 @@ import it.niedermann.owncloud.notes.shared.util.extensions.toExpirationDateStrin
import org.json.JSONObject
import java.util.Date

class ShareRepository(
private val applicationContext: Context,
private val account: SingleSignOnAccount
) {
class ShareRepository(private val applicationContext: Context, private val account: SingleSignOnAccount) {

private val tag = "ShareRepository"
private val gson = Gson()
private val apiProvider: ApiProvider by lazy { ApiProvider.getInstance() }
private val notesRepository: NotesRepository by lazy {
NotesRepository.getInstance(
applicationContext,
applicationContext
)
}

Expand All @@ -61,7 +58,13 @@ class ShareRepository(
val notesPathResponseResult = getNotesPathResponseResult() ?: return null
val notesPath = notesPathResponseResult.notesPath
val notesSuffix = notesPathResponseResult.fileSuffix
return StringConstants.PATH + notesPath + StringConstants.PATH + note.title + notesSuffix
return if (note.category.isEmpty()) {
StringConstants.PATH + notesPath + StringConstants.PATH + note.title + notesSuffix
} else {
StringConstants.PATH + notesPath + StringConstants.PATH + note.category + StringConstants.PATH +
note.title +
notesSuffix
}
}

fun getShareEntitiesForSpecificNote(note: Note): List<ShareEntity> {
Expand Down Expand Up @@ -135,11 +138,17 @@ class ShareRepository(

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

fun getSharees(
searchString: String,
page: Int,
perPage: Int
): ArrayList<JSONObject> {
/**
* Searches for potential share recipients (sharees).
*
* Queries the server for users, groups, remotes, emails, circles, and rooms that match the provided criteria.
*
* @param searchString Query string.
* @param page Page number for paginated results.
* @param perPage Number of results to return per page.
* @return [ArrayList] of [JSONObject]s representing the share recipients.
*/
fun getSharees(searchString: String, page: Int, perPage: Int): ArrayList<JSONObject> {
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
val call = shareAPI.getSharees(
search = searchString,
Expand Down Expand Up @@ -232,6 +241,13 @@ class ShareRepository(
)
}

/**
* Fetches all shares for the given file or folder identified by its remote ID.
*
* @param remoteId The remote file ID on the server for which to retrieve shares.
* @return A list of [OCShare] objects if the request is successful, or `null` if the request fails or an exception
* occurs.
*/
fun getShares(remoteId: Long): List<OCShare>? {
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
val call = shareAPI.getShares(remoteId)
Expand Down Expand Up @@ -299,7 +315,6 @@ class ShareRepository(
val call = shareAPI.removeShare(share.id)
val response = call.execute()
if (response.isSuccessful) {

if (share.shareType != null && share.shareType == ShareType.PUBLIC_LINK) {
note.setIsShared(false)
updateNote(note)
Expand All @@ -316,16 +331,20 @@ class ShareRepository(
}
}

fun updateShare(
shareId: Long,
requestBody: UpdateShareRequest
): ApiResult<OcsResponse<CreateShareResponse>?> {
/**
* Updates an existing share.
*
* @param shareId The id of the share to update.
* @param requestBody The [UpdateShareRequest] containing the new share attributes.
* @return An [ApiResult] with the server response [OcsResponse] on success, or an error result on failure.
*/
fun updateShare(shareId: Long, requestBody: UpdateShareRequest): ApiResult<OcsResponse<CreateShareResponse>?> {
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
val call = shareAPI.updateShare(shareId, requestBody)
val response = call.execute()
return try {
if (response.isSuccessful) {
Log_OC.d(tag, "Share updated successfully: ${response.body().toString()}")
Log_OC.d(tag, "Share updated successfully: ${response.body()}")
ApiResult.Success(
data = response.body(),
message = applicationContext.getString(R.string.note_share_created)
Expand Down Expand Up @@ -396,10 +415,15 @@ class ShareRepository(
}
}

fun updateSharePermission(
shareId: Long,
permissions: Int? = null,
): ApiResult<OcsResponse<CreateShareResponse>?> {
/**
* Updates the permissions for an existing share.
*
* @param shareId The id of the share to update.
* @param permissions The new permission level to set
* @return An [ApiResult] containing the server response [OcsResponse] with the updated share details on success,
* or an error message on failure.
*/
fun updateSharePermission(shareId: Long, permissions: Int? = null): ApiResult<OcsResponse<CreateShareResponse>?> {
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
val requestBody = UpdateSharePermissionRequest(permissions = permissions)

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_content_copy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<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" />
<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" />
</vector>
Loading
Loading