added possibility to enable/disable sync folder in the settings screen

This commit is contained in:
AndyScherzinger 2016-10-26 12:14:56 +02:00
parent d2d8352bac
commit cc45b0f1e9
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
4 changed files with 59 additions and 47 deletions

View file

@ -45,27 +45,13 @@
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:id="@+id/local_folder_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"> android:minHeight="?android:attr/listPreferredItemHeightSmall">
<LinearLayout
android:id="@+id/local_folder_icon_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="start|center_vertical"
android:minWidth="58dip"
android:orientation="horizontal">
<ImageView
android:id="@+id/local_folder_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/standard_half_margin"
android:src="@drawable/ic_cellphone"/>
</LinearLayout>
<RelativeLayout <RelativeLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -95,17 +81,23 @@
</RelativeLayout> </RelativeLayout>
<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_status_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_cloud_sync_off"/>
</LinearLayout> </LinearLayout>
<TextView </LinearLayout>
android:id="@+id/settings_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dip"
android:paddingTop="@dimen/standard_padding"
android:text="@string/folder_sync_settings"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@color/color_accent"/>
<LinearLayout <LinearLayout
android:id="@+id/remote_folder_container" android:id="@+id/remote_folder_container"
@ -115,22 +107,6 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"> android:minHeight="?android:attr/listPreferredItemHeightSmall">
<LinearLayout
android:id="@+id/remote_folder_icon_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="start|center_vertical"
android:minWidth="58dip"
android:orientation="horizontal">
<ImageView
android:id="@+id/remote_folder_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/standard_half_margin"
android:src="@drawable/ic_cloud_outline"/>
</LinearLayout>
<RelativeLayout <RelativeLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View file

@ -354,9 +354,10 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
@Override @Override
public void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder) { public void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder) {
SyncedFolderDisplayItem item = syncFolderItems.get(syncedFolder.getSection()); SyncedFolderDisplayItem item = syncFolderItems.get(syncedFolder.getSection());
boolean dirty = !(item.isEnabled() == syncedFolder.getEnabled());
item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder
.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder .getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder
.getUploadAction()); .getUploadAction(), syncedFolder.getEnabled());
if (syncedFolder.getId() == UNPERSISTED_ID) { if (syncedFolder.getId() == UNPERSISTED_ID) {
// newly set up folder sync config // newly set up folder sync config
@ -366,6 +367,10 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
mSyncedFolderProvider.updateSyncFolder(item); mSyncedFolderProvider.updateSyncFolder(item);
} }
mSyncedFolderPreferencesDialogFragment = null; mSyncedFolderPreferencesDialogFragment = null;
if(dirty) {
mAdapter.setSyncFolderItem(syncedFolder.getSection(), item);
}
} }
@Override @Override
@ -383,6 +388,7 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
* @param chargingOnly upload on charging only * @param chargingOnly upload on charging only
* @param subfolderByDate created sub folders * @param subfolderByDate created sub folders
* @param uploadAction upload action * @param uploadAction upload action
* @param enabled is sync enabled
* @return the updated item * @return the updated item
*/ */
private SyncedFolderDisplayItem updateSyncedFolderItem(SyncedFolderDisplayItem item, private SyncedFolderDisplayItem updateSyncedFolderItem(SyncedFolderDisplayItem item,
@ -391,13 +397,15 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
Boolean wifiOnly, Boolean wifiOnly,
Boolean chargingOnly, Boolean chargingOnly,
Boolean subfolderByDate, Boolean subfolderByDate,
Integer uploadAction) { Integer uploadAction,
Boolean enabled) {
item.setLocalPath(localPath); item.setLocalPath(localPath);
item.setRemotePath(remotePath); item.setRemotePath(remotePath);
item.setWifiOnly(wifiOnly); item.setWifiOnly(wifiOnly);
item.setChargingOnly(chargingOnly); item.setChargingOnly(chargingOnly);
item.setSubfolderByDate(subfolderByDate); item.setSubfolderByDate(subfolderByDate);
item.setUploadAction(uploadAction); item.setUploadAction(uploadAction);
item.setEnabled(enabled);
return item; return item;
} }
} }

View file

