30
30
import com .nutomic .syncthingandroid .databinding .FragmentFolderBinding ;
31
31
import com .nutomic .syncthingandroid .model .Device ;
32
32
import com .nutomic .syncthingandroid .model .Folder ;
33
+ import com .nutomic .syncthingandroid .model .FolderStatus ;
33
34
import com .nutomic .syncthingandroid .service .Constants ;
34
35
import com .nutomic .syncthingandroid .service .RestApi ;
35
36
import com .nutomic .syncthingandroid .service .SyncthingService ;
@@ -65,13 +66,16 @@ public class FolderActivity extends SyncthingActivity
65
66
"com.nutomic.syncthingandroid.activities.FolderActivity.FOLDER_ID" ;
66
67
public static final String EXTRA_FOLDER_LABEL =
67
68
"com.nutomic.syncthingandroid.activities.FolderActivity.FOLDER_LABEL" ;
69
+ public static final String EXTRA_FOLDER_OVERRIDABLE_CHANGES =
70
+ "com.nutomic.syncthingandroid.activities.FolderActivity.FOLDER_OVERRIDABLE_CHANGES" ;
68
71
public static final String EXTRA_DEVICE_ID =
69
72
"com.nutomic.syncthingandroid.activities.FolderActivity.DEVICE_ID" ;
70
73
71
74
private static final String TAG = "FolderActivity" ;
72
75
73
- private static final String IS_SHOWING_DELETE_DIALOG = "DELETE_FOLDER_DIALOG_STATE" ;
76
+ private static final String IS_SHOW_DELETE_DIALOG = "DELETE_FOLDER_DIALOG_STATE" ;
74
77
private static final String IS_SHOW_DISCARD_DIALOG = "DISCARD_FOLDER_DIALOG_STATE" ;
78
+ private static final String IS_SHOW_OVERRIDE_CHANGES_DIALOG = "OVERRIDE_REMOTES_DIALOG_STATE" ;
75
79
76
80
private static final int FILE_VERSIONING_DIALOG_REQUEST = 3454 ;
77
81
private static final int PULL_ORDER_DIALOG_REQUEST = 3455 ;
@@ -93,6 +97,7 @@ public class FolderActivity extends SyncthingActivity
93
97
94
98
private Dialog mDeleteDialog ;
95
99
private Dialog mDiscardDialog ;
100
+ private Dialog mOverrideChangesDialog ;
96
101
97
102
private Folder .Versioning mVersioning ;
98
103
@@ -148,6 +153,7 @@ public void onCreate(Bundle savedInstanceState) {
148
153
findViewById (R .id .pullOrderContainer ).setOnClickListener (v -> showPullOrderDialog ());
149
154
findViewById (R .id .versioningContainer ).setOnClickListener (v -> showVersioningDialog ());
150
155
binding .editIgnores .setOnClickListener (v -> editIgnores ());
156
+ binding .overrideChangesContainer .setOnClickListener (v -> showOverrideChangesDialog ());
151
157
152
158
if (mIsCreateMode ) {
153
159
if (savedInstanceState != null ) {
@@ -162,26 +168,40 @@ public void onCreate(Bundle savedInstanceState) {
162
168
// Open keyboard on label view in edit mode.
163
169
binding .label .requestFocus ();
164
170
binding .editIgnores .setEnabled (false );
171
+ setOverrideChangesContainerEnabled (false );
165
172
}
166
173
else {
167
174
// Prepare edit mode.
168
175
binding .id .clearFocus ();
169
176
binding .id .setFocusable (false );
170
177
binding .id .setEnabled (false );
171
178
binding .directoryTextView .setEnabled (false );
179
+
180
+ // overridable remotes button
181
+ setOverrideChangesContainerEnabled (
182
+ getIntent ().hasExtra (EXTRA_FOLDER_OVERRIDABLE_CHANGES )
183
+ && getIntent ().getBooleanExtra (EXTRA_FOLDER_OVERRIDABLE_CHANGES , false )
184
+ );
172
185
}
173
186
174
187
if (savedInstanceState != null ){
175
- if (savedInstanceState .getBoolean (IS_SHOWING_DELETE_DIALOG )){
188
+ if (savedInstanceState .getBoolean (IS_SHOW_DELETE_DIALOG )){
176
189
showDeleteDialog ();
177
190
}
178
191
}
179
192
180
193
if (savedInstanceState != null ){
181
- if (savedInstanceState .getBoolean (IS_SHOWING_DELETE_DIALOG )){
194
+ if (savedInstanceState .getBoolean (IS_SHOW_DELETE_DIALOG )){
182
195
showDeleteDialog ();
183
196
}
184
197
}
198
+
199
+ if (savedInstanceState != null ) {
200
+ if (savedInstanceState .getBoolean (IS_SHOW_OVERRIDE_CHANGES_DIALOG )){
201
+ showOverrideChangesDialog ();
202
+ }
203
+ }
204
+
185
205
}
186
206
187
207
/**
@@ -304,12 +324,18 @@ public void onPause() {
304
324
@ Override
305
325
protected void onSaveInstanceState (Bundle outState ) {
306
326
super .onSaveInstanceState (outState );
307
- outState .putBoolean (IS_SHOWING_DELETE_DIALOG , mDeleteDialog != null && mDeleteDialog .isShowing ());
327
+ outState .putBoolean (IS_SHOW_DELETE_DIALOG , mDeleteDialog != null && mDeleteDialog .isShowing ());
308
328
Util .dismissDialogSafe (mDeleteDialog , this );
309
329
330
+ outState .putBoolean (IS_SHOW_OVERRIDE_CHANGES_DIALOG , mOverrideChangesDialog != null && mOverrideChangesDialog .isShowing ());
331
+ Util .dismissDialogSafe (mOverrideChangesDialog , this );
332
+
310
333
if (mIsCreateMode ){
311
334
outState .putBoolean (IS_SHOW_DISCARD_DIALOG , mDiscardDialog != null && mDiscardDialog .isShowing ());
312
335
Util .dismissDialogSafe (mDiscardDialog , this );
336
+
337
+ outState .putBoolean (IS_SHOW_OVERRIDE_CHANGES_DIALOG , mOverrideChangesDialog != null && mOverrideChangesDialog .isShowing ());
338
+ Util .dismissDialogSafe (mOverrideChangesDialog , this );
313
339
}
314
340
}
315
341
@@ -778,4 +804,34 @@ private void setVersioningDescription(String type, String description) {
778
804
binding .versioningType .setText (type );
779
805
binding .versioningDescription .setText (description );
780
806
}
807
+
808
+ private void setOverrideChangesContainerEnabled (boolean state ) {
809
+ LinearLayout container = (LinearLayout ) findViewById (R .id .overrideChangesContainer );
810
+ binding .overrideChangesContainer .setEnabled (state );
811
+ for ( int i = 0 ; i < container .getChildCount (); i ++ ) {
812
+ container .getChildAt (i ).setEnabled (state );
813
+ }
814
+ }
815
+
816
+ private void showOverrideChangesDialog (){
817
+ mOverrideChangesDialog = createOverrideChangesDialog ();
818
+ mOverrideChangesDialog .show ();
819
+ }
820
+
821
+ private Dialog createOverrideChangesDialog (){
822
+ return Util .getAlertDialogBuilder (this )
823
+ .setIcon (R .drawable .outline_arrow_circle_up_24 )
824
+ .setTitle (R .string .override_changes )
825
+ .setMessage (R .string .override_changes_are_you_sure )
826
+ .setNegativeButton (android .R .string .cancel , null )
827
+ .setPositiveButton (android .R .string .yes , (dialogInterface , i ) -> {
828
+ RestApi restApi = getApi ();
829
+ if (restApi != null ) {
830
+ restApi .overrideChanges (mFolder .id );
831
+ mFolderNeedsToUpdate = true ;
832
+ }
833
+ finish ();
834
+ })
835
+ .create ();
836
+ }
781
837
}
0 commit comments