1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 00:01:19 +00:00

Add "Revert local changes" button to UI (fixes #437) (#439)

* Add icon: ic_cloud_download_red_24

* Update strings.xml

* Add "Revert local changes" button code (fixes #437)

* Update model: FolderStatus - add "receiveOnly*"

* item_folder_list: Add revert UI button

* Update icon: ic_cloud_download_red_24

* Update item_folder_list.xml

* Update icon for the override changes button

* Imported de translation
This commit is contained in:
Catfriend1 2019-07-11 15:03:48 +02:00 committed by GitHub
parent 35839feeb9
commit 388d68fac7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 99 additions and 16 deletions

View file

@ -15,6 +15,7 @@ public class PostRequest extends ApiRequest {
public static final String URI_DB_IGNORES = "/rest/db/ignores"; public static final String URI_DB_IGNORES = "/rest/db/ignores";
public static final String URI_DB_OVERRIDE = "/rest/db/override"; public static final String URI_DB_OVERRIDE = "/rest/db/override";
public static final String URI_DB_REVERT = "/rest/db/revert";
public static final String URI_SYSTEM_CONFIG = "/rest/system/config"; public static final String URI_SYSTEM_CONFIG = "/rest/system/config";
public static final String URI_SYSTEM_SHUTDOWN = "/rest/system/shutdown"; public static final String URI_SYSTEM_SHUTDOWN = "/rest/system/shutdown";

View file

@ -21,6 +21,12 @@ public class FolderStatus {
public long needFiles; public long needFiles;
public long needSymlinks; public long needSymlinks;
public long pullErrors; public long pullErrors;
public long receiveOnlyChangedBytes;
public long receiveOnlyChangedDeletes;
public long receiveOnlyChangedDirectories;
public long receiveOnlyChangedFiles;
public long receiveOnlyChangedSymlinks;
public long receiveOnlyTotalItems;
public long sequence; public long sequence;
public String state; public String state;
public String stateChanged; public String stateChanged;

View file

@ -382,6 +382,16 @@ public class RestApi {
ImmutableMap.of("folder", folderId), null, null); ImmutableMap.of("folder", folderId), null, null);
} }
/**
* Revert local folder changes. This is the same as hitting
* the "Revert local changes" button from the web UI.
*/
public void revertLocalChanges(String folderId) {
Log.d(TAG, "revertLocalChanges '" + folderId + "'");
new PostRequest(mContext, mUrl, PostRequest.URI_DB_REVERT, mApiKey,
ImmutableMap.of("folder", folderId), null, null);
}
/** /**
* Sends current config to Syncthing. * Sends current config to Syncthing.
* Will result in a "ConfigSaved" event. * Will result in a "ConfigSaved" event.

View file

@ -95,6 +95,13 @@ public class SyncthingService extends Service {
public static final String ACTION_OVERRIDE_CHANGES = public static final String ACTION_OVERRIDE_CHANGES =
"com.github.catfriend1.syncthingandroid.SyncthingService.OVERRIDE_CHANGES"; "com.github.catfriend1.syncthingandroid.SyncthingService.OVERRIDE_CHANGES";
/**
* Intent action to revert local folder changes.
*/
public static final String ACTION_REVERT_LOCAL_CHANGES =
"com.github.catfriend1.syncthingandroid.SyncthingService.REVERT_LOCAL_CHANGES";
/** /**
* Extra used together with ACTION_IGNORE_DEVICE, ACTION_IGNORE_FOLDER. * Extra used together with ACTION_IGNORE_DEVICE, ACTION_IGNORE_FOLDER.
*/ */
@ -349,6 +356,8 @@ public class SyncthingService extends Service {
mNotificationHandler.cancelConsentNotification(intent.getIntExtra(EXTRA_NOTIFICATION_ID, 0)); mNotificationHandler.cancelConsentNotification(intent.getIntExtra(EXTRA_NOTIFICATION_ID, 0));
} else if (ACTION_OVERRIDE_CHANGES.equals(intent.getAction()) && mCurrentState == State.ACTIVE) { } else if (ACTION_OVERRIDE_CHANGES.equals(intent.getAction()) && mCurrentState == State.ACTIVE) {
mRestApi.overrideChanges(intent.getStringExtra(EXTRA_FOLDER_ID)); mRestApi.overrideChanges(intent.getStringExtra(EXTRA_FOLDER_ID));
} else if (ACTION_REVERT_LOCAL_CHANGES.equals(intent.getAction()) && mCurrentState == State.ACTIVE) {
mRestApi.revertLocalChanges(intent.getStringExtra(EXTRA_FOLDER_ID));
} }
return START_STICKY; return START_STICKY;
} }