@ -67,6 +67,11 @@ public class FolderSyncAdapter extends SectionedRecyclerViewAdapter<FolderSyncAd
notifyDataSetChanged(); notifyDataSetChanged();
} }
public void setSyncFolderItem(int location, SyncedFolderDisplayItem syncFolderItem) {
mSyncFolderItems.set(location, syncFolderItem);
notifyDataSetChanged();
}
@Override @Override
public int getSectionCount() { public int getSectionCount() {
return mSyncFolderItems.size(); return mSyncFolderItems.size();

View file

@ -33,6 +33,7 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.owncloud.android.R; import com.owncloud.android.R;
@ -53,6 +54,8 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
private CharSequence[] mUploadBehaviorItemStrings; private CharSequence[] mUploadBehaviorItemStrings;
protected View mView = null; protected View mView = null;
private boolean mEnabled;
private ImageView mEnabledIcon;
private CheckBox mUploadOnWifiCheckbox; private CheckBox mUploadOnWifiCheckbox;
private CheckBox mUploadOnChargingCheckbox; private CheckBox mUploadOnChargingCheckbox;
private CheckBox mUploadUseSubfoldersCheckbox; private CheckBox mUploadUseSubfoldersCheckbox;
@ -105,9 +108,6 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
mView = inflater.inflate(R.layout.folder_sync_settings_layout, container, false); mView = inflater.inflate(R.layout.folder_sync_settings_layout, container, false);
((TextView) mView.findViewById(R.id.local_folder_summary)).setText(mSyncedFolder.getLocalPath());
((TextView) mView.findViewById(R.id.remote_folder_summary)).setText(mSyncedFolder.getRemotePath());
setupDialogElements(mView); setupDialogElements(mView);
setupListeners(mView); setupListeners(mView);
@ -121,6 +121,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
*/ */
private void setupDialogElements(View view) { private void setupDialogElements(View view) {
// find/saves UI elements // find/saves UI elements
mEnabledIcon = (ImageView) view.findViewById(R.id.local_folder_status_icon);
mLocalFolderSummary = (TextView) view.findViewById(R.id.local_folder_summary); mLocalFolderSummary = (TextView) view.findViewById(R.id.local_folder_summary);
mRemoteFolderSummary = (TextView) view.findViewById(R.id.remote_folder_summary); mRemoteFolderSummary = (TextView) view.findViewById(R.id.remote_folder_summary);
@ -132,6 +133,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
mUploadBehaviorSummary = (TextView) view.findViewById(R.id.setting_instant_behaviour_summary); mUploadBehaviorSummary = (TextView) view.findViewById(R.id.setting_instant_behaviour_summary);
// Set values // Set values
setEnabled(mSyncedFolder.getEnabled());
mLocalFolderSummary.setText(mSyncedFolder.getLocalPath()); mLocalFolderSummary.setText(mSyncedFolder.getLocalPath());
mRemoteFolderSummary.setText(mSyncedFolder.getRemotePath()); mRemoteFolderSummary.setText(mSyncedFolder.getRemotePath());
@ -142,6 +144,20 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
mUploadBehaviorSummary.setText(mUploadBehaviorItemStrings[mSyncedFolder.getUploadAction()]); mUploadBehaviorSummary.setText(mUploadBehaviorItemStrings[mSyncedFolder.getUploadAction()]);
} }
/**
* set correct icon/flag.
*
* @param enabled if enabled or disabled
*/
private void setEnabled(boolean enabled) {
mSyncedFolder.setEnabled(enabled);
if(enabled) {
mEnabledIcon.setImageResource(R.drawable.ic_cloud_sync_on);
} else {
mEnabledIcon.setImageResource(R.drawable.ic_cloud_sync_off);
}
}
/** /**
* set (new) remote path on activity result of the folder picker activity. The result gets originally propagated * set (new) remote path on activity result of the folder picker activity. The result gets originally propagated
* to the underlying activity since the picker is an activity and the result can't get passed to the dialog * to the underlying activity since the picker is an activity and the result can't get passed to the dialog
@ -200,6 +216,13 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
} }
}); });
view.findViewById(R.id.local_folder_container).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setEnabled(!mSyncedFolder.getEnabled());
}
});
view.findViewById(R.id.setting_instant_behaviour_container).setOnClickListener( view.findViewById(R.id.setting_instant_behaviour_container).setOnClickListener(
new OnClickListener() { new OnClickListener() {
@Override @Override