ソースを参照

open folder sync preference for new, custom folder (work in progress)

AndyScherzinger 8 年 前
コミット
de83a02156

+ 5 - 0
src/main/java/com/owncloud/android/ui/activity/FolderSyncActivity.java

@@ -548,6 +548,11 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void onMessageEvent(CustomFolderEvent event) {
         Log.d(TAG, "Show custom folder magic here");
+        SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
+                SyncedFolder.UNPERSISTED_ID, null, null, true, false,
+                false, AccountUtils.getCurrentOwnCloudAccount(this).name,
+                FileUploader.LOCAL_BEHAVIOUR_FORGET, false, null, MediaFolder.CUSTOM);
+        onSyncFolderSettingsClick(0, emptyCustomFolder);
     };
 
 }

+ 36 - 8
src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java

@@ -41,6 +41,7 @@ import android.view.ViewGroup;
 import android.widget.TextView;
 
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.MediaFolder;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.activity.FolderPickerActivity;
@@ -57,6 +58,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
     public static final String SYNCED_FOLDER_PARCELABLE = "SyncedFolderParcelable";
     private static final String BEHAVIOUR_DIALOG_STATE = "BEHAVIOUR_DIALOG_STATE";
     public static final int REQUEST_CODE__SELECT_REMOTE_FOLDER = 0;
+    public static final int REQUEST_CODE__SELECT_LOCAL_FOLDER = 1;
 
     private CharSequence[] mUploadBehaviorItemStrings;
 
@@ -67,6 +69,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
     private AppCompatCheckBox mUploadUseSubfoldersCheckbox;
     private TextView mUploadBehaviorSummary;
     private TextView mLocalFolderPath;
+    private TextView mLocalFolderSummary;
     private TextView mRemoteFolderSummary;
 
     private SyncedFolderParcelable mSyncedFolder;
@@ -132,12 +135,17 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
     private void setupDialogElements(View view) {
         int accentColor = ThemeUtils.primaryAccentColor();
 
+        if (mSyncedFolder.getType() > MediaFolder.CUSTOM) {
+            view.findViewById(R.id.local_folder_container).setVisibility(View.GONE);
+        }
+
         // find/saves UI elements
         mEnabledSwitch = (SwitchCompat) view.findViewById(R.id.sync_enabled);
         ThemeUtils.tintSwitch(mEnabledSwitch, accentColor);
 
         mLocalFolderPath = (TextView) view.findViewById(R.id.folder_sync_settings_local_folder_path);
 
+        mLocalFolderSummary = (TextView) view.findViewById(R.id.local_folder_summary);
         mRemoteFolderSummary = (TextView) view.findViewById(R.id.remote_folder_summary);
 
         mUploadOnWifiCheckbox = (AppCompatCheckBox) view.findViewById(R.id.setting_instant_upload_on_wifi_checkbox);
@@ -161,15 +169,25 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
 
         // Set values
         setEnabled(mSyncedFolder.getEnabled());
-        mLocalFolderPath.setText(
-                DisplayUtils.createTextWithSpan(
-                        String.format(
-                                getString(R.string.folder_sync_preferences_folder_path),
-                                mSyncedFolder.getLocalPath()),
-                        mSyncedFolder.getFolderName(),
-                        new StyleSpan(Typeface.BOLD)));
 
-        mRemoteFolderSummary.setText(mSyncedFolder.getRemotePath());
+        if(mSyncedFolder.getLocalPath() != null && mSyncedFolder.getLocalPath().length() > 0) {
+            mLocalFolderPath.setText(
+                    DisplayUtils.createTextWithSpan(
+                            String.format(
+                                    getString(R.string.folder_sync_preferences_folder_path),
+                                    mSyncedFolder.getLocalPath()),
+                            mSyncedFolder.getFolderName(),
+                            new StyleSpan(Typeface.BOLD)));
+            mLocalFolderSummary.setText(mSyncedFolder.getLocalPath());
+        } else {
+            mLocalFolderSummary.setText(R.string.choose_local_folder);
+        }
+
+        if(mSyncedFolder.getLocalPath() != null && mSyncedFolder.getLocalPath().length() > 0) {
+            mRemoteFolderSummary.setText(mSyncedFolder.getRemotePath());
+        } else {
+            mRemoteFolderSummary.setText(R.string.choose_remote_folder);
+        }
 
         mUploadOnWifiCheckbox.setChecked(mSyncedFolder.getWifiOnly());
         mUploadOnChargingCheckbox.setChecked(mSyncedFolder.getChargingOnly());
@@ -246,6 +264,16 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
             }
         });
 
