Эх сурвалжийг харах

wip

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 4 жил өмнө
parent
commit
82d36f0cab

+ 15 - 15
build.gradle

@@ -434,21 +434,21 @@ android.applicationVariants.all { variant ->
     }
 }
 
-tasks.register("combinedTestReport", JacocoReport) {
-
-    reports {
-        xml.enabled true
-        html.enabled true
-        csv.enabled false
-    }
-
-    additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
-    sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
-    classDirectories.setFrom files(subprojects.sourceSets.main.output)
-    executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
-        'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
-    ])
-}
+//tasks.register("combinedTestReport", JacocoReport) {
+//
+//    reports {
+//        xml.enabled true
+//        html.enabled true
+//        csv.enabled false
+//    }
+//
+//    additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
+//    sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
+//    classDirectories.setFrom files(subprojects.sourceSets.main.output)
+//    executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
+//        'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
+//    ])
+//}
 
 task ktlint(type: JavaExec, group: "verification") {
     description = "Check Kotlin code style."

+ 0 - 33
src/main/java/com/owncloud/android/ui/adapter/PublicShareInterface.java

@@ -1,33 +0,0 @@
-/*
- *
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * Copyright (C) 2020 Tobias Kaminsky
- * Copyright (C) 2020 Nextcloud GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package com.owncloud.android.ui.adapter;
-
-import android.widget.ImageView;
-
-import com.owncloud.android.lib.resources.shares.OCShare;
-
-public interface PublicShareInterface {
-    void copyLink(OCShare share);
-
-    void showLinkOverflowMenu(OCShare publicShare, ImageView overflowMenuShareLink);
-}

+ 0 - 68
src/main/java/com/owncloud/android/ui/adapter/PublicShareListAdapter.java

@@ -1,68 +0,0 @@
-/*
- *
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * Copyright (C) 2020 Tobias Kaminsky
- * Copyright (C) 2020 Nextcloud GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package com.owncloud.android.ui.adapter;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.ViewGroup;
-
-import com.owncloud.android.databinding.FileDetailsSharePublicLinkItemBinding;
-import com.owncloud.android.lib.resources.shares.OCShare;
-
-import java.util.List;
-
-import androidx.annotation.NonNull;
-import androidx.recyclerview.widget.RecyclerView;
-
-public class PublicShareListAdapter extends RecyclerView.Adapter<PublicShareViewHolder> {
-    private Context context;
-    private List<OCShare> shares;
-    private PublicShareInterface listener;
-
-    public PublicShareListAdapter(Context context, List<OCShare> shares, PublicShareInterface listener) {
-        this.context = context;
-        this.shares = shares;
-        this.listener = listener;
-    }
-
-    @NonNull
-    @Override
-    public PublicShareViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
-        FileDetailsSharePublicLinkItemBinding binding =
-            FileDetailsSharePublicLinkItemBinding.inflate(LayoutInflater.from(context), parent, false);
-
-        return new PublicShareViewHolder(binding, context);
-    }
-
-    @Override
-    public void onBindViewHolder(@NonNull PublicShareViewHolder holder, int position) {
-        OCShare share = shares.get(position);
-
-        holder.bind(share, listener);
-    }
-
-    @Override
-    public int getItemCount() {
-        return shares.size();
-    }
-}

+ 1 - 1
src/main/java/com/owncloud/android/ui/adapter/PublicShareViewHolder.java

@@ -47,7 +47,7 @@ class PublicShareViewHolder extends RecyclerView.ViewHolder {
         this.context = context;
     }
 
-    public void bind(OCShare publicShare, PublicShareInterface listener) {
+    public void bind(OCShare publicShare, ShareeListAdapter.ShareeListAdapterListener listener) {
         if (!TextUtils.isEmpty(publicShare.getLabel())) {
             binding.publicShareLabel.setText(publicShare.getLabel());
         }

+ 64 - 29
src/main/java/com/owncloud/android/ui/adapter/ShareeListAdapter.java

@@ -38,6 +38,7 @@ import android.widget.PopupMenu;
 import android.widget.TextView;
 
 import com.owncloud.android.R;
+import com.owncloud.android.databinding.FileDetailsSharePublicLinkItemBinding;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.resources.shares.OCShare;
@@ -65,8 +66,8 @@ import butterknife.ButterKnife;
 /**
  * Adapter to show a user/group/email/remote in Sharing list in file details view.
  */
-public class ShareeListAdapter extends RecyclerView.Adapter<ShareeListAdapter.UserViewHolder>
-        implements DisplayUtils.AvatarGenerationListener {
+public class ShareeListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
+    implements DisplayUtils.AvatarGenerationListener {
 
     private ShareeListAdapterListener listener;
     private OCCapability capabilities;
@@ -92,56 +93,82 @@ public class ShareeListAdapter extends RecyclerView.Adapter<ShareeListAdapter.Us
         avatarRadiusDimension = context.getResources().getDimension(R.dimen.user_icon_radius);
     }
 
+    @Override
+    public int getItemViewType(int position) {
+        return shares.get(position).getShareType().getValue();
+    }
+
     @NonNull
     @Override
-    public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
-        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.file_details_share_user_item, parent, false);
-        return new UserViewHolder(v);
+    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+        switch (ShareType.fromValue(viewType)) {
+            case PUBLIC_LINK:
+                FileDetailsSharePublicLinkItemBinding binding =
+                    FileDetailsSharePublicLinkItemBinding.inflate(LayoutInflater.from(context), parent, false);
+
+                return new PublicShareViewHolder(binding, context);
+
+//            case USER:
+//                 nothing for now
+//                break;
+
+            default:
+                View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.file_details_share_user_item, parent, false);
+                return new UserViewHolder(v);
+        }
     }
 
     @Override
-    public void onBindViewHolder(@NonNull UserViewHolder holder, int position) {
-        if (shares != null && shares.size() > position) {
-            final OCShare share = shares.get(position);
+    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+        if (shares == null || shares.size() <= position) {
+            return;
+        }
+
+        final OCShare share = shares.get(position);
 
+        if (holder instanceof PublicShareViewHolder) {
+            PublicShareViewHolder publicShareViewHolder = (PublicShareViewHolder) holder;
+            publicShareViewHolder.bind(share, listener);
+        } else {
+            UserViewHolder userViewHolder = (UserViewHolder) holder;
             String name = share.getSharedWithDisplayName();
 
             switch (share.getShareType()) {
                 case GROUP:
                     name = context.getString(R.string.share_group_clarification, name);
-                    setImage(holder, name, R.drawable.ic_group);
+                    setImage(userViewHolder, name, R.drawable.ic_group);
                     break;
                 case EMAIL:
                     name = context.getString(R.string.share_email_clarification, name);
-                    setImage(holder, name, R.drawable.ic_email);
+                    setImage(userViewHolder, name, R.drawable.ic_email);
                     break;
                 case ROOM:
                     name = context.getString(R.string.share_room_clarification, name);
-                    setImage(holder, name, R.drawable.ic_chat_bubble);
+                    setImage(userViewHolder, name, R.drawable.ic_chat_bubble);
                     break;
                 case CIRCLE:
-                    holder.avatar.setImageResource(R.drawable.ic_circles);
+                    userViewHolder.avatar.setImageResource(R.drawable.ic_circles);
                     break;
                 default:
-                    setImage(holder, name, R.drawable.ic_user);
+                    setImage(userViewHolder, name, R.drawable.ic_user);
                     break;
             }
 
-            holder.name.setText(name);
+            userViewHolder.name.setText(name);
 
             if (share.getShareWith().equalsIgnoreCase(userId) || share.getUserId().equalsIgnoreCase(userId)) {
-                holder.allowEditing.setVisibility(View.VISIBLE);
-                holder.editShareButton.setVisibility(View.VISIBLE);
+                userViewHolder.allowEditing.setVisibility(View.VISIBLE);
+                userViewHolder.editShareButton.setVisibility(View.VISIBLE);
 
-                ThemeUtils.tintCheckbox(holder.allowEditing, accentColor);
-                holder.allowEditing.setChecked(canEdit(share));
-                holder.allowEditing.setOnClickListener(v -> allowEditClick(holder.allowEditing, share));
+                ThemeUtils.tintCheckbox(userViewHolder.allowEditing, accentColor);
+                userViewHolder.allowEditing.setChecked(canEdit(share));
+                userViewHolder.allowEditing.setOnClickListener(v -> allowEditClick(userViewHolder.allowEditing, share));
 
                 // bind listener to edit privileges
-                holder.editShareButton.setOnClickListener(v -> onOverflowIconClicked(v, holder.allowEditing, share));
+                userViewHolder.editShareButton.setOnClickListener(v -> onOverflowIconClicked(v, userViewHolder.allowEditing, share));
             } else {
-                holder.allowEditing.setVisibility(View.GONE);
-                holder.editShareButton.setVisibility(View.GONE);
+                userViewHolder.allowEditing.setVisibility(View.GONE);
+                userViewHolder.editShareButton.setVisibility(View.GONE);
             }
         }
     }
@@ -355,13 +382,17 @@ public class ShareeListAdapter extends RecyclerView.Adapter<ShareeListAdapter.Us
     private int updatePermissionsToShare(OCShare share, boolean canReshare, boolean canEdit, boolean canEditCreate,
                                          boolean canEditChange, boolean canEditDelete) {
         return listener.updatePermissionsToShare(
-                share,
-                canReshare,
-                canEdit,
-                canEditCreate,
-                canEditChange,
-                canEditDelete
-        );
+            share,
+            canReshare,
+            canEdit,
+            canEditCreate,
+            canEditChange,
+            canEditDelete
+                                                );
+    }
+
+    public void addShares(List<OCShare> sharesToAdd) {
+        shares.addAll(sharesToAdd);
     }
 
     @Override
@@ -429,5 +460,9 @@ public class ShareeListAdapter extends RecyclerView.Adapter<ShareeListAdapter.Us
          * @param share the share for which a password shall be configured/removed
          */
         void requestPasswordForShare(OCShare share, boolean askForPassword);
+
+        void copyLink(OCShare share);
+
+        void showLinkOverflowMenu(OCShare publicShare, ImageView overflowMenuShareLink);
     }
 }

+ 16 - 25
src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java

@@ -55,8 +55,6 @@ import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.lib.resources.status.OCCapability;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
-import com.owncloud.android.ui.adapter.PublicShareInterface;
-import com.owncloud.android.ui.adapter.PublicShareListAdapter;
 import com.owncloud.android.ui.adapter.ShareeListAdapter;
 import com.owncloud.android.ui.decoration.SimpleListItemDividerDecoration;
 import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment;
@@ -88,7 +86,6 @@ import butterknife.Unbinder;
 
 public class FileDetailSharingFragment extends Fragment implements ShareeListAdapter.ShareeListAdapterListener,
     DisplayUtils.AvatarGenerationListener,
-    PublicShareInterface,
     Injectable {
 
     private static final String ARG_FILE = "FILE";
@@ -108,11 +105,8 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
     @BindView(R.id.searchView)
     SearchView searchView;
 
-    @BindView(R.id.shareUsersList)
-    RecyclerView usersList;
-
-    @BindView(R.id.publicShareList)
-    RecyclerView publicShareList;
+    @BindView(R.id.sharesList)
+    RecyclerView sharesList;
 
     @BindView(R.id.new_public_share)
     View addPublicShare;
@@ -280,6 +274,7 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
     private void setShareWithUserInfo() {
         // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed
         // to show share with users/groups info
+        // TODO combine this with refreshPublicShareFromDB()
         List<OCShare> shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(),
                                                                             user.toPlatformAccount().name);
         if (shares.size() > 0) {
@@ -287,18 +282,18 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
             String userId = accountManager.getUserData(user.toPlatformAccount(),
                                                        com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
 
-            usersList.setVisibility(View.VISIBLE);
-            usersList.setAdapter(new ShareeListAdapter(fileActivity.getSupportFragmentManager(),
-                                                       fileActivity,
-                                                       shares,
-                                                       user.toPlatformAccount(),
-                                                       file,
-                                                       this,
-                                                       userId));
-            usersList.setLayoutManager(new LinearLayoutManager(getContext()));
-            usersList.addItemDecoration(new SimpleListItemDividerDecoration(getContext()));
+            sharesList.setVisibility(View.VISIBLE);
+            sharesList.setAdapter(new ShareeListAdapter(fileActivity.getSupportFragmentManager(),
+                                                        fileActivity,
+                                                        shares,
+                                                        user.toPlatformAccount(),
+                                                        file,
+                                                        this,
+                                                        userId));
+            sharesList.setLayoutManager(new LinearLayoutManager(getContext()));
+            sharesList.addItemDecoration(new SimpleListItemDividerDecoration(getContext()));
         } else {
-            usersList.setVisibility(View.GONE);
+            sharesList.setVisibility(View.GONE);
         }
     }
 
@@ -536,7 +531,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
      */
     public void refreshPublicShareFromDB() {
         if (FileDetailSharingFragmentHelper.isPublicShareDisabled(capabilities) || !file.canReshare()) {
-            publicShareList.setVisibility(View.GONE);
             return;
         }
 
@@ -547,7 +541,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
 
         if (shares.isEmpty()) {
             addPublicShare.setVisibility(View.VISIBLE);
-            publicShareList.setVisibility(View.GONE);
             ImageView icon = requireView().findViewById(R.id.copy_internal_link_icon);
             icon.getBackground().setColorFilter(requireContext()
                                                     .getResources()
@@ -558,10 +551,8 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
             requireView().findViewById(R.id.add_new_public_share_link).setOnClickListener(v -> createShareLink());
         } else {
             addPublicShare.setVisibility(View.GONE);
-            publicShareList.setVisibility(View.VISIBLE);
-            publicShareList.setAdapter(new PublicShareListAdapter(getContext(), shares, this));
-            publicShareList.setLayoutManager(new LinearLayoutManager(getContext()));
-            publicShareList.addItemDecoration(new SimpleListItemDividerDecoration(getContext()));
+            ((ShareeListAdapter) sharesList.getAdapter()).addShares(shares);
+
         }
     }
 

+ 1 - 8
src/main/res/layout/file_details_sharing_fragment.xml

@@ -98,17 +98,10 @@
             </LinearLayout>
         </LinearLayout>
 
-        <androidx.recyclerview.widget.RecyclerView
-            android:id="@+id/publicShareList"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:divider="@drawable/divider"
-            android:dividerHeight="1dp" />
-
         <include layout="@layout/file_details_share_public_link_add_new_item" />
 
         <androidx.recyclerview.widget.RecyclerView
-            android:id="@+id/shareUsersList"
+            android:id="@+id/sharesList"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:divider="@drawable/divider"

+ 0 - 74
src/main/res/layout/share_user_item.xml

@@ -1,74 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ownCloud Android client application
-  Copyright (C) 2015 ownCloud Inc.
-
-  This program is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License version 2,
-  as published by the Free Software Foundation.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
--->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical">
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal"
-        android:weightSum="1"
-        android:longClickable="true">
-        <ImageView
-            android:layout_width="@dimen/file_details_user_icon_layout_width"
-            android:layout_height="@dimen/file_details_user_icon_layout_height"
-            android:id="@+id/icon"
-            android:src="@drawable/ic_user"
-            android:layout_gravity="center_vertical"
-            android:contentDescription="@string/user_icon"/>
-
-        <TextView
-            android:layout_width="0dp"
-            android:layout_height="match_parent"
-            android:layout_weight="1"
-            android:textSize="@dimen/two_line_primary_text_size"
-            android:text="@string/username"
-            android:id="@+id/userOrGroupName"
-            android:layout_marginStart="@dimen/standard_half_margin"
-            android:textColor="@color/text_color"
-            android:singleLine="true"
-            android:ellipsize="middle"
-            android:gravity="center_vertical"/>
-
-        <ImageView
-            android:layout_width="@dimen/unshare_icon_size"
-            android:layout_height="@dimen/unshare_icon_size"
-            android:id="@+id/unshareButton"
-            android:src="@drawable/ic_action_delete_grey"
-            android:layout_gravity="center_vertical"
-            android:padding="@dimen/standard_half_padding"
-            android:contentDescription="@string/common_delete"/>
-
-        <ImageView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:id="@+id/editShareButton"
-            android:src="@drawable/ic_dots_vertical"
-            android:padding="@dimen/standard_half_padding"
-            android:layout_gravity="center_vertical"
-            android:contentDescription="@string/overflow_menu"/>
-
-    </LinearLayout>
-
-    <View
-        android:layout_width="match_parent"
-        android:layout_height="1dp"
-        android:background="@color/list_divider_background" />
-</LinearLayout>