View file

@ -55,6 +55,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
binding.label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label); binding.label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label);
binding.directory.setText(folder.path); binding.directory.setText(folder.path);
binding.override.setOnClickListener(view -> { onClickOverride(view, folder); } ); binding.override.setOnClickListener(view -> { onClickOverride(view, folder); } );
binding.revert.setOnClickListener(view -> { onClickRevert(view, folder); } );
binding.openFolder.setOnClickListener(view -> { FileUtils.openFolder(mContext, folder.path); } ); binding.openFolder.setOnClickListener(view -> { FileUtils.openFolder(mContext, folder.path); } );
// Update folder icon. // Update folder icon.
@ -79,6 +80,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
if (folderStatus == null) { if (folderStatus == null) {
binding.items.setVisibility(GONE); binding.items.setVisibility(GONE);
binding.override.setVisibility(GONE); binding.override.setVisibility(GONE);
binding.revert.setVisibility(GONE);
binding.size.setVisibility(GONE); binding.size.setVisibility(GONE);
binding.state.setVisibility(GONE); binding.state.setVisibility(GONE);
setTextOrHide(binding.invalid, folder.invalid); setTextOrHide(binding.invalid, folder.invalid);
@ -89,6 +91,10 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
boolean outOfSync = folderStatus.state.equals("idle") && neededItems > 0; boolean outOfSync = folderStatus.state.equals("idle") && neededItems > 0;
boolean overrideButtonVisible = folder.type.equals(Constants.FOLDER_TYPE_SEND_ONLY) && outOfSync; boolean overrideButtonVisible = folder.type.equals(Constants.FOLDER_TYPE_SEND_ONLY) && outOfSync;
binding.override.setVisibility(overrideButtonVisible ? VISIBLE : GONE); binding.override.setVisibility(overrideButtonVisible ? VISIBLE : GONE);
boolean revertButtonVisible = folder.type.equals(Constants.FOLDER_TYPE_RECEIVE_ONLY) && (folderStatus.receiveOnlyTotalItems > 0);
binding.revert.setVisibility(revertButtonVisible ? VISIBLE : GONE);
binding.state.setVisibility(VISIBLE); binding.state.setVisibility(VISIBLE);
if (outOfSync) { if (outOfSync) {
binding.state.setText(mContext.getString(R.string.status_outofsync)); binding.state.setText(mContext.getString(R.string.status_outofsync));
@ -204,4 +210,19 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
confirmDialog.show(); confirmDialog.show();
} }
private void onClickRevert(View view, Folder folder) {
AlertDialog.Builder confirmDialog = new AlertDialog.Builder(mContext)
.setTitle(R.string.revert_local_changes)
.setMessage(R.string.revert_local_changes_question)
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
// Send "Revert local changes" through our service to the REST API.
Intent intent = new Intent(mContext, SyncthingService.class)
.putExtra(SyncthingService.EXTRA_FOLDER_ID, folder.id);
intent.setAction(SyncthingService.ACTION_REVERT_LOCAL_CHANGES);
mContext.startService(intent);
})
.setNegativeButton(android.R.string.no, (dialogInterface, i) -> {});
confirmDialog.show();
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 689 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 882 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View file

@ -44,26 +44,49 @@
android:ellipsize="end" android:ellipsize="end"
android:textAppearance="?textAppearanceListItemSecondary" /> android:textAppearance="?textAppearanceListItemSecondary" />
<RelativeLayout
android:id="@+id/override_revert_container"
android:layout_below="@id/directory"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<Button <Button
android:id="@+id/override" android:id="@+id/override"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/directory"
android:contentDescription="@string/override_changes" android:contentDescription="@string/override_changes"
android:paddingEnd="20dp" android:paddingEnd="20dp"
android:paddingLeft="20dp" android:paddingLeft="20dp"
android:paddingRight="20dp" android:paddingRight="20dp"
android:paddingStart="20dp" android:paddingStart="20dp"
android:text="@string/override_changes" android:text="@string/override_changes"
android:drawableLeft="@android:drawable/ic_menu_upload" android:drawableLeft="@drawable/ic_cloud_upload_red_24"
android:drawableStart="@android:drawable/ic_menu_upload" android:drawableStart="@drawable/ic_cloud_upload_red_24"
android:drawablePadding="5sp"
android:textSize="12sp" /> android:textSize="12sp" />
<Button
android:id="@+id/revert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/revert_local_changes"
android:paddingEnd="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingStart="20dp"
android:text="@string/revert_local_changes"
android:drawableLeft="@drawable/ic_cloud_download_red_24"
android:drawableStart="@drawable/ic_cloud_download_red_24"
android:drawablePadding="5sp"
android:textSize="12sp" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/items" android:id="@+id/items"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/override" android:layout_below="@id/override_revert_container"
android:textAppearance="?textAppearanceListItemSecondary" /> android:textAppearance="?textAppearanceListItemSecondary" />
<TextView <TextView

View file

@ -124,6 +124,14 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="override_changes">Änderungen überschreiben</string> <string name="override_changes">Änderungen überschreiben</string>
<!-- Override Changes Confirmation Dialog -->
<string name="override_changes_question">Dadurch werden alle Änderungen rückgängig gemacht, die in diesem Ordner auf anderen Geräten vorgenommen wurden. Fortfahren?</string>
<string name="revert_local_changes">Lokale Änderungen zurücksetzen</string>
<!-- Revert Local Changes Confirmation Dialog -->
<string name="revert_local_changes_question">Dadurch werden alle in diesem Ordner auf diesem Gerät vorgenommenen Änderungen rückgängig gemacht. Fortfahren?</string>
<string name="open_file_manager">Dateimanager öffnen</string> <string name="open_file_manager">Dateimanager öffnen</string>
<string name="open_file_with">Öffne Datei mit</string> <string name="open_file_with">Öffne Datei mit</string>
<string name="open_file_no_compatible_app">Keine App zum Öffnen der Datei gefunden.</string> <string name="open_file_no_compatible_app">Keine App zum Öffnen der Datei gefunden.</string>
@ -865,7 +873,7 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
</string-array> </string-array>
<!-- Possible folder states --> <!-- Possible folder states -->
<string name="state_idle">Untätig</string> <string name="state_idle">Aktuell</string>
<string name="state_scanning">Scannen</string> <string name="state_scanning">Scannen</string>
<string name="state_scan_waiting">Warte auf Scan</string> <string name="state_scan_waiting">Warte auf Scan</string>
<string name="state_syncing_general">Synchronisiere</string> <string name="state_syncing_general">Synchronisiere</string>

View file

@ -130,6 +130,11 @@ Please report any problems you encounter via Github.</string>
<!-- Override Changes Confirmation Dialog --> <!-- Override Changes Confirmation Dialog -->
<string name="override_changes_question">This will undo all changes made on the other devices sharing this folder. Proceed?</string> <string name="override_changes_question">This will undo all changes made on the other devices sharing this folder. Proceed?</string>
<string name="revert_local_changes">Revert local changes</string>
<!-- Revert Local Changes Confirmation Dialog -->
<string name="revert_local_changes_question">This will undo all changes made on this device within that folder. Proceed?</string>
<string name="open_file_manager">Open file manager</string> <string name="open_file_manager">Open file manager</string>
<string name="open_file_with">Open file with</string> <string name="open_file_with">Open file with</string>
<string name="open_file_no_compatible_app">No app found to open the file.</string> <string name="open_file_no_compatible_app">No app found to open the file.</string>