-
Notifications
You must be signed in to change notification settings - Fork 423
Greatly improve "Override Changes" button and UX (fixes #1769) #2063
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import com.nutomic.syncthingandroid.databinding.FragmentFolderBinding; | ||
import com.nutomic.syncthingandroid.model.Device; | ||
import com.nutomic.syncthingandroid.model.Folder; | ||
import com.nutomic.syncthingandroid.model.FolderStatus; | ||
import com.nutomic.syncthingandroid.service.Constants; | ||
import com.nutomic.syncthingandroid.service.RestApi; | ||
import com.nutomic.syncthingandroid.service.SyncthingService; | ||
|
@@ -65,13 +66,16 @@ public class FolderActivity extends SyncthingActivity | |
"com.nutomic.syncthingandroid.activities.FolderActivity.FOLDER_ID"; | ||
public static final String EXTRA_FOLDER_LABEL = | ||
"com.nutomic.syncthingandroid.activities.FolderActivity.FOLDER_LABEL"; | ||
public static final String EXTRA_FOLDER_OVERRIDABLE_CHANGES = | ||
"com.nutomic.syncthingandroid.activities.FolderActivity.FOLDER_OVERRIDABLE_CHANGES"; | ||
public static final String EXTRA_DEVICE_ID = | ||
"com.nutomic.syncthingandroid.activities.FolderActivity.DEVICE_ID"; | ||
|
||
private static final String TAG = "FolderActivity"; | ||
|
||
private static final String IS_SHOWING_DELETE_DIALOG = "DELETE_FOLDER_DIALOG_STATE"; | ||
private static final String IS_SHOW_DELETE_DIALOG = "DELETE_FOLDER_DIALOG_STATE"; | ||
private static final String IS_SHOW_DISCARD_DIALOG = "DISCARD_FOLDER_DIALOG_STATE"; | ||
private static final String IS_SHOW_OVERRIDE_CHANGES_DIALOG = "OVERRIDE_REMOTES_DIALOG_STATE"; | ||
|
||
private static final int FILE_VERSIONING_DIALOG_REQUEST = 3454; | ||
private static final int PULL_ORDER_DIALOG_REQUEST = 3455; | ||
|
@@ -93,6 +97,7 @@ public class FolderActivity extends SyncthingActivity | |
|
||
private Dialog mDeleteDialog; | ||
private Dialog mDiscardDialog; | ||
private Dialog mOverrideChangesDialog; | ||
|
||
private Folder.Versioning mVersioning; | ||
|
||
|
@@ -148,6 +153,7 @@ public void onCreate(Bundle savedInstanceState) { | |
findViewById(R.id.pullOrderContainer).setOnClickListener(v -> showPullOrderDialog()); | ||
findViewById(R.id.versioningContainer).setOnClickListener(v -> showVersioningDialog()); | ||
binding.editIgnores.setOnClickListener(v -> editIgnores()); | ||
binding.overrideChangesContainer.setOnClickListener(v -> showOverrideChangesDialog()); | ||
|
||
if (mIsCreateMode) { | ||
if (savedInstanceState != null) { | ||
|
@@ -162,26 +168,39 @@ public void onCreate(Bundle savedInstanceState) { | |
// Open keyboard on label view in edit mode. | ||
binding.label.requestFocus(); | ||
binding.editIgnores.setEnabled(false); | ||
setOverrideChangesContainerEnabled(false); | ||
} | ||
else { | ||
// Prepare edit mode. | ||
binding.id.clearFocus(); | ||
binding.id.setFocusable(false); | ||
binding.id.setEnabled(false); | ||
binding.directoryTextView.setEnabled(false); | ||
|
||
// overridable remotes button | ||
setOverrideChangesContainerEnabled( | ||
getIntent().getBooleanExtra(EXTRA_FOLDER_OVERRIDABLE_CHANGES, false) | ||
); | ||
} | ||
|
||
if (savedInstanceState != null){ | ||
if (savedInstanceState.getBoolean(IS_SHOWING_DELETE_DIALOG)){ | ||
if (savedInstanceState.getBoolean(IS_SHOW_DELETE_DIALOG)){ | ||
showDeleteDialog(); | ||
} | ||
} | ||
|
||
if (savedInstanceState != null){ | ||
if (savedInstanceState.getBoolean(IS_SHOWING_DELETE_DIALOG)){ | ||
if (savedInstanceState.getBoolean(IS_SHOW_DELETE_DIALOG)){ | ||
showDeleteDialog(); | ||
} | ||
} | ||
|
||
if (savedInstanceState != null) { | ||
if (savedInstanceState.getBoolean(IS_SHOW_OVERRIDE_CHANGES_DIALOG)){ | ||
showOverrideChangesDialog(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
@@ -304,12 +323,18 @@ public void onPause() { | |
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
outState.putBoolean(IS_SHOWING_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing()); | ||
outState.putBoolean(IS_SHOW_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing()); | ||
Util.dismissDialogSafe(mDeleteDialog, this); | ||
|
||
outState.putBoolean(IS_SHOW_OVERRIDE_CHANGES_DIALOG, mOverrideChangesDialog != null && mOverrideChangesDialog.isShowing()); | ||
Util.dismissDialogSafe(mOverrideChangesDialog, this); | ||
|
||
if (mIsCreateMode){ | ||
outState.putBoolean(IS_SHOW_DISCARD_DIALOG, mDiscardDialog != null && mDiscardDialog.isShowing()); | ||
Util.dismissDialogSafe(mDiscardDialog, this); | ||
|
||
outState.putBoolean(IS_SHOW_OVERRIDE_CHANGES_DIALOG, mOverrideChangesDialog != null && mOverrideChangesDialog.isShowing()); | ||
Util.dismissDialogSafe(mOverrideChangesDialog, this); | ||
Comment on lines
+335
to
+337
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed again within this condition? As far as I see it's the exact same function call that already happens uncoditionally before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, was simply following the existing code... will remove, again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case you forgot, as you already removed the code in the other case: It's not removed yet here. |
||
} | ||
} | ||
|
||
|
@@ -778,4 +803,33 @@ private void setVersioningDescription(String type, String description) { | |
binding.versioningType.setText(type); | ||
binding.versioningDescription.setText(description); | ||
} | ||
|
||
private void setOverrideChangesContainerEnabled(boolean state) { | ||
binding.overrideChangesContainer.setEnabled(state); | ||
for ( int i = 0; i < binding.overrideChangesContainer.getChildCount(); i++ ) { | ||
binding.overrideChangesContainer.getChildAt(i).setEnabled(state); | ||
} | ||
} | ||
|
||
private void showOverrideChangesDialog(){ | ||
mOverrideChangesDialog = createOverrideChangesDialog(); | ||
mOverrideChangesDialog.show(); | ||
} | ||
|
||
private Dialog createOverrideChangesDialog(){ | ||
return Util.getAlertDialogBuilder(this) | ||
.setIcon(R.drawable.outline_arrow_circle_up_24) | ||
.setTitle(R.string.override_changes) | ||
.setMessage(R.string.override_changes_are_you_sure) | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> { | ||
RestApi restApi = getApi(); | ||
if (restApi != null) { | ||
restApi.overrideChanges(mFolder.id); | ||
mFolderNeedsToUpdate = true; | ||
} | ||
finish(); | ||
}) | ||
.create(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,12 @@ public class FolderStatus { | |
public long version; | ||
public String error; | ||
public String watchError; | ||
|
||
public boolean isNeedsItems() { | ||
return needFiles + needDirectories + needSymlinks + needDeletes > 0; | ||
} | ||
|
||
public boolean isOutOfSync() { | ||
return state.equals("idle") && isNeedsItems(); | ||
} | ||
Comment on lines
+31
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given you aren't using |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8s8,3.59 8,8S16.41,20 12,20M12,22c5.52,0 10,-4.48 10,-10c0,-5.52 -4.48,-10 -10,-10C6.48,2 2,6.48 2,12C2,17.52 6.48,22 12,22L12,22zM11,12l0,4h2l0,-4h3l-4,-4l-4,4H11z"/> | ||
</vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entirely optional, just suggesting it as you are renaming the constant which is also a somewhat unrelated cleanup: You could delete one of the two redundant blobs of code.