Skip to content

Commit

Permalink
Fix #1260
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Danic <mario@lovelyhq.com>
  • Loading branch information
mario authored and tobiasKaminsky committed Apr 10, 2018
1 parent 15c8296 commit dad3d2b
Showing 1 changed file with 61 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@
*/
public class SyncedFolderPreferencesDialogFragment extends DialogFragment {

private final static String TAG = SyncedFolderPreferencesDialogFragment.class.getSimpleName();
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;

private final static String TAG = SyncedFolderPreferencesDialogFragment.class.getSimpleName();
private static final String BEHAVIOUR_DIALOG_STATE = "BEHAVIOUR_DIALOG_STATE";
protected View mView = null;
private CharSequence[] mUploadBehaviorItemStrings;
private SwitchCompat mEnabledSwitch;
private AppCompatCheckBox mUploadOnWifiCheckbox;
private AppCompatCheckBox mUploadOnChargingCheckbox;
Expand Down Expand Up @@ -163,7 +161,7 @@ private void setupDialogElements(View view) {
}

// find/saves UI elements
mEnabledSwitch = (SwitchCompat) view.findViewById(R.id.sync_enabled);
mEnabledSwitch = view.findViewById(R.id.sync_enabled);
ThemeUtils.tintSwitch(mEnabledSwitch, accentColor);

mLocalFolderPath = (TextView) view.findViewById(R.id.synced_folders_settings_local_folder_path);
Expand Down Expand Up @@ -235,6 +233,8 @@ private void setupDialogElements(View view) {
private void setEnabled(boolean enabled) {
mSyncedFolder.setEnabled(enabled);
mEnabledSwitch.setChecked(enabled);

setupViews(mView, enabled);
}

/**
Expand Down Expand Up @@ -278,6 +278,34 @@ private void checkAndUpdateSaveButtonState() {
}
}

private void setupViews(View view, boolean enable) {
float alpha;
if (enable) {
alpha = 1.0f;
} else {
alpha = 0.7f;
}
view.findViewById(R.id.setting_instant_upload_on_wifi_container).setEnabled(enable);
view.findViewById(R.id.setting_instant_upload_on_wifi_container).setAlpha(alpha);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
view.findViewById(R.id.setting_instant_upload_on_charging_container).setEnabled(enable);
view.findViewById(R.id.setting_instant_upload_on_charging_container).setAlpha(alpha);
}

view.findViewById(R.id.setting_instant_upload_path_use_subfolders_container).setEnabled(enable);
view.findViewById(R.id.setting_instant_upload_path_use_subfolders_container).setAlpha(alpha);

view.findViewById(R.id.remote_folder_container).setEnabled(enable);
view.findViewById(R.id.remote_folder_container).setAlpha(alpha);

view.findViewById(R.id.local_folder_container).setEnabled(enable);
view.findViewById(R.id.local_folder_container).setAlpha(alpha);

view.findViewById(R.id.setting_instant_behaviour_container).setEnabled(enable);
view.findViewById(R.id.setting_instant_behaviour_container).setAlpha(alpha);
}

/**
* setup all listeners.
*
Expand Down Expand Up @@ -403,6 +431,33 @@ public void onDestroyView() {
super.onDestroyView();
}

@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(BEHAVIOUR_DIALOG_STATE, behaviourDialogShown);

super.onSaveInstanceState(outState);
}

@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
behaviourDialogShown = savedInstanceState != null &&
savedInstanceState.getBoolean(BEHAVIOUR_DIALOG_STATE, false);

if (behaviourDialogShown) {
showBehaviourDialog();
}

super.onViewStateRestored(savedInstanceState);
}

public interface OnSyncedFolderPreferenceListener {
void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder);

void onCancelSyncedFolderPreference();

void onDeleteSyncedFolderPreference(SyncedFolderParcelable syncedFolder);
}

private class OnSyncedFolderSaveClickListener implements OnClickListener {
@Override
public void onClick(View v) {
Expand All @@ -426,31 +481,4 @@ public void onClick(View v) {
((OnSyncedFolderPreferenceListener) getActivity()).onDeleteSyncedFolderPreference(mSyncedFolder);
}
}

public interface OnSyncedFolderPreferenceListener {
void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder);

void onCancelSyncedFolderPreference();

void onDeleteSyncedFolderPreference(SyncedFolderParcelable syncedFolder);
}

@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(BEHAVIOUR_DIALOG_STATE, behaviourDialogShown);

super.onSaveInstanceState(outState);
}

@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
behaviourDialogShown = savedInstanceState != null &&
savedInstanceState.getBoolean(BEHAVIOUR_DIALOG_STATE, false);

if (behaviourDialogShown) {
showBehaviourDialog();
}

super.onViewStateRestored(savedInstanceState);
}
}

0 comments on commit dad3d2b

Please sign in to comment.