+        view.findViewById(R.id.local_folder_container).setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Intent action = new Intent(getActivity(), FolderPickerActivity.class);
+                action.putExtra(
+                        FolderPickerActivity.EXTRA_ACTION, getResources().getText(R.string.choose_remote_folder));
+                getActivity().startActivityForResult(action, REQUEST_CODE__SELECT_LOCAL_FOLDER);
+            }
+        });
+
         view.findViewById(R.id.sync_enabled).setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {

+ 12 - 0
src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java

@@ -38,6 +38,7 @@ public class SyncedFolderParcelable implements Parcelable {
     private Boolean mEnabled = false;
     private Boolean mSubfolderByDate = false;
     private Integer mUploadAction;
+    private int mType;
     private long mId;
     private String mAccount;
     private int mSection;
@@ -54,6 +55,7 @@ public class SyncedFolderParcelable implements Parcelable {
         mChargingOnly = syncedFolderDisplayItem.getChargingOnly();
         mEnabled = syncedFolderDisplayItem.isEnabled();
         mSubfolderByDate = syncedFolderDisplayItem.getSubfolderByDate();
+        mType = syncedFolderDisplayItem.getType();
         mAccount = syncedFolderDisplayItem.getAccount();
         mUploadAction = syncedFolderDisplayItem.getUploadAction();
         mSection = section;
@@ -68,6 +70,7 @@ public class SyncedFolderParcelable implements Parcelable {
         mChargingOnly = read.readInt() != 0;
         mEnabled = read.readInt() != 0;
         mSubfolderByDate = read.readInt() != 0;
+        mType = read.readInt();
         mAccount = read.readString();
         mUploadAction = read.readInt();
         mSection = read.readInt();
@@ -83,6 +86,7 @@ public class SyncedFolderParcelable implements Parcelable {
         dest.writeInt(mChargingOnly ? 1 : 0);
         dest.writeInt(mEnabled ? 1 : 0);
         dest.writeInt(mSubfolderByDate ? 1 : 0);
+        dest.writeInt(mType);
         dest.writeString(mAccount);
         dest.writeInt(mUploadAction);
         dest.writeInt(mSection);
@@ -163,6 +167,14 @@ public class SyncedFolderParcelable implements Parcelable {
         this.mSubfolderByDate = mSubfolderByDate;
     }
 
+    public int getType() {
+        return mType;
+    }
+
+    public void setType(int mType) {
+        this.mType = mType;
+    }
+
     public Integer getUploadAction() {
         return mUploadAction;
     }

+ 5 - 2
src/main/res/layout/folder_sync_item_header.xml

@@ -94,13 +94,15 @@
         android:layout_height="wrap_content"
         android:minHeight="48dp">
 
-        <ImageView
-            android:id="@+id/imageView"
+        <ImageButton
+            android:id="@+id/custom_folder_iv"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerVertical="true"
             android:layout_toLeftOf="@+id/custom_folder_tv"
             android:paddingRight="4dp"
+            android:clickable="true"
+            android:background="@color/transparent"
             android:src="@drawable/ic_folder_star_24dp"/>
 
         <TextView
@@ -108,6 +110,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerInParent="true"
+            android:clickable="true"
             android:text="@string/autoupload_custom_folder"/>
     </RelativeLayout>
 

+ 109 - 24
src/main/res/layout/folder_sync_settings_layout.xml

@@ -18,8 +18,8 @@
   You should have received a copy of the GNU Affero General Public
   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
-<LinearLayout android:id="@+id/root"
-              xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/root"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:gravity="center"
@@ -35,9 +35,9 @@
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:layout_weight="1"
+            android:orientation="vertical"
             android:paddingBottom="@dimen/standard_padding"
-            android:paddingTop="@dimen/standard_padding"
-            android:orientation="vertical">
+            android:paddingTop="@dimen/standard_padding">
 
             <TextView
                 android:id="@+id/folder_sync_settings_title"
@@ -52,7 +52,6 @@
                 android:layout_height="wrap_content"
                 android:ellipsize="middle"
                 android:maxLines="2"
-                android:text="@string/folder_sync_preferences_folder_path"
                 android:textColor="?android:attr/textColorSecondary"/>
 
         </LinearLayout>
@@ -62,8 +61,8 @@
             android:layout_height="match_parent"
             android:gravity="end|top"
             android:orientation="vertical"
-            android:paddingTop="@dimen/standard_padding"
-            android:paddingLeft="@dimen/standard_padding">
+            android:paddingLeft="@dimen/standard_padding"
+            android:paddingTop="@dimen/standard_padding">
 
             <android.support.v7.widget.SwitchCompat
                 android:id="@+id/sync_enabled"
@@ -89,32 +88,118 @@
             android:orientation="vertical">
 
             <LinearLayout
-                android:id="@+id/remote_folder_container"
+                android:id="@+id/local_folder_container"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:baselineAligned="false"
+                android:clipToPadding="false"
                 android:gravity="center_vertical"
-                android:minHeight="?android:attr/listPreferredItemHeightSmall"
-                android:orientation="vertical"
-                android:paddingBottom="@dimen/standard_padding"
-                android:paddingTop="@dimen/standard_padding">
+                android:minHeight="?attr/listPreferredItemHeightSmall">
 
-                <TextView
-                    android:id="@+id/remote_folder_title"
-                    android:layout_width="wrap_content"
+                <RelativeLayout
+                    android:layout_width="0dp"
                     android:layout_height="wrap_content"
-                    android:maxLines="1"
-                    android:text="@string/prefs_folder_sync_remote_path_title"
-                    android:textAppearance="?attr/textAppearanceListItem"/>
+                    android:layout_weight="1"
+                    android:paddingBottom="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_padding">
 
-                <TextView
-                    android:id="@+id/remote_folder_summary"
+                    <TextView
+                        android:id="@+id/local_folder_title"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:maxLines="1"
+                        android:text="@string/prefs_folder_sync_local_path_title"
+                        android:textAppearance="?attr/textAppearanceListItem"/>
+
+                    <TextView
+                        android:id="@+id/local_folder_summary"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_alignLeft="@id/local_folder_title"
+                        android:layout_below="@id/local_folder_title"
+                        android:ellipsize="middle"
+                        android:maxLines="2"
+                        android:text="@string/choose_remote_folder"
+                        android:textColor="?android:attr/textColorSecondary"/>
+
+                </RelativeLayout>
+
+                <!-- Preference should place its actual preference widget here. -->
+                <LinearLayout
+                    android:id="@+id/local_folder_frame"
                     android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:gravity="end|center_vertical"
+                    android:orientation="vertical"
+                    android:paddingLeft="@dimen/standard_padding">
+
+                    <ImageView
+                        android:id="@+id/local_folder_icon"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:background="@null"
+                        android:padding="@dimen/standard_quarter_padding"
+                        android:src="@drawable/ic_folder_open"/>
+
+                </LinearLayout>
+
+            </LinearLayout>
+
+            <LinearLayout
+                android:id="@+id/remote_folder_container"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:baselineAligned="false"
+                android:clipToPadding="false"
+                android:gravity="center_vertical"
+                android:minHeight="?attr/listPreferredItemHeightSmall">
+
+                <RelativeLayout
+                    android:layout_width="0dp"
                     android:layout_height="wrap_content"
-                    android:ellipsize="middle"
-                    android:maxLines="2"
-                    android:text="@string/placeholder_filename"
-                    android:textColor="?android:attr/textColorSecondary"/>
+                    android:layout_weight="1"
+                    android:paddingBottom="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_padding">
+
+                    <TextView
+                        android:id="@+id/remote_folder_title"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:maxLines="1"
+                        android:text="@string/prefs_folder_sync_remote_path_title"
+                        android:textAppearance="?attr/textAppearanceListItem"/>
+
+                    <TextView
+                        android:id="@+id/remote_folder_summary"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_alignLeft="@id/remote_folder_title"
+                        android:layout_below="@id/remote_folder_title"
+                        android:ellipsize="middle"
+                        android:maxLines="2"
+                        android:text="@string/choose_remote_folder"
+                        android:textColor="?android:attr/textColorSecondary"/>
+
+                </RelativeLayout>
+
+                <!-- Preference should place its actual preference widget here. -->
+                <LinearLayout
+                    android:id="@+id/remote_folder_frame"
+                    android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:gravity="end|center_vertical"
+                    android:orientation="vertical"
+                    android:paddingLeft="@dimen/standard_padding">
+
+                    <ImageView
+                        android:id="@+id/remote_folder_icon"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:background="@null"
+                        android:padding="@dimen/standard_quarter_padding"
+                        android:src="@drawable/ic_folder_open"/>
+
+                </LinearLayout>
 
             </LinearLayout>
 

+ 2 - 1
src/main/res/values/strings.xml

@@ -582,7 +582,8 @@
     <string name="participate_contribute_github_text_link" translatable="false">&lt;font color=\"%1$s\">&lt;a href=\"%2$s\">CONTRIBUTING.md&lt;/a>&lt;/font></string>
     <string name="move_to">Move to&#8230;</string>
     <string name="copy_to">Copy to&#8230;</string>
-    <string name="choose_remote_folder">Choose folder&#8230;</string>
+    <string name="choose_remote_folder">Choose remote folder&#8230;</string>
+    <string name="choose_local_folder">Choose local folder&#8230;</string>
     <string name="folder_sync_loading_folders">Loading folders&#8230;</string>
     <string name="folder_sync_no_results">No media folders found.</string>
     <string name="folder_sync_preferences">Preferences for auto uploading</string>