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"
- xmlns:tools="http://schemas.android.com/tools"
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="@color/background_material_light"
- android:orientation="vertical"
- tools:context="com.owncloud.android.ui.fragment.ShareFileFragment">
+ tools:context="com.owncloud.android.ui.fragment.ShareFileFragment"
+ >
- <RelativeLayout
- android:id="@+id/shareHeaderContainer"
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginTop="6dp"
- android:layout_marginBottom="6dp"
- android:background="@color/background_color">
-
- <ImageView
- android:id="@+id/shareFileIcon"
- android:layout_width="@dimen/file_icon_size"
- android:layout_height="@dimen/file_icon_size"
- android:src="@drawable/file"
- android:layout_marginLeft="12dp"
- android:layout_marginRight="12dp"
- android:layout_gravity="center_vertical"
- android:layout_marginTop="12dp"
- android:layout_marginBottom="12dp"/>
+ android:background="@color/background_material_light"
+ android:orientation="vertical"
+ >
+
+ <RelativeLayout
+ android:id="@+id/shareHeaderContainer"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="6dp"
+ android:background="@color/background_color">
+
+ <ImageView
+ android:id="@+id/shareFileIcon"
+ android:layout_width="@dimen/file_icon_size"
+ android:layout_height="@dimen/file_icon_size"
+ android:src="@drawable/file"
+ android:layout_marginLeft="12dp"
+ android:layout_marginRight="12dp"
+ android:layout_gravity="center_vertical"
+ android:layout_marginTop="12dp"
+ android:layout_marginBottom="12dp"/>
+
+ <TextView
+ android:id="@+id/shareFileName"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/placeholder_filename"
+ android:textSize="16sp"
+ android:layout_gravity="center_vertical"
+ android:layout_marginLeft="4dp"
+ android:layout_marginStart="4dp"
+ android:layout_marginRight="8dp"
+ android:layout_marginEnd="8dp"
+ android:layout_toRightOf="@+id/shareFileIcon"
+ android:layout_toEndOf="@+id/shareFileIcon"
+ android:singleLine="true"
+ android:ellipsize="middle"
+ android:layout_marginTop="12dp"/>
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="12sp"
+ android:text="@string/placeholder_filesize"
+ android:id="@+id/shareFileSize"
+ android:layout_below="@+id/shareFileName"
+ android:layout_toRightOf="@+id/shareFileIcon"
+ android:layout_toEndOf="@+id/shareFileIcon"
+ android:layout_marginTop="4dp"
+ android:layout_marginLeft="4dp"
+ android:layout_marginStart="4dp"
+ android:layout_marginBottom="12dp"
+ android:layout_gravity="center_vertical"/>
+
+ </RelativeLayout>
<TextView
- android:id="@+id/shareFileName"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="@string/placeholder_filename"
- android:textSize="16dip"
- android:layout_gravity="center_vertical"
- android:layout_marginLeft="4dp"
- android:layout_marginRight="8dp"
- android:layout_toRightOf="@+id/shareFileIcon"
- android:layout_toEndOf="@+id/shareFileIcon"
- android:singleLine="true"
- android:ellipsize="middle"
- android:layout_marginTop="12dp"/>
+ android:textSize="16sp"
+ android:text="@string/share_with_user_section_title"
+ android:id="@+id/shareWithUsersSectionTitle"
+ android:layout_gravity="start"
+ android:padding="8dp"
+ android:background="@color/actionbar_start_color"
+ android:textColor="@color/white"/>
+
+ <ListView
+ android:layout_width="match_parent"
+ android:layout_height="0dip"
+ android:id="@+id/shareUsersList"
+ android:visibility="gone"
+ android:scrollbars="vertical"
+ android:layout_weight="1"/>
<TextView
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:textSize="12dip"
- android:text="@string/placeholder_filesize"
- android:id="@+id/shareFileSize"
- android:layout_below="@+id/shareFileName"
- android:layout_toRightOf="@+id/shareFileIcon"
- android:layout_toEndOf="@+id/shareFileIcon"
- android:layout_marginTop="4dp"
- android:layout_marginLeft="4dp"
- android:layout_marginBottom="12dp"
- android:layout_gravity="center_vertical"/>
-
- </RelativeLayout>
-
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="16dip"
- android:text="@string/share_with_user_section_title"
- android:id="@+id/shareWithUsersSectionTitle"
- android:layout_gravity="left"
- android:padding="8dp"
- android:background="@color/actionbar_start_color"
- android:textColor="@color/white"/>
-
- <ListView
- android:layout_width="match_parent"
- android:layout_height="0dip"
- android:id="@+id/shareUsersList"
- android:visibility="gone"
- android:scrollbars="vertical"
- android:layout_weight="1"/>
+ android:id="@+id/shareNoUsers"
+ android:text="@string/share_no_users"
+ android:textSize="12sp"
+ android:padding="12dp" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/shareNoUsers"
- android:text="@string/share_no_users"
- android:textSize="12dip"
- android:padding="12dp" />
-
- <android.support.v7.widget.AppCompatButton
- android:id="@+id/addUserButton"
- style="@style/ownCloud.Button"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:text="@string/share_add_user_or_group"
- android:contentDescription="shareAddUserButton"/>
+ <android.support.v7.widget.AppCompatButton
+ android:id="@+id/addUserButton"
+ style="@style/ownCloud.Button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:text="@string/share_add_user_or_group"
+ android:contentDescription="shareAddUserButton"/>
+
+ <Switch
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="16sp"
+ android:text="@string/share_via_link_section_title"
+ android:id="@+id/shareViaLinkSectionSwitch"
+ android:layout_gravity="start"
+ android:padding="8dp"
+ android:background="@color/actionbar_start_color"
+ android:textColor="@color/white"/>
+
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/shareViaLinkExpirationSection"
+ >
+
+ <Switch
+ android:id="@+id/shareViaLinkExpirationSwitch"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentEnd="true"
+ android:layout_centerInParent="true"
+ android:padding="8dp"
+ />
+
+ <TextView
+ android:id="@+id/shareViaLinkExpirationLabel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
+ android:layout_toLeftOf="@id/shareViaLinkExpirationSwitch"
+ android:layout_toStartOf="@id/shareViaLinkExpirationSwitch"
+ android:padding="8dp"
+ android:text="@string/share_via_link_expiration_date_label"
+ android:textSize="16sp"
+ />
+
+ <TextView
+ android:id="@+id/shareViaLinkExpirationValue"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
+ android:layout_toLeftOf="@id/shareViaLinkExpirationSwitch"
+ android:layout_toStartOf="@id/shareViaLinkExpirationSwitch"
+ android:layout_below="@id/shareViaLinkExpirationLabel"
+ android:padding="8dp"
+ android:textSize="12sp"
+ />
+
+ </RelativeLayout>
+
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/shareViaLinkPasswordSection"
+ >
+
+ <Switch
+ android:id="@+id/shareViaLinkPasswordSwitch"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentEnd="true"
+ android:layout_centerInParent="true"
+ android:padding="8dp"
+ />
+
+ <TextView
+ android:id="@+id/shareViaLinkPasswordLabel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
+ android:layout_toLeftOf="@id/shareViaLinkPasswordSwitch"
+ android:layout_toStartOf="@id/shareViaLinkPasswordSwitch"
+ android:padding="8dp"
+ android:text="@string/share_via_link_password_label"
+ android:textSize="16sp"
+ />
+
+ <TextView
+ android:id="@+id/shareViaLinkPasswordValue"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
+ android:layout_toLeftOf="@id/shareViaLinkPasswordSwitch"
+ android:layout_toStartOf="@id/shareViaLinkPasswordSwitch"
+ android:layout_below="@id/shareViaLinkPasswordLabel"
+ android:padding="8dp"
+ android:text="@string/share_via_link_password_title"
+ android:textSize="12sp"
+ android:visibility="invisible"
+ />
+
+ </RelativeLayout>
+
+ <android.support.v7.widget.AppCompatButton
+ android:id="@+id/shareViewLinkGetLinkButton"
+ style="@style/ownCloud.Button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:text="@string/share_get_public_link_button"
+ android:contentDescription="shareGetLinkButton"/>
+
+ </LinearLayout>
-</LinearLayout>
+</ScrollView>
\ No newline at end of file
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
+import android.support.v7.widget.AppCompatButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ListView;
+import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.ShareActivity;
import com.owncloud.android.ui.adapter.ShareUserListAdapter;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimetypeIconUtil;
import java.util.ArrayList;
/**
- * Fragment for Sharing a file with sharees (users or groups)
+ * Fragment for Sharing a file with sharees (users or groups) or creating
+ * a public link.
*
* A simple {@link Fragment} subclass.
*
private static final String ARG_FILE = "FILE";
private static final String ARG_ACCOUNT = "ACCOUNT";
- // Parameters
+ /** File to share, received as a parameter in construction time */
private OCFile mFile;
+
+ /** OC account holding the file to share, received as a parameter in construction time */
private Account mAccount;
- // other members
- private ArrayList<OCShare> mShares;
- private ShareUserListAdapter mUserGroupsAdapter = null;
+ /** Reference to parent listener */
private OnShareFragmentInteractionListener mListener;
+ /** List of private shares bound to the file */
+ private ArrayList<OCShare> mPrivateShares;
+
+ /** Adapter to show private shares */
+ private ShareUserListAdapter mUserGroupsAdapter = null;
+
+ /** Public share bound to the file */
+ private OCShare mPublicShare;
+
+
/**
* Public factory method to create new ShareFileFragment instances.
*
addUserGroupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- boolean shareWithUsersEnable = AccountUtils.hasSearchUsersSupport(mAccount);
+ boolean shareWithUsersEnable = AccountUtils.hasSearchUsersSupport(mAccount);
if (shareWithUsersEnable) {
// Show Search Fragment
mListener.showSearchUsersAndGroups();
}
});
+ // Switch to create public share
+ Switch shareViaLinkSwitch = (Switch) view.findViewById(R.id.shareViaLinkSectionSwitch);
+ shareViaLinkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked) {
+ // TODO real implementation: create public share
+ // expand section
+ getExpirationDateSection().setVisibility(View.VISIBLE);
+ getPasswordSection().setVisibility(View.VISIBLE);
+ getGetLinkButton().setVisibility(View.VISIBLE);
+
+ } else {
+ // TODO real implementation: unshare
+ // collapse section
+ getExpirationDateSection().setVisibility(View.GONE);
+ getPasswordSection().setVisibility(View.GONE);
+ getGetLinkButton().setVisibility(View.GONE);
+ }
+ }
+ });
+
+ // Switch for expiration date
+ Switch shareViaLinkExpirationSwitch = (Switch) view.findViewById(R.id.shareViaLinkExpirationSwitch);
+ shareViaLinkExpirationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked) {
+ // TODO real implementation: update share with expiration date
+ // show value of expiration date
+ getExpirationDateValue().setText(R.string.placeholder_timestamp);
+
+ } else {
+ // TODO real implementation: update share without expiration date
+ // empty value
+ getExpirationDateValue().setText(R.string.empty);
+ }
+ }
+ });
+
+ // Switch for password
+ Switch shareViaLinkPasswordSwitch = (Switch) view.findViewById(R.id.shareViaLinkPasswordSwitch);
+ shareViaLinkPasswordSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked) {
+ // TODO real implementation: update share with password
+ // show
+ getExpirationPasswordValue().setVisibility(View.VISIBLE);
+
+ } else {
+ // TODO real implementation: update share without password
+ // empty value
+ getExpirationPasswordValue().setVisibility(View.INVISIBLE);
+ }
+ }
+ });
+
+
return view;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- // Load data into the list
+ // Load data into the list of private shares
refreshUsersOrGroupsListFromDB();
+
+ // Load data of public share, if exists
+ refreshPublicShareFromDB();
}
@Override
public void refreshUsersOrGroupsListFromDB (){
if (((FileActivity) mListener).getStorageManager() != null) {
// Get Users and Groups
- mShares = ((FileActivity) mListener).getStorageManager().getSharesWithForAFile(
+ mPrivateShares = ((FileActivity) mListener).getStorageManager().getSharesWithForAFile(
mFile.getRemotePath(),
mAccount.name
);
mUserGroupsAdapter = new ShareUserListAdapter(
getActivity(),
R.layout.share_user_item,
- mShares,
+ mPrivateShares,
this
);
TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers);
ListView usersList = (ListView) getView().findViewById(R.id.shareUsersList);
- if (mShares.size() > 0) {
+ if (mPrivateShares.size() > 0) {
noShares.setVisibility(View.GONE);
usersList.setVisibility(View.VISIBLE);
usersList.setAdapter(mUserGroupsAdapter);
}
+
+ /**
+ * Get public link from the DB to fill in the "Share link" section
+ *
+ * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager}
+ * instance ready to use. If not ready, does nothing.
+ */
+ public void refreshPublicShareFromDB() {
+ if (((FileActivity) mListener).getStorageManager() != null) {
+ // Get public share
+ mPublicShare = ((FileActivity) mListener).getStorageManager().getFirstShareByPathAndType(
+ mFile.getRemotePath(),
+ ShareType.PUBLIC_LINK,
+ ""
+ );
+
+ // Update list of users/groups
+ updatePublicShareSection();
+ }
+ }
+
+ /**
+ * Updates in the UI the section about public share with the information in the current
+ * public share bound to mFile, if any
+ */
+ private void updatePublicShareSection() {
+ if (mPublicShare != null && ShareType.PUBLIC_LINK.equals(mPublicShare.getShareType())) {
+ // public share bound -> expand section
+ getShareViaLinkSwitch().setChecked(true);
+ getExpirationDateSection().setVisibility(View.VISIBLE);
+ getPasswordSection().setVisibility(View.VISIBLE);
+ getGetLinkButton().setVisibility(View.VISIBLE);
+
+ } else {
+ // no public share -> collapse section
+ getShareViaLinkSwitch().setChecked(false);
+ getExpirationDateSection().setVisibility(View.GONE);
+ getPasswordSection().setVisibility(View.GONE);
+ getGetLinkButton().setVisibility(View.GONE);
+ }
+ }
+
+ private Switch getShareViaLinkSwitch() {
+ return (Switch) getView().findViewById(R.id.shareViaLinkSectionSwitch);
+ }
+
+ private View getExpirationDateSection() {
+ return getView().findViewById(R.id.shareViaLinkExpirationSection);
+ }
+
+ private TextView getExpirationDateValue() {
+ return (TextView) getView().findViewById(R.id.shareViaLinkExpirationValue);
+ }
+
+ private View getPasswordSection() {
+ return getView().findViewById(R.id.shareViaLinkPasswordSection);
+ }
+
+ private TextView getExpirationPasswordValue() {
+ return (TextView) getView().findViewById(R.id.shareViaLinkPasswordValue);
+ }
+
+ private AppCompatButton getGetLinkButton() {
+ return (AppCompatButton) getView().findViewById(R.id.shareViewLinkGetLinkButton);
+ }
+
+
